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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2017-11-30 05:01:06 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "include/gpu/mock/GrMockTypes.h"
|
|
|
|
#include "include/private/GrSurfaceProxy.h"
|
|
|
|
#include "include/private/GrTextureProxy.h"
|
|
|
|
#include "src/core/SkExchange.h"
|
|
|
|
#include "src/core/SkMakeUnique.h"
|
|
|
|
#include "src/core/SkRectPriv.h"
|
|
|
|
#include "src/gpu/GrClip.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrOnFlushResourceProvider.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContextPriv.h"
|
|
|
|
#include "src/gpu/GrSurfaceProxyPriv.h"
|
|
|
|
#include "src/gpu/GrTextureProxyPriv.h"
|
|
|
|
#include "src/gpu/mock/GrMockGpu.h"
|
2017-11-30 05:01:06 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2019-02-13 16:02:28 +00:00
|
|
|
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
|
2018-06-07 15:05:56 +00:00
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
LazyProxyTest* test,
|
|
|
|
bool nullTexture) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-06-19 17:09:54 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
return pool->allocate<Op>(context, proxyProvider, test, nullTexture);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 01:35:29 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func) const override {
|
2019-05-23 21:15:47 +00:00
|
|
|
func(fProxy.get(), GrMipMapped::kNo);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 18:56:37 +00:00
|
|
|
void onExecute(GrOpFlushState*, const SkRect& chainBounds) override {
|
2018-06-07 15:05:56 +00:00
|
|
|
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
|
|
|
|
|
2019-02-13 16:02:28 +00:00
|
|
|
Op(GrRecordingContext* ctx, GrProxyProvider* proxyProvider,
|
|
|
|
LazyProxyTest* test, bool nullTexture)
|
2018-01-17 16:40:14 +00:00
|
|
|
: GrDrawOp(ClassID()), fTest(test) {
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromColorType(kRGB_565_SkColorType);
|
2018-06-16 23:22:59 +00:00
|
|
|
fProxy = GrProxyProvider::MakeFullyLazyProxy(
|
2019-04-01 16:29:34 +00:00
|
|
|
[this, nullTexture](
|
|
|
|
GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult {
|
2018-06-16 23:22:59 +00:00
|
|
|
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
|
|
|
|
fTest->fHasOpTexture = true;
|
|
|
|
if (nullTexture) {
|
2019-04-01 16:29:34 +00:00
|
|
|
return {};
|
2018-06-16 23:22:59 +00:00
|
|
|
} else {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = 1234;
|
|
|
|
desc.fHeight = 567;
|
|
|
|
desc.fConfig = kRGB_565_GrPixelConfig;
|
2019-04-09 22:41:27 +00:00
|
|
|
sk_sp<GrTexture> texture = rp->createTexture(
|
|
|
|
desc, SkBudgeted::kYes, GrResourceProvider::Flags::kNoPendingIO);
|
2018-06-16 23:22:59 +00:00
|
|
|
REPORTER_ASSERT(fTest->fReporter, texture);
|
2019-04-01 16:29:34 +00:00
|
|
|
return std::move(texture);
|
2018-06-16 23:22:59 +00:00
|
|
|
}
|
|
|
|
},
|
2018-11-16 20:43:41 +00:00
|
|
|
format, GrProxyProvider::Renderable::kNo, kTopLeft_GrSurfaceOrigin,
|
2018-06-16 23:22:59 +00:00
|
|
|
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; }
|
2019-03-05 17:11:58 +00:00
|
|
|
GrProcessorSet::Analysis finalize(
|
2019-04-17 20:03:30 +00:00
|
|
|
const GrCaps&, const GrAppliedClip* clip, GrFSAAType, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
|
|
|
|
|
|
|
LazyProxyTest* const fTest;
|
|
|
|
sk_sp<GrTextureProxy> fProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClipFP : public GrFragmentProcessor {
|
|
|
|
public:
|
2019-02-13 16:02:28 +00:00
|
|
|
ClipFP(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test,
|
2018-11-16 20:43:41 +00:00
|
|
|
GrTextureProxy* atlas)
|
2017-11-30 05:01:06 +00:00
|
|
|
: GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
|
2018-11-16 20:43:41 +00:00
|
|
|
, fContext(ctx)
|
2018-01-17 16:40:14 +00:00
|
|
|
, fProxyProvider(proxyProvider)
|
2017-11-30 05:01:06 +00:00
|
|
|
, fTest(test)
|
|
|
|
, fAtlas(atlas) {
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromGrColorType(GrColorType::kAlpha_F16,
|
|
|
|
GrSRGBEncoded::kNo);
|
2018-06-16 23:22:59 +00:00
|
|
|
fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
|
2019-04-01 16:29:34 +00:00
|
|
|
[this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult {
|
|
|
|
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
|
|
|
|
fTest->fHasClipTexture = true;
|
|
|
|
fAtlas->instantiate(rp);
|
|
|
|
return sk_ref_sp(fAtlas->peekTexture());
|
|
|
|
},
|
|
|
|
format, GrProxyProvider::Renderable::kYes, kBottomLeft_GrSurfaceOrigin,
|
|
|
|
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-11-16 20:43:41 +00:00
|
|
|
return skstd::make_unique<ClipFP>(fContext, 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
|
|
|
|
2019-02-13 16:02:28 +00:00
|
|
|
GrRecordingContext* const fContext;
|
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:
|
2019-02-13 16:02:28 +00:00
|
|
|
bool apply(GrRecordingContext* context, GrRenderTargetContext*, bool useHWAA,
|
|
|
|
bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
2018-11-16 20:43:41 +00:00
|
|
|
out->addCoverageFP(skstd::make_unique<ClipFP>(context, 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());
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
|
2017-11-30 05:01:06 +00:00
|
|
|
for (bool nullTexture : {false, true}) {
|
|
|
|
LazyProxyTest test(reporter);
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().addOnFlushCallbackObject(&test);
|
2018-11-16 20:43:41 +00:00
|
|
|
GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
|
|
|
|
sk_sp<GrRenderTargetContext> rtc = ctx->priv().makeDeferredRenderTargetContext(
|
2018-11-16 20:43:41 +00:00
|
|
|
format, SkBackingFit::kExact, 100, 100,
|
2018-03-06 13:20:37 +00:00
|
|
|
kRGBA_8888_GrPixelConfig, nullptr);
|
2017-11-30 05:01:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, rtc);
|
2018-11-16 20:43:41 +00:00
|
|
|
format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromGrColorType(GrColorType::kAlpha_F16,
|
2018-11-16 20:43:41 +00:00
|
|
|
GrSRGBEncoded::kNo);
|
2019-02-04 18:26:26 +00:00
|
|
|
sk_sp<GrRenderTargetContext> mockAtlas = ctx->priv().makeDeferredRenderTargetContext(
|
2018-11-16 20:43:41 +00:00
|
|
|
format, 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));
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test);
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
2019-02-04 18:26:26 +00:00
|
|
|
auto proxyProvider = ctx->priv().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-11-16 20:43:41 +00:00
|
|
|
GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2018-02-08 20:05:44 +00:00
|
|
|
using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType;
|
2019-04-01 16:29:34 +00:00
|
|
|
using LazyInstantiationResult = GrSurfaceProxy::LazyInstantiationResult;
|
2018-01-16 21:14:41 +00:00
|
|
|
for (bool doInstantiate : {true, false}) {
|
2019-03-08 16:12:14 +00:00
|
|
|
for (auto lazyType : {LazyInstantiationType::kSingleUse,
|
|
|
|
LazyInstantiationType::kMultipleUse,
|
|
|
|
LazyInstantiationType::kDeinstantiate}) {
|
2018-02-08 20:05:44 +00:00
|
|
|
int testCount = 0;
|
2019-02-14 18:05:25 +00:00
|
|
|
// Sets an integer to 1 when the callback is called and -1 when it is deleted.
|
|
|
|
class TestCallback {
|
|
|
|
public:
|
|
|
|
TestCallback(int* value) : fValue(value) {}
|
|
|
|
TestCallback(const TestCallback& that) { SkASSERT(0); }
|
|
|
|
TestCallback(TestCallback&& that) : fValue(that.fValue) { that.fValue = nullptr; }
|
|
|
|
|
|
|
|
~TestCallback() { fValue ? (void)(*fValue = -1) : void(); }
|
|
|
|
|
|
|
|
TestCallback& operator=(TestCallback&& that) {
|
|
|
|
fValue = skstd::exchange(that.fValue, nullptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
TestCallback& operator=(const TestCallback& that) = delete;
|
|
|
|
|
2019-04-01 16:29:34 +00:00
|
|
|
LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const {
|
2019-02-14 18:05:25 +00:00
|
|
|
*fValue = 1;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int* fValue = nullptr;
|
|
|
|
};
|
2018-02-08 20:05:44 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
|
2019-02-14 18:05:25 +00:00
|
|
|
TestCallback(&testCount), format, desc, kTopLeft_GrSurfaceOrigin,
|
|
|
|
GrMipMapped::kNo, 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) {
|
2019-02-04 18:26:26 +00:00
|
|
|
proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider());
|
2018-02-08 20:05:44 +00:00
|
|
|
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) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-06-19 17:09:54 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider,
|
2018-06-19 17:09:54 +00:00
|
|
|
testExecuteValue,
|
|
|
|
shouldFailInstantiation);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 01:35:29 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func) const override {
|
2019-05-23 21:15:47 +00:00
|
|
|
func(fLazyProxy.get(), GrMipMapped::kNo);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class GrOpMemoryPool; // for ctor
|
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider,
|
|
|
|
int* testExecuteValue, bool shouldFailInstantiation)
|
2018-01-29 15:34:25 +00:00
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fTestExecuteValue(testExecuteValue) {
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = kSize;
|
|
|
|
desc.fHeight = kSize;
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2018-11-16 20:43:41 +00:00
|
|
|
GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
|
2018-01-29 15:34:25 +00:00
|
|
|
|
|
|
|
fLazyProxy = proxyProvider->createLazyProxy(
|
2019-04-01 16:29:34 +00:00
|
|
|
[testExecuteValue, shouldFailInstantiation,
|
|
|
|
desc](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult {
|
2018-02-01 17:21:39 +00:00
|
|
|
if (shouldFailInstantiation) {
|
|
|
|
*testExecuteValue = 1;
|
2019-04-01 16:29:34 +00:00
|
|
|
return {};
|
2018-01-29 15:34:25 +00:00
|
|
|
}
|
2019-04-09 22:41:27 +00:00
|
|
|
return {rp->createTexture(desc, SkBudgeted::kNo,
|
|
|
|
GrResourceProvider::Flags::kNoPendingIO),
|
2019-04-02 15:49:54 +00:00
|
|
|
GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
|
2018-03-04 03:43:43 +00:00
|
|
|
},
|
2019-04-01 16:29:34 +00:00
|
|
|
format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, 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; }
|
2019-03-15 14:15:29 +00:00
|
|
|
GrProcessorSet::Analysis finalize(
|
|
|
|
const GrCaps&, const GrAppliedClip*, GrFSAAType, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2018-01-29 15:34:25 +00:00
|
|
|
}
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
2018-11-14 18:56:37 +00:00
|
|
|
void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {
|
2018-01-29 15:34:25 +00:00
|
|
|
*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());
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
|
2018-11-16 20:43:41 +00:00
|
|
|
GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
|
2018-01-29 15:34:25 +00:00
|
|
|
for (bool failInstantiation : {false, true}) {
|
2019-02-04 18:26:26 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc = ctx->priv().makeDeferredRenderTargetContext(
|
2018-11-16 20:43:41 +00:00
|
|
|
format, SkBackingFit::kExact, 100, 100,
|
2018-01-29 15:34:25 +00:00
|
|
|
kRGBA_8888_GrPixelConfig, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, rtc);
|
|
|
|
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad),
|
|
|
|
GrRenderTargetContext::CanClearFullscreen::kYes);
|
2018-01-29 15:34:25 +00:00
|
|
|
|
|
|
|
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) {
|
2019-04-23 11:36:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == executeTestValue);
|
2018-01-29 15:34:25 +00:00
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 2 == executeTestValue);
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
class LazyDeinstantiateTestOp : public GrDrawOp {
|
2018-03-08 20:27:36 +00:00
|
|
|
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) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrOpMemoryPool* pool = context->priv().opMemoryPool();
|
2018-06-19 17:09:54 +00:00
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
return pool->allocate<LazyDeinstantiateTestOp>(std::move(proxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 01:35:29 +00:00
|
|
|
void visitProxies(const VisitProxyFunc& func) const override {
|
2019-05-23 21:15:47 +00:00
|
|
|
func(fLazyProxy.get(), GrMipMapped::kNo);
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-06-12 14:11:12 +00:00
|
|
|
friend class GrOpMemoryPool; // for ctor
|
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
LazyDeinstantiateTestOp(sk_sp<GrTextureProxy> proxy)
|
|
|
|
: INHERITED(ClassID()), fLazyProxy(std::move(proxy)) {
|
2018-06-07 15:05:56 +00:00
|
|
|
this->setBounds(SkRect::MakeIWH(kSize, kSize), HasAABloat::kNo, IsZeroArea::kNo);
|
|
|
|
}
|
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
const char* name() const override { return "LazyDeinstantiateTestOp"; }
|
2018-03-08 20:27:36 +00:00
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2019-03-15 14:15:29 +00:00
|
|
|
GrProcessorSet::Analysis finalize(
|
|
|
|
const GrCaps&, const GrAppliedClip*, GrFSAAType, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
void onPrepare(GrOpFlushState*) override {}
|
2018-11-14 18:56:37 +00:00
|
|
|
void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {}
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> fLazyProxy;
|
|
|
|
|
|
|
|
typedef GrDrawOp INHERITED;
|
|
|
|
};
|
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
static void DeinstantiateReleaseProc(void* releaseValue) { (*static_cast<int*>(releaseValue))++; }
|
2018-03-08 20:27:36 +00:00
|
|
|
|
2018-12-07 16:15:53 +00:00
|
|
|
// Test that lazy proxies with the Deinstantiate LazyCallbackType are deinstantiated and released as
|
2018-03-08 20:27:36 +00:00
|
|
|
// expected.
|
2018-12-07 16:15:53 +00:00
|
|
|
DEF_GPUTEST(LazyProxyDeinstantiateTest, reporter, /* options */) {
|
2018-03-08 20:27:36 +00:00
|
|
|
GrMockOptions mockOptions;
|
|
|
|
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
|
2018-03-08 20:27:36 +00:00
|
|
|
|
2018-11-16 20:43:41 +00:00
|
|
|
GrBackendFormat format =
|
2019-02-04 18:26:26 +00:00
|
|
|
ctx->priv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2018-03-08 20:27:36 +00:00
|
|
|
using LazyType = GrSurfaceProxy::LazyInstantiationType;
|
2019-03-08 16:12:14 +00:00
|
|
|
for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kDeinstantiate}) {
|
2019-02-04 18:26:26 +00:00
|
|
|
sk_sp<GrRenderTargetContext> rtc = ctx->priv().makeDeferredRenderTargetContext(
|
2018-11-16 20:43:41 +00:00
|
|
|
format, SkBackingFit::kExact, 100, 100,
|
2018-03-08 20:27:36 +00:00
|
|
|
kRGBA_8888_GrPixelConfig, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, rtc);
|
|
|
|
|
2018-11-05 20:06:26 +00:00
|
|
|
rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad),
|
|
|
|
GrRenderTargetContext::CanClearFullscreen::kYes);
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture backendTex = ctx->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
kSize, kSize, kRGBA_8888_SkColorType, SkColors::kTransparent,
|
|
|
|
GrMipMapped::kNo, GrRenderable::kNo);
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy(
|
2019-04-01 16:29:34 +00:00
|
|
|
[instantiatePtr, releasePtr,
|
|
|
|
backendTex](GrResourceProvider* rp) -> GrSurfaceProxy::LazyInstantiationResult {
|
2019-01-24 20:58:58 +00:00
|
|
|
sk_sp<GrTexture> texture =
|
|
|
|
rp->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
|
2019-01-24 21:03:07 +00:00
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
2018-03-08 20:27:36 +00:00
|
|
|
if (!texture) {
|
2019-04-01 16:29:34 +00:00
|
|
|
return {};
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
|
|
|
(*instantiatePtr)++;
|
2018-12-07 16:15:53 +00:00
|
|
|
texture->setRelease(DeinstantiateReleaseProc, releasePtr);
|
2019-04-01 16:29:34 +00:00
|
|
|
return std::move(texture);
|
2018-03-08 20:27:36 +00:00
|
|
|
},
|
2018-11-16 20:43:41 +00:00
|
|
|
format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
|
2018-12-06 15:00:03 +00:00
|
|
|
GrInternalSurfaceFlags::kReadOnly, 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-12-07 16:15:53 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
ctx->flush();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
|
2019-03-08 16:12:14 +00:00
|
|
|
if (LazyType::kDeinstantiate == 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-12-07 16:15:53 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
// Add a second op to make sure we only instantiate once.
|
2018-12-07 16:15:53 +00:00
|
|
|
rtc->priv().testingOnly_addDrawOp(LazyDeinstantiateTestOp::Make(ctx.get(), lazyProxy));
|
2018-03-08 20:27:36 +00:00
|
|
|
ctx->flush();
|
|
|
|
|
2019-03-08 16:12:14 +00:00
|
|
|
if (LazyType::kDeinstantiate == lazyType) {
|
|
|
|
REPORTER_ASSERT(reporter, 2 == instantiateTestValue);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == releaseTestValue);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == releaseTestValue);
|
|
|
|
}
|
2018-03-08 20:27:36 +00:00
|
|
|
|
|
|
|
lazyProxy.reset();
|
2019-03-08 16:12:14 +00:00
|
|
|
if (LazyType::kDeinstantiate == lazyType) {
|
|
|
|
REPORTER_ASSERT(reporter, 2 == releaseTestValue);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, 1 == releaseTestValue);
|
|
|
|
}
|
2018-03-08 20:27:36 +00:00
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
ctx->deleteBackendTexture(backendTex);
|
2018-03-08 20:27:36 +00:00
|
|
|
}
|
2018-01-29 15:34:25 +00:00
|
|
|
}
|