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