• 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     // planning: adapt isRenderThread
38     if (!RSProcessor::Init(node, offsetX, offsetY, mirroredId, renderEngine)) {
39         return false;
40     }
41 
42     return composerAdapter_->Init(node, screenInfo_, mirroredScreenInfo_, mirrorAdaptiveCoefficient_,
43         [this](const auto& surface, const auto& layers) { Redraw(surface, layers); });
44 }
45 
PostProcess()46 void RSPhysicalScreenProcessor::PostProcess()
47 {
48     composerAdapter_->CommitLayers(layers_);
49     MultiLayersPerf(layers_.size());
50 }
51 
ProcessSurface(RSSurfaceRenderNode & node)52 void RSPhysicalScreenProcessor::ProcessSurface(RSSurfaceRenderNode &node)
53 {
54     if (renderEngine_) {
55         composerAdapter_->SetColorFilterMode(renderEngine_->GetColorFilterMode());
56     }
57     auto layer = composerAdapter_->CreateLayer(node);
58     if (layer == nullptr) {
59         RS_LOGD("RSPhysicalScreenProcessor::ProcessSurface: failed to createLayer for"
60             " node(id: %{public}" 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 
ProcessRcdSurface(RSRcdSurfaceRenderNode & node)72 void RSPhysicalScreenProcessor::ProcessRcdSurface(RSRcdSurfaceRenderNode& node)
73 {
74     RS_LOGI("RSPhysicalScreenProcessor::ProcessRcdSurface() 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 || renderEngine_ == nullptr) {
81         RS_LOGE("RSPhysicalScreenProcessor::Redraw: surface or renderEngine_ 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 
99     if (mirroredScreenInfo_.id != INVALID_SCREEN_ID) {
100         canvas->ConcatMatrix(mirrorAdaptiveMatrix_);
101     } else {
102         canvas->ConcatMatrix(screenTransformMatrix_);
103     }
104 
105     renderEngine_->DrawLayers(*canvas, layers, forceCPU);
106     renderFrame->Flush();
107     RS_LOGD("RsDebug RSPhysicalScreenProcessor::Redraw flush frame buffer end");
108 }
109 } // namespace Rosen
110 } // namespace OHOS
111