• 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(RSScreenRenderNode & node,int32_t offsetX,int32_t offsetY,ScreenId mirroredId,std::shared_ptr<RSBaseRenderEngine> renderEngine)38 bool RSVirtualScreenProcessor::Init(RSScreenRenderNode& 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 
77     if (mirroredScreenInfo_.id != INVALID_SCREEN_ID) {
78         canvas_->ConcatMatrix(mirrorAdaptiveMatrix_);
79     } else {
80         canvas_->ConcatMatrix(screenTransformMatrix_);
81     }
82 
83     return true;
84 }
85 
PostProcess()86 void RSVirtualScreenProcessor::PostProcess()
87 {
88     if (renderFrame_ == nullptr || canvas_ == nullptr || renderEngine_ == nullptr) {
89         RS_LOGE("RSVirtualScreenProcessor::PostProcess renderFrame or canvas or renderEngine is nullptr");
90         return;
91     }
92     if (isSecurityDisplay_ && displayHasSecSurface_) {
93         canvas_->Clear(Drawing::Color::COLOR_BLACK);
94     }
95     auto surfaceOhos = renderFrame_->GetSurface();
96     RSBaseRenderEngine::SetUiTimeStamp(renderFrame_, surfaceOhos);
97     renderFrame_->Flush();
98 }
99 
ProcessSurface(RSSurfaceRenderNode & node)100 void RSVirtualScreenProcessor::ProcessSurface(RSSurfaceRenderNode& node)
101 {
102     if (canvas_ == nullptr || renderEngine_ == nullptr) {
103         RS_LOGE("RSVirtualScreenProcessor::ProcessSurface canvas or renderEngine is nullptr");
104         return;
105     }
106 
107     std::string traceInfo;
108     AppendFormat(traceInfo, "RSVirtualScreenProcessor::ProcessSurface Node:%s ", node.GetName().c_str());
109     RS_TRACE_NAME(traceInfo);
110 
111     // prepare BufferDrawParam
112     // in display's coordinate.
113     // clipHole: false.
114     // forceCPU: true.
115     auto params = RSDividedRenderUtil::CreateBufferDrawParam(node, false, false, false);
116     renderEngine_->DrawSurfaceNodeWithParams(*canvas_, node, params);
117 }
118 
ProcessScreenSurface(RSScreenRenderNode & node)119 void RSVirtualScreenProcessor::ProcessScreenSurface(RSScreenRenderNode& node)
120 {
121     RS_LOGI("RSVirtualScreenProcessor::ProcessScreenSurface() is not supported.");
122 }
123 
ProcessRcdSurface(RSRcdSurfaceRenderNode & node)124 void RSVirtualScreenProcessor::ProcessRcdSurface(RSRcdSurfaceRenderNode& node)
125 {
126     RS_LOGI("RSVirtualScreenProcessor::ProcessRcdSurface() is not supported.");
127 }
128 } // namespace Rosen
129 } // namespace OHOS
130