• 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_rcd_render_visitor.h"
17 #include "pipeline/main_thread/rs_main_thread.h"
18 #include "feature/round_corner_display/rs_rcd_surface_render_node.h"
19 #include "feature/round_corner_display/rs_rcd_surface_render_node_drawable.h"
20 #include "rs_rcd_render_listener.h"
21 #include "rs_trace.h"
22 
23 namespace OHOS {
24 namespace Rosen {
RSRcdRenderVisitor()25 RSRcdRenderVisitor::RSRcdRenderVisitor()
26 {
27     renderEngine_ = RSUniRenderThread::Instance().GetRenderEngine();
28 }
29 
PrepareResourceBuffer(RSRcdSurfaceRenderNode & node,std::shared_ptr<rs_rcd::RoundCornerLayer> & layerInfo)30 bool RSRcdRenderVisitor::PrepareResourceBuffer(
31     RSRcdSurfaceRenderNode &node, std::shared_ptr<rs_rcd::RoundCornerLayer> &layerInfo)
32 {
33     auto drawable = std::static_pointer_cast<DrawableV2::RSRcdSurfaceRenderNodeDrawable>(node.GetRenderDrawable());
34     if (drawable == nullptr) {
35         RS_LOGE("RSRcdRenderVisitor::PrepareResourceBuffer CreateSurface drawable is nullptr");
36         return false;
37     }
38     sptr<IBufferConsumerListener> listener = new RSRcdRenderListener(node.GetRSSurfaceHandler());
39     if (listener == nullptr || (!drawable->CreateSurface(listener))) {
40         RS_LOGE("RSRcdRenderVisitor::PrepareResourceBuffer CreateSurface failed");
41         return false;
42     }
43     if (layerInfo == nullptr || (!node.PrepareHardwareResourceBuffer(layerInfo))) {
44         RS_LOGE("PrepareHardwareResourceBuffer is wrong");
45         return false;
46     }
47     return true;
48 }
49 
ProcessRcdSurfaceRenderNode(RSRcdSurfaceRenderNode & node,bool resourceChanged)50 void RSRcdRenderVisitor::ProcessRcdSurfaceRenderNode(RSRcdSurfaceRenderNode& node, bool resourceChanged)
51 {
52     if (uniProcessor_ == nullptr || node.IsInvalidSurface() || resourceChanged) {
53         RS_LOGE("RSRcdRenderVisitor RSProcessor is null or node invalid or resource is changed!");
54         return;
55     }
56 
57     if (node.GetRSSurfaceHandler() != nullptr && node.GetRSSurfaceHandler()->GetBuffer() != nullptr) {
58         uniProcessor_->ProcessRcdSurface(node);
59         return;
60     }
61 }
62 
SetUniProcessor(std::shared_ptr<RSProcessor> processor)63 void RSRcdRenderVisitor::SetUniProcessor(std::shared_ptr<RSProcessor> processor)
64 {
65     uniProcessor_ = processor;
66 }
67 } // namespace Rosen
68 } // namespace OHOS