34 fBackendTextures[0] = backendTex;
41 , fHasTwoBackendTextures(
true) {
42 fBackendTextures[0] = backendTex0;
43 fBackendTextures[1] = backendTex1;
50 int totalReleaseCount()
const {
return fTextureReleaseCounts[0] + fTextureReleaseCounts[1]; }
53 bool fHasTwoBackendTextures =
false;
56 int fImageReleaseCount = 0;
57 int fTextureReleaseCounts[2] = { 0, 0 };
59 static std::tuple<BackendTexture, void*>
Fulfill(
void*
self) {
64 if (checker->fHasTwoBackendTextures) {
65 int whichToUse = checker->fFulfillCount % 2;
66 return { checker->fBackendTextures[whichToUse],
67 &checker->fTextureReleaseCounts[whichToUse] };
69 return { checker->fBackendTextures[0], &checker->fTextureReleaseCounts[0] };
73 static void ImageRelease(
void*
self) {
76 checker->fImageReleaseCount++;
79 static void TextureRelease(
void* context) {
80 int* releaseCount =
reinterpret_cast<int*
>(context);
95 int expectedFulfillCnt,
99 if (!expectedFulfillCnt) {
106 int releaseDiff = promiseChecker.
fFulfillCount - promiseChecker.totalReleaseCount();
107 switch (releaseBalanceExpectation) {
112 case ReleaseBalanceExpectation::kOffByOne:
116 case ReleaseBalanceExpectation::kOffByTwo:
120 case ReleaseBalanceExpectation::kFulfillsOnly:
134 int expectedFulfillCnt) {
136 ReleaseBalanceExpectation::kOffByOne);
141 int expectedFulfillCnt) {
143 ReleaseBalanceExpectation::kOffByTwo);
148 int expectedFulfillCnt) {
155 int expectedFulfillCnt) {
157 ReleaseBalanceExpectation::kFulfillsOnly);
164 for (
int i = 0;
i < 2; ++
i) {
165 if (fBackendTextures[
i].isValid()) {
172 std::unique_ptr<Recorder> fRecorder;
179void setup_test_context(
Context* context,
184 bool invalidBackendTex) {
185 testCtx->fContext = context;
197 if (invalidBackendTex) {
202 testCtx->fBackendTextures[0] = testCtx->fRecorder->createBackendTexture(dimensions,
206 if (isVolatile == Volatile::kYes) {
207 testCtx->fBackendTextures[1] = testCtx->fRecorder->createBackendTexture(dimensions,
213 if (isVolatile == Volatile::kYes) {
215 testCtx->fBackendTextures[1],
232 PromiseTextureChecker::Fulfill,
233 PromiseTextureChecker::ImageRelease,
234 PromiseTextureChecker::TextureRelease,
235 &testCtx->fPromiseChecker);
248 constexpr SkISize kDimensions { 16, 16 };
251 setup_test_context(context,
reporter, &testContext,
252 kDimensions, Volatile::kNo,
false);
255 SkCanvas* canvas = testContext.fSurface->getCanvas();
257 canvas->
drawImage(testContext.fImg, 0, 0);
260 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
264 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
268 context->
submit(SyncToCpu::kNo);
270 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
273 testGpuContext->syncedSubmit(context);
274 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
279 SkCanvas* canvas = testContext.fSurface->getCanvas();
281 canvas->
drawImage(testContext.fImg, 0, 0);
282 canvas->
drawImage(testContext.fImg, 0, 0);
284 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
285 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
290 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
294 testGpuContext->syncedSubmit(context);
295 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
300 SkCanvas* canvas = testContext.fSurface->getCanvas();
302 canvas->
drawImage(testContext.fImg, 0, 0);
303 testContext.fImg.reset();
305 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
306 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
310 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
316 testContext.fPromiseChecker.checkImageReleased(
reporter, 1);
319 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
322 testGpuContext->syncedSubmit(context);
329 NonVolatileGraphitePromiseImageFulfillFailureTest,
335 constexpr SkISize kDimensions { 16, 16 };
338 setup_test_context(context,
reporter, &testContext,
339 kDimensions, Volatile::kNo,
true);
343 SkCanvas* canvas = testContext.fSurface->getCanvas();
345 canvas->
drawImage(testContext.fImg, 0, 0);
348 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
352 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
357 check_fulfills_only(
reporter, testContext.fPromiseChecker, 2);
361 SkCanvas* canvas = testContext.fSurface->getCanvas();
367 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
368 check_fulfills_only(
reporter, testContext.fPromiseChecker, 2);
371 check_fulfills_only(
reporter, testContext.fPromiseChecker, 3);
375 SkCanvas* canvas = testContext.fSurface->getCanvas();
381 paint.setShader(std::move(shader));
384 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
385 check_fulfills_only(
reporter, testContext.fPromiseChecker, 3);
388 check_fulfills_only(
reporter, testContext.fPromiseChecker, 4);
391 testContext.fSurface.reset();
392 testContext.fImg.reset();
395 testContext.fPromiseChecker.checkImageReleased(
reporter, 1);
397 testGpuContext->syncedSubmit(context);
399 check_fulfills_only(
reporter, testContext.fPromiseChecker, 4);
403 NonVolatileGraphitePromiseImageCreationFailureTest,
410 constexpr SkISize kDimensions { 0, 0 };
413 setup_test_context(context,
reporter, &testContext,
414 kDimensions, Volatile::kNo,
true);
430 constexpr SkISize kDimensions { 16, 16 };
433 setup_test_context(context,
reporter, &testContext,
434 kDimensions, Volatile::kYes,
false);
437 SkCanvas* canvas = testContext.fSurface->getCanvas();
439 canvas->
drawImage(testContext.fImg, 0, 0);
442 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
447 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
452 check_fulfilled_ahead_by_two(
reporter, testContext.fPromiseChecker,
456 testGpuContext->syncedSubmit(context);
463 SkCanvas* canvas = testContext.fSurface->getCanvas();
465 canvas->
drawImage(testContext.fImg, 0, 0);
466 canvas->
drawImage(testContext.fImg, 0, 0);
468 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
473 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
477 check_fulfilled_ahead_by_two(
reporter, testContext.fPromiseChecker,
481 testGpuContext->syncedSubmit(context);
488 SkCanvas* canvas = testContext.fSurface->getCanvas();
490 canvas->
drawImage(testContext.fImg, 0, 0);
491 testContext.fImg.reset();
493 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
498 check_fulfilled_ahead_by_one(
reporter, testContext.fPromiseChecker,
502 check_fulfilled_ahead_by_two(
reporter, testContext.fPromiseChecker,
507 check_fulfilled_ahead_by_two(
reporter, testContext.fPromiseChecker,
510 testGpuContext->syncedSubmit(context);
525 constexpr SkISize kDimensions { 16, 16 };
528 setup_test_context(context,
reporter, &testContext,
529 kDimensions, Volatile::kYes,
true);
533 SkCanvas* canvas = testContext.fSurface->getCanvas();
535 canvas->
drawImage(testContext.fImg, 0, 0);
538 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
542 check_fulfills_only(
reporter, testContext.fPromiseChecker, 1);
545 check_fulfills_only(
reporter, testContext.fPromiseChecker, 2);
549 SkCanvas* canvas = testContext.fSurface->getCanvas();
555 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
556 check_fulfills_only(
reporter, testContext.fPromiseChecker, 2);
559 check_fulfills_only(
reporter, testContext.fPromiseChecker, 3);
562 check_fulfills_only(
reporter, testContext.fPromiseChecker, 4);
566 SkCanvas* canvas = testContext.fSurface->getCanvas();
572 paint.setShader(std::move(shader));
575 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
576 check_fulfills_only(
reporter, testContext.fPromiseChecker, 4);
579 check_fulfills_only(
reporter, testContext.fPromiseChecker, 5);
582 check_fulfills_only(
reporter, testContext.fPromiseChecker, 6);
585 testContext.fSurface.reset();
586 testContext.fImg.reset();
588 testGpuContext->syncedSubmit(context);
589 check_fulfills_only(
reporter, testContext.fPromiseChecker, 6);
599 constexpr SkISize kDimensions{ 16, 16 };
601 for (
Volatile isVolatile : { Volatile::kNo, Volatile::kYes }) {
603 setup_test_context(context,
reporter, &testContext,
604 kDimensions, isVolatile,
false);
606 SkCanvas* canvas = testContext.fSurface->getCanvas();
608 canvas->
drawImage(testContext.fImg, 0, 0);
611 std::unique_ptr<Recording> recording = testContext.fRecorder->snap();
614 testContext.fRecorder.reset();
617 check_fulfills_only(
reporter, testContext.fPromiseChecker, 1);
619 testGpuContext->syncedSubmit(context);
621 testContext.fSurface.reset();
622 testContext.fImg.reset();
637 constexpr SkISize kDimensions{ 16, 16 };
639 static constexpr int kNumRecordings = 3;
641 for (
Volatile isVolatile : { Volatile::kNo, Volatile::kYes }) {
642 int expectedVolatile = (isVolatile == Volatile::kYes) ? 1 : 0;
643 int expectedNonVolatile = 1 - expectedVolatile;
646 setup_test_context(context,
reporter, &testContext,
647 kDimensions, isVolatile,
false);
649 std::unique_ptr<Recording> recordings[kNumRecordings];
651 SkCanvas* canvas = testContext.fSurface->getCanvas();
653 for (
int i = 0;
i < kNumRecordings; ++
i) {
654 canvas->
drawImage(testContext.fImg, 0, 0);
656 recordings[
i] = testContext.fRecorder->snap();
658 if (isVolatile == Volatile::kYes) {
659 check_fulfills_only(
reporter, testContext.fPromiseChecker,
662 check_fulfills_only(
reporter, testContext.fPromiseChecker,
667 recordings[
i]->
priv().numVolatilePromiseImages() == expectedVolatile);
669 recordings[
i]->
priv().numNonVolatilePromiseImages() ==
670 expectedNonVolatile);
674 if (isVolatile == Volatile::kYes) {
675 check_fulfills_only(
reporter, testContext.fPromiseChecker,
678 check_fulfills_only(
reporter, testContext.fPromiseChecker,
686 testGpuContext->syncedSubmit(context);
688 testContext.fSurface.reset();
689 testContext.fImg.reset();
690 for (
int i = 0;
i < kNumRecordings; ++
i) {
691 recordings[
i].reset();
694 if (isVolatile == Volatile::kYes) {
DEF_CONDITIONAL_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(NonVolatileGraphitePromiseImageTest, reporter, context, testGpuContext, true, CtsEnforcement::kNextRelease)
ReleaseBalanceExpectation
static void check_fulfill_and_release_cnts(skiatest::Reporter *reporter, const PromiseTextureChecker &promiseChecker, int expectedFulfillCnt, ReleaseBalanceExpectation releaseBalanceExpecation)
static void check_unfulfilled(const PromiseTextureChecker &promiseChecker, skiatest::Reporter *reporter)
static void check_all_done(skiatest::Reporter *reporter, const PromiseTextureChecker &promiseChecker, int expectedFulfillCnt=1)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
#define REPORTER_ASSERT(r, cond,...)
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static sk_sp< SkColorFilter > LinearToSRGBGamma()
bool protectedSupport() const
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
const Caps * caps() const
std::unique_ptr< Recorder > makeRecorder(const RecorderOptions &={})
bool submit(SyncToCpu=SyncToCpu::kNo)
void deleteBackendTexture(const BackendTexture &)
bool insertRecording(const InsertRecordingInfo &)
FlPixelBufferTexturePrivate * priv
SK_API sk_sp< SkImage > PromiseTextureFrom(skgpu::graphite::Recorder *, SkISize dimensions, const skgpu::graphite::TextureInfo &, const SkColorInfo &, skgpu::Origin origin, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext, std::string_view label={})
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
SkSamplingOptions(SkFilterMode::kLinear))
static sk_sp< GrPromiseImageTexture > Fulfill(void *self)
skiatest::Reporter * fReporter
const SkColorInfo & colorInfo() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeWH(float w, float h)