1 /*
2 * Copyright (c) 2024 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 <cstddef>
17 #include "gtest/gtest.h"
18 #include "skia_adapter/skia_gpu_context.h"
19 #include "text/font.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaGPUContextTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void SkiaGPUContextTest::SetUpTestCase() {}
TearDownTestCase()36 void SkiaGPUContextTest::TearDownTestCase() {}
SetUp()37 void SkiaGPUContextTest::SetUp() {}
TearDown()38 void SkiaGPUContextTest::TearDown() {}
39
40 #ifdef RS_ENABLE_VK
41 /**
42 * @tc.name: BuildFromVK001
43 * @tc.desc: Test BuildFromVK
44 * @tc.type: FUNC
45 * @tc.require: I91F9L
46 */
47 HWTEST_F(SkiaGPUContextTest, BuildFromVK001, TestSize.Level1)
48 {
49 auto gpuContext = std::make_shared<SkiaGPUContext>();
50 ASSERT_TRUE(gpuContext != nullptr);
51 GrVkBackendContext grVkBackendContext;
52 gpuContext->BuildFromVK(grVkBackendContext);
53 }
54
55 /**
56 * @tc.name: storeVkPipelineCacheData001
57 * @tc.desc: Test storeVkPipelineCacheData
58 * @tc.type: FUNC
59 * @tc.require: I91F9L
60 */
61 HWTEST_F(SkiaGPUContextTest, storeVkPipelineCacheData001, TestSize.Level1)
62 {
63 auto gpuContext = std::make_shared<SkiaGPUContext>();
64 ASSERT_TRUE(gpuContext != nullptr);
65 gpuContext->storeVkPipelineCacheData();
66 #ifdef NEW_SKIA
67 GrMockOptions options;
68 gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
69 #endif
70 gpuContext->storeVkPipelineCacheData();
71 }
72 #endif
73
74 /**
75 * @tc.name: GetResourceCacheUsage001
76 * @tc.desc: Test GetResourceCacheUsage
77 * @tc.type: FUNC
78 * @tc.require: I91F9L
79 */
80 HWTEST_F(SkiaGPUContextTest, GetResourceCacheUsage001, TestSize.Level1)
81 {
82 auto gpuContext = std::make_shared<SkiaGPUContext>();
83 ASSERT_TRUE(gpuContext != nullptr);
84 gpuContext->GetResourceCacheUsage(nullptr, nullptr);
85 #ifdef NEW_SKIA
86 GrMockOptions options;
87 gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
88 #endif
89 int resourceCount = 1;
90 size_t resourceBytes = 1;
91 gpuContext->GetResourceCacheUsage(&resourceCount, &resourceBytes);
92 }
93
94 /**
95 * @tc.name: FreeGpuResources001
96 * @tc.desc: Test FreeGpuResources
97 * @tc.type: FUNC
98 * @tc.require: I91F9L
99 */
100 HWTEST_F(SkiaGPUContextTest, FreeGpuResources001, TestSize.Level1)
101 {
102 auto gpuContext = std::make_shared<SkiaGPUContext>();
103 ASSERT_TRUE(gpuContext != nullptr);
104 gpuContext->FreeGpuResources();
105 }
106
107 /**
108 * @tc.name: DumpGpuStats001
109 * @tc.desc: Test DumpGpuStats
110 * @tc.type: FUNC
111 * @tc.require: I91F9L
112 */
113 HWTEST_F(SkiaGPUContextTest, DumpGpuStats001, TestSize.Level1)
114 {
115 auto gpuContext = std::make_shared<SkiaGPUContext>();
116 ASSERT_TRUE(gpuContext != nullptr);
117 std::string out = "11";
118 gpuContext->DumpGpuStats(out);
119 }
120
121 /**
122 * @tc.name: ReleaseResourcesAndAbandonContext001
123 * @tc.desc: Test ReleaseResourcesAndAbandonContext
124 * @tc.type: FUNC
125 * @tc.require: I91F9L
126 */
127 HWTEST_F(SkiaGPUContextTest, ReleaseResourcesAndAbandonContext001, TestSize.Level1)
128 {
129 auto gpuContext = std::make_shared<SkiaGPUContext>();
130 ASSERT_TRUE(gpuContext != nullptr);
131 gpuContext->ReleaseResourcesAndAbandonContext();
132 #ifdef NEW_SKIA
133 GrMockOptions options;
134 gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
135 #endif
136 gpuContext->ReleaseResourcesAndAbandonContext();
137 }
138
139 /**
140 * @tc.name: PurgeUnlockedResources001
141 * @tc.desc: Test PurgeUnlockedResources
142 * @tc.type: FUNC
143 * @tc.require: I91F9L
144 */
145 HWTEST_F(SkiaGPUContextTest, PurgeUnlockedResources001, TestSize.Level1)
146 {
147 auto gpuContext = std::make_shared<SkiaGPUContext>();
148 ASSERT_TRUE(gpuContext != nullptr);
149 gpuContext->PurgeUnlockedResources(true);
150 }
151
152 /**
153 * @tc.name: PurgeUnlockedResourcesByTag001
154 * @tc.desc: Test PurgeUnlockedResourcesByTag
155 * @tc.type: FUNC
156 * @tc.require: I91F9L
157 */
158 HWTEST_F(SkiaGPUContextTest, PurgeUnlockedResourcesByTag001, TestSize.Level1)
159 {
160 auto gpuContext = std::make_shared<SkiaGPUContext>();
161 ASSERT_TRUE(gpuContext != nullptr);
162 GPUResourceTag tag;
163 gpuContext->PurgeUnlockedResourcesByTag(true, tag);
164 #ifdef NEW_SKIA
165 GrMockOptions options;
166 gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
167 #endif
168 gpuContext->PurgeUnlockedResourcesByTag(true, tag);
169 }
170
171 /**
172 * @tc.name: PurgeUnlockAndSafeCacheGpuResources001
173 * @tc.desc: Test PurgeUnlockAndSafeCacheGpuResources
174 * @tc.type: FUNC
175 * @tc.require: I91F9L
176 */
177 HWTEST_F(SkiaGPUContextTest, PurgeUnlockAndSafeCacheGpuResources001, TestSize.Level1)
178 {
179 auto gpuContext = std::make_shared<SkiaGPUContext>();
180 ASSERT_TRUE(gpuContext != nullptr);
181 gpuContext->PurgeUnlockAndSafeCacheGpuResources();
182 }
183
184 /**
185 * @tc.name: Submit001
186 * @tc.desc: Test Submit
187 * @tc.type: FUNC
188 * @tc.require: I91F9L
189 */
190 HWTEST_F(SkiaGPUContextTest, Submit001, TestSize.Level1)
191 {
192 auto gpuContext = std::make_shared<SkiaGPUContext>();
193 ASSERT_TRUE(gpuContext != nullptr);
194 gpuContext->Submit();
195 }
196
197 /**
198 * @tc.name: ReleaseByTag001
199 * @tc.desc: Test ReleaseByTag
200 * @tc.type: FUNC
201 * @tc.require: I91F9L
202 */
203 HWTEST_F(SkiaGPUContextTest, ReleaseByTag001, TestSize.Level1)
204 {
205 auto gpuContext = std::make_shared<SkiaGPUContext>();
206 ASSERT_TRUE(gpuContext != nullptr);
207 GPUResourceTag tag;
208 gpuContext->ReleaseByTag(tag);
209 #ifdef NEW_SKIA
210 GrMockOptions options;
211 gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
212 #endif
213 gpuContext->ReleaseByTag(tag);
214 }
215
216 /**
217 * @tc.name: DumpMemoryStatisticsByTag001
218 * @tc.desc: Test DumpMemoryStatisticsByTag
219 * @tc.type: FUNC
220 * @tc.require: I91F9L
221 */
222 HWTEST_F(SkiaGPUContextTest, DumpMemoryStatisticsByTag001, TestSize.Level1)
223 {
224 auto gpuContext = std::make_shared<SkiaGPUContext>();
225 ASSERT_TRUE(gpuContext != nullptr);
226 GPUResourceTag tag;
227 gpuContext->DumpMemoryStatisticsByTag(nullptr, tag);
228 #ifdef NEW_SKIA
229 GrMockOptions options;
230 gpuContext->SetGrContext(GrDirectContext::MakeMock(&options));
231 #endif
232 gpuContext->DumpMemoryStatisticsByTag(nullptr, tag);
233 }
234
235 /**
236 * @tc.name: DumpMemoryStatistics001
237 * @tc.desc: Test DumpMemoryStatistics
238 * @tc.type: FUNC
239 * @tc.require: I91F9L
240 */
241 HWTEST_F(SkiaGPUContextTest, DumpMemoryStatistics001, TestSize.Level1)
242 {
243 auto gpuContext = std::make_shared<SkiaGPUContext>();
244 ASSERT_TRUE(gpuContext != nullptr);
245 gpuContext->DumpMemoryStatistics(nullptr);
246 }
247
248 /**
249 * @tc.name: SetCurrentGpuResourceTag001
250 * @tc.desc: Test SetCurrentGpuResourceTag
251 * @tc.type: FUNC
252 * @tc.require: I91F9L
253 */
254 HWTEST_F(SkiaGPUContextTest, SetCurrentGpuResourceTag001, TestSize.Level1)
255 {
256 auto gpuContext = std::make_shared<SkiaGPUContext>();
257 ASSERT_TRUE(gpuContext != nullptr);
258 GPUResourceTag gPUResourceTag;
259 gpuContext->SetCurrentGpuResourceTag(gPUResourceTag);
260 }
261 } // namespace Drawing
262 } // namespace Rosen
263 } // namespace OHOS