• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_uni_render_processor.h"
17 
18 #include "rs_trace.h"
19 #include "string_utils.h"
20 
21 #include "platform/common/rs_log.h"
22 
23 namespace OHOS {
24 namespace Rosen {
RSUniRenderProcessor()25 RSUniRenderProcessor::RSUniRenderProcessor()
26     : composerAdapter_(std::make_unique<RSComposerAdapter>())
27 {
28 }
29 
~RSUniRenderProcessor()30 RSUniRenderProcessor::~RSUniRenderProcessor() noexcept
31 {
32 }
33 
Init(RSDisplayRenderNode & node,int32_t offsetX,int32_t offsetY,ScreenId mirroredId)34 bool RSUniRenderProcessor::Init(RSDisplayRenderNode& node, int32_t offsetX, int32_t offsetY, ScreenId mirroredId)
35 {
36     if (!RSProcessor::Init(node, offsetX, offsetY, mirroredId)) {
37         return false;
38     }
39 
40     // In uni render mode, we can handle screen rotation in the rendering process,
41     // so we do not need to handle rotation in composer adapter any more,
42     // just pass the buffer to composer straightly.
43     screenInfo_.rotation = ScreenRotation::ROTATION_0;
44     return composerAdapter_->Init(screenInfo_, offsetX, offsetY, mirrorAdaptiveCoefficient_,
45         [this](const auto& surface, const auto& layers) {
46         Redraw(surface, layers);
47     });
48 }
49 
PostProcess()50 void RSUniRenderProcessor::PostProcess()
51 {
52     composerAdapter_->CommitLayers(layers_);
53     MultiLayersPerf(layerNum);
54 }
55 
ProcessSurface(RSSurfaceRenderNode & node)56 void RSUniRenderProcessor::ProcessSurface(RSSurfaceRenderNode &node)
57 {
58     if (!node.IsNotifyRTBufferAvailable()) {
59         // Only ipc for one time.
60         RS_LOGD("RsDebug RSUniRenderProcessor::ProcessSurface id = %" PRIu64 " Notify RT buffer available",
61             node.GetId());
62         node.NotifyRTBufferAvailable();
63     }
64 
65     auto layer = composerAdapter_->CreateLayer(node);
66     if (layer == nullptr) {
67         RS_LOGE("RSUniRenderProcessor::ProcessSurface: failed to createLayer for node(id: %" PRIu64 ")", node.GetId());
68         return;
69     }
70 
71     layers_.emplace_back(layer);
72     layerNum++;
73 }
74 
ProcessDisplaySurface(RSDisplayRenderNode & node)75 void RSUniRenderProcessor::ProcessDisplaySurface(RSDisplayRenderNode& node)
76 {
77     auto layer = composerAdapter_->CreateLayer(node);
78     if (layer == nullptr) {
79         RS_LOGE("RSUniRenderProcessor::ProcessDisplaySurface: failed to createLayer for node(id: %" PRIu64 ")",
80             node.GetId());
81         return;
82     }
83 
84     layers_.emplace_back(layer);
85     layerNum += node.GetCurAllSurfaces().size();
86 }
87 
Redraw(const sptr<Surface> & surface,const std::vector<LayerInfoPtr> & layers)88 void RSUniRenderProcessor::Redraw(const sptr<Surface>& surface, const std::vector<LayerInfoPtr>& layers)
89 {
90     if (surface == nullptr) {
91         RS_LOGE("RSUniRenderProcessor::Redraw: surface is null.");
92         return;
93     }
94 
95     RS_LOGD("RsDebug RSUniRenderProcessor::Redraw flush frame buffer start");
96     bool forceCPU = RSBaseRenderEngine::NeedForceCPU(layers);
97     auto renderFrame = renderEngine_->RequestFrame(surface, renderFrameConfig_, forceCPU);
98     if (renderFrame == nullptr) {
99         RS_LOGE("RsDebug RSUniRenderProcessor::Redraw:failed to request frame.");
100         return;
101     }
102 
103     auto canvas = renderFrame->GetCanvas();
104     if (canvas == nullptr) {
105         RS_LOGE("RsDebug RSUniRenderProcessor::Redraw:canvas is nullptr.");
106         return;
107     }
108     renderEngine_->DrawLayers(*canvas, layers, forceCPU);
109     renderFrame->Flush();
110     RS_LOGD("RsDebug RSUniRenderProcessor::Redraw flush frame buffer end");
111 }
112 } // namespace Rosen
113 } // namespace OHOS
114