2018-03-09 17:05:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2018-03-09 17:05:04 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkPromiseImageTexture.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrGpu.h"
|
|
|
|
#include "src/gpu/ganesh/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/ganesh/GrTexture.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkImage_Gpu.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2018-03-09 17:05:04 +00:00
|
|
|
|
|
|
|
using namespace sk_gpu_test;
|
|
|
|
|
|
|
|
struct PromiseTextureChecker {
|
2019-01-24 17:18:33 +00:00
|
|
|
// shared indicates whether the backend texture is used to fulfill more than one promise
|
|
|
|
// image.
|
2020-11-09 20:40:27 +00:00
|
|
|
explicit PromiseTextureChecker(const GrBackendTexture& tex,
|
|
|
|
skiatest::Reporter* reporter,
|
2019-01-24 17:18:33 +00:00
|
|
|
bool shared)
|
2020-11-09 20:40:27 +00:00
|
|
|
: fTexture(SkPromiseImageTexture::Make(tex)), fReporter(reporter), fShared(shared) {}
|
2019-01-11 21:03:19 +00:00
|
|
|
sk_sp<SkPromiseImageTexture> fTexture;
|
2019-01-24 17:18:33 +00:00
|
|
|
skiatest::Reporter* fReporter;
|
|
|
|
bool fShared;
|
2020-11-09 20:40:27 +00:00
|
|
|
int fFulfillCount = 0;
|
|
|
|
int fReleaseCount = 0;
|
2019-01-10 17:09:52 +00:00
|
|
|
|
2019-01-11 21:03:19 +00:00
|
|
|
static sk_sp<SkPromiseImageTexture> Fulfill(void* self) {
|
2019-01-10 17:09:52 +00:00
|
|
|
auto checker = static_cast<PromiseTextureChecker*>(self);
|
|
|
|
checker->fFulfillCount++;
|
2019-01-11 21:03:19 +00:00
|
|
|
return checker->fTexture;
|
2018-03-09 17:05:04 +00:00
|
|
|
}
|
2020-11-09 20:40:27 +00:00
|
|
|
static void Release(void* self) { static_cast<PromiseTextureChecker*>(self)->fReleaseCount++; }
|
2018-03-09 17:05:04 +00:00
|
|
|
};
|
|
|
|
|
2019-03-08 18:28:46 +00:00
|
|
|
enum class ReleaseBalanceExpectation {
|
|
|
|
kBalanced,
|
|
|
|
kAllUnbalanced,
|
|
|
|
kUnknown,
|
|
|
|
kUnbalancedByOne,
|
|
|
|
kBalancedOrOffByOne,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void check_fulfill_and_release_cnts(skiatest::Reporter* reporter,
|
|
|
|
const PromiseTextureChecker& promiseChecker,
|
2018-03-09 17:05:04 +00:00
|
|
|
int expectedFulfillCnt,
|
2020-11-09 20:40:27 +00:00
|
|
|
ReleaseBalanceExpectation releaseBalanceExpecation) {
|
2019-03-08 18:28:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, promiseChecker.fFulfillCount == expectedFulfillCnt);
|
|
|
|
if (!expectedFulfillCnt) {
|
|
|
|
// Release and Done should only ever be called after Fulfill.
|
|
|
|
REPORTER_ASSERT(reporter, !promiseChecker.fReleaseCount);
|
|
|
|
return;
|
2018-03-09 17:05:04 +00:00
|
|
|
}
|
2019-03-08 18:28:46 +00:00
|
|
|
int releaseDiff = promiseChecker.fFulfillCount - promiseChecker.fReleaseCount;
|
|
|
|
switch (releaseBalanceExpecation) {
|
|
|
|
case ReleaseBalanceExpectation::kBalanced:
|
|
|
|
REPORTER_ASSERT(reporter, !releaseDiff);
|
|
|
|
break;
|
|
|
|
case ReleaseBalanceExpectation::kAllUnbalanced:
|
|
|
|
REPORTER_ASSERT(reporter, releaseDiff == promiseChecker.fFulfillCount);
|
|
|
|
break;
|
2020-11-09 20:40:27 +00:00
|
|
|
case ReleaseBalanceExpectation::kUnknown:
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
releaseDiff >= 0 && releaseDiff <= promiseChecker.fFulfillCount);
|
|
|
|
break;
|
2019-03-08 18:28:46 +00:00
|
|
|
case ReleaseBalanceExpectation::kUnbalancedByOne:
|
|
|
|
REPORTER_ASSERT(reporter, releaseDiff == 1);
|
|
|
|
break;
|
2020-11-09 20:40:27 +00:00
|
|
|
case ReleaseBalanceExpectation::kBalancedOrOffByOne:
|
|
|
|
REPORTER_ASSERT(reporter, releaseDiff == 0 || releaseDiff == 1);
|
2019-03-08 18:28:46 +00:00
|
|
|
break;
|
2019-03-07 15:23:30 +00:00
|
|
|
}
|
2019-03-08 18:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_unfulfilled(const PromiseTextureChecker& promiseChecker,
|
|
|
|
skiatest::Reporter* reporter) {
|
|
|
|
check_fulfill_and_release_cnts(reporter, promiseChecker, 0,
|
2020-11-09 20:40:27 +00:00
|
|
|
ReleaseBalanceExpectation::kBalanced);
|
2019-03-08 18:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_only_fulfilled(skiatest::Reporter* reporter,
|
|
|
|
const PromiseTextureChecker& promiseChecker,
|
|
|
|
int expectedFulfillCnt = 1) {
|
|
|
|
check_fulfill_and_release_cnts(reporter, promiseChecker, expectedFulfillCnt,
|
2020-11-09 20:40:27 +00:00
|
|
|
ReleaseBalanceExpectation::kAllUnbalanced);
|
2019-03-08 18:28:46 +00:00
|
|
|
}
|
2019-03-06 18:51:09 +00:00
|
|
|
|
2019-03-08 18:28:46 +00:00
|
|
|
static void check_all_flushed_but_not_synced(skiatest::Reporter* reporter,
|
|
|
|
const PromiseTextureChecker& promiseChecker,
|
|
|
|
GrBackendApi api,
|
|
|
|
int expectedFulfillCnt = 1) {
|
2020-11-09 20:40:27 +00:00
|
|
|
ReleaseBalanceExpectation releaseBalanceExpectation = ReleaseBalanceExpectation::kBalanced;
|
2020-06-24 17:38:08 +00:00
|
|
|
// On Vulkan and D3D Done isn't guaranteed to be called until a sync has occurred.
|
|
|
|
if (api == GrBackendApi::kVulkan || api == GrBackendApi::kDirect3D) {
|
2020-11-09 20:40:27 +00:00
|
|
|
releaseBalanceExpectation = expectedFulfillCnt == 1
|
|
|
|
? ReleaseBalanceExpectation::kBalancedOrOffByOne
|
|
|
|
: ReleaseBalanceExpectation::kUnknown;
|
2018-03-16 18:57:21 +00:00
|
|
|
}
|
2019-03-08 18:28:46 +00:00
|
|
|
check_fulfill_and_release_cnts(reporter, promiseChecker, expectedFulfillCnt,
|
2020-11-09 20:40:27 +00:00
|
|
|
releaseBalanceExpectation);
|
2019-03-08 18:28:46 +00:00
|
|
|
}
|
2018-03-16 18:57:21 +00:00
|
|
|
|
2019-03-08 18:28:46 +00:00
|
|
|
static void check_all_done(skiatest::Reporter* reporter,
|
|
|
|
const PromiseTextureChecker& promiseChecker,
|
|
|
|
int expectedFulfillCnt = 1) {
|
|
|
|
check_fulfill_and_release_cnts(reporter, promiseChecker, expectedFulfillCnt,
|
2020-11-09 20:40:27 +00:00
|
|
|
ReleaseBalanceExpectation::kBalanced);
|
2018-03-09 17:05:04 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 15:03:03 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageTest, reporter, ctxInfo) {
|
2019-01-30 22:28:20 +00:00
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
auto ctx = ctxInfo.directContext();
|
2019-01-30 22:28:20 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture backendTex = ctx->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
kWidth, kHeight, kRGBA_8888_SkColorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes, GrProtected::kNo);
|
2019-01-30 22:28:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex.isValid());
|
|
|
|
|
|
|
|
GrBackendFormat backendFormat = backendTex.getBackendFormat();
|
|
|
|
REPORTER_ASSERT(reporter, backendFormat.isValid());
|
|
|
|
|
|
|
|
PromiseTextureChecker promiseChecker(backendTex, reporter, false);
|
|
|
|
GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin;
|
2021-02-19 17:33:46 +00:00
|
|
|
sk_sp<SkImage> refImg(SkImage_Gpu::MakePromiseTexture(ctx->threadSafeProxy(),
|
2020-11-09 20:40:27 +00:00
|
|
|
backendFormat,
|
|
|
|
{kWidth, kHeight},
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
texOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
PromiseTextureChecker::Fulfill,
|
|
|
|
PromiseTextureChecker::Release,
|
|
|
|
&promiseChecker));
|
2019-01-30 22:28:20 +00:00
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info);
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
2019-03-07 15:23:30 +00:00
|
|
|
canvas->drawImage(refImg, 0, 0);
|
2019-03-08 18:28:46 +00:00
|
|
|
check_unfulfilled(promiseChecker, reporter);
|
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-03-08 18:28:46 +00:00
|
|
|
// We still own the image so we should not have called Release or Done.
|
|
|
|
check_only_fulfilled(reporter, promiseChecker);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
2021-02-12 17:10:43 +00:00
|
|
|
ctx->submit(true);
|
2019-03-08 18:28:46 +00:00
|
|
|
check_only_fulfilled(reporter, promiseChecker);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
|
|
|
|
2021-02-12 17:10:43 +00:00
|
|
|
surface->flushAndSubmit(true);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
2019-03-08 18:28:46 +00:00
|
|
|
// Image should still be fulfilled from the first time we drew/flushed it.
|
|
|
|
check_only_fulfilled(reporter, promiseChecker);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-03-08 18:28:46 +00:00
|
|
|
check_only_fulfilled(reporter, promiseChecker);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
|
|
|
refImg.reset();
|
2019-03-08 18:28:46 +00:00
|
|
|
// We no longer own the image but the last draw is still unflushed.
|
|
|
|
check_only_fulfilled(reporter, promiseChecker);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-03-08 18:28:46 +00:00
|
|
|
// Flushing should have called Release. Depending on the backend and timing it may have called
|
|
|
|
// done.
|
|
|
|
check_all_flushed_but_not_synced(reporter, promiseChecker, ctx->backend());
|
2021-02-12 17:10:43 +00:00
|
|
|
ctx->submit(true);
|
2019-03-08 18:28:46 +00:00
|
|
|
// Now Done should definitely have been called.
|
|
|
|
check_all_done(reporter, promiseChecker);
|
2019-01-30 22:28:20 +00:00
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
ctx->deleteBackendTexture(backendTex);
|
2019-01-30 22:28:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 17:18:33 +00:00
|
|
|
DEF_GPUTEST(PromiseImageTextureShutdown, reporter, ctxInfo) {
|
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
|
|
|
|
|
|
|
// Different ways of killing contexts.
|
2020-07-23 13:41:57 +00:00
|
|
|
using DeathFn = std::function<void(sk_gpu_test::GrContextFactory*, GrDirectContext*)>;
|
|
|
|
DeathFn destroy = [](sk_gpu_test::GrContextFactory* factory, GrDirectContext*) {
|
2019-01-24 17:18:33 +00:00
|
|
|
factory->destroyContexts();
|
|
|
|
};
|
2020-07-23 13:41:57 +00:00
|
|
|
DeathFn abandon = [](sk_gpu_test::GrContextFactory* factory, GrDirectContext* dContext) {
|
|
|
|
dContext->abandonContext();
|
2019-01-24 17:18:33 +00:00
|
|
|
};
|
|
|
|
DeathFn releaseResourcesAndAbandon = [](sk_gpu_test::GrContextFactory* factory,
|
2020-07-23 13:41:57 +00:00
|
|
|
GrDirectContext* dContext) {
|
|
|
|
dContext->releaseResourcesAndAbandonContext();
|
2019-01-24 17:18:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int type = 0; type < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++type) {
|
|
|
|
auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(type);
|
|
|
|
// These tests are difficult to get working with Vulkan. See http://skbug.com/8705
|
|
|
|
// and http://skbug.com/8275
|
2020-06-04 13:02:04 +00:00
|
|
|
// Also problematic on Dawn; see http://skbug.com/10326
|
2020-06-23 19:00:04 +00:00
|
|
|
// And Direct3D, for similar reasons.
|
2019-01-24 17:18:33 +00:00
|
|
|
GrBackendApi api = sk_gpu_test::GrContextFactory::ContextTypeBackend(contextType);
|
2020-06-23 19:00:04 +00:00
|
|
|
if (api == GrBackendApi::kVulkan || api == GrBackendApi::kDawn ||
|
|
|
|
api == GrBackendApi::kDirect3D) {
|
2019-01-24 17:18:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DeathFn contextKillers[] = {destroy, abandon, releaseResourcesAndAbandon};
|
2020-07-31 00:24:57 +00:00
|
|
|
for (const DeathFn& contextDeath : contextKillers) {
|
2019-01-24 17:18:33 +00:00
|
|
|
sk_gpu_test::GrContextFactory factory;
|
|
|
|
auto ctx = factory.get(contextType);
|
|
|
|
if (!ctx) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(ctx,
|
|
|
|
kWidth,
|
|
|
|
kHeight,
|
|
|
|
kAlpha_8_SkColorType,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
GrRenderable::kNo);
|
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not create texture alpha texture.");
|
|
|
|
continue;
|
|
|
|
}
|
2019-01-24 17:18:33 +00:00
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info);
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
PromiseTextureChecker promiseChecker(mbet->texture(), reporter, false);
|
2021-02-19 17:33:46 +00:00
|
|
|
sk_sp<SkImage> image(SkImage_Gpu::MakePromiseTexture(ctx->threadSafeProxy(),
|
2020-11-09 20:40:27 +00:00
|
|
|
mbet->texture().getBackendFormat(),
|
|
|
|
{kWidth, kHeight},
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kAlpha_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
/*color space*/ nullptr,
|
|
|
|
PromiseTextureChecker::Fulfill,
|
|
|
|
PromiseTextureChecker::Release,
|
|
|
|
&promiseChecker));
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
|
|
|
|
canvas->drawImage(image, 0, 0);
|
|
|
|
image.reset();
|
|
|
|
// If the surface still holds a ref to the context then the factory will not be able
|
|
|
|
// to destroy the context (and instead will release-all-and-abandon).
|
|
|
|
surface.reset();
|
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
ctx->flushAndSubmit();
|
2019-01-24 17:18:33 +00:00
|
|
|
contextDeath(&factory, ctx);
|
|
|
|
|
2019-03-08 18:28:46 +00:00
|
|
|
check_all_done(reporter, promiseChecker);
|
2019-01-24 17:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageTextureFullCache, reporter, ctxInfo) {
|
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2019-01-24 17:18:33 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
GrBackendTexture backendTex = dContext->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
kWidth, kHeight, kAlpha_8_SkColorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex.isValid());
|
|
|
|
|
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2020-07-23 13:41:57 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
|
2019-01-24 17:18:33 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
|
|
|
PromiseTextureChecker promiseChecker(backendTex, reporter, false);
|
2021-02-19 17:33:46 +00:00
|
|
|
sk_sp<SkImage> image(SkImage_Gpu::MakePromiseTexture(dContext->threadSafeProxy(),
|
2020-11-09 20:40:27 +00:00
|
|
|
backendTex.getBackendFormat(),
|
|
|
|
{kWidth, kHeight},
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kAlpha_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
PromiseTextureChecker::Fulfill,
|
|
|
|
PromiseTextureChecker::Release,
|
|
|
|
&promiseChecker));
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, image);
|
|
|
|
|
|
|
|
// Make the cache full. This tests that we don't preemptively purge cached textures for
|
|
|
|
// fulfillment due to cache pressure.
|
2019-09-03 14:29:20 +00:00
|
|
|
static constexpr int kMaxBytes = 1;
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->setResourceCacheLimit(kMaxBytes);
|
2019-09-03 14:29:20 +00:00
|
|
|
SkTArray<sk_sp<GrTexture>> textures;
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto format = dContext->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kNo);
|
2022-05-03 20:00:24 +00:00
|
|
|
textures.emplace_back(dContext->priv().resourceProvider()->createTexture({100, 100},
|
|
|
|
format,
|
|
|
|
GrTextureType::k2D,
|
|
|
|
GrRenderable::kNo,
|
|
|
|
1,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBudgeted::kYes,
|
|
|
|
GrProtected::kNo,
|
|
|
|
/*label=*/{}));
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, textures[i]);
|
|
|
|
}
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t bytesUsed;
|
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->getResourceCacheUsage(nullptr, &bytesUsed);
|
2019-09-03 14:29:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, bytesUsed > kMaxBytes);
|
|
|
|
|
2019-01-24 17:18:33 +00:00
|
|
|
// Relying on the asserts in the promiseImageChecker to ensure that fulfills and releases are
|
|
|
|
// properly ordered.
|
|
|
|
canvas->drawImage(image, 0, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-01-24 17:18:33 +00:00
|
|
|
canvas->drawImage(image, 1, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-01-24 17:18:33 +00:00
|
|
|
canvas->drawImage(image, 2, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-01-24 17:18:33 +00:00
|
|
|
canvas->drawImage(image, 3, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-01-24 17:18:33 +00:00
|
|
|
canvas->drawImage(image, 4, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-01-24 17:18:33 +00:00
|
|
|
canvas->drawImage(image, 5, 0);
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-03-08 16:12:14 +00:00
|
|
|
// Must call these to ensure that all callbacks are performed before the checker is destroyed.
|
|
|
|
image.reset();
|
2021-02-12 17:10:43 +00:00
|
|
|
dContext->flushAndSubmit(true);
|
2019-03-08 16:12:14 +00:00
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->deleteBackendTexture(backendTex);
|
2019-01-24 17:18:33 +00:00
|
|
|
}
|
2019-04-04 16:18:17 +00:00
|
|
|
|
|
|
|
// Test case where promise image fulfill returns nullptr.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageNullFulfill, reporter, ctxInfo) {
|
|
|
|
const int kWidth = 10;
|
|
|
|
const int kHeight = 10;
|
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2019-04-04 16:18:17 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
GrBackendFormat backendFormat =
|
|
|
|
dContext->defaultBackendFormat(kRGBA_8888_SkColorType, GrRenderable::kYes);
|
|
|
|
if (!backendFormat.isValid()) {
|
|
|
|
ERRORF(reporter, "No valid default kRGBA_8888 texture format.");
|
|
|
|
return;
|
|
|
|
}
|
2019-04-04 16:18:17 +00:00
|
|
|
|
|
|
|
struct Counts {
|
|
|
|
int fFulfillCount = 0;
|
|
|
|
int fReleaseCount = 0;
|
|
|
|
} counts;
|
|
|
|
auto fulfill = [](SkDeferredDisplayListRecorder::PromiseImageTextureContext ctx) {
|
|
|
|
++static_cast<Counts*>(ctx)->fFulfillCount;
|
|
|
|
return sk_sp<SkPromiseImageTexture>();
|
|
|
|
};
|
|
|
|
auto release = [](SkDeferredDisplayListRecorder::PromiseImageTextureContext ctx) {
|
|
|
|
++static_cast<Counts*>(ctx)->fReleaseCount;
|
|
|
|
};
|
|
|
|
GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin;
|
2021-02-19 17:33:46 +00:00
|
|
|
sk_sp<SkImage> refImg(SkImage_Gpu::MakePromiseTexture(dContext->threadSafeProxy(),
|
2020-11-09 20:40:27 +00:00
|
|
|
backendFormat,
|
|
|
|
{kWidth, kHeight},
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
texOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
fulfill,
|
|
|
|
release,
|
|
|
|
&counts));
|
2019-04-04 16:18:17 +00:00
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
|
2020-07-23 13:41:57 +00:00
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
|
2019-04-04 16:18:17 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
// Draw the image a few different ways.
|
|
|
|
canvas->drawImage(refImg, 0, 0);
|
|
|
|
SkPaint paint;
|
2019-04-08 20:23:20 +00:00
|
|
|
paint.setColorFilter(SkColorFilters::LinearToSRGBGamma());
|
2021-01-28 02:21:08 +00:00
|
|
|
canvas->drawImage(refImg, 0, 0, SkSamplingOptions(), &paint);
|
2020-12-09 02:58:35 +00:00
|
|
|
auto shader = refImg->makeShader(SkSamplingOptions());
|
2019-04-04 16:18:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, shader);
|
|
|
|
paint.setShader(std::move(shader));
|
|
|
|
canvas->drawRect(SkRect::MakeWH(1,1), paint);
|
|
|
|
paint.setShader(nullptr);
|
|
|
|
refImg.reset();
|
2020-05-14 19:45:44 +00:00
|
|
|
surface->flushAndSubmit();
|
2019-04-04 16:18:17 +00:00
|
|
|
// We should only call each callback once and we should have made all the calls by this point.
|
|
|
|
REPORTER_ASSERT(reporter, counts.fFulfillCount == 1);
|
|
|
|
REPORTER_ASSERT(reporter, counts.fReleaseCount == 1);
|
|
|
|
}
|