• 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 
17 #include "rs_virtual_screen_processor.h"
18 
19 #include <ctime>
20 
21 #include "draw/color.h"
22 #include "platform/common/rs_log.h"
23 #include "rs_base_render_util.h"
24 #include "rs_divided_render_util.h"
25 #include "rs_trace.h"
26 #include "string_utils.h"
27 
28 namespace OHOS {
29 namespace Rosen {
RSVirtualScreenProcessor()30 RSVirtualScreenProcessor::RSVirtualScreenProcessor()
31 {
32 }
33 
~RSVirtualScreenProcessor()34 RSVirtualScreenProcessor::~RSVirtualScreenProcessor() noexcept
35 {
36 }
37 
Init(RSDisplayRenderNode & node,int32_t offsetX,int32_t offsetY,ScreenId mirroredId,std::shared_ptr<RSBaseRenderEngine> renderEngine)38 bool RSVirtualScreenProcessor::Init(RSDisplayRenderNode& node, int32_t offsetX, int32_t offsetY, ScreenId mirroredId,
39                                     std::shared_ptr<RSBaseRenderEngine> renderEngine)
40 {
41 #ifdef RS_ENABLE_GPU
42     if (!RSProcessor::Init(node, offsetX, offsetY, mirroredId, renderEngine)) {
43         return false;
44     }
45 #endif
46 
47     if (mirroredId != INVALID_SCREEN_ID) {
48         SetMirrorScreenSwap(node);
49     }
50 
51     renderFrameConfig_.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA;
52 
53     auto screenManager = CreateOrGetScreenManager();
54     if (screenManager == nullptr) {
55         RS_LOGE("RSVirtualScreenProcessor::Init for Screen(id %{public}" PRIu64 "): screenManager is null!",
56             node.GetScreenId());
57         return false;
58     }
59     producerSurface_ = screenManager->GetProducerSurface(node.GetScreenId());
60     if (producerSurface_ == nullptr) {
61         RS_LOGE("RSVirtualScreenProcessor::Init for Screen(id %{public}" PRIu64 "): ProducerSurface is null!",
62             node.GetScreenId());
63         return false;
64     }
65 
66     bool forceCPU = false;
67     renderFrame_ = renderEngine_->RequestFrame(producerSurface_, renderFrameConfig_, forceCPU, false);
68     if (renderFrame_ == nullptr) {
69         RS_LOGE("RSVirtualScreenProcessor::Init: renderFrame_ is null!");
70         return false;
71     }
72     canvas_ = renderFrame_->GetCanvas();
73     if (canvas_ == nullptr) {
74         return false;
75     }
76     canvas_->ConcatMatrix(screenTransformMatrix_);
77 
78     return true;
79 }
80 
PostProcess()81 void RSVirtualScreenProcessor::PostProcess()
82 {
83     if (renderFrame_ == nullptr || canvas_ == nullptr || renderEngine_ == nullptr) {
84         RS_LOGE("RSVirtualScreenProcessor::PostProcess renderFrame or canvas or renderEngine is nullptr");
85         return;
86     }
87     if (isSecurityDisplay_ && displayHasSecSurface_) {
88         canvas_->Clear(Drawing::Color::COLOR_BLACK);
89     }
90     auto surfaceOhos = renderFrame_->GetSurface();
91     RSBaseRenderEngine::SetUiTimeStamp(renderFrame_, surfaceOhos);
92     renderFrame_->Flush();
93 }
94 
ProcessSurface(RSSurfaceRenderNode & node)95 void RSVirtualScreenProcessor::ProcessSurface(RSSurfaceRenderNode& node)
96 {
97     if (canvas_ == nullptr || renderEngine_ == nullptr) {
98         RS_LOGE("RSVirtualScreenProcessor::ProcessSurface canvas or renderEngine is nullptr");
99         return;
100     }
101 
102     std::string traceInfo;
103     AppendFormat(traceInfo, "RSVirtualScreenProcessor::ProcessSurface Node:%s ", node.GetName().c_str());
104     RS_TRACE_NAME(traceInfo);
105 
106     // prepare BufferDrawParam
107     // in display's coordinate.
108     // clipHole: false.
109     // forceCPU: true.
110     auto params = RSDividedRenderUtil::CreateBufferDrawParam(node, false, false, false);
111     const float adaptiveDstWidth = params.dstRect.GetWidth() * mirrorAdaptiveCoefficient_;
112     const float adaptiveDstHeight = params.dstRect.GetHeight() * mirrorAdaptiveCoefficient_;
113     params.dstRect.SetLeft(0);
114     params.dstRect.SetTop(0);
115     params.dstRect.SetRight(adaptiveDstWidth);
116     params.dstRect.SetBottom(adaptiveDstHeight);
117     renderEngine_->DrawSurfaceNodeWithParams(*canvas_, node, params);
118 }
119 
ProcessDisplaySurface(RSDisplayRenderNode & node)120 void RSVirtualScreenProcessor::ProcessDisplaySurface(RSDisplayRenderNode& node)
121 {
122     RS_LOGI("RSVirtualScreenProcessor::ProcessDisplaySurface() is not supported.");
123 }
124 
ProcessRcdSurface(RSRcdSurfaceRenderNode & node)125 void RSVirtualScreenProcessor::ProcessRcdSurface(RSRcdSurfaceRenderNode& node)
126 {
127     RS_LOGI("RSVirtualScreenProcessor::ProcessRcdSurface() is not supported.");
128 }
129 } // namespace Rosen
130 } // namespace OHOS
131