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_SURFACE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_RESOURCE_EXT_SURFACE_H 18 19 #include <functional> 20 #include <utility> 21 #include "core/common/platform_res_register.h" 22 #include "core/components/video/resource/resource.h" 23 #include "core/pipeline/pipeline_base.h" 24 25 namespace OHOS::Ace { 26 27 class ACE_EXPORT ExtSurface : public Resource { 28 DECLARE_ACE_TYPE(ExtSurface, Resource); 29 public: 30 ExtSurface(const WeakPtr<PipelineBase> & context,ErrorCallback && onError)31 ExtSurface(const WeakPtr<PipelineBase>& context, ErrorCallback&& onError) 32 : Resource("surface", context, std::move(onError)) {} 33 ~ExtSurface() override; 34 35 void Create(const std::function<void(int64_t)>& onCreate); 36 void CreateExtSurface(const std::function<void(int64_t)>& onCreate); 37 void SetBounds(int64_t surfaceId, int32_t left, int32_t top, int32_t width, int32_t height); 38 void SetIsFullScreen(bool isFullScreen); SetCreateCallback(std::function<void ()> && callback)39 void SetCreateCallback(std::function<void()>&& callback) 40 { 41 onSurfaceCreated_ = std::move(callback); 42 } SetSurfaceChanged(std::function<void (int32_t,int32_t)> && callback)43 void SetSurfaceChanged(std::function<void(int32_t, int32_t)>&& callback) 44 { 45 onSurfaceChanged_ = std::move(callback); 46 } 47 SetSurfaceDestroyed(std::function<void ()> && callback)48 void SetSurfaceDestroyed(std::function<void()>&& callback) 49 { 50 onSurfaceDestroyed_ = std::move(callback); 51 } 52 53 void* AttachNativeWindow(); 54 55 private: 56 void OnSurfaceCreated(); 57 void OnSurfaceChanged(int32_t width, int32_t height); 58 void OnSurfaceDestroyed(); 59 60 std::function<void()> onSurfaceCreated_; 61 std::function<void(int32_t, int32_t)> onSurfaceChanged_; 62 std::function<void()> onSurfaceDestroyed_; 63 }; 64 65 } // namespace OHOS::Ace 66 67 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_RESOURCE_EXT_SURFACE_H 68