1 /*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 // This is a Vulkan protected memory specific test.
9
10 #include "include/core/SkTypes.h"
11
12 #if defined(SK_VULKAN)
13
14 #include "include/core/SkAlphaType.h"
15 #include "include/core/SkBitmap.h"
16 #include "include/core/SkBlendMode.h"
17 #include "include/core/SkBlurTypes.h"
18 #include "include/core/SkCanvas.h"
19 #include "include/core/SkColor.h"
20 #include "include/core/SkColorSpace.h"
21 #include "include/core/SkColorType.h"
22 #include "include/core/SkImageInfo.h"
23 #include "include/core/SkMaskFilter.h"
24 #include "include/core/SkPaint.h"
25 #include "include/core/SkPath.h"
26 #include "include/core/SkRect.h"
27 #include "include/core/SkRefCnt.h"
28 #include "include/core/SkSurface.h"
29 #include "include/gpu/GpuTypes.h"
30 #include "include/gpu/ganesh/GrTypes.h"
31 #include "tests/CtsEnforcement.h"
32 #include "tests/Test.h"
33 #include "tools/gpu/vk/VkTestHelper.h"
34
35 #if defined(SK_GANESH)
36 #include "include/gpu/ganesh/GrBackendSurface.h"
37 #include "include/gpu/ganesh/GrDirectContext.h"
38 #include "include/gpu/ganesh/SkSurfaceGanesh.h"
39 #endif
40
41 #if defined(SK_GRAPHITE)
42 #include "include/gpu/graphite/BackendTexture.h"
43 #include "include/gpu/graphite/Context.h"
44 #include "include/gpu/graphite/Recorder.h"
45 #include "include/gpu/graphite/TextureInfo.h"
46 #include "include/gpu/graphite/vk/VulkanGraphiteTypes.h"
47 #endif
48
49 #include <memory>
50 #include <utility>
51
52 struct GrContextOptions;
53
54 static const int kSize = 8;
55
56 namespace {
57
create_nonprotected_context(skiatest::Reporter * reporter,skiatest::TestType testType)58 void create_nonprotected_context(skiatest::Reporter* reporter, skiatest::TestType testType) {
59 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ false);
60 REPORTER_ASSERT(reporter, helper);
61 }
62
63 } // anonymous namespace
64
DEF_GANESH_TEST(VkProtectedContext_CreateNonprotectedContext,reporter,options,CtsEnforcement::kNever)65 DEF_GANESH_TEST(VkProtectedContext_CreateNonprotectedContext,
66 reporter,
67 options,
68 CtsEnforcement::kNever) {
69 create_nonprotected_context(reporter, skiatest::TestType::kGanesh);
70 }
71
72 #if defined(SK_GRAPHITE)
73
DEF_GRAPHITE_TEST(VkProtectedContext_CreateNonprotectedContext_Graphite,reporter,CtsEnforcement::kNextRelease)74 DEF_GRAPHITE_TEST(VkProtectedContext_CreateNonprotectedContext_Graphite,
75 reporter,
76 CtsEnforcement::kNextRelease) {
77 create_nonprotected_context(reporter, skiatest::TestType::kGraphite);
78 }
79
80 #endif
81
DEF_GANESH_TEST(VkProtectedContext_CreateProtectedContext,reporter,options,CtsEnforcement::kNever)82 DEF_GANESH_TEST(VkProtectedContext_CreateProtectedContext,
83 reporter,
84 options,
85 CtsEnforcement::kNever) {
86 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(skiatest::TestType::kGanesh,
87 /* isProtected= */ true);
88 }
89
DEF_GRAPHITE_TEST(VkProtectedContext_CreateProtectedContext_Graphite,reporter,CtsEnforcement::kNextRelease)90 DEF_GRAPHITE_TEST(VkProtectedContext_CreateProtectedContext_Graphite,
91 reporter,
92 CtsEnforcement::kNextRelease) {
93 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(skiatest::TestType::kGraphite,
94 /* isProtected= */ true);
95 }
96
97 namespace {
98
create_protected_surface(skiatest::Reporter * reporter,skiatest::TestType testType)99 void create_protected_surface(skiatest::Reporter* reporter, skiatest::TestType testType) {
100
101 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
102 if (!helper) {
103 return;
104 }
105
106 REPORTER_ASSERT(reporter, helper->isValid());
107
108 sk_sp<SkSurface> textureable = helper->createSurface({ kSize, kSize },
109 /* textureable= */ true,
110 /* isProtected= */ true);
111 REPORTER_ASSERT(reporter, textureable);
112
113 sk_sp<SkSurface> untextureable = helper->createSurface({ kSize, kSize },
114 /* textureable= */ false,
115 /* isProtected= */ true);
116 REPORTER_ASSERT(reporter, untextureable);
117 }
118
119 } // anonymous namespace
120
DEF_GANESH_TEST(VkProtectedContext_CreateProtectedSkSurface,reporter,options,CtsEnforcement::kNever)121 DEF_GANESH_TEST(VkProtectedContext_CreateProtectedSkSurface,
122 reporter,
123 options,
124 CtsEnforcement::kNever) {
125 create_protected_surface(reporter, skiatest::TestType::kGanesh);
126 }
127
DEF_GRAPHITE_TEST(VkProtectedContext_CreateProtectedSkSurface_Graphite,reporter,CtsEnforcement::kNextRelease)128 DEF_GRAPHITE_TEST(VkProtectedContext_CreateProtectedSkSurface_Graphite,
129 reporter,
130 CtsEnforcement::kNextRelease) {
131 create_protected_surface(reporter, skiatest::TestType::kGraphite);
132 }
133
134 namespace {
135
create_backend_texture_ganesh(skiatest::Reporter * reporter,bool contextIsProtected,bool beTexIsProtected)136 void create_backend_texture_ganesh(skiatest::Reporter* reporter,
137 bool contextIsProtected,
138 bool beTexIsProtected) {
139
140 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(skiatest::TestType::kGanesh,
141 contextIsProtected);
142 if (!helper) {
143 return;
144 }
145
146 REPORTER_ASSERT(reporter, helper->isValid());
147 GrDirectContext* dContext = helper->directContext();
148
149 GrBackendTexture backendTex = dContext->createBackendTexture(kSize,
150 kSize,
151 kRGBA_8888_SkColorType,
152 skgpu::Mipmapped::kNo,
153 GrRenderable::kNo,
154 GrProtected(beTexIsProtected));
155
156 REPORTER_ASSERT(reporter, backendTex.isValid() == (contextIsProtected == beTexIsProtected));
157 if (backendTex.isValid()) {
158 REPORTER_ASSERT(reporter, backendTex.isProtected() == beTexIsProtected);
159 }
160
161 dContext->deleteBackendTexture(backendTex);
162 }
163
164 } // anonymous namespace
165
DEF_GANESH_TEST(VkProtectedContext_CreateBackendTextures,reporter,options,CtsEnforcement::kNever)166 DEF_GANESH_TEST(VkProtectedContext_CreateBackendTextures,
167 reporter,
168 options,
169 CtsEnforcement::kNever) {
170 for (bool contextIsProtected : { true, false }) {
171 for (bool beTexIsProtected : { true, false }) {
172 create_backend_texture_ganesh(reporter, contextIsProtected, beTexIsProtected);
173 }
174 }
175 }
176
177 #if defined(SK_GRAPHITE)
178
179 namespace {
180
create_backend_texture_graphite(skiatest::Reporter * reporter,bool contextIsProtected,bool beTexIsProtected)181 void create_backend_texture_graphite(skiatest::Reporter* reporter,
182 bool contextIsProtected,
183 bool beTexIsProtected) {
184 using namespace skgpu::graphite;
185
186 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(skiatest::TestType::kGraphite,
187 contextIsProtected);
188 if (!helper) {
189 return;
190 }
191
192 REPORTER_ASSERT(reporter, helper->isValid());
193
194 VulkanTextureInfo vkTextureInfo;
195 vkTextureInfo.fFlags = beTexIsProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
196 vkTextureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
197 vkTextureInfo.fImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT |
198 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
199 VK_IMAGE_USAGE_TRANSFER_DST_BIT;
200 TextureInfo textureInfo = TextureInfos::MakeVulkan(vkTextureInfo);
201
202 BackendTexture backendTex = helper->recorder()->createBackendTexture({ kSize, kSize },
203 textureInfo);
204 REPORTER_ASSERT(reporter, backendTex.isValid() == (contextIsProtected == beTexIsProtected));
205 if (backendTex.isValid()) {
206 REPORTER_ASSERT(reporter,
207 backendTex.info().isProtected() == skgpu::Protected(beTexIsProtected));
208 }
209
210 helper->recorder()->deleteBackendTexture(backendTex);
211 }
212
213 } // anonymous namespace
214
DEF_GRAPHITE_TEST(VkProtectedContext_CreateBackendTextures_Graphite,reporter,CtsEnforcement::kNextRelease)215 DEF_GRAPHITE_TEST(VkProtectedContext_CreateBackendTextures_Graphite,
216 reporter,
217 CtsEnforcement::kNextRelease) {
218 for (bool contextIsProtected : { true, false }) {
219 for (bool beTexIsProtected : { true, false }) {
220 create_backend_texture_graphite(reporter, contextIsProtected, beTexIsProtected);
221 }
222 }
223 }
224
225 #endif // SK_GRAPHITE
226
DEF_GANESH_TEST(VkProtectedContext_ReadFromProtectedSurface,reporter,options,CtsEnforcement::kNever)227 DEF_GANESH_TEST(VkProtectedContext_ReadFromProtectedSurface,
228 reporter,
229 options,
230 CtsEnforcement::kNever) {
231 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(skiatest::TestType::kGanesh,
232 /* isProtected= */ true);
233 if (!helper) {
234 return;
235 }
236
237 REPORTER_ASSERT(reporter, helper->isValid());
238
239 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
240 /* textureable= */ true,
241 /* isProtected= */ true);
242 REPORTER_ASSERT(reporter, surface);
243 REPORTER_ASSERT(reporter, !surface->readPixels(SkImageInfo(), nullptr, 8, 0, 0));
244 }
245
246 // Graphite does not perform Copy-on-Write which is why there is no DEF_GRAPHITE_TEST correlate
DEF_GANESH_TEST(VkProtectedContext_CopyOnWrite,reporter,options,CtsEnforcement::kNever)247 DEF_GANESH_TEST(VkProtectedContext_CopyOnWrite,
248 reporter,
249 options,
250 CtsEnforcement::kNever) {
251 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(skiatest::TestType::kGanesh,
252 /* isProtected= */ true);
253 if (!helper) {
254 return;
255 }
256
257 REPORTER_ASSERT(reporter, helper->isValid());
258
259 GrDirectContext* dContext = helper->directContext();
260
261 SkImageInfo ii = SkImageInfo::Make({ kSize, kSize },
262 kRGBA_8888_SkColorType,
263 kPremul_SkAlphaType);
264
265 // We can't use VkTestHelper::createSurface here bc that will wrap a backend
266 // texture which blocks the copy-on-write-behavior
267 sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(dContext,
268 skgpu::Budgeted::kNo,
269 ii,
270 /* sampleCount= */ 1,
271 kBottomLeft_GrSurfaceOrigin,
272 /* surfaceProps= */ nullptr,
273 /* shouldCreateWithMips= */ false,
274 /* isProtected= */ true);
275
276
277 REPORTER_ASSERT(reporter, surface);
278 SkCanvas* canvas = surface->getCanvas();
279 REPORTER_ASSERT(reporter, canvas);
280
281 sk_sp<SkImage> imageBefore = surface->makeImageSnapshot();
282 REPORTER_ASSERT(reporter, imageBefore);
283 REPORTER_ASSERT(reporter, imageBefore->isProtected());
284
285 SkPaint paint;
286 paint.setColor(SK_ColorBLACK);
287 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
288
289 sk_sp<SkImage> imageAfter = surface->makeImageSnapshot();
290 REPORTER_ASSERT(reporter, imageAfter);
291 REPORTER_ASSERT(reporter, imageAfter->isProtected());
292
293 REPORTER_ASSERT(reporter, imageBefore != imageAfter);
294
295 SkBitmap readback;
296 readback.allocPixels(imageAfter->imageInfo());
297 REPORTER_ASSERT(reporter, !imageAfter->readPixels(dContext, readback.pixmap(), 0, 0));
298 }
299
300 namespace {
301
302 struct AsyncContext {
303 bool fCalled = false;
304 std::unique_ptr<const SkSurface::AsyncReadResult> fResult;
305 };
306
async_callback(void * c,std::unique_ptr<const SkSurface::AsyncReadResult> result)307 void async_callback(void* c, std::unique_ptr<const SkSurface::AsyncReadResult> result) {
308 auto context = static_cast<AsyncContext*>(c);
309 context->fResult = std::move(result);
310 context->fCalled = true;
311 }
312
async_read_from_protected_surface(skiatest::Reporter * reporter,skiatest::TestType testType)313 void async_read_from_protected_surface(skiatest::Reporter* reporter, skiatest::TestType testType) {
314 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
315 if (!helper) {
316 return;
317 }
318
319 REPORTER_ASSERT(reporter, helper->isValid());
320
321 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
322 /* textureable= */ true,
323 /* isProtected= */ true);
324 REPORTER_ASSERT(reporter, surface);
325 AsyncContext cbContext;
326 const SkImageInfo imageInfo = SkImageInfo::Make(6, 6, kRGBA_8888_SkColorType,
327 kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
328
329 if (testType == skiatest::TestType::kGanesh) {
330 surface->asyncRescaleAndReadPixelsYUV420(kIdentity_SkYUVColorSpace,
331 SkColorSpace::MakeSRGB(),
332 imageInfo.bounds(),
333 imageInfo.dimensions(),
334 SkSurface::RescaleGamma::kSrc,
335 SkSurface::RescaleMode::kNearest,
336 &async_callback,
337 &cbContext);
338 }
339 #if defined(SK_GRAPHITE)
340 else {
341 // Graphite deprecates SkSurface::asyncRescaleAndReadPixelsYUVA420 in favor of
342 // Context::asyncRescaleAndReadPixelsYUV420.
343 skgpu::graphite::Context* context = helper->context();
344
345 context->asyncRescaleAndReadPixelsYUV420(surface.get(),
346 kIdentity_SkYUVColorSpace,
347 SkColorSpace::MakeSRGB(),
348 imageInfo.bounds(),
349 imageInfo.dimensions(),
350 SkSurface::RescaleGamma::kSrc,
351 SkSurface::RescaleMode::kNearest,
352 &async_callback,
353 &cbContext);
354 }
355 #endif
356
357 helper->submitAndWaitForCompletion(&cbContext.fCalled);
358 REPORTER_ASSERT(reporter, !cbContext.fResult);
359 }
360
361 } // anonymous namespace
362
DEF_GANESH_TEST(VkProtectedContext_AsyncReadFromProtectedSurface,reporter,options,CtsEnforcement::kNever)363 DEF_GANESH_TEST(VkProtectedContext_AsyncReadFromProtectedSurface,
364 reporter,
365 options,
366 CtsEnforcement::kNever) {
367 async_read_from_protected_surface(reporter, skiatest::TestType::kGanesh);
368 }
369
DEF_GRAPHITE_TEST(VkProtectedContext_AsyncReadFromProtectedSurface_Graphite,reporter,CtsEnforcement::kNextRelease)370 DEF_GRAPHITE_TEST(VkProtectedContext_AsyncReadFromProtectedSurface_Graphite,
371 reporter,
372 CtsEnforcement::kNextRelease) {
373 async_read_from_protected_surface(reporter, skiatest::TestType::kGraphite);
374 }
375
376 namespace {
377
draw_rectangle(skiatest::Reporter * reporter,skiatest::TestType testType)378 void draw_rectangle(skiatest::Reporter* reporter, skiatest::TestType testType) {
379 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
380 if (!helper) {
381 return;
382 }
383
384 REPORTER_ASSERT(reporter, helper->isValid());
385
386 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
387 /* textureable= */ true,
388 /* isProtected= */ true);
389 REPORTER_ASSERT(reporter, surface);
390 SkCanvas* canvas = surface->getCanvas();
391 REPORTER_ASSERT(reporter, canvas);
392 SkPaint paint;
393 paint.setColor(SK_ColorBLACK);
394 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
395 }
396
397 } // anonymous namespace
398
DEF_GANESH_TEST(VkProtectedContext_DrawRectangle,reporter,options,CtsEnforcement::kNever)399 DEF_GANESH_TEST(VkProtectedContext_DrawRectangle,
400 reporter,
401 options,
402 CtsEnforcement::kNever) {
403 draw_rectangle(reporter, skiatest::TestType::kGanesh);
404 }
405
DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangle_Graphite,reporter,CtsEnforcement::kNextRelease)406 DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangle_Graphite,
407 reporter,
408 CtsEnforcement::kNextRelease) {
409 draw_rectangle(reporter, skiatest::TestType::kGraphite);
410 }
411
412 namespace {
413
draw_rectangle_with_aa(skiatest::Reporter * reporter,skiatest::TestType testType)414 void draw_rectangle_with_aa(skiatest::Reporter* reporter, skiatest::TestType testType) {
415 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
416 if (!helper) {
417 return;
418 }
419
420 REPORTER_ASSERT(reporter, helper->isValid());
421
422 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
423 /* textureable= */ true,
424 /* isProtected= */ true);
425 REPORTER_ASSERT(reporter, surface);
426 SkCanvas* canvas = surface->getCanvas();
427 REPORTER_ASSERT(reporter, canvas);
428 SkPaint paint;
429 paint.setColor(SK_ColorBLACK);
430 paint.setAntiAlias(true);
431 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
432 }
433
434 } // anonymous namespace
435
DEF_GANESH_TEST(VkProtectedContext_DrawRectangleWithAntiAlias,reporter,options,CtsEnforcement::kNever)436 DEF_GANESH_TEST(VkProtectedContext_DrawRectangleWithAntiAlias,
437 reporter,
438 options,
439 CtsEnforcement::kNever) {
440 draw_rectangle_with_aa(reporter, skiatest::TestType::kGanesh);
441 }
442
DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangleWithAntiAlias_Graphite,reporter,CtsEnforcement::kNextRelease)443 DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangleWithAntiAlias_Graphite,
444 reporter,
445 CtsEnforcement::kNextRelease) {
446 draw_rectangle_with_aa(reporter, skiatest::TestType::kGraphite);
447 }
448
449 namespace {
450
draw_rectangle_with_blendmode(skiatest::Reporter * reporter,skiatest::TestType testType)451 void draw_rectangle_with_blendmode(skiatest::Reporter* reporter, skiatest::TestType testType) {
452 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
453 if (!helper) {
454 return;
455 }
456
457 REPORTER_ASSERT(reporter, helper->isValid());
458
459 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
460 /* textureable= */ true,
461 /* isProtected= */ true);
462 REPORTER_ASSERT(reporter, surface);
463 SkCanvas* canvas = surface->getCanvas();
464 REPORTER_ASSERT(reporter, canvas);
465 SkPaint paint;
466 paint.setColor(SK_ColorBLACK);
467 paint.setBlendMode(SkBlendMode::kColorDodge);
468 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
469 }
470
471 } // anonymous namespace
472
DEF_GANESH_TEST(VkProtectedContext_DrawRectangleWithBlendMode,reporter,options,CtsEnforcement::kNever)473 DEF_GANESH_TEST(VkProtectedContext_DrawRectangleWithBlendMode,
474 reporter,
475 options,
476 CtsEnforcement::kNever) {
477 draw_rectangle_with_blendmode(reporter, skiatest::TestType::kGanesh);
478 }
479
DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangleWithBlendMode_Graphite,reporter,CtsEnforcement::kNextRelease)480 DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangleWithBlendMode_Graphite,
481 reporter,
482 CtsEnforcement::kNextRelease) {
483 draw_rectangle_with_blendmode(reporter, skiatest::TestType::kGraphite);
484 }
485
486 namespace {
487
draw_rectangle_with_filter(skiatest::Reporter * reporter,skiatest::TestType testType)488 void draw_rectangle_with_filter(skiatest::Reporter* reporter, skiatest::TestType testType) {
489 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
490 if (!helper) {
491 return;
492 }
493
494 REPORTER_ASSERT(reporter, helper->isValid());
495
496 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
497 /* textureable= */ true,
498 /* isProtected= */ true);
499 REPORTER_ASSERT(reporter, surface);
500 SkCanvas* canvas = surface->getCanvas();
501 REPORTER_ASSERT(reporter, canvas);
502 SkPaint paint;
503 paint.setColor(SK_ColorBLACK);
504 paint.setStyle(SkPaint::kFill_Style);
505 paint.setMaskFilter(SkMaskFilter::MakeBlur(SkBlurStyle::kOuter_SkBlurStyle, 30.0f));
506 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
507 }
508
509 } // anonymous namespace
510
DEF_GANESH_TEST(VkProtectedContext_DrawRectangleWithFilter,reporter,options,CtsEnforcement::kNever)511 DEF_GANESH_TEST(VkProtectedContext_DrawRectangleWithFilter,
512 reporter,
513 options,
514 CtsEnforcement::kNever) {
515 draw_rectangle_with_filter(reporter, skiatest::TestType::kGanesh);
516 }
517
DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangleWithFilter_Graphite,reporter,CtsEnforcement::kNextRelease)518 DEF_GRAPHITE_TEST(VkProtectedContext_DrawRectangleWithFilter_Graphite,
519 reporter,
520 CtsEnforcement::kNextRelease) {
521 draw_rectangle_with_filter(reporter, skiatest::TestType::kGraphite);
522 }
523
524 namespace {
525
draw_thin_path(skiatest::Reporter * reporter,skiatest::TestType testType)526 void draw_thin_path(skiatest::Reporter* reporter, skiatest::TestType testType) {
527 constexpr bool kIsProtected = true;
528
529 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, kIsProtected);
530 if (!helper) {
531 return;
532 }
533
534 REPORTER_ASSERT(reporter, helper->isValid());
535
536 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
537 /* textureable= */ true,
538 kIsProtected);
539 REPORTER_ASSERT(reporter, surface);
540 SkCanvas* canvas = surface->getCanvas();
541 REPORTER_ASSERT(reporter, canvas);
542 SkPaint paint;
543 paint.setColor(SK_ColorBLACK);
544 paint.setStyle(SkPaint::kStroke_Style);
545 paint.setAntiAlias(true);
546 paint.setStrokeWidth(.4f);
547 canvas->drawPath(SkPath().moveTo(4, 4).lineTo(6, 6), paint);
548 }
549
550 } // anonymous namespace
551
DEF_GANESH_TEST(VkProtectedContext_DrawThinPath,reporter,options,CtsEnforcement::kNever)552 DEF_GANESH_TEST(VkProtectedContext_DrawThinPath,
553 reporter,
554 options,
555 CtsEnforcement::kNever) {
556 draw_thin_path(reporter, skiatest::TestType::kGanesh);
557 }
558
DEF_GRAPHITE_TEST(VkProtectedContext_DrawThinPath_Graphite,reporter,CtsEnforcement::kNextRelease)559 DEF_GRAPHITE_TEST(VkProtectedContext_DrawThinPath_Graphite,
560 reporter,
561 CtsEnforcement::kNextRelease) {
562 draw_thin_path(reporter, skiatest::TestType::kGraphite);
563 }
564
565 namespace {
566
save_layer(skiatest::Reporter * reporter,skiatest::TestType testType)567 void save_layer(skiatest::Reporter* reporter, skiatest::TestType testType) {
568 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, /* isProtected= */ true);
569 if (!helper) {
570 return;
571 }
572
573 REPORTER_ASSERT(reporter, helper->isValid());
574
575 sk_sp<SkSurface> surface = helper->createSurface({ kSize, kSize },
576 /* textureable= */ true,
577 /* isProtected= */ true);
578 REPORTER_ASSERT(reporter, surface);
579 SkCanvas* canvas = surface->getCanvas();
580 REPORTER_ASSERT(reporter, canvas);
581 canvas->saveLayer(nullptr, nullptr);
582 SkPaint paint;
583 paint.setColor(SK_ColorBLACK);
584 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
585 canvas->restore();
586 }
587
588 } // anonymous namespace
589
DEF_GANESH_TEST(VkProtectedContext_SaveLayer,reporter,options,CtsEnforcement::kNever)590 DEF_GANESH_TEST(VkProtectedContext_SaveLayer,
591 reporter,
592 options,
593 CtsEnforcement::kNever) {
594 save_layer(reporter, skiatest::TestType::kGanesh);
595 }
596
DEF_GRAPHITE_TEST(VkProtectedContext_SaveLayer_Graphite,reporter,CtsEnforcement::kNextRelease)597 DEF_GRAPHITE_TEST(VkProtectedContext_SaveLayer_Graphite,
598 reporter,
599 CtsEnforcement::kNextRelease) {
600 save_layer(reporter, skiatest::TestType::kGraphite);
601 }
602
603 namespace {
604
draw_protected_image_on_protected_surface(skiatest::Reporter * reporter,skiatest::TestType testType)605 void draw_protected_image_on_protected_surface(skiatest::Reporter* reporter,
606 skiatest::TestType testType) {
607 constexpr bool kIsProtected = true;
608
609 std::unique_ptr<VkTestHelper> helper = VkTestHelper::Make(testType, kIsProtected);
610 if (!helper) {
611 return;
612 }
613
614 REPORTER_ASSERT(reporter, helper->isValid());
615
616 // Create protected image.
617 sk_sp<SkSurface> surface1 = helper->createSurface({ kSize, kSize },
618 /* textureable= */ true,
619 kIsProtected);
620 REPORTER_ASSERT(reporter, surface1);
621 sk_sp<SkImage> image = surface1->makeImageSnapshot();
622 REPORTER_ASSERT(reporter, image);
623 REPORTER_ASSERT(reporter, image->isProtected() == kIsProtected);
624
625 // Create protected canvas.
626 sk_sp<SkSurface> surface2 = helper->createSurface({ kSize, kSize },
627 /* textureable= */ true,
628 kIsProtected);
629 REPORTER_ASSERT(reporter, surface2);
630 SkCanvas* canvas = surface2->getCanvas();
631 REPORTER_ASSERT(reporter, canvas);
632
633 canvas->drawImage(image, 0, 0);
634 }
635
636 } // anonymous namespace
637
DEF_GANESH_TEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface,reporter,options,CtsEnforcement::kNever)638 DEF_GANESH_TEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface,
639 reporter,
640 options,
641 CtsEnforcement::kNever) {
642 draw_protected_image_on_protected_surface(reporter, skiatest::TestType::kGanesh);
643 }
644
DEF_GRAPHITE_TEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface_Graphite,reporter,CtsEnforcement::kNextRelease)645 DEF_GRAPHITE_TEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface_Graphite,
646 reporter,
647 CtsEnforcement::kNextRelease) {
648 draw_protected_image_on_protected_surface(reporter, skiatest::TestType::kGraphite);
649 }
650
651 #endif // SK_VULKAN
652