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 "pipeline/rs_render_engine.h"
17 #include "rs_physical_screen_processor.h"
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 {
RSPhysicalScreenProcessor()25 RSPhysicalScreenProcessor::RSPhysicalScreenProcessor()
26 : composerAdapter_(std::make_unique<RSComposerAdapter>())
27 {
28 }
29
~RSPhysicalScreenProcessor()30 RSPhysicalScreenProcessor::~RSPhysicalScreenProcessor() noexcept
31 {
32 }
33
Init(RSDisplayRenderNode & node,int32_t offsetX,int32_t offsetY,ScreenId mirroredId,std::shared_ptr<RSBaseRenderEngine> renderEngine)34 bool RSPhysicalScreenProcessor::Init(RSDisplayRenderNode& node, int32_t offsetX, int32_t offsetY, ScreenId mirroredId,
35 std::shared_ptr<RSBaseRenderEngine> renderEngine)
36 {
37 // planning: adapt isRenderThread
38 if (!RSProcessor::Init(node, offsetX, offsetY, mirroredId, renderEngine)) {
39 return false;
40 }
41
42 if (mirroredId != INVALID_SCREEN_ID) {
43 SetMirrorScreenSwap(node);
44 }
45
46 return composerAdapter_->Init(screenInfo_, offsetX, offsetY, mirrorAdaptiveCoefficient_,
47 [this](const auto& surface, const auto& layers) { Redraw(surface, layers); });
48 }
49
PostProcess()50 void RSPhysicalScreenProcessor::PostProcess()
51 {
52 composerAdapter_->CommitLayers(layers_);
53 MultiLayersPerf(layers_.size());
54 }
55
ProcessSurface(RSSurfaceRenderNode & node)56 void RSPhysicalScreenProcessor::ProcessSurface(RSSurfaceRenderNode &node)
57 {
58 if (renderEngine_) {
59 composerAdapter_->SetColorFilterMode(renderEngine_->GetColorFilterMode());
60 }
61 auto layer = composerAdapter_->CreateLayer(node);
62 if (layer == nullptr) {
63 RS_LOGD("RSPhysicalScreenProcessor::ProcessSurface: failed to createLayer for"
64 " node(id: %{public}" PRIu64 ")", node.GetId());
65 return;
66 }
67
68 layers_.emplace_back(layer);
69 }
70
ProcessDisplaySurface(RSDisplayRenderNode & node)71 void RSPhysicalScreenProcessor::ProcessDisplaySurface(RSDisplayRenderNode& node)
72 {
73 RS_LOGI("RSPhysicalScreenProcessor::ProcessDisplaySurface() is not supported.");
74 }
75
ProcessRcdSurface(RSRcdSurfaceRenderNode & node)76 void RSPhysicalScreenProcessor::ProcessRcdSurface(RSRcdSurfaceRenderNode& node)
77 {
78 RS_LOGI("RSPhysicalScreenProcessor::ProcessRcdSurface() is not supported");
79 }
80
Redraw(const sptr<Surface> & surface,const std::vector<LayerInfoPtr> & layers)81 void RSPhysicalScreenProcessor::Redraw(const sptr<Surface>& surface, const std::vector<LayerInfoPtr>& layers)
82 {
83 RS_TRACE_NAME("Redraw");
84 if (surface == nullptr || renderEngine_ == nullptr) {
85 RS_LOGE("RSPhysicalScreenProcessor::Redraw: surface or renderEngine_ is null");
86 return;
87 }
88
89 RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer start");
90 bool forceCPU = RSBaseRenderEngine::NeedForceCPU(layers);
91 auto renderFrame = renderEngine_->RequestFrame(surface, renderFrameConfig_, forceCPU);
92 if (renderFrame == nullptr) {
93 RS_LOGE("RsDebug RSPhysicalScreenProcessor::Redraw: failed to request frame.");
94 return;
95 }
96
97 auto canvas = renderFrame->GetCanvas();
98 if (canvas == nullptr) {
99 RS_LOGE("RsDebug RSPhysicalScreenProcessor::Redraw: canvas is nullptr.");
100 return;
101 }
102 canvas->ConcatMatrix(screenTransformMatrix_);
103 renderEngine_->DrawLayers(*canvas, layers, forceCPU);
104 renderFrame->Flush();
105 RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer end");
106 }
107 } // namespace Rosen
108 } // namespace OHOS
109