1 /* 2 * Copyright (c) 2023-2024 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_NG_PATTERNS_XCOMPONENT_INNER_XCOMPONENT_CONTROLLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_INNER_XCOMPONENT_CONTROLLER_H 18 19 #include <functional> 20 #include <string> 21 #include <optional> 22 23 #include "interfaces/inner_api/xcomponent_controller/xcomponent_controller.h" 24 25 #ifndef ACE_UNITTEST 26 namespace OHOS::Rosen::Drawing { 27 class Canvas; 28 } 29 using RSCanvas = OHOS::Rosen::Drawing::Canvas; 30 #else 31 namespace OHOS::Ace::Testing { 32 class TestingCanvas; 33 } 34 using RSCanvas = OHOS::Ace::Testing::TestingCanvas; 35 #endif 36 37 namespace OHOS::Ace { 38 enum class ImageAnalyzerState; 39 using OnAnalyzedCallback = std::optional<std::function<void(ImageAnalyzerState)>>; 40 class InnerXComponentController : public OHOS::Ace::XComponentController { 41 public: 42 InnerXComponentController() = default; 43 ~InnerXComponentController() override = default; 44 45 using ConfigSurfaceImpl = std::function<void(uint32_t, uint32_t)>; 46 GetSurfaceId()47 std::string GetSurfaceId() 48 { 49 return surfaceId_; 50 } 51 SetSurfaceId(const std::string & surfaceId)52 void SetSurfaceId(const std::string& surfaceId) 53 { 54 surfaceId_ = surfaceId; 55 } 56 ConfigSurface(uint32_t surfaceWidth,uint32_t surfaceHeight)57 void ConfigSurface(uint32_t surfaceWidth, uint32_t surfaceHeight) 58 { 59 if (configSurfaceImpl_) { 60 configSurfaceImpl_(surfaceWidth, surfaceHeight); 61 } 62 } 63 SetConfigSurfaceImpl(ConfigSurfaceImpl && ConfigSurfaceImpl)64 void SetConfigSurfaceImpl(ConfigSurfaceImpl&& ConfigSurfaceImpl) 65 { 66 configSurfaceImpl_ = std::move(ConfigSurfaceImpl); 67 } 68 GetSurfaceOffset(float & offsetX,float & offsetY)69 virtual void GetSurfaceOffset(float& offsetX, float& offsetY) {} GetSurfaceSize(float & surfaceWidth,float & surfaceHeight)70 virtual void GetSurfaceSize(float& surfaceWidth, float& surfaceHeight) {} 71 SetIdealSurfaceWidth(float surfaceWidth)72 virtual void SetIdealSurfaceWidth(float surfaceWidth) {} SetIdealSurfaceHeight(float surfaceHeight)73 virtual void SetIdealSurfaceHeight(float surfaceHeight) {} SetIdealSurfaceOffsetX(float offsetX)74 virtual void SetIdealSurfaceOffsetX(float offsetX) {} SetIdealSurfaceOffsetY(float offsetY)75 virtual void SetIdealSurfaceOffsetY(float offsetY) {} ClearIdealSurfaceOffset(bool isXAxis)76 virtual void ClearIdealSurfaceOffset(bool isXAxis) {} UpdateSurfaceBounds()77 virtual void UpdateSurfaceBounds() {} StartImageAnalyzer(void * config,OnAnalyzedCallback & onAnalyzed)78 virtual void StartImageAnalyzer(void* config, OnAnalyzedCallback& onAnalyzed) {} StopImageAnalyzer()79 virtual void StopImageAnalyzer() {} SetSurfaceRotation(bool isLock)80 virtual void SetSurfaceRotation(bool isLock) {} GetSurfaceRotation()81 virtual bool GetSurfaceRotation() 82 { 83 return false; 84 } LockCanvas()85 virtual RSCanvas* LockCanvas() 86 { 87 return nullptr; 88 } UnlockCanvasAndPost(RSCanvas * canvas)89 virtual void UnlockCanvasAndPost(RSCanvas* canvas) {} 90 91 private: 92 ConfigSurfaceImpl configSurfaceImpl_; 93 std::string surfaceId_; 94 }; 95 } // namespace OHOS::Ace 96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_INNER_XCOMPONENT_CONTROLLER_H 97