1 /*
2  * Copyright (c) 2022-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_PAINTS_RENDER_SURFACE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_RENDER_SURFACE_H
18 
19 #include <cstdint>
20 #include <stdint.h>
21 
22 #include "base/geometry/axis.h"
23 #include "base/memory/ace_type.h"
24 #include "base/utils/noncopyable.h"
25 #include "core/components_ng/render/ext_surface_callback_interface.h"
26 #include "core/components_ng/render/render_context.h"
27 
28 namespace OHOS::Ace::NG {
29 // RenderSurface is used for SurfaceNode
30 class ACE_FORCE_EXPORT RenderSurface : public virtual AceType {
31     DECLARE_ACE_TYPE(NG::RenderSurface, AceType)
32 
33 public:
34     RenderSurface() = default;
35     ~RenderSurface() override = default;
36 
37 // under the condition of supporting cross platform and texture rendering,
38 // it is necessary to dynamically set the rendering type of the surface node.
39 // the defalut type is RenderSurfaceType::TEXTURE.
40 #ifdef RENDER_EXTRACT_SUPPORTED
41     enum class RenderSurfaceType {
42         UNKNOWN = -1,
43         SURFACE = 0,
44         TEXTURE
45     };
46     static RefPtr<RenderSurface> Create(const RenderSurfaceType& type = RenderSurfaceType::TEXTURE);
47 #else
48 // under the condition of supporting ohos platform
49     static RefPtr<RenderSurface> Create();
50 #endif
51 
InitSurface()52     virtual void InitSurface() {}
53 
UpdateSurfaceConfig()54     virtual void UpdateSurfaceConfig() {}
55 
GetNativeWindow()56     virtual void* GetNativeWindow()
57     {
58         return nullptr;
59     }
60 
SetRenderContext(const RefPtr<RenderContext> & renderContext)61     virtual void SetRenderContext(const RefPtr<RenderContext>& renderContext) {};
62 
ConfigSurface(uint32_t surfaceWidth,uint32_t surfaceHeight)63     virtual void ConfigSurface(uint32_t surfaceWidth, uint32_t surfaceHeight) {};
64 
IsSurfaceValid()65     virtual bool IsSurfaceValid() const
66     {
67         return false;
68     }
69 
CreateNativeWindow()70     virtual void CreateNativeWindow() {};
71 
AdjustNativeWindowSize(uint32_t width,uint32_t height)72     virtual void AdjustNativeWindowSize(uint32_t width, uint32_t height) {}
73 
GetUniqueId()74     virtual std::string GetUniqueId() const
75     {
76         return "";
77     }
78 
UpdateSurfaceSizeInUserData(uint32_t width,uint32_t height)79     virtual void UpdateSurfaceSizeInUserData(uint32_t width, uint32_t height) {}
80 
SetExtSurfaceBounds(int32_t left,int32_t top,int32_t width,int32_t height)81     virtual void SetExtSurfaceBounds(int32_t left, int32_t top, int32_t width, int32_t height) {}
82 
SetExtSurfaceBoundsSync(int32_t left,int32_t top,int32_t width,int32_t height)83     virtual bool SetExtSurfaceBoundsSync(int32_t left, int32_t top, int32_t width, int32_t height)
84     {
85         return true;
86     }
87 
SetExtSurfaceCallback(const RefPtr<ExtSurfaceCallbackInterface> & extSurfaceCallback)88     virtual void SetExtSurfaceCallback(const RefPtr<ExtSurfaceCallbackInterface>& extSurfaceCallback) {}
89 
SetTransformHint(uint32_t rotation)90     virtual void SetTransformHint(uint32_t rotation) {}
91 
DumpInfo()92     virtual void DumpInfo() {}
93 
SetIsTexture(bool isTexture)94     virtual void SetIsTexture(bool isTexture) {}
95 
SetIsFullScreen(bool isFullScreen)96     virtual void SetIsFullScreen(bool isFullScreen) {}
97 
SetInstanceId(int32_t instanceId)98     virtual void SetInstanceId(int32_t instanceId) {}
99 
SetSurfaceDefaultSize(int32_t width,int32_t height)100     virtual void SetSurfaceDefaultSize(int32_t width, int32_t height) {}
101 
IsTexture()102     virtual bool IsTexture()
103     {
104         return false;
105     }
106 
AttachToGLContext(int64_t textureId,bool isAttach)107     virtual void AttachToGLContext(int64_t textureId, bool isAttach) {}
108 
UpdateTextureImage(std::vector<float> & matrix)109     virtual void UpdateTextureImage(std::vector<float>& matrix) {}
110 
SetWebMessage(OffsetF offset)111     virtual void SetWebMessage(OffsetF offset) {}
112 
SetWebSlideAxis(Axis axis)113     virtual void SetWebSlideAxis(Axis axis) {}
114 
SetWebOffset(float webOffset)115     virtual void SetWebOffset(float webOffset) {}
116 
SetPatternType(const std::string & type)117     virtual void SetPatternType(const std::string& type) {}
118 
SetSurfaceQueueSize(int32_t queueSize)119     virtual void SetSurfaceQueueSize(int32_t queueSize) {}
120 
DrawBufferForXComponent(RSCanvas & canvas,float width,float height,float offsetX,float offsetY)121     virtual void DrawBufferForXComponent(RSCanvas& canvas, float width, float height, float offsetX, float offsetY) {};
122 
ReleaseSurfaceBuffers()123     virtual void ReleaseSurfaceBuffers() {}
124 
RegisterSurface()125     virtual void RegisterSurface() const {};
126 
UnregisterSurface()127     virtual void UnregisterSurface() const {};
128 
Connect()129     virtual void Connect() const {};
130 
Disconnect()131     virtual void Disconnect() const {};
132 
RegisterBufferCallback()133     virtual void RegisterBufferCallback() {}
134 
SetIsNeedSyncGeometryProperties(bool isNeedSyncGeometryProperties)135     virtual void SetIsNeedSyncGeometryProperties(bool isNeedSyncGeometryProperties) {}
136 
SetKeyBoardAvoidRect(RectF keyBoardAvoidRect)137     virtual void SetKeyBoardAvoidRect(RectF keyBoardAvoidRect) {}
138 
OnWindowStateChange(bool isShow)139     virtual void OnWindowStateChange(bool isShow) {}
140 
141 protected:
142     ACE_DISALLOW_COPY_AND_MOVE(RenderSurface);
143 };
144 } // namespace OHOS::Ace::NG
145 
146 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_RENDER_SURFACE_H
147