blob: 25ece8c94f2582694a17bf5e4d30f72397c70157 [file] [log] [blame]
Emircan Uysaler23ca4e72019-06-24 10:53:09 -04001/*
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"
22#include "tools/gpu/GrContextFactory.h"
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040023#include "tools/gpu/vk/VkTestHelper.h"
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040024
Robert Phillipsc8ae4942020-07-20 10:56:01 -040025static sk_sp<SkSurface> create_protected_sksurface(GrDirectContext* dContext,
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040026 skiatest::Reporter* reporter) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040027 const int kW = 8;
28 const int kH = 8;
Robert Phillipsc8ae4942020-07-20 10:56:01 -040029 GrBackendTexture backendTex = dContext->createBackendTexture(
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040030 kW, kH, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes, GrProtected::kYes);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040031 REPORTER_ASSERT(reporter, backendTex.isValid());
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040032 REPORTER_ASSERT(reporter, backendTex.isProtected());
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040033
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040034 SkSurfaceProps surfaceProps = SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
Greg Danieldd68b782020-05-12 14:17:44 -040035 sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
Robert Phillipsc8ae4942020-07-20 10:56:01 -040036 dContext, backendTex, kTopLeft_GrSurfaceOrigin, 1,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040037 kRGBA_8888_SkColorType, nullptr, &surfaceProps);
38 REPORTER_ASSERT(reporter, surface);
39 return surface;
40}
41
42DEF_GPUTEST(VkProtectedContext_CreateNonprotectedContext, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040043 auto nonprotectedTestHelper = std::make_unique<VkTestHelper>(false);
44 REPORTER_ASSERT(reporter, nonprotectedTestHelper->init());
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040045}
46
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040047DEF_GPUTEST(VkProtectedContext_CreateProtectedContext, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040048 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
49 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040050 return;
51 }
52}
53
54DEF_GPUTEST(VkProtectedContext_CreateProtectedSkSurface, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040055 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
56 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040057 return;
58 }
Robert Phillipsc8ae4942020-07-20 10:56:01 -040059
60 auto dContext = protectedTestHelper->directContext();
61 REPORTER_ASSERT(reporter, dContext != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040062
63 const int kW = 8;
64 const int kH = 8;
Robert Phillipsc8ae4942020-07-20 10:56:01 -040065 GrBackendTexture backendTex = dContext->createBackendTexture(kW, kH, kRGBA_8888_SkColorType,
66 GrMipMapped::kNo,
67 GrRenderable::kNo,
68 GrProtected::kYes);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040069 REPORTER_ASSERT(reporter, backendTex.isValid());
70 REPORTER_ASSERT(reporter, backendTex.isProtected());
71
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040072 SkSurfaceProps surfaceProps = SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040073 sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
Robert Phillipsc8ae4942020-07-20 10:56:01 -040074 dContext, backendTex, kTopLeft_GrSurfaceOrigin, 1,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040075 kRGBA_8888_SkColorType, nullptr, &surfaceProps);
76 REPORTER_ASSERT(reporter, surface);
77
Robert Phillipsc8ae4942020-07-20 10:56:01 -040078 dContext->deleteBackendTexture(backendTex);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040079}
80
81DEF_GPUTEST(VkProtectedContext_CreateNonprotectedTextureInProtectedContext, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040082 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
83 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040084 return;
85 }
Robert Phillips2a4acf32020-07-06 15:50:15 -040086 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040087
88 const int kW = 8;
89 const int kH = 8;
90 GrBackendTexture backendTex =
Robert Phillips2a4acf32020-07-06 15:50:15 -040091 protectedTestHelper->directContext()->createBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040092 kW, kH, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo,
93 GrProtected::kNo);
94 REPORTER_ASSERT(reporter, !backendTex.isValid());
95}
96
97DEF_GPUTEST(VkProtectedContext_CreateProtectedTextureInNonprotectedContext, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -040098 auto protectedTestHelper = std::make_unique<VkTestHelper>(false);
99 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400100 return;
101 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400102 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400103
104 const int kW = 8;
105 const int kH = 8;
106 GrBackendTexture backendTex =
Robert Phillips2a4acf32020-07-06 15:50:15 -0400107 protectedTestHelper->directContext()->createBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400108 kW, kH, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo,
109 GrProtected::kYes);
110 REPORTER_ASSERT(reporter, !backendTex.isValid());
111}
112
113DEF_GPUTEST(VkProtectedContext_ReadFromProtectedSurface, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400114 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
115 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400116 return;
117 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400118 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400119
Robert Phillips2a4acf32020-07-06 15:50:15 -0400120 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400121 REPORTER_ASSERT(reporter, surface);
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400122 REPORTER_ASSERT(reporter, !surface->readPixels(SkImageInfo(), nullptr, 8, 0, 0));
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400123
Robert Phillips2a4acf32020-07-06 15:50:15 -0400124 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400125 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
126}
127
Emircan Uysaler76974762019-10-25 13:28:54 -0400128namespace {
129
130struct AsyncContext {
131 bool fCalled = false;
132 std::unique_ptr<const SkSurface::AsyncReadResult> fResult;
133};
134
135static void async_callback(void* c, std::unique_ptr<const SkSurface::AsyncReadResult> result) {
136 auto context = static_cast<AsyncContext*>(c);
137 context->fResult = std::move(result);
138 context->fCalled = true;
139};
140
141} // anonymous namespace
142
143DEF_GPUTEST(VkProtectedContext_AsyncReadFromProtectedSurface, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400144 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
145 if (!protectedTestHelper->init()) {
Emircan Uysaler76974762019-10-25 13:28:54 -0400146 return;
147 }
Emircan Uysaler76974762019-10-25 13:28:54 -0400148
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400149 auto dContext = protectedTestHelper->directContext();
Robert Phillipsb27b38b2020-07-10 16:23:47 -0400150
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400151 REPORTER_ASSERT(reporter, dContext != nullptr);
Robert Phillipsb27b38b2020-07-10 16:23:47 -0400152
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400153 auto surface = create_protected_sksurface(dContext, reporter);
Emircan Uysaler76974762019-10-25 13:28:54 -0400154 REPORTER_ASSERT(reporter, surface);
155 AsyncContext cbContext;
156 const auto image_info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType,
157 SkColorSpace::MakeSRGB());
158 surface->asyncRescaleAndReadPixelsYUV420(kIdentity_SkYUVColorSpace, SkColorSpace::MakeSRGB(),
159 image_info.bounds(), image_info.dimensions(),
160 SkSurface::RescaleGamma::kSrc, kNone_SkFilterQuality,
161 &async_callback, &cbContext);
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400162 dContext->submit();
Emircan Uysaler76974762019-10-25 13:28:54 -0400163 while (!cbContext.fCalled) {
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400164 dContext->checkAsyncWorkCompletion();
Emircan Uysaler76974762019-10-25 13:28:54 -0400165 }
166 REPORTER_ASSERT(reporter, !cbContext.fResult);
167
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400168 dContext->deleteBackendTexture(
Robert Phillipsb27b38b2020-07-10 16:23:47 -0400169 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
Emircan Uysaler76974762019-10-25 13:28:54 -0400170}
171
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400172DEF_GPUTEST(VkProtectedContext_DrawRectangle, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400173 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
174 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400175 return;
176 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400177 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400178
Robert Phillips2a4acf32020-07-06 15:50:15 -0400179 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400180 REPORTER_ASSERT(reporter, surface);
181 SkCanvas* canvas = surface->getCanvas();
182 REPORTER_ASSERT(reporter, canvas);
183 SkPaint paint;
184 paint.setColor(SK_ColorBLACK);
185 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
186
Greg Danielce9f0162020-06-30 13:42:46 -0400187 surface->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400188 protectedTestHelper->directContext()->submit(true);
189 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400190 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
191}
192
193DEF_GPUTEST(VkProtectedContext_DrawRectangleWithAntiAlias, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400194 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
195 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400196 return;
197 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400198 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400199
Robert Phillips2a4acf32020-07-06 15:50:15 -0400200 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400201 REPORTER_ASSERT(reporter, surface);
202 SkCanvas* canvas = surface->getCanvas();
203 REPORTER_ASSERT(reporter, canvas);
204 SkPaint paint;
205 paint.setColor(SK_ColorBLACK);
206 paint.setAntiAlias(true);
207 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
208
Greg Danielce9f0162020-06-30 13:42:46 -0400209 surface->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400210 protectedTestHelper->directContext()->submit(true);
211 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400212 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
213}
214
215DEF_GPUTEST(VkProtectedContext_DrawRectangleWithBlendMode, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400216 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
217 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400218 return;
219 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400220 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400221
Robert Phillips2a4acf32020-07-06 15:50:15 -0400222 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400223 REPORTER_ASSERT(reporter, surface);
224 SkCanvas* canvas = surface->getCanvas();
225 REPORTER_ASSERT(reporter, canvas);
226 SkPaint paint;
227 paint.setColor(SK_ColorBLACK);
228 paint.setBlendMode(SkBlendMode::kColorDodge);
229 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
230
Greg Danielce9f0162020-06-30 13:42:46 -0400231 surface->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400232 protectedTestHelper->directContext()->submit(true);
233 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400234 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
235}
236
237DEF_GPUTEST(VkProtectedContext_DrawRectangleWithFilter, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400238 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
239 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400240 return;
241 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400242 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400243
Robert Phillips2a4acf32020-07-06 15:50:15 -0400244 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400245 REPORTER_ASSERT(reporter, surface);
246 SkCanvas* canvas = surface->getCanvas();
247 REPORTER_ASSERT(reporter, canvas);
248 SkPaint paint;
249 paint.setColor(SK_ColorBLACK);
250 paint.setStyle(SkPaint::kFill_Style);
251 paint.setMaskFilter(SkMaskFilter::MakeBlur(
252 SkBlurStyle::kOuter_SkBlurStyle, 1.1f));
253 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
254
Greg Danielce9f0162020-06-30 13:42:46 -0400255 surface->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400256 protectedTestHelper->directContext()->submit(true);
257 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400258 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
259}
260
261DEF_GPUTEST(VkProtectedContext_DrawThinPath, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400262 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
263 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400264 return;
265 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400266 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400267
Robert Phillips2a4acf32020-07-06 15:50:15 -0400268 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400269 REPORTER_ASSERT(reporter, surface);
270 SkCanvas* canvas = surface->getCanvas();
271 REPORTER_ASSERT(reporter, canvas);
272 SkPaint paint;
273 paint.setColor(SK_ColorBLACK);
274 paint.setStyle(SkPaint::kStroke_Style);
275 paint.setAntiAlias(true);
276 paint.setStrokeWidth(.4f);
277 canvas->drawPath(SkPath().moveTo(4, 4).lineTo(6, 6), paint);
278
Greg Danielce9f0162020-06-30 13:42:46 -0400279 surface->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400280 protectedTestHelper->directContext()->submit(true);
281 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400282 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
283}
284
285DEF_GPUTEST(VkProtectedContext_SaveLayer, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400286 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
287 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400288 return;
289 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400290 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400291
Robert Phillips2a4acf32020-07-06 15:50:15 -0400292 auto surface = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400293 REPORTER_ASSERT(reporter, surface);
294 SkCanvas* canvas = surface->getCanvas();
295 REPORTER_ASSERT(reporter, canvas);
296 canvas->saveLayer(nullptr, nullptr);
297 SkPaint paint;
298 paint.setColor(SK_ColorBLACK);
299 canvas->drawRect(SkRect::MakeWH(4, 4), paint);
300 canvas->restore();
301
Greg Danielce9f0162020-06-30 13:42:46 -0400302 surface->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400303 protectedTestHelper->directContext()->submit(true);
304 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400305 surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
306}
307
308
309DEF_GPUTEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface, reporter, options) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400310 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
311 if (!protectedTestHelper->init()) {
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400312 return;
313 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400314 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400315
316 // Create protected image.
Robert Phillips2a4acf32020-07-06 15:50:15 -0400317 auto surface1 = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400318 REPORTER_ASSERT(reporter, surface1);
319 auto image = surface1->makeImageSnapshot();
320 REPORTER_ASSERT(reporter, image);
321
322 // Create protected canvas.
Robert Phillips2a4acf32020-07-06 15:50:15 -0400323 auto surface2 = create_protected_sksurface(protectedTestHelper->directContext(), reporter);
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400324 REPORTER_ASSERT(reporter, surface2);
325 SkCanvas* canvas = surface2->getCanvas();
326 REPORTER_ASSERT(reporter, canvas);
327
328 canvas->drawImage(image, 0, 0);
329
Greg Danielce9f0162020-06-30 13:42:46 -0400330 surface1->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400331 protectedTestHelper->directContext()->submit(true);
332 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400333 surface1->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
Greg Danielce9f0162020-06-30 13:42:46 -0400334 surface2->flush();
Robert Phillips2a4acf32020-07-06 15:50:15 -0400335 protectedTestHelper->directContext()->submit(true);
336 protectedTestHelper->directContext()->deleteBackendTexture(
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400337 surface2->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
338}
339
Robert Phillips3cd54322019-07-10 09:28:59 -0400340//////////////////////////////////////////////////////////////////////////////////////////////////
341// Test out DDLs using a protected Vulkan context
342
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400343void DDLMakeRenderTargetTestImpl(GrDirectContext*, skiatest::Reporter*);
Robert Phillips3cd54322019-07-10 09:28:59 -0400344
345DEF_GPUTEST(VkProtectedContext_DDLMakeRenderTargetTest, reporter, ctxInfo) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400346 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
347 if (!protectedTestHelper->init()) {
Robert Phillips3cd54322019-07-10 09:28:59 -0400348 return;
349 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400350 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Robert Phillips3cd54322019-07-10 09:28:59 -0400351
Robert Phillips2a4acf32020-07-06 15:50:15 -0400352 DDLMakeRenderTargetTestImpl(protectedTestHelper->directContext(), reporter);
Robert Phillips3cd54322019-07-10 09:28:59 -0400353}
354
Robert Phillipsc8ae4942020-07-20 10:56:01 -0400355void DDLSurfaceCharacterizationTestImpl(GrDirectContext*, skiatest::Reporter*);
Robert Phillips3cd54322019-07-10 09:28:59 -0400356
357DEF_GPUTEST(VkProtectedContext_DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
Robert Phillips0d6ce7c2020-06-11 08:51:50 -0400358 auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
359 if (!protectedTestHelper->init()) {
Robert Phillips3cd54322019-07-10 09:28:59 -0400360 return;
361 }
Robert Phillips2a4acf32020-07-06 15:50:15 -0400362 REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
Robert Phillips3cd54322019-07-10 09:28:59 -0400363
Robert Phillips2a4acf32020-07-06 15:50:15 -0400364 DDLSurfaceCharacterizationTestImpl(protectedTestHelper->directContext(), reporter);
Robert Phillips3cd54322019-07-10 09:28:59 -0400365}
366
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400367#endif // SK_SUPPORT_GPU && defined(SK_VULKAN)