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_uni_render_mirror_processor.h"
17
18 #include <ctime>
19
20 #include "platform/common/rs_log.h"
21 #include "platform/ohos/backend/rs_surface_frame_ohos_raster.h"
22 #include "pipeline/rs_uni_render_util.h"
23 #include "rs_trace.h"
24 #include "string_utils.h"
25
26 namespace OHOS {
27 namespace Rosen {
Init(RSDisplayRenderNode & node,int32_t offsetX,int32_t offsetY,ScreenId mirroredId)28 bool RSUniRenderMirrorProcessor::Init(RSDisplayRenderNode& node, int32_t offsetX, int32_t offsetY, ScreenId mirroredId)
29 {
30 if (!RSProcessor::Init(node, offsetX, offsetY, mirroredId)) {
31 return false;
32 }
33
34 renderFrameConfig_.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA;
35
36 auto screenManager = CreateOrGetScreenManager();
37 producerSurface_ = screenManager->GetProducerSurface(node.GetScreenId());
38 if (producerSurface_ == nullptr) {
39 RS_LOGE("RSUniRenderMirrorProcessor::Init for Screen(id %" PRIu64 "): ProducerSurface is null!",
40 node.GetScreenId());
41 return false;
42 }
43 renderFrame_ = renderEngine_->RequestFrame(producerSurface_, renderFrameConfig_, forceCPU_, false);
44 if (renderFrame_ == nullptr) {
45 return false;
46 }
47 canvas_ = renderFrame_->GetCanvas();
48 if (canvas_ == nullptr) {
49 return false;
50 }
51
52 return true;
53 }
54
PostProcess()55 void RSUniRenderMirrorProcessor::PostProcess()
56 {
57 if (producerSurface_ == nullptr) {
58 RS_LOGE("RSUniRenderMirrorProcessor::PostProcess surface is null!");
59 return;
60 }
61 auto surfaceId = producerSurface_->GetUniqueId();
62 renderEngine_->SetUiTimeStamp(renderFrame_, surfaceId);
63 if (renderFrame_ == nullptr) {
64 RS_LOGE("RSUniRenderMirrorProcessor::PostProcess renderFrame_ is null.");
65 return;
66 }
67 RSProcessor::RequestPerf(3, true); // set perf level 3 in mirrorScreen state
68 renderFrame_->Flush();
69 }
70
ProcessSurface(RSSurfaceRenderNode & node)71 void RSUniRenderMirrorProcessor::ProcessSurface(RSSurfaceRenderNode& node)
72 {
73 RS_LOGI("RSUniRenderMirrorProcessor::ProcessSurface() is not supported.");
74 }
75
ProcessDisplaySurface(RSDisplayRenderNode & node)76 void RSUniRenderMirrorProcessor::ProcessDisplaySurface(RSDisplayRenderNode& node)
77 {
78 RS_TRACE_NAME("RSUniRenderMirrorProcessor::ProcessDisplaySurface");
79 if (canvas_ == nullptr || node.GetBuffer() == nullptr) {
80 RS_LOGE("RSUniRenderMirrorProcessor::ProcessDisplaySurface: Canvas or buffer is null!");
81 return;
82 }
83 auto params = RSUniRenderUtil::CreateBufferDrawParam(node, forceCPU_);
84 renderEngine_->DrawDisplayNodeWithParams(*canvas_, node, params);
85 }
86 } // namespace Rosen
87 } // namespace OHOS