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 "monitor/self_drawing_node_monitor.h"
17 #include "platform/common/rs_log.h"
18 #include "rs_trace.h"
19 namespace OHOS {
20 namespace Rosen {
21
GetInstance()22 SelfDrawingNodeMonitor &SelfDrawingNodeMonitor::GetInstance()
23 {
24 static SelfDrawingNodeMonitor monitor;
25 return monitor;
26 }
27
InsertCurRectMap(NodeId id,std::string nodeName,RectI rect)28 void SelfDrawingNodeMonitor::InsertCurRectMap(NodeId id, std::string nodeName, RectI rect)
29 {
30 curRect_[id] = std::make_pair(nodeName, rect);
31 }
32
EraseCurRectMap(NodeId id)33 void SelfDrawingNodeMonitor::EraseCurRectMap(NodeId id)
34 {
35 curRect_.erase(id);
36 }
37
ClearRectMap()38 void SelfDrawingNodeMonitor::ClearRectMap()
39 {
40 curRect_.clear();
41 lastRect_.clear();
42 }
43
GetCallingPid() const44 pid_t SelfDrawingNodeMonitor::GetCallingPid() const
45 {
46 return callingPid_;
47 }
48
RegisterRectChangeCallback(pid_t pid,sptr<RSISelfDrawingNodeRectChangeCallback> callback)49 void SelfDrawingNodeMonitor::RegisterRectChangeCallback(
50 pid_t pid, sptr<RSISelfDrawingNodeRectChangeCallback> callback)
51 {
52 if (isListeningEnabled_) {
53 RS_LOGI("SelfDrawingNodeRectChangeCallback has registered");
54 return;
55 }
56 callingPid_ = pid;
57 isListeningEnabled_ = true;
58 rectChangeCallbackListenner_ = std::make_pair(pid, callback);
59 }
60
UnRegisterRectChangeCallback(pid_t pid)61 void SelfDrawingNodeMonitor::UnRegisterRectChangeCallback(pid_t pid)
62 {
63 isListeningEnabled_ = false;
64 }
65
TriggerRectChangeCallback()66 void SelfDrawingNodeMonitor::TriggerRectChangeCallback()
67 {
68 if (!isListeningEnabled_) {
69 return;
70 }
71
72 if (curRect_ != lastRect_) {
73 RS_TRACE_NAME("SelfDrawingNodeMonitor::TriggerRectChangeCallback");
74 if (rectChangeCallbackListenner_.second) {
75 rectChangeCallbackListenner_.second->OnSelfDrawingNodeRectChange(
76 std::make_shared<RSSelfDrawingNodeRectData>(curRect_));
77 } else {
78 RS_LOGE("SelfDrawingNodeMonitor::TriggerRectChangeCallback callback is null");
79 }
80 lastRect_ = curRect_;
81 }
82 }
83 } // namespace Rosen
84 } // namespace OHOS