• 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 <ibuffer_consumer_listener.h>
20 #include <memory>
21 #include <surface.h>
22 
23 #include "common/rs_rect.h"
24 #include "pipeline/rs_render_node.h"
25 #include "pipeline/rs_surface_handler.h"
26 #include "pipeline/round_corner_display/rs_round_corner_config.h"
27 #ifdef NEW_RENDER_CONTEXT
28 #include "rs_render_surface.h"
29 #include "render_context_base.h"
30 #else
31 #include "platform/drawing/rs_surface.h"
32 #include "render_context/render_context.h"
33 #endif
34 #include "sync_fence.h"
35 #include <filesystem>
36 #include "include/core/SkBitmap.h"
37 
38 namespace OHOS {
39 namespace Rosen {
40 
41 
42 enum class RCDSurfaceType : uint32_t {
43     BOTTOM,
44     TOP,
45     INVALID
46 };
47 
48 struct RcdExtInfo {
49     bool surfaceCreated = false;
50     RectI srcRect_;
51     RectI dstRect_;
52 
53     RectF surfaceBounds;
54     RectF frameBounds;
55     RectF frameViewPort;
56 
57     RCDSurfaceType surfaceType = RCDSurfaceType::INVALID;
58 
ClearRcdExtInfo59     void Clear()
60     {
61         surfaceBounds.Clear();
62         frameBounds.Clear();
63         frameViewPort.Clear();
64     }
65 
GetFrameOffsetXRcdExtInfo66     float GetFrameOffsetX() const
67     {
68         return frameViewPort.GetLeft() - surfaceBounds.GetLeft();
69     }
70 
GetFrameOffsetYRcdExtInfo71     float GetFrameOffsetY() const
72     {
73         return frameViewPort.GetTop() - surfaceBounds.GetTop();
74     }
75 };
76 
77 struct RcdSourceInfo {
78     uint32_t bufferWidth = 0;
79     uint32_t bufferHeight = 0;
80     uint32_t bufferSize = 0;
81 };
82 
83 struct HardwareLayerInfo {
84     std::filesystem::path pathBin;
85     int bufferSize = 0;
86     int cldWidth = 0;
87     int cldHeight = 0;
88 };
89 
90 struct CldInfo {
91     uint32_t cldDataOffset = 0;
92     uint32_t cldSize = 0;
93     uint32_t cldWidth = 0;
94     uint32_t cldHeight = 0;
95     uint32_t cldStride = 0;
96     uint32_t exWidth = 0;
97     uint32_t exHeight = 0;
98     uint32_t baseColor = 0;
99 };
100 
101 class RSRcdSurfaceRenderNode : public RSRenderNode, public RSSurfaceHandler {
102 public:
103     using WeakPtr = std::weak_ptr<RSRcdSurfaceRenderNode>;
104     using SharedPtr = std::shared_ptr<RSRcdSurfaceRenderNode>;
105 
106     RSRcdSurfaceRenderNode(NodeId id, RCDSurfaceType type, const std::weak_ptr<RSContext>& context = {});
107     ~RSRcdSurfaceRenderNode() override;
108 
109     const RectI& GetSrcRect() const;
110     const RectI& GetDstRect() const;
111 
112     bool CreateSurface(sptr<IBufferConsumerListener> listener);
113     bool IsSurfaceCreated() const;
114 #ifdef NEW_RENDER_CONTEXT
115     std::shared_ptr<RSRenderSurface> GetRSSurface() const;
116 #else
117     std::shared_ptr<RSSurface> GetRSSurface() const;
118 #endif
119     sptr<IBufferConsumerListener> GetConsumerListener() const;
120     RcdSourceInfo rcdSourceInfo;
121     void SetRcdBufferWidth(uint32_t width);
122     void SetRcdBufferHeight(uint32_t height);
123     void SetRcdBufferSize(uint32_t bufferSize);
124     void ClearBufferCache();
125     void ResetCurrFrameState();
126     void Reset();
127     bool SetHardwareResourceToBuffer();
128     BufferRequestConfig GetHardenBufferRequestConfig() const;
129     bool PrepareHardwareResourceBuffer(rs_rcd::RoundCornerLayer* layerInfo);
130     bool IsBottomSurface() const;
131     bool IsTopSurface() const;
132     bool IsInvalidSurface() const;
133 
134     float GetFrameOffsetX() const;
135     float GetFrameOffsetY() const;
136 
137     const CldInfo& GetCldInfo() const;
138 
139 private:
140     float GetSurfaceWidth() const;
141     float GetSurfaceHeight() const;
142     bool FillHardwareResource(HardwareLayerInfo &cldLayerInfo, int height, int width);
143     HardwareLayerInfo cldLayerInfo;
144     Drawing::Bitmap layerBitmap;
145 
146     uint32_t GetRcdBufferWidth() const;
147     uint32_t GetRcdBufferHeight() const;
148     uint32_t GetRcdBufferSize() const;
149 
150 #ifdef NEW_RENDER_CONTEXT
151     std::shared_ptr<RSRenderSurface> surface_ = nullptr;
152 #else
153     std::shared_ptr<RSSurface> surface_ = nullptr;
154 #endif
155     sptr<IBufferConsumerListener> consumerListener_;
156 
157     RcdExtInfo rcdExtInfo_;
158 
159     CldInfo cldInfo_;
160 };
161 } // namespace Rosen
162 } // namespace OHOS
163 #endif // RENDER_SERVICE_CORE_RS_RCD_SURFACE_RENDER_NODE_H