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