• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     LOGD("takeEffectBlurScene eventName : %s description : %s eventStatus %s",
70         eventInfo.eventName.c_str(), eventInfo.description.c_str(), eventInfo.eventStatus? "true" : "false");
71 }
72 
PredictDrawLargeAreaBlur(RSRenderNode & node)73 void RsFrameBlurPredict::PredictDrawLargeAreaBlur(RSRenderNode& node)
74 {
75     std::pair<bool, bool> nodeDrawLargeAreaBlur = {false, false};
76     node.NodeDrawLargeAreaBlur(nodeDrawLargeAreaBlur);
77     predictDrawLargeAreaBlur_.first = predictDrawLargeAreaBlur_.first || nodeDrawLargeAreaBlur.first;
78     predictDrawLargeAreaBlur_.second = predictDrawLargeAreaBlur_.second || nodeDrawLargeAreaBlur.second;
79 }
80 
GetCurrentFrameDrawLargeAreaBlurPredictively()81 void RsFrameBlurPredict::GetCurrentFrameDrawLargeAreaBlurPredictively()
82 {
83     std::unordered_map<std::string, std::string> param = {};
84     if (!predictBegin_.load()) {
85         RS_TRACE_NAME("predict invalid frame");
86         param["frameBlurPredict"] = RS_BLUR_PREDICT_INVALID;
87         RsFrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::RS_BLUR_PREDICT, param);
88         return;
89     }
90     RS_TRACE_NAME_FMT("predict current %d frame", predictDrawLargeAreaBlur_.first);
91     if (predictDrawLargeAreaBlur_.first) {
92         param["frameBlurPredict"] = RS_BLUR_PREDICT_LONG;
93     } else {
94         param["frameBlurPredict"] = RS_BLUR_PREDICT_SHORT;
95     }
96     RsFrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::RS_BLUR_PREDICT, param);
97     predictDrawLargeAreaBlur_.first = false;
98 }
99 
GetCurrentFrameDrawLargeAreaBlurPrecisely()100 void RsFrameBlurPredict::GetCurrentFrameDrawLargeAreaBlurPrecisely()
101 {
102     RS_TRACE_NAME_FMT("precise current %d frame", predictDrawLargeAreaBlur_.second);
103     std::unordered_map<std::string, std::string> param = {};
104     if (predictDrawLargeAreaBlur_.second) {
105         predictBegin_.store(true);
106         param["frameBlurPredict"] = RS_BLUR_PREDICT_LONG;
107     } else {
108         param["frameBlurPredict"] = RS_BLUR_PREDICT_SHORT;
109     }
110     RsFrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::RS_BLUR_PREDICT, param);
111     predictDrawLargeAreaBlur_.second = false;
112 }
113 
ResetPredictDrawLargeAreaBlur()114 void RsFrameBlurPredict::ResetPredictDrawLargeAreaBlur()
115 {
116     predictDrawLargeAreaBlur_.first = false;
117     predictDrawLargeAreaBlur_.second = false;
118 }
119 } // namespace Rosen
120 } // namespace OHOS
121