1 /*
2 * Copyright (c) 2025 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_frame_blur_predict.h"
17
18 #include "hilog/log.h"
19 #include "rs_trace.h"
20 #include "rs_frame_report.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 #undef LOG_DOMAIN
25 #define LOG_DOMAIN 0xD001400
26
27 #undef LOG_TAG
28 #define LOG_TAG "OHOS::RS"
29 #define LOGI(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
30 #define LOGD(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
31 #define LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
GetInstance()32 RsFrameBlurPredict& RsFrameBlurPredict::GetInstance()
33 {
34 static RsFrameBlurPredict instance;
35 return instance;
36 }
37
RsFrameBlurPredict()38 RsFrameBlurPredict::RsFrameBlurPredict() {}
39
~RsFrameBlurPredict()40 RsFrameBlurPredict::~RsFrameBlurPredict()
41 {
42 ResetPredictDrawLargeAreaBlur();
43 isValidBlurFrame_.store(false);
44 predictBegin_.store(false);
45 }
46
AdjustCurrentFrameDrawLargeAreaBlurFrequencyPredictively()47 void RsFrameBlurPredict::AdjustCurrentFrameDrawLargeAreaBlurFrequencyPredictively()
48 {
49 if (isValidBlurFrame_.load()) {
50 GetCurrentFrameDrawLargeAreaBlurPredictively();
51 ResetPredictDrawLargeAreaBlur();
52 }
53 }
54
UpdateCurrentFrameDrawLargeAreaBlurFrequencyPrecisely()55 void RsFrameBlurPredict::UpdateCurrentFrameDrawLargeAreaBlurFrequencyPrecisely()
56 {
57 if (isValidBlurFrame_.load()) {
58 GetCurrentFrameDrawLargeAreaBlurPrecisely();
59 }
60 }
61
TakeEffectBlurScene(const EventInfo & eventInfo)62 void RsFrameBlurPredict::TakeEffectBlurScene(const EventInfo& eventInfo)
63 {
64 isValidBlurFrame_.store(eventInfo.eventStatus);
65 RS_TRACE_INT(eventInfo.description.c_str(), eventInfo.eventStatus);
66 if (!eventInfo.eventStatus) {
67 predictBegin_.store(false);
68 }
69 }
70
PredictDrawLargeAreaBlur(RSRenderNode & node)71 void RsFrameBlurPredict::PredictDrawLargeAreaBlur(RSRenderNode& node)
72 {
73 if (!isValidBlurFrame_.load()) {
74 return;
75 }
76 std::pair<bool, bool> nodeDrawLargeAreaBlur = {false, false};
77 node.NodeDrawLargeAreaBlur(nodeDrawLargeAreaBlur);
78 predictDrawLargeAreaBlur_.first = predictDrawLargeAreaBlur_.first || nodeDrawLargeAreaBlur.first;
79 predictDrawLargeAreaBlur_.second = predictDrawLargeAreaBlur_.second || nodeDrawLargeAreaBlur.second;
80 }
81
GetCurrentFrameDrawLargeAreaBlurPredictively()82 void RsFrameBlurPredict::GetCurrentFrameDrawLargeAreaBlurPredictively()
83 {
84 std::unordered_map<std::string, std::string> param = {};
85 if (!predictBegin_.load()) {
86 RS_TRACE_NAME("predict invalid frame");
87 param["frameBlurPredict"] = RS_BLUR_PREDICT_INVALID;
88 RsFrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::RS_BLUR_PREDICT, param);
89 return;
90 }
91 RS_TRACE_NAME_FMT("predict current %d frame", predictDrawLargeAreaBlur_.first);
92 if (predictDrawLargeAreaBlur_.first) {
93 param["frameBlurPredict"] = RS_BLUR_PREDICT_LONG;
94 } else {
95 param["frameBlurPredict"] = RS_BLUR_PREDICT_SHORT;
96 }
97 RsFrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::RS_BLUR_PREDICT, param);
98 predictDrawLargeAreaBlur_.first = false;
99 }
100
GetCurrentFrameDrawLargeAreaBlurPrecisely()101 void RsFrameBlurPredict::GetCurrentFrameDrawLargeAreaBlurPrecisely()
102 {
103 RS_TRACE_NAME_FMT("precise current %d frame", predictDrawLargeAreaBlur_.second);
104 std::unordered_map<std::string, std::string> param = {};
105 if (predictDrawLargeAreaBlur_.second) {
106 predictBegin_.store(true);
107 param["frameBlurPredict"] = RS_BLUR_PREDICT_LONG;
108 } else {
109 param["frameBlurPredict"] = RS_BLUR_PREDICT_SHORT;
110 }
111 RsFrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::RS_BLUR_PREDICT, param);
112 predictDrawLargeAreaBlur_.second = false;
113 }
114
ResetPredictDrawLargeAreaBlur()115 void RsFrameBlurPredict::ResetPredictDrawLargeAreaBlur()
116 {
117 predictDrawLargeAreaBlur_.first = false;
118 predictDrawLargeAreaBlur_.second = false;
119 }
120 } // namespace Rosen
121 } // namespace OHOS
122