1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_RESOURCE_EXT_TEXTURE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_RESOURCE_EXT_TEXTURE_H 18 19 #include "core/common/platform_res_register.h" 20 #include "core/components/video/resource/resource.h" 21 #include "core/pipeline/pipeline_base.h" 22 23 namespace OHOS::Ace { 24 class ACE_EXPORT ExtTexture : public Resource { 25 DECLARE_ACE_TYPE(ExtTexture, Resource); 26 public: ExtTexture(const WeakPtr<PipelineBase> & context,ErrorCallback && onError)27 ExtTexture(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError) 28 : Resource("texture", context, std::move(onError)) {} 29 ~ExtTexture() override; 30 31 void Create(const std::function<void(int64_t)>& onCreate); 32 void CreateTexture(const std::function<void(int64_t)>& onCreate); 33 void SetSize(int64_t textureId, int32_t textureWidth, int32_t textureHeight); SetTextureFreshCallback(std::function<void (int32_t,int64_t)> && callback)34 void SetTextureFreshCallback(std::function<void(int32_t, int64_t)>&& callback) 35 { 36 onTextureRefresh_ = std::move(callback); 37 } SetCreateCallback(std::function<void ()> && callback)38 void SetCreateCallback(std::function<void()>&& callback) 39 { 40 onSurfaceCreated_ = std::move(callback); 41 } SetSurfaceChanged(std::function<void (int32_t,int32_t)> && callback)42 void SetSurfaceChanged(std::function<void(int32_t, int32_t)>&& callback) 43 { 44 onSurfaceChanged_ = std::move(callback); 45 } 46 47 void AttachToGLContext(int64_t textureId, bool isAttach); 48 49 void UpdateTextureImage(std::vector<float>& matrix); 50 51 private: 52 void OnRefresh(const std::string& param); 53 void OnSurfaceCreated(); 54 void OnSurfaceChanged(int32_t width, int32_t height); 55 56 int64_t textureId_ = INVALID_ID; 57 int64_t instanceId_ = INVALID_ID; 58 59 std::function<void(int32_t, int64_t)> onTextureRefresh_; 60 std::function<void()> onSurfaceCreated_; 61 std::function<void(int32_t, int32_t)> onSurfaceChanged_; 62 }; 63 } // namespace OHOS::Ace 64 65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_RESOURCE_EXT_TEXTURE_H