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)34 bool RSPhysicalScreenProcessor::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 if (mirroredId != INVALID_SCREEN_ID) {
41 SetMirrorScreenSwap(node);
42 }
43
44 return composerAdapter_->Init(screenInfo_, offsetX, offsetY, 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 MultiLayersPerf(layers_.size());
52 }
53
ProcessSurface(RSSurfaceRenderNode & node)54 void RSPhysicalScreenProcessor::ProcessSurface(RSSurfaceRenderNode &node)
55 {
56 auto layer = composerAdapter_->CreateLayer(node);
57 if (layer == nullptr) {
58 RS_LOGD(
59 "RSPhysicalScreenProcessor::ProcessSurface: failed to createLayer for node(id: %" PRIu64 ")", node.GetId());
60 return;
61 }
62
63 layers_.emplace_back(layer);
64 }
65
ProcessDisplaySurface(RSDisplayRenderNode & node)66 void RSPhysicalScreenProcessor::ProcessDisplaySurface(RSDisplayRenderNode& node)
67 {
68 RS_LOGI("RSPhysicalScreenProcessor::ProcessDisplaySurface() is not supported.");
69 }
70
Redraw(const sptr<Surface> & surface,const std::vector<LayerInfoPtr> & layers)71 void RSPhysicalScreenProcessor::Redraw(const sptr<Surface>& surface, const std::vector<LayerInfoPtr>& layers)
72 {
73 RS_TRACE_NAME("Redraw");
74 if (surface == nullptr) {
75 RS_LOGE("RSPhysicalScreenProcessor::Redraw: surface is null.");
76 return;
77 }
78
79 RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer start");
80 bool forceCPU = RSBaseRenderEngine::NeedForceCPU(layers);
81 auto renderFrame = renderEngine_->RequestFrame(surface, renderFrameConfig_, forceCPU);
82 if (renderFrame == nullptr) {
83 RS_LOGE("RsDebug RSPhysicalScreenProcessor::Redraw:failed to request frame.");
84 return;
85 }
86
87 auto canvas = renderFrame->GetCanvas();
88 if (canvas == nullptr) {
89 RS_LOGE("RsDebug RSPhysicalScreenProcessor::Redraw:canvas is nullptr.");
90 return;
91 }
92 canvas->concat(screenTransformMatrix_);
93 renderEngine_->DrawLayers(*canvas, layers, forceCPU, mirrorAdaptiveCoefficient_);
94 renderFrame->Flush();
95 RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer end");
96 }
97 } // namespace Rosen
98 } // namespace OHOS
99