2017-11-30 05:01:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#include "GrClip.h"
|
|
|
|
#include "GrContextPriv.h"
|
2018-06-12 14:11:12 +00:00
|
|
|
#include "GrMemoryPool.h"
|
2017-11-30 05:01:06 +00:00
|
|
|
#include "GrOnFlushResourceProvider.h"
|
2018-06-12 14:11:12 +00:00
|
|
|
#include "GrProxyProvider.h"
|
2017-11-30 05:01:06 +00:00
|
|
|
#include "GrRenderTargetContext.h"
|
|
|
|
#include "GrRenderTargetContextPriv.h"
|
|
|
|
#include "GrSurfaceProxy.h"
|
2018-01-16 21:14:41 +00:00
|
|
|
#include "GrSurfaceProxyPriv.h"
|
2017-11-30 05:01:06 +00:00
|
|
|
#include "GrTexture.h"
|
|
|
|
#include "GrTextureProxy.h"
|
|
|
|
#include "GrTextureProxyPriv.h"
|
|
|
|
#include "SkMakeUnique.h"
|
2018-01-08 20:05:02 +00:00
|
|
|
#include "SkRectPriv.h"
|
2018-03-08 20:27:36 +00:00
|
|
|
#include "mock/GrMockGpu.h"
|
2017-11-30 05:01:06 +00:00
|
|
|
#include "mock/GrMockTypes.h"
|
|
|
|
|
|
|
|
// This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks,
|
|
|
|
// but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for
|
|
|
|
// regular Ops and for clips.
|
|
|
|
class LazyProxyTest final : public GrOnFlushCallbackObject {
|
|
|
|
public:
|
|
|
|
LazyProxyTest(skiatest::Reporter* reporter)
|
|
|
|
: fReporter(reporter)
|
|
|
|
, fHasOpTexture(false)
|
|
|
|
, fHasClipTexture(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
~LazyProxyTest() override {
|
|
|
|
REPORTER_ASSERT(fReporter, fHasOpTexture);
|
|
|
|
REPORTER_ASSERT(fReporter, fHasClipTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int,
|
|
|
|
SkTArray<sk_sp<GrRenderTargetContext>>*) override {
|
|
|
|
REPORTER_ASSERT(fReporter, !fHasOpTexture);
|
|
|
|
REPORTER_ASSERT(fReporter, !fHasClipTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, int numOpListIDs) override {
|
|
|
|
REPORTER_ASSERT(fReporter, fHasOpTexture);
|
|
|
|
REPORTER_ASSERT(fReporter, fHasClipTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Op final : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2018-06-07 15:05:56 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
|
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
LazyProxyTest* test,
|
|
|
|
bool nullTexture) {
|
2018-06-19 17:09:54 +00:00
|
|
|
GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
|
|
|
|
|
|
|
|
return pool->allocate<Op>(proxyProvider, test, nullTexture);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 18:37:19 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
|
2018-06-07 15:05:56 +00:00
|
|
|
func(fProxy.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void onExecute(GrOpFlushState*) override {
|
|
|
|
REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture);
|
|
|
|
REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class GrOpMemoryPool; // for ctor
|
|
|
|
|
2018-01-17 16:40:14 +00:00
|
|
|
Op(GrProxyProvider* proxyProvider, LazyProxyTest* test, bool nullTexture)
|
|
|
|
: GrDrawOp(ClassID()), fTest(test) {
|
2018-06-16 23:22:59 +00:00
|
|
|
fProxy = GrProxyProvider::MakeFullyLazyProxy(
|
|
|
|
[this, nullTexture](GrResourceProvider* rp) {
|
|
|
|
if (!rp) {
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
|
|
|
|
fTest->fHasOpTexture = true;
|
|
|
|
if (nullTexture) {
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
} else {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = 1234;
|
|
|
|
desc.fHeight = 567;
|
|
|
|
desc.fConfig = kRGB_565_GrPixelConfig;
|
|
|
|
sk_sp<GrTexture> texture = rp->createTexture(desc, SkBudgeted::kYes);
|
|
|
|
REPORTER_ASSERT(fTest->fReporter, texture);
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
GrProxyProvider::Renderable::kNo, kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGB_565_GrPixelConfig, *proxyProvider->caps());
|
|
|
|
|
|
|
|
this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo,
|
|
|
|
GrOp::IsZeroArea::kNo);
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "LazyProxyTest::Op"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2018-07-11 14:02:07 +00:00
|
|
|
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override {
|
2017-11-30 05:01:06 +00:00
|
|
|
return RequiresDstTexture::kNo;
|
|
|
|
}
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
|
|
|
|
|
|
|
LazyProxyTest* const fTest;
|
|
|
|
sk_sp<GrTextureProxy> fProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClipFP : public GrFragmentProcessor {
|
|
|
|
public:
|
2018-01-17 16:40:14 +00:00
|
|
|
ClipFP(GrProxyProvider* proxyProvider, LazyProxyTest* test, GrTextureProxy* atlas)
|
2017-11-30 05:01:06 +00:00
|
|
|
: GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
|
2018-01-17 16:40:14 +00:00
|
|
|
, fProxyProvider(proxyProvider)
|
2017-11-30 05:01:06 +00:00
|
|
|
, fTest(test)
|
|
|
|
, fAtlas(atlas) {
|
2018-06-16 23:22:59 +00:00
|
|
|
fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
|
2018-02-13 16:13:51 +00:00
|
|
|
[this](GrResourceProvider* rp) {
|
|
|
|
if (!rp) {
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
|
|
|
|
fTest->fHasClipTexture = true;
|
|
|
|
fAtlas->instantiate(rp);
|
2018-07-31 21:25:29 +00:00
|
|
|
return sk_ref_sp(fAtlas->peekTexture());
|
2018-02-13 16:13:51 +00:00
|
|
|
},
|
|
|
|
GrProxyProvider::Renderable::kYes,
|
|
|
|
kBottomLeft_GrSurfaceOrigin,
|
2018-06-16 23:22:59 +00:00
|
|
|
kAlpha_half_GrPixelConfig, *proxyProvider->caps());
|
2017-11-30 05:01:06 +00:00
|
|
|
fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest,
|
2018-07-31 17:53:11 +00:00
|
|
|
GrSamplerState::WrapMode::kClamp);
|
2018-07-30 18:48:15 +00:00
|
|
|
this->setTextureSamplerCnt(1);
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name() const override { return "LazyProxyTest::ClipFP"; }
|
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
2018-01-17 16:40:14 +00:00
|
|
|
return skstd::make_unique<ClipFP>(fProxyProvider, fTest, fAtlas);
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; }
|
|
|
|
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
|
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
|
2018-07-30 18:48:15 +00:00
|
|
|
const TextureSampler& onTextureSampler(int) const override { return fAccess; }
|
2017-11-30 05:01:06 +00:00
|
|
|
|
2018-01-17 16:40:14 +00:00
|
|
|
GrProxyProvider* const fProxyProvider;
|
2017-11-30 05:01:06 +00:00
|
|
|
LazyProxyTest* const fTest;
|
|
|
|
GrTextureProxy* const fAtlas;
|
|
|
|
sk_sp<GrTextureProxy> fLazyProxy;
|
|
|
|
TextureSampler fAccess;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Clip : public GrClip {
|
|
|
|
public:
|
|
|
|
Clip(LazyProxyTest* test, GrTextureProxy* atlas)
|
|
|
|
: fTest(test)
|
|
|
|
, fAtlas(atlas) {}
|
|
|
|
|
|
|
|
private:
|
2018-01-17 16:40:14 +00:00
|
|
|
bool apply(GrContext* context, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
|
2017-11-30 05:01:06 +00:00
|
|
|
SkRect* bounds) const override {
|
2018-01-17 16:40:14 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
|
|
|
|
out->addCoverageFP(skstd::make_unique<ClipFP>(proxyProvider, fTest, fAtlas));
|
2017-11-30 05:01:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool quickContains(const SkRect&) const final { return false; }
|
|
|
|
bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
|
|
|
|
void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
|
|
|
|
rect->set(0, 0, width, height);
|
|
|
|
if (iior) {
|
|
|
|
*iior = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LazyProxyTest* const fTest;
|
|
|
|
GrTextureProxy* fAtlas;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
skiatest::Reporter* fReporter;
|
|
|
|
bool fHasOpTexture;
|
|
|
|
bool fHasClipTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GPUTEST(LazyProxyTest, reporter, /* options */) {
|
|
|
|
GrMockOptions mockOptions;
|
2018-02-03 01:32:49 +00:00
|
|
|
mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability =
|
|
|
|
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
|
2017-11-30 05:01:06 +00:00
|
|
|
mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true;
|
|
|
|
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
|
2018-01-17 16:40:14 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
|
2017-11-30 05:01:06 +00:00
|
|
|
for (bool nullTexture : {false, true}) {
|
|
|
|
LazyProxyTest test(reporter);
|
|
|
|
ctx->contextPriv().addOnFlushCallbackObject(&test);
|
2018-03-06 13:20:37 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
|
|
|
|
SkBackingFit::kExact, 100, 100,
|
|
|
|
kRGBA_8888_GrPixelConfig, nullptr);
|
2017-11-30 05:01:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtc);
|
2018-03-06 13:20:37 +00:00
|
|
|
sk_sp<GrRenderTargetContext> mockAtlas = ctx->contextPriv().makeDeferredRenderTargetContext(
|
|
|
|
SkBackingFit::kExact, 10, 10,
|
2017-11-30 05:01:06 +00:00
|
|
|
kAlpha_half_GrPixelConfig, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, mockAtlas);
|
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()),
|
2018-06-07 15:05:56 +00:00
|
|
|
LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture));
|
2017-11-30 05:01:06 +00:00
|
|
|
ctx->contextPriv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:34:25 +00:00
|
|
|
static const int kSize = 16;
|
|
|
|
|
2018-01-16 21:14:41 +00:00
|
|
|
DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
|
|
|
|
GrMockOptions mockOptions;
|
|
|
|
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
|
2018-01-17 16:40:14 +00:00
|
|
|
auto proxyProvider = ctx->contextPriv().proxyProvider();
|
2018-01-16 21:14:41 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
2018-01-29 15:34:25 +00:00
|
|
|
desc.fWidth = kSize;
|
|
|
|
desc.fHeight = kSize;
|
2018-01-16 21:14:41 +00:00
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
2018-02-08 20:05:44 +00:00
|
|
|
using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType;
|
2018-01-16 21:14:41 +00:00
|
|
|
for (bool doInstantiate : {true, false}) {
|
2018-02-08 20:05:44 +00:00
|
|
|
for (auto lazyType : {LazyInstantiationType::kSingleUse,
|
2018-03-09 17:05:04 +00:00
|
|
|
LazyInstantiationType::kMultipleUse,
|
|
|
|
LazyInstantiationType::kUninstantiate}) {
|
2018-02-08 20:05:44 +00:00
|
|
|
int testCount = 0;
|
|
|
|
int* testCountPtr = &testCount;
|
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
|
2018-02-13 16:13:51 +00:00
|
|
|
[testCountPtr](GrResourceProvider* resourceProvider) {
|
2018-02-08 20:05:44 +00:00
|
|
|
if (!resourceProvider) {
|
|
|
|
*testCountPtr = -1;
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
*testCountPtr = 1;
|
2018-01-16 21:14:41 +00:00
|
|
|
return sk_sp<GrTexture>();
|
2018-03-04 03:43:43 +00:00
|
|
|
},
|
2018-07-30 17:13:17 +00:00
|
|
|
desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D,
|
|
|
|
GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, lazyType);
|
2018-02-08 20:05:44 +00:00
|
|
|
|
2018-04-12 20:50:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy.get());
|
2018-02-08 20:05:44 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == testCount);
|
|
|
|
|
|
|
|
if (doInstantiate) {
|
|
|
|
proxy->priv().doLazyInstantiation(ctx->contextPriv().resourceProvider());
|
|
|
|
if (LazyInstantiationType::kSingleUse == proxy->priv().lazyInstantiationType()) {
|
|
|
|
// In SingleUse we will call the cleanup and delete the callback in the
|
|
|
|
// doLazyInstantiationCall.
|
|
|
|
REPORTER_ASSERT(reporter, -1 == testCount);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == testCount);
|
|
|
|
}
|
|
|
|
proxy.reset();
|
|
|
|
REPORTER_ASSERT(reporter, -1 == testCount);
|
|
|
|
} else {
|
|
|
|
proxy.reset();
|
|
|
|
REPORTER_ASSERT(reporter, -1 == testCount);
|
|
|
|
}
|
2018-01-16 21:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:34:25 +00:00
|
|
|
class LazyFailedInstantiationTestOp : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2018-06-07 15:05:56 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
|
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
int* testExecuteValue,
|
|
|
|
bool shouldFailInstantiation) {
|
2018-06-19 17:09:54 +00:00
|
|
|
GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
|
|
|
|
|
|
|
|
return pool->allocate<LazyFailedInstantiationTestOp>(proxyProvider,
|
|
|
|
testExecuteValue,
|
|
|
|
shouldFailInstantiation);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 18:37:19 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
|
2018-06-07 15:05:56 +00:00
|
|
|
func(fLazyProxy.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class GrOpMemoryPool; // for ctor
|
|
|
|
|
2018-01-29 15:34:25 +00:00
|
|
|
LazyFailedInstantiationTestOp(GrProxyProvider* proxyProvider, int* testExecuteValue,
|
|
|
|
bool shouldFailInstantiation)
|
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fTestExecuteValue(testExecuteValue) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = kSize;
|
|
|
|
desc.fHeight = kSize;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
fLazyProxy = proxyProvider->createLazyProxy(
|
2018-03-04 03:43:43 +00:00
|
|
|
[testExecuteValue, shouldFailInstantiation, desc](GrResourceProvider* rp) {
|
2018-02-01 17:21:39 +00:00
|
|
|
if (!rp) {
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
if (shouldFailInstantiation) {
|
|
|
|
*testExecuteValue = 1;
|
2018-01-29 15:34:25 +00:00
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
return rp->createTexture(desc, SkBudgeted::kNo);
|
2018-03-04 03:43:43 +00:00
|
|
|
},
|
2018-07-30 17:13:17 +00:00
|
|
|
desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D,
|
|
|
|
SkBackingFit::kExact, SkBudgeted::kNo);
|
2018-01-29 15:34:25 +00:00
|
|
|
|
2018-04-12 20:50:17 +00:00
|
|
|
SkASSERT(fLazyProxy.get());
|
|
|
|
|
2018-01-29 15:34:25 +00:00
|
|
|
this->setBounds(SkRect::MakeIWH(kSize, kSize),
|
|
|
|
HasAABloat::kNo, IsZeroArea::kNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "LazyFailedInstantiationTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2018-07-11 14:02:07 +00:00
|
|
|
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override {
|
2018-01-29 15:34:25 +00:00
|
|
|
return RequiresDstTexture::kNo;
|
|
|
|
}
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
|
|
|
void onExecute(GrOpFlushState* state) override {
|
|
|
|
*fTestExecuteValue = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int* fTestExecuteValue;
|
|
|
|
sk_sp<GrSurfaceProxy> fLazyProxy;
|
|
|
|
|
|
|
|
typedef GrDrawOp INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was
|
|
|
|
// associated with.
|
|
|
|
DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) {
|
|
|
|
GrMockOptions mockOptions;
|
|
|
|
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
|
2018-02-07 22:08:21 +00:00
|
|
|
GrResourceProvider* resourceProvider = ctx->contextPriv().resourceProvider();
|
2018-01-29 15:34:25 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
|
|
|
|
for (bool failInstantiation : {false, true}) {
|
2018-03-06 13:20:37 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
|
|
|
|
SkBackingFit::kExact, 100, 100,
|
2018-01-29 15:34:25 +00:00
|
|
|
kRGBA_8888_GrPixelConfig, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, rtc);
|
|
|
|
|
|
|
|
rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
|
|
|
|
|
|
|
|
int executeTestValue = 0;
|
2018-06-07 15:05:56 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make(
|
|
|
|
ctx.get(), proxyProvider, &executeTestValue, failInstantiation));
|
2018-01-29 15:34:25 +00:00
|
|
|
ctx->flush();
|
|
|
|
|
|
|
|
if (failInstantiation) {
|
2018-02-07 22:08:21 +00:00
|
|
|
if (resourceProvider->explicitlyAllocateGPUResources()) {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == executeTestValue);
|
|
|
|
} else {
|
|
|
|
// When we disable explicit gpu resource allocation we don't throw away ops that
|
|
|
|
// have uninstantiated proxies.
|
|
|
|
REPORTER_ASSERT(reporter, 2 == executeTestValue);
|
|
|
|
}
|
2018-01-29 15:34:25 +00:00
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 2 == executeTestValue);
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class LazyUninstantiateTestOp : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2018-06-07 15:05:56 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrContext* context, sk_sp<GrTextureProxy> proxy) {
|
2018-06-19 17:09:54 +00:00
|
|
|
GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
|
|
|
|
|
|
|
|
return pool->allocate<LazyUninstantiateTestOp>(std::move(proxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 18:37:19 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
|
2018-03-08 20:27:36 +00:00
|
|
|
func(fLazyProxy.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class GrOpMemoryPool; // for ctor
|
|
|
|
|
2018-06-07 15:05:56 +00:00
|
|
|
LazyUninstantiateTestOp(sk_sp<GrTextureProxy> proxy)
|
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fLazyProxy(std::move(proxy)) {
|
|
|
|
this->setBounds(SkRect::MakeIWH(kSize, kSize), HasAABloat::kNo, IsZeroArea::kNo);
|
|
|
|
}
|
|
|
|
|
2018-03-08 20:27:36 +00:00
|
|
|
const char* name() const override { return "LazyUninstantiateTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2018-07-11 14:02:07 +00:00
|
|
|
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) override {
|
2018-03-08 20:27:36 +00:00
|
|
|
return RequiresDstTexture::kNo;
|
|
|
|
}
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
|
|
|
void onExecute(GrOpFlushState* state) override {}
|
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> fLazyProxy;
|
|
|
|
|
|
|
|
typedef GrDrawOp INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void UninstantiateReleaseProc(void* releaseValue) {
|
|
|
|
(*static_cast<int*>(releaseValue))++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that lazy proxies with the Uninstantiate LazyCallbackType are uninstantiated and released as
|
|
|
|
// expected.
|
|
|
|
DEF_GPUTEST(LazyProxyUninstantiateTest, reporter, /* options */) {
|
|
|
|
GrMockOptions mockOptions;
|
|
|
|
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
|
|
|
|
GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
|
|
|
|
GrGpu* gpu = ctx->contextPriv().getGpu();
|
|
|
|
|
|
|
|
using LazyType = GrSurfaceProxy::LazyInstantiationType;
|
|
|
|
for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kUninstantiate}) {
|
|
|
|
sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
|
|
|
|
SkBackingFit::kExact, 100, 100,
|
|
|
|
kRGBA_8888_GrPixelConfig, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, rtc);
|
|
|
|
|
|
|
|
rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
|
|
|
|
|
|
|
|
int instantiateTestValue = 0;
|
|
|
|
int releaseTestValue = 0;
|
|
|
|
int* instantiatePtr = &instantiateTestValue;
|
|
|
|
int* releasePtr = &releaseTestValue;
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = kSize;
|
|
|
|
desc.fHeight = kSize;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
2018-09-25 13:31:10 +00:00
|
|
|
nullptr, kSize, kSize, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy(
|
|
|
|
[instantiatePtr, releasePtr, backendTex](GrResourceProvider* rp) {
|
|
|
|
if (!rp) {
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<GrTexture> texture = rp->wrapBackendTexture(backendTex);
|
|
|
|
if (!texture) {
|
|
|
|
return sk_sp<GrTexture>();
|
|
|
|
}
|
|
|
|
(*instantiatePtr)++;
|
|
|
|
texture->setRelease(UninstantiateReleaseProc, releasePtr);
|
|
|
|
return texture;
|
|
|
|
},
|
2018-07-30 17:13:17 +00:00
|
|
|
desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D,
|
|
|
|
GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, lazyType);
|
2018-03-08 20:27:36 +00:00
|
|
|
|
2018-04-12 20:50:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, lazyProxy.get());
|
|
|
|
|
2018-06-07 15:05:56 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyUninstantiateTestOp::Make(ctx.get(), lazyProxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
ctx->flush();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
|
|
|
|
if (LazyType::kUninstantiate == lazyType) {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == releaseTestValue);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 0 == releaseTestValue);
|
|
|
|
}
|
2018-01-29 15:34:25 +00:00
|
|
|
|
2018-03-08 20:27:36 +00:00
|
|
|
// This should cause the uninstantiate proxies to be instantiated again but have no effect
|
|
|
|
// on the others
|
2018-06-07 15:05:56 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyUninstantiateTestOp::Make(ctx.get(), lazyProxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
// Add a second op to make sure we only instantiate once.
|
2018-06-07 15:05:56 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyUninstantiateTestOp::Make(ctx.get(), lazyProxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
ctx->flush();
|
|
|
|
|
|
|
|
if (LazyType::kUninstantiate == lazyType) {
|
|
|
|
REPORTER_ASSERT(reporter, 2 == instantiateTestValue);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == releaseTestValue);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == releaseTestValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
lazyProxy.reset();
|
|
|
|
if (LazyType::kUninstantiate == lazyType) {
|
|
|
|
REPORTER_ASSERT(reporter, 2 == releaseTestValue);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == releaseTestValue);
|
|
|
|
}
|
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
2018-01-29 15:34:25 +00:00
|
|
|
}
|