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