• 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 #include "rs_driven_surface_render_node.h"
17 
18 #include "common/rs_obj_abs_geometry.h"
19 #include "platform/common/rs_log.h"
20 #include "rs_driven_render_ext.h"
21 #include "screen_manager/screen_types.h"
22 #include "transaction/rs_render_service_client.h"
23 #include "visitor/rs_node_visitor.h"
24 
25 namespace OHOS {
26 namespace Rosen {
RSDrivenSurfaceRenderNode(NodeId id,DrivenSurfaceType type,std::weak_ptr<RSContext> context)27 RSDrivenSurfaceRenderNode::RSDrivenSurfaceRenderNode(
28     NodeId id, DrivenSurfaceType type, std::weak_ptr<RSContext> context)
29     : RSRenderNode(id, context), RSSurfaceHandler(id)
30 {
31     drivenExtInfo_.surfaceType_ = type;
32    MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
33     MemoryTrack::Instance().AddNodeRecord(id, info);
34 }
35 
~RSDrivenSurfaceRenderNode()36 RSDrivenSurfaceRenderNode::~RSDrivenSurfaceRenderNode()
37 {
38     MemoryTrack::Instance().RemoveNodeRecord(GetId());
39 }
40 
SetDrivenCanvasNode(RSBaseRenderNode::SharedPtr node)41 void RSDrivenSurfaceRenderNode::SetDrivenCanvasNode(RSBaseRenderNode::SharedPtr node)
42 {
43     drivenCanvasNode_ = node;
44 }
45 
GetDrivenCanvasNode() const46 RSBaseRenderNode::SharedPtr RSDrivenSurfaceRenderNode::GetDrivenCanvasNode() const
47 {
48     return drivenCanvasNode_;
49 }
50 
GetSrcRect() const51 const RectI& RSDrivenSurfaceRenderNode::GetSrcRect() const
52 {
53     return drivenExtInfo_.srcRect_;
54 }
55 
GetDstRect() const56 const RectI& RSDrivenSurfaceRenderNode::GetDstRect() const
57 {
58     return drivenExtInfo_.dstRect_;
59 }
60 
GetBufferRequestConfig() const61 BufferRequestConfig RSDrivenSurfaceRenderNode::GetBufferRequestConfig() const
62 {
63     BufferRequestConfig config {};
64     config.width = static_cast<int32_t>(GetSurfaceWidth());
65     config.height = static_cast<int32_t>(GetSurfaceHeight());
66     config.strideAlignment = 0x8; // default stride is 8 Bytes.
67     config.format = GRAPHIC_PIXEL_FMT_RGBA_8888;
68     config.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_MEM_FB;
69     config.timeout = 0;
70     return config;
71 }
72 
CreateSurface(sptr<IBufferConsumerListener> listener)73 bool RSDrivenSurfaceRenderNode::CreateSurface(sptr<IBufferConsumerListener> listener)
74 {
75     if (consumer_ != nullptr && surface_ != nullptr) {
76         RS_LOGI("RSDrivenSurfaceRenderNode::CreateSurface already created, return");
77         return true;
78     }
79     consumer_ = IConsumerSurface::Create("DrivenSurfaceNode");
80     if (consumer_ == nullptr) {
81         RS_LOGE("RSDrivenSurfaceRenderNode::CreateSurface get consumer surface fail");
82         return false;
83     }
84     SurfaceError ret = consumer_->RegisterConsumerListener(listener);
85     if (ret != SURFACE_ERROR_OK) {
86         RS_LOGE("RSDrivenSurfaceRenderNode::CreateSurface RegisterConsumerListener fail");
87         return false;
88     }
89     consumerListener_ = listener;
90     auto producer = consumer_->GetProducer();
91     sptr<Surface> surface = Surface::CreateSurfaceAsProducer(producer);
92     auto client = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
93     surface_ = client->CreateRSSurface(surface);
94     RS_LOGI("RSDrivenSurfaceRenderNode::CreateSurface end");
95     drivenExtInfo_.surfaceCreated_ = true;
96     return true;
97 }
98 
IsSurfaceCreated() const99 bool RSDrivenSurfaceRenderNode::IsSurfaceCreated() const
100 {
101     return drivenExtInfo_.surfaceCreated_;
102 }
103 #ifdef NEW_RENDER_CONTEXT
GetRSSurface() const104 std::shared_ptr<RSRenderSurface> RSDrivenSurfaceRenderNode::GetRSSurface() const
105 #else
106 std::shared_ptr<RSSurface> RSDrivenSurfaceRenderNode::GetRSSurface() const
107 #endif
108 {
109     return surface_;
110 }
111 
GetConsumerListener() const112 sptr<IBufferConsumerListener> RSDrivenSurfaceRenderNode::GetConsumerListener() const
113 {
114     return consumerListener_;
115 }
116 
ClearBufferCache()117 void RSDrivenSurfaceRenderNode::ClearBufferCache()
118 {
119     if (surface_ && consumer_) {
120         surface_->ClearBuffer();
121         consumer_->GoBackground();
122     }
123 }
124 
PushFramePaintItem(Vector4f paintItem,int32_t itemIndex)125 void RSDrivenSurfaceRenderNode::PushFramePaintItem(Vector4f paintItem, int32_t itemIndex)
126 {
127     drivenExtInfo_.currentState_.framePaintItems.emplace_back(std::make_pair(itemIndex, paintItem));
128 }
129 
ResetCurrFrameState()130 void RSDrivenSurfaceRenderNode::ResetCurrFrameState()
131 {
132     drivenExtInfo_.renderMode_ = DrivenSurfaceRenderMode::DISABLED;
133     drivenExtInfo_.currentState_.Clear();
134     drivenExtInfo_.srcRect_.Clear();
135     drivenExtInfo_.dstRect_.Clear();
136     drivenExtInfo_.yOffset_ = 0.0;
137 }
138 
Reset()139 void RSDrivenSurfaceRenderNode::Reset()
140 {
141     ResetCurrFrameState();
142     drivenExtInfo_.activateState_.Clear();
143     drivenCanvasNode_ = nullptr;
144 }
145 
DisabledRenderMode()146 void RSDrivenSurfaceRenderNode::DisabledRenderMode()
147 {
148     RSDrivenRenderExt::Instance().DisabledRenderMode(drivenExtInfo_);
149 }
150 
SetCurrFrameBounds(const RectF & bounds,const RectF & viewPort,const RectI & contentAbsRect)151 void RSDrivenSurfaceRenderNode::SetCurrFrameBounds(const RectF& bounds, const RectF& viewPort,
152     const RectI& contentAbsRect)
153 {
154     RSDrivenRenderExt::Instance().SetCurrFrameBounds(drivenExtInfo_, bounds, viewPort, contentAbsRect);
155 }
156 
UpdateActivateFrameState(const RectI & dstRect,bool backgroundDirty,bool contentDirty,bool nonContentDirty)157 void RSDrivenSurfaceRenderNode::UpdateActivateFrameState(
158     const RectI& dstRect, bool backgroundDirty, bool contentDirty, bool nonContentDirty)
159 {
160     RSDrivenRenderExt::Instance().UpdateActivateFrameState(
161         drivenExtInfo_, dstRect, backgroundDirty, contentDirty, nonContentDirty);
162 }
163 
IsExpandedMode() const164 bool RSDrivenSurfaceRenderNode::IsExpandedMode() const
165 {
166     return drivenExtInfo_.renderMode_ == DrivenSurfaceRenderMode::EXPANDED;
167 }
168 
IsReusableMode() const169 bool RSDrivenSurfaceRenderNode::IsReusableMode() const
170 {
171     return drivenExtInfo_.renderMode_ == DrivenSurfaceRenderMode::REUSABLE;
172 }
173 
IsDisabledMode() const174 bool RSDrivenSurfaceRenderNode::IsDisabledMode() const
175 {
176     return drivenExtInfo_.renderMode_ == DrivenSurfaceRenderMode::DISABLED;
177 }
178 
IsBackgroundSurface() const179 bool RSDrivenSurfaceRenderNode::IsBackgroundSurface() const
180 {
181     return drivenExtInfo_.surfaceType_ == DrivenSurfaceType::BACKGROUND;
182 }
183 
IsContentSurface() const184 bool RSDrivenSurfaceRenderNode::IsContentSurface() const
185 {
186     return drivenExtInfo_.surfaceType_ == DrivenSurfaceType::CONTENT;
187 }
188 
IsInvalidSurface() const189 bool RSDrivenSurfaceRenderNode::IsInvalidSurface() const
190 {
191     return drivenExtInfo_.surfaceType_ == DrivenSurfaceType::INVALID;
192 }
193 
GetSurfaceWidth() const194 float RSDrivenSurfaceRenderNode::GetSurfaceWidth() const
195 {
196     return drivenExtInfo_.activateState_.surfaceBounds.GetWidth();
197 }
198 
GetSurfaceHeight() const199 float RSDrivenSurfaceRenderNode::GetSurfaceHeight() const
200 {
201     return drivenExtInfo_.activateState_.surfaceBounds.GetHeight();
202 }
203 
GetFrameOffsetX() const204 float RSDrivenSurfaceRenderNode::GetFrameOffsetX() const
205 {
206     return drivenExtInfo_.activateState_.GetFrameOffsetX();
207 }
208 
GetFrameOffsetY() const209 float RSDrivenSurfaceRenderNode::GetFrameOffsetY() const
210 {
211     return drivenExtInfo_.activateState_.GetFrameOffsetY();
212 }
213 
GetFrameClipRect() const214 const RectI& RSDrivenSurfaceRenderNode::GetFrameClipRect() const
215 {
216     return drivenExtInfo_.activateState_.frameClipRect;
217 }
218 } // namespace Rosen
219 } // namespace OHOS
220