1 /* 2 * Copyright (c) 2021 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_XCOMPONENT_RESOURCE_TEXTURE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_XCOMPONENT_RESOURCE_TEXTURE_H 18 19 #include "core/common/platform_res_register.h" 20 #include "core/components/xcomponent/resource/xcomponent_resource.h" 21 22 namespace OHOS::Ace { 23 class ACE_EXPORT NativeTexture : public XComponentResource { 24 DECLARE_ACE_TYPE(NativeTexture, XComponentResource); 25 public: 26 using RefreshListener = std::function<void()>; 27 NativeTexture(const WeakPtr<PipelineContext> & context,ErrorCallback && onError)28 NativeTexture(const WeakPtr<PipelineContext>& context, ErrorCallback&& onError) 29 : XComponentResource("texture", context, std::move(onError)) {} 30 ~NativeTexture() override; 31 32 void Create(const std::function<void(int64_t)>& onCreate, const std::string& idStr); 33 void CreateTexture(const std::function<void(int64_t)>& onCreate, const std::string& idStr); 34 void SetSize(int64_t textureId, int32_t textureWidth, int32_t textureHeight, 35 const std::function<void(std::string&)>& callback = nullptr); 36 SetRefreshListener(RefreshListener && listener)37 void SetRefreshListener(RefreshListener&& listener) 38 { 39 onRefreshListener_ = std::move(listener); 40 } 41 private: 42 void OnRefresh(const std::string& param); 43 RefreshListener onRefreshListener_; 44 }; 45 } // namespace OHOS::Ace 46 47 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_XCOMPONENT_RESOURCE_TEXTURE_H 48