• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RENDER_SERVICE_CORE_RS_RCD_SURFACE_RENDER_NODE_H
17 #define RENDER_SERVICE_CORE_RS_RCD_SURFACE_RENDER_NODE_H
18 
19 #include <atomic>
20 #include <ibuffer_consumer_listener.h>
21 #include <memory>
22 #include <surface.h>
23 
24 #include "common/rs_rect.h"
25 #include "pipeline/rs_render_node.h"
26 #include "pipeline/rs_surface_handler.h"
27 #include "feature/round_corner_display/rs_round_corner_config.h"
28 #include "platform/drawing/rs_surface.h"
29 #include "render_context/render_context.h"
30 #include "sync_fence.h"
31 #include <filesystem>
32 #include "include/core/SkBitmap.h"
33 
34 namespace OHOS {
35 namespace Rosen {
36 
37 class RSRcdSurfaceRenderNode;
38 class RSProcessor;
39 
40 struct RcdPrepareInfo {
41     std::shared_ptr<RSRcdSurfaceRenderNode> bottomNode = nullptr;
42     std::shared_ptr<RSRcdSurfaceRenderNode> topNode = nullptr;
43     bool hasInvalidScene = false;
44 };
45 
46 struct RcdProcessInfo {
47     std::shared_ptr<RSProcessor> uniProcessor = nullptr;
48     std::shared_ptr<rs_rcd::RoundCornerLayer> topLayer = nullptr;
49     std::shared_ptr<rs_rcd::RoundCornerLayer> bottomLayer = nullptr;
50     bool resourceChanged = false;
51 };
52 
53 struct RoundCornerDisplayInfo {
54     RcdPrepareInfo prepareInfo;
55     RcdProcessInfo processInfo;
56 };
57 
58 enum class RCDNodeId : NodeId {
59     TOP_RCD_NODE_ID = 1,
60     BACKGROUND_RCD_NODE_ID = 2
61 };
62 
63 enum class RCDSurfaceType : uint32_t {
64     BOTTOM,
65     TOP,
66     INVALID
67 };
68 
69 struct RcdExtInfo {
70     bool surfaceCreated = false;
71     RectI srcRect_;
72     RectI dstRect_;
73 
74     RectF surfaceBounds;
75     RectF frameBounds;
76     RectF frameViewPort;
77 
78     RCDSurfaceType surfaceType = RCDSurfaceType::INVALID;
79 
ClearRcdExtInfo80     void Clear()
81     {
82         surfaceBounds.Clear();
83         frameBounds.Clear();
84         frameViewPort.Clear();
85     }
86 
GetFrameOffsetXRcdExtInfo87     float GetFrameOffsetX() const
88     {
89         return frameViewPort.GetLeft() - surfaceBounds.GetLeft();
90     }
91 
GetFrameOffsetYRcdExtInfo92     float GetFrameOffsetY() const
93     {
94         return frameViewPort.GetTop() - surfaceBounds.GetTop();
95     }
96 };
97 
98 struct RcdSourceInfo {
99     uint32_t bufferWidth = 0;
100     uint32_t bufferHeight = 0;
101     uint32_t bufferSize = 0;
102 };
103 
104 struct HardwareLayerInfo {
105     std::string pathBin;
106     int bufferSize = 0;
107     int cldWidth = 0;
108     int cldHeight = 0;
109 };
110 
111 struct CldInfo;
112 
113 // use normal hardware composer node instead if it supports rcd feature in OH 6.0 rcd refactoring
114 class RSRcdSurfaceRenderNode : public RSRenderNode {
115 public:
116     using WeakPtr = std::weak_ptr<RSRcdSurfaceRenderNode>;
117     using SharedPtr = std::shared_ptr<RSRcdSurfaceRenderNode>;
118 
119     static inline constexpr RSRenderNodeType Type = RSRenderNodeType::ROUND_CORNER_NODE;
GetType()120     RSRenderNodeType GetType() const override
121     {
122         return Type;
123     }
124 
125     RSRcdSurfaceRenderNode(RCDSurfaceType type, const std::weak_ptr<RSContext>& context);
126     RSRcdSurfaceRenderNode(NodeId id, RCDSurfaceType type, const std::weak_ptr<RSContext>& context = {});
127     static SharedPtr Create(NodeId id, RCDSurfaceType type, const std::weak_ptr<RSContext>& context = {});
128     ~RSRcdSurfaceRenderNode() override;
129 
130     void InitRenderParams() override;
131 
GetRSSurfaceHandler()132     const std::shared_ptr<RSSurfaceHandler> GetRSSurfaceHandler() const
133     {
134         return surfaceHandler_;
135     }
136 
GetMutableRSSurfaceHandler()137     std::shared_ptr<RSSurfaceHandler> GetMutableRSSurfaceHandler()
138     {
139         return surfaceHandler_;
140     }
141 
142     const RectI& GetSrcRect() const;
143     const RectI& GetDstRect() const;
144 
145     RcdSourceInfo rcdSourceInfo;
146     void SetRcdBufferWidth(uint32_t width);
147     void SetRcdBufferHeight(uint32_t height);
148     void SetRcdBufferSize(uint32_t bufferSize);
149     void ResetCurrFrameState();
150     void Reset();
151     bool PrepareHardwareResourceBuffer(const std::shared_ptr<rs_rcd::RoundCornerLayer>& layerInfo);
152     bool IsTopSurface() const;
153     bool IsBottomSurface() const;
154     bool IsInvalidSurface() const;
155 
156     const CldInfo GetCldInfo() const;
157 
SetRenderDisplayRect(const RectT<uint32_t> & rect)158     void SetRenderDisplayRect(const RectT<uint32_t>& rect)
159     {
160         displayRect_ = rect;
161     }
162 
163     void PrepareHardwareResource(std::shared_ptr<rs_rcd::RoundCornerLayer>& layerInfo);
164 
165     void UpdateRcdRenderParams(bool resourceChanged, const std::shared_ptr<Drawing::Bitmap> curBitmap);
166 
167     void DoProcessRenderMainThreadTask(bool resourceChanged, std::shared_ptr<RSProcessor> processor);
168 
169     void PrintRcdNodeInfo();
170 
171 protected:
172     void OnSync() override;
173 
174 private:
175     std::shared_ptr<RSSurfaceHandler> surfaceHandler_;
176 
177     HardwareLayerInfo cldLayerInfo_;
178     Drawing::Bitmap layerBitmap_;
179 
180     uint32_t GetRcdBufferWidth() const;
181     uint32_t GetRcdBufferHeight() const;
182     uint32_t GetRcdBufferSize() const;
183 
184     RectT<uint32_t> displayRect_;
185     RcdExtInfo rcdExtInfo_;
186 
187     NodeId renderTargetId_ = 0;
188 
189     void OnRegister(const std::weak_ptr<RSContext>& context) = delete;
190 };
191 } // namespace Rosen
192 } // namespace OHOS
193 #endif // RENDER_SERVICE_CORE_RS_RCD_SURFACE_RENDER_NODE_H