Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 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 SK_SUPPORT_GPU && defined(SK_VULKAN) |
| 13 | |
| 14 | #include "include/core/SkCanvas.h" |
| 15 | #include "include/core/SkMaskFilter.h" |
| 16 | #include "include/core/SkPaint.h" |
| 17 | #include "include/core/SkSurface.h" |
| 18 | #include "include/gpu/GrBackendSurface.h" |
| 19 | #include "include/gpu/vk/GrVkBackendContext.h" |
| 20 | #include "include/gpu/vk/GrVkExtensions.h" |
| 21 | #include "tests/Test.h" |
Brian Salomon | 60003f7 | 2020-10-08 16:05:35 -0400 | [diff] [blame] | 22 | #include "tools/gpu/BackendSurfaceFactory.h" |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 23 | #include "tools/gpu/GrContextFactory.h" |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 24 | #include "tools/gpu/vk/VkTestHelper.h" |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 25 | |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 26 | static sk_sp<SkSurface> create_protected_sksurface(GrDirectContext* dContext, |
Brian Salomon | 60003f7 | 2020-10-08 16:05:35 -0400 | [diff] [blame] | 27 | skiatest::Reporter* reporter, |
| 28 | bool textureable = true) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 29 | const int kW = 8; |
| 30 | const int kH = 8; |
Ben Wagner | ae4bb98 | 2020-09-24 14:49:00 -0400 | [diff] [blame] | 31 | SkSurfaceProps surfaceProps = SkSurfaceProps(0, kRGB_H_SkPixelGeometry); |
Brian Salomon | 60003f7 | 2020-10-08 16:05:35 -0400 | [diff] [blame] | 32 | sk_sp<SkSurface> surface; |
| 33 | if (textureable) { |
| 34 | surface = sk_gpu_test::MakeBackendTextureSurface(dContext, |
| 35 | {kW, kH}, |
| 36 | kTopLeft_GrSurfaceOrigin, |
| 37 | 1, |
| 38 | kRGBA_8888_SkColorType, |
| 39 | /* color space */ nullptr, |
| 40 | GrMipmapped::kNo, |
| 41 | GrProtected::kYes, |
| 42 | &surfaceProps); |
| 43 | } else { |
| 44 | surface = sk_gpu_test::MakeBackendRenderTargetSurface(dContext, |
| 45 | {kW, kH}, |
| 46 | kTopLeft_GrSurfaceOrigin, |
| 47 | 1, |
| 48 | kRGBA_8888_SkColorType, |
| 49 | /* color space */ nullptr, |
| 50 | GrProtected::kYes, |
| 51 | &surfaceProps); |
| 52 | } |
| 53 | if (!surface) { |
| 54 | ERRORF(reporter, "Could not create protected surface."); |
| 55 | return nullptr; |
| 56 | } |
| 57 | if (textureable) { |
| 58 | GrBackendTexture backendTex = |
| 59 | surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess); |
| 60 | REPORTER_ASSERT(reporter, backendTex.isValid()); |
| 61 | REPORTER_ASSERT(reporter, backendTex.isProtected()); |
| 62 | } else { |
| 63 | GrBackendRenderTarget backendRT = |
| 64 | surface->getBackendRenderTarget(SkSurface::kFlushRead_BackendHandleAccess); |
| 65 | REPORTER_ASSERT(reporter, backendRT.isValid()); |
| 66 | REPORTER_ASSERT(reporter, backendRT.isProtected()); |
| 67 | } |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 68 | return surface; |
| 69 | } |
| 70 | |
| 71 | DEF_GPUTEST(VkProtectedContext_CreateNonprotectedContext, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 72 | auto nonprotectedTestHelper = std::make_unique<VkTestHelper>(false); |
| 73 | REPORTER_ASSERT(reporter, nonprotectedTestHelper->init()); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 76 | DEF_GPUTEST(VkProtectedContext_CreateProtectedContext, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 77 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 78 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 79 | return; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | DEF_GPUTEST(VkProtectedContext_CreateProtectedSkSurface, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 84 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 85 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 86 | return; |
| 87 | } |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 88 | |
| 89 | auto dContext = protectedTestHelper->directContext(); |
| 90 | REPORTER_ASSERT(reporter, dContext != nullptr); |
Brian Salomon | 60003f7 | 2020-10-08 16:05:35 -0400 | [diff] [blame] | 91 | create_protected_sksurface(dContext, reporter, /*textureable*/ true); |
| 92 | create_protected_sksurface(dContext, reporter, /*textureable*/ false); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | DEF_GPUTEST(VkProtectedContext_CreateNonprotectedTextureInProtectedContext, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 96 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 97 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 98 | return; |
| 99 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 100 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 101 | |
| 102 | const int kW = 8; |
| 103 | const int kH = 8; |
| 104 | GrBackendTexture backendTex = |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 105 | protectedTestHelper->directContext()->createBackendTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 106 | kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 107 | GrProtected::kNo); |
| 108 | REPORTER_ASSERT(reporter, !backendTex.isValid()); |
| 109 | } |
| 110 | |
| 111 | DEF_GPUTEST(VkProtectedContext_CreateProtectedTextureInNonprotectedContext, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 112 | auto protectedTestHelper = std::make_unique<VkTestHelper>(false); |
| 113 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 114 | return; |
| 115 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 116 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 117 | |
| 118 | const int kW = 8; |
| 119 | const int kH = 8; |
| 120 | GrBackendTexture backendTex = |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 121 | protectedTestHelper->directContext()->createBackendTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 122 | kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 123 | GrProtected::kYes); |
| 124 | REPORTER_ASSERT(reporter, !backendTex.isValid()); |
| 125 | } |
| 126 | |
| 127 | DEF_GPUTEST(VkProtectedContext_ReadFromProtectedSurface, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 128 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 129 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 130 | return; |
| 131 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 132 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 133 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 134 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, surface); |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, !surface->readPixels(SkImageInfo(), nullptr, 8, 0, 0)); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 139 | namespace { |
| 140 | |
| 141 | struct AsyncContext { |
| 142 | bool fCalled = false; |
| 143 | std::unique_ptr<const SkSurface::AsyncReadResult> fResult; |
| 144 | }; |
| 145 | |
| 146 | static void async_callback(void* c, std::unique_ptr<const SkSurface::AsyncReadResult> result) { |
| 147 | auto context = static_cast<AsyncContext*>(c); |
| 148 | context->fResult = std::move(result); |
| 149 | context->fCalled = true; |
| 150 | }; |
| 151 | |
| 152 | } // anonymous namespace |
| 153 | |
| 154 | DEF_GPUTEST(VkProtectedContext_AsyncReadFromProtectedSurface, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 155 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 156 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 157 | return; |
| 158 | } |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 159 | |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 160 | auto dContext = protectedTestHelper->directContext(); |
Robert Phillips | b27b38b | 2020-07-10 16:23:47 -0400 | [diff] [blame] | 161 | |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 162 | REPORTER_ASSERT(reporter, dContext != nullptr); |
Robert Phillips | b27b38b | 2020-07-10 16:23:47 -0400 | [diff] [blame] | 163 | |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 164 | auto surface = create_protected_sksurface(dContext, reporter); |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 165 | REPORTER_ASSERT(reporter, surface); |
| 166 | AsyncContext cbContext; |
| 167 | const auto image_info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, |
| 168 | SkColorSpace::MakeSRGB()); |
| 169 | surface->asyncRescaleAndReadPixelsYUV420(kIdentity_SkYUVColorSpace, SkColorSpace::MakeSRGB(), |
| 170 | image_info.bounds(), image_info.dimensions(), |
Mike Reed | 1efa14d | 2021-01-02 21:44:59 -0500 | [diff] [blame] | 171 | SkSurface::RescaleGamma::kSrc, |
| 172 | SkSurface::RescaleMode::kNearest, |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 173 | &async_callback, &cbContext); |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 174 | dContext->submit(); |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 175 | while (!cbContext.fCalled) { |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 176 | dContext->checkAsyncWorkCompletion(); |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 177 | } |
| 178 | REPORTER_ASSERT(reporter, !cbContext.fResult); |
Emircan Uysaler | 7697476 | 2019-10-25 13:28:54 -0400 | [diff] [blame] | 179 | } |
| 180 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 181 | DEF_GPUTEST(VkProtectedContext_DrawRectangle, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 182 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 183 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 184 | return; |
| 185 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 186 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 187 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 188 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 189 | REPORTER_ASSERT(reporter, surface); |
| 190 | SkCanvas* canvas = surface->getCanvas(); |
| 191 | REPORTER_ASSERT(reporter, canvas); |
| 192 | SkPaint paint; |
| 193 | paint.setColor(SK_ColorBLACK); |
| 194 | canvas->drawRect(SkRect::MakeWH(4, 4), paint); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | DEF_GPUTEST(VkProtectedContext_DrawRectangleWithAntiAlias, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 198 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 199 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 200 | return; |
| 201 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 202 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 203 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 204 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 205 | REPORTER_ASSERT(reporter, surface); |
| 206 | SkCanvas* canvas = surface->getCanvas(); |
| 207 | REPORTER_ASSERT(reporter, canvas); |
| 208 | SkPaint paint; |
| 209 | paint.setColor(SK_ColorBLACK); |
| 210 | paint.setAntiAlias(true); |
| 211 | canvas->drawRect(SkRect::MakeWH(4, 4), paint); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | DEF_GPUTEST(VkProtectedContext_DrawRectangleWithBlendMode, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 215 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 216 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 217 | return; |
| 218 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 219 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 220 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 221 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 222 | REPORTER_ASSERT(reporter, surface); |
| 223 | SkCanvas* canvas = surface->getCanvas(); |
| 224 | REPORTER_ASSERT(reporter, canvas); |
| 225 | SkPaint paint; |
| 226 | paint.setColor(SK_ColorBLACK); |
| 227 | paint.setBlendMode(SkBlendMode::kColorDodge); |
| 228 | canvas->drawRect(SkRect::MakeWH(4, 4), paint); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | DEF_GPUTEST(VkProtectedContext_DrawRectangleWithFilter, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 232 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 233 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 234 | return; |
| 235 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 236 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 237 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 238 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 239 | REPORTER_ASSERT(reporter, surface); |
| 240 | SkCanvas* canvas = surface->getCanvas(); |
| 241 | REPORTER_ASSERT(reporter, canvas); |
| 242 | SkPaint paint; |
| 243 | paint.setColor(SK_ColorBLACK); |
| 244 | paint.setStyle(SkPaint::kFill_Style); |
| 245 | paint.setMaskFilter(SkMaskFilter::MakeBlur( |
| 246 | SkBlurStyle::kOuter_SkBlurStyle, 1.1f)); |
| 247 | canvas->drawRect(SkRect::MakeWH(4, 4), paint); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | DEF_GPUTEST(VkProtectedContext_DrawThinPath, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 251 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 252 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 253 | return; |
| 254 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 255 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 256 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 257 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 258 | REPORTER_ASSERT(reporter, surface); |
| 259 | SkCanvas* canvas = surface->getCanvas(); |
| 260 | REPORTER_ASSERT(reporter, canvas); |
| 261 | SkPaint paint; |
| 262 | paint.setColor(SK_ColorBLACK); |
| 263 | paint.setStyle(SkPaint::kStroke_Style); |
| 264 | paint.setAntiAlias(true); |
| 265 | paint.setStrokeWidth(.4f); |
| 266 | canvas->drawPath(SkPath().moveTo(4, 4).lineTo(6, 6), paint); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | DEF_GPUTEST(VkProtectedContext_SaveLayer, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 270 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 271 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 272 | return; |
| 273 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 274 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 275 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 276 | auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 277 | REPORTER_ASSERT(reporter, surface); |
| 278 | SkCanvas* canvas = surface->getCanvas(); |
| 279 | REPORTER_ASSERT(reporter, canvas); |
| 280 | canvas->saveLayer(nullptr, nullptr); |
| 281 | SkPaint paint; |
| 282 | paint.setColor(SK_ColorBLACK); |
| 283 | canvas->drawRect(SkRect::MakeWH(4, 4), paint); |
| 284 | canvas->restore(); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | |
| 288 | DEF_GPUTEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface, reporter, options) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 289 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 290 | if (!protectedTestHelper->init()) { |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 291 | return; |
| 292 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 293 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 294 | |
| 295 | // Create protected image. |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 296 | auto surface1 = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 297 | REPORTER_ASSERT(reporter, surface1); |
| 298 | auto image = surface1->makeImageSnapshot(); |
| 299 | REPORTER_ASSERT(reporter, image); |
| 300 | |
| 301 | // Create protected canvas. |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 302 | auto surface2 = create_protected_sksurface(protectedTestHelper->directContext(), reporter); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 303 | REPORTER_ASSERT(reporter, surface2); |
| 304 | SkCanvas* canvas = surface2->getCanvas(); |
| 305 | REPORTER_ASSERT(reporter, canvas); |
| 306 | |
| 307 | canvas->drawImage(image, 0, 0); |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 310 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 311 | // Test out DDLs using a protected Vulkan context |
| 312 | |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 313 | void DDLMakeRenderTargetTestImpl(GrDirectContext*, skiatest::Reporter*); |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 314 | |
| 315 | DEF_GPUTEST(VkProtectedContext_DDLMakeRenderTargetTest, reporter, ctxInfo) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 316 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 317 | if (!protectedTestHelper->init()) { |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 318 | return; |
| 319 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 320 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 321 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 322 | DDLMakeRenderTargetTestImpl(protectedTestHelper->directContext(), reporter); |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Robert Phillips | c8ae494 | 2020-07-20 10:56:01 -0400 | [diff] [blame] | 325 | void DDLSurfaceCharacterizationTestImpl(GrDirectContext*, skiatest::Reporter*); |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 326 | |
| 327 | DEF_GPUTEST(VkProtectedContext_DDLSurfaceCharacterizationTest, reporter, ctxInfo) { |
Robert Phillips | 0d6ce7c | 2020-06-11 08:51:50 -0400 | [diff] [blame] | 328 | auto protectedTestHelper = std::make_unique<VkTestHelper>(true); |
| 329 | if (!protectedTestHelper->init()) { |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 330 | return; |
| 331 | } |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 332 | REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr); |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 333 | |
Robert Phillips | 2a4acf3 | 2020-07-06 15:50:15 -0400 | [diff] [blame] | 334 | DDLSurfaceCharacterizationTestImpl(protectedTestHelper->directContext(), reporter); |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 337 | #endif // SK_SUPPORT_GPU && defined(SK_VULKAN) |