• 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 "memory/rs_tag_tracker.h"
17 
18 #include "platform/common/rs_log.h"
19 
20 namespace OHOS::Rosen {
21 ReleaseGpuResourceType RSTagTracker::releaseGpuResourceEnable_ = ReleaseGpuResourceType::DISABLED;
22 #if defined(NEW_SKIA)
RSTagTracker(GrDirectContext * grContext,RSTagTracker::TAGTYPE tagType)23 RSTagTracker::RSTagTracker(GrDirectContext* grContext, RSTagTracker::TAGTYPE tagType)
24 #else
25 RSTagTracker::RSTagTracker(GrContext* grContext, RSTagTracker::TAGTYPE tagType)
26 #endif
27     : grContext_(grContext)
28 {
29     if (!grContext_) {
30         RS_LOGE("RSTagTracker tag fail, grContext is nullptr");
31         return;
32     }
33     if (releaseGpuResourceEnable_ == ReleaseGpuResourceType::DISABLED) {
34         return;
35     }
36 #ifdef RS_ENABLE_GL
37     GrGpuResourceTag tag(0, 0, 0, tagType);
38     grContext_->setCurrentGrResourceTag(tag);
39 #endif
40 }
41 
UpdateReleaseGpuResourceEnable(ReleaseGpuResourceType releaseResEnable)42 void RSTagTracker::UpdateReleaseGpuResourceEnable(ReleaseGpuResourceType releaseResEnable)
43 {
44     releaseGpuResourceEnable_ = releaseResEnable;
45 }
46 
TagType2String(TAGTYPE type)47 std::string RSTagTracker::TagType2String(TAGTYPE type)
48 {
49     std::string tagType;
50     switch (type) {
51         case TAG_SAVELAYER_DRAW_NODE :
52             tagType = "savelayer_draw_node";
53             break;
54         case TAG_RESTORELAYER_DRAW_NODE :
55             tagType = "restorelayer_draw_node";
56             break;
57         case TAG_SAVELAYER_COLOR_FILTER :
58             tagType = "savelayer_color_filter";
59             break;
60         case TAG_FILTER :
61             tagType = "filter";
62             break;
63         case TAG_CAPTURE :
64             tagType = "capture";
65             break;
66         case TAG_COLD_START :
67             tagType = "cold_start";
68             break;
69         case TAG_SUB_THREAD :
70             tagType = "sub_thread";
71             break;
72         case TAG_ACQUIRE_SURFACE :
73             tagType = "acquire_surface";
74             break;
75         case TAG_RENDER_FRAME :
76             tagType = "render_frame";
77             break;
78         case TAG_DRAW_SURFACENODE :
79             tagType = "draw_surface_node";
80             break;
81         default :
82             tagType = "";
83             break;
84     }
85     return tagType;
86 }
87 
88 #if defined(NEW_SKIA)
RSTagTracker(GrDirectContext * grContext,NodeId nodeId,RSTagTracker::TAGTYPE tagType)89 RSTagTracker::RSTagTracker(GrDirectContext* grContext, NodeId nodeId, RSTagTracker::TAGTYPE tagType)
90 #else
91 RSTagTracker::RSTagTracker(GrContext* grContext, NodeId nodeId, RSTagTracker::TAGTYPE tagType)
92 #endif
93     : grContext_(grContext)
94 {
95     if (!grContext_) {
96         RS_LOGE("RSTagTracker tag fail, grContext is nullptr");
97         return;
98     }
99     if (releaseGpuResourceEnable_ == ReleaseGpuResourceType::DISABLED) {
100         return;
101     }
102 #ifdef RS_ENABLE_GL
103     GrGpuResourceTag tag(ExtractPid(nodeId), 0, nodeId, tagType);
104     grContext_->setCurrentGrResourceTag(tag);
105 #endif
106 }
107 
108 #if defined(NEW_SKIA)
RSTagTracker(GrDirectContext * grContext,GrGpuResourceTag & tag)109 RSTagTracker::RSTagTracker(GrDirectContext* grContext, GrGpuResourceTag& tag)
110 #else
111 RSTagTracker::RSTagTracker(GrContext* grContext, GrGpuResourceTag& tag)
112 #endif
113     : grContext_(grContext)
114 {
115     if (!grContext_) {
116         RS_LOGE("RSTagTracker tag fail, grContext is nullptr");
117         return;
118     }
119     if (releaseGpuResourceEnable_ == ReleaseGpuResourceType::DISABLED) {
120         return;
121     }
122 #ifdef RS_ENABLE_GL
123     grContext_->setCurrentGrResourceTag(tag);
124 #endif
125 }
126 
SetTagEnd()127 void RSTagTracker::SetTagEnd()
128 {
129     if (!grContext_) {
130         RS_LOGE("RSTagTracker tag fail, grContext is nullptr");
131         return;
132     }
133     if (releaseGpuResourceEnable_ == ReleaseGpuResourceType::DISABLED) {
134         return;
135     }
136     isSetTagEnd_ = true;
137 #ifdef RS_ENABLE_GL
138     GrGpuResourceTag tagEnd;
139     grContext_->setCurrentGrResourceTag(tagEnd);
140 #endif
141 }
142 
~RSTagTracker()143 RSTagTracker::~RSTagTracker()
144 {
145     if (releaseGpuResourceEnable_ == ReleaseGpuResourceType::DISABLED) {
146         return;
147     }
148 #ifdef RS_ENABLE_GL
149     // Set empty tag to notify skia that the tag is complete
150     if (!isSetTagEnd_ && grContext_) {
151         GrGpuResourceTag tagEnd;
152         grContext_->setCurrentGrResourceTag(tagEnd);
153     }
154 #endif
155 }
156 } // namespace OHOS::Rosen