• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_rcd_render_manager.h"
17 #include "common/rs_optional_trace.h"
18 #include "common/rs_singleton.h"
19 #include "pipeline/parallel_render/rs_sub_thread_manager.h"
20 #include "pipeline/round_corner_display/rs_message_bus.h"
21 #include "platform/common/rs_log.h"
22 #include "rs_rcd_render_visitor.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 static std::unique_ptr<RSRcdRenderManager> g_rcdRenderManagerInstance =
27     std::make_unique<RSRcdRenderManager>();
28 
GetInstance()29 RSRcdRenderManager& RSRcdRenderManager::GetInstance()
30 {
31     return *g_rcdRenderManagerInstance;
32 }
33 
InitInstance()34 void RSRcdRenderManager::InitInstance()
35 {
36     g_rcdRenderManagerInstance->rcdRenderEnabled_ = true;
37 }
38 
GetRcdRenderEnabled() const39 bool RSRcdRenderManager::GetRcdRenderEnabled() const
40 {
41     return rcdRenderEnabled_;
42 }
43 
DoPrepareRenderTask(const RcdPrepareInfo & info)44 void RSRcdRenderManager::DoPrepareRenderTask(const RcdPrepareInfo& info)
45 {
46     if (!isBufferCacheClear_) {
47         topSurfaceNode_->ClearBufferCache();
48         bottomSurfaceNode_->ClearBufferCache();
49         isBufferCacheClear_ = true;
50     }
51 }
52 
IsRcdProcessInfoValid(const RcdProcessInfo & info)53 bool RSRcdRenderManager::IsRcdProcessInfoValid(const RcdProcessInfo& info)
54 {
55     if (info.uniProcessor == nullptr) {
56         RS_LOGE("info uniProcessor is nullptr");
57         return false;
58     } else if (info.topLayer == nullptr || info.bottomLayer == nullptr) {
59         RS_LOGE("info toplayer or bottomlayer resource is nullptr");
60         return false;
61     }
62     return true;
63 }
64 
DoProcessRenderTask(const RcdProcessInfo & info)65 void RSRcdRenderManager::DoProcessRenderTask(const RcdProcessInfo& info)
66 {
67     RS_TRACE_BEGIN("RSUniRender:DoRCDProcessTask");
68     if (!IsRcdProcessInfoValid(info)) {
69         RS_LOGE("RCD: RcdProcessInfo is incorrect");
70         RS_TRACE_END();
71         return;
72     }
73     auto visitor = std::make_shared<RSRcdRenderVisitor>();
74     visitor->SetUniProcessor(info.uniProcessor);
75     auto bottomRes = visitor->ProcessRcdSurfaceRenderNode(*bottomSurfaceNode_, info.bottomLayer, info.resourceChanged);
76     auto topRes = visitor->ProcessRcdSurfaceRenderNode(*topSurfaceNode_, info.topLayer, info.resourceChanged);
77     if (info.resourceChanged && bottomRes && topRes) {
78         RSSingleton<RsMessageBus>::GetInstance().SendMsg<bool>(TOPIC_RCD_DISPLAY_HWRESOURCE, true);
79     }
80     RS_TRACE_END();
81 }
82 
DoProcessRenderMainThreadTask(const RcdProcessInfo & info)83 void RSRcdRenderManager::DoProcessRenderMainThreadTask(const RcdProcessInfo& info)
84 {
85     RS_TRACE_BEGIN("RSUniRender:DoRCDProcessMainThreadTask");
86     if (!IsRcdProcessInfoValid(info)) {
87         RS_LOGE("RCD: RcdProcessInfo in MainThread is incorrect");
88         RS_TRACE_END();
89         return;
90     }
91     auto visitor = std::make_shared<RSRcdRenderVisitor>();
92     visitor->SetUniProcessor(info.uniProcessor);
93     visitor->ProcessRcdSurfaceRenderNodeMainThread(*bottomSurfaceNode_, info.resourceChanged);
94     visitor->ProcessRcdSurfaceRenderNodeMainThread(*topSurfaceNode_, info.resourceChanged);
95     RS_TRACE_END();
96 }
97 
Reset()98 void RSRcdRenderManager::Reset()
99 {
100     topSurfaceNode_->Reset();
101     bottomSurfaceNode_->Reset();
102 }
103 
104 } // namespace Rosen
105 } // namespace OHOS