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/mock/GrMockTypes.h"
|
|
|
|
#include "src/core/SkRectPriv.h"
|
|
|
|
#include "src/gpu/GrClip.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrOnFlushResourceProvider.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2021-07-01 14:27:44 +00:00
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrSurfaceProxyPriv.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2021-02-09 19:41:52 +00:00
|
|
|
#include "src/gpu/GrTextureProxyPriv.h"
|
2021-07-06 20:28:52 +00:00
|
|
|
#include "src/gpu/effects/GrTextureEffect.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/mock/GrMockGpu.h"
|
2021-08-11 19:43:50 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.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);
|
|
|
|
}
|
|
|
|
|
2020-11-11 13:51:25 +00:00
|
|
|
void preFlush(GrOnFlushResourceProvider*, SkSpan<const uint32_t>) override {
|
2017-11-30 05:01:06 +00:00
|
|
|
REPORTER_ASSERT(fReporter, !fHasOpTexture);
|
|
|
|
REPORTER_ASSERT(fReporter, !fHasClipTexture);
|
|
|
|
}
|
|
|
|
|
2020-11-11 13:51:25 +00:00
|
|
|
void postFlush(GrDeferredUploadToken, SkSpan<const uint32_t>) override {
|
2017-11-30 05:01:06 +00:00
|
|
|
REPORTER_ASSERT(fReporter, fHasOpTexture);
|
|
|
|
REPORTER_ASSERT(fReporter, fHasClipTexture);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Op final : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* context,
|
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
LazyProxyTest* test,
|
|
|
|
bool nullTexture) {
|
|
|
|
return GrOp::Make<Op>(context, context, proxyProvider, test, nullTexture);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 13:23:58 +00:00
|
|
|
void visitProxies(const GrVisitProxyFunc& func) const override {
|
2020-07-21 13:27:25 +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:
|
2020-10-07 20:46:15 +00:00
|
|
|
friend class GrOp; // for ctor
|
2018-06-12 14:11:12 +00:00
|
|
|
|
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-07-30 16:49:10 +00:00
|
|
|
ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kBGR_565,
|
|
|
|
GrRenderable::kNo);
|
2018-06-16 23:22:59 +00:00
|
|
|
fProxy = GrProxyProvider::MakeFullyLazyProxy(
|
2020-03-23 22:32:50 +00:00
|
|
|
[this, nullTexture](GrResourceProvider* rp,
|
|
|
|
const GrSurfaceProxy::LazySurfaceDesc& desc)
|
|
|
|
-> GrSurfaceProxy::LazyCallbackResult {
|
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 {
|
2020-02-07 19:17:25 +00:00
|
|
|
static constexpr SkISize kDimensions = {1234, 567};
|
2019-07-19 18:24:36 +00:00
|
|
|
sk_sp<GrTexture> texture = rp->createTexture(
|
2020-03-23 22:32:50 +00:00
|
|
|
kDimensions, desc.fFormat, desc.fRenderable, desc.fSampleCnt,
|
2020-07-21 14:32:07 +00:00
|
|
|
desc.fMipmapped, desc.fBudgeted, desc.fProtected);
|
2018-06-16 23:22:59 +00:00
|
|
|
REPORTER_ASSERT(fTest->fReporter, texture);
|
2019-08-15 14:55:49 +00:00
|
|
|
return texture;
|
2018-06-16 23:22:59 +00:00
|
|
|
}
|
|
|
|
},
|
2020-03-27 00:37:01 +00:00
|
|
|
format, GrRenderable::kNo, 1, GrProtected::kNo, *proxyProvider->caps(),
|
|
|
|
GrSurfaceProxy::UseAllocator::kYes);
|
2018-06-16 23:22:59 +00:00
|
|
|
|
|
|
|
this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo,
|
2019-10-01 19:14:44 +00:00
|
|
|
GrOp::IsHairline::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-06-24 00:07:38 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip* clip,
|
2021-04-22 18:57:28 +00:00
|
|
|
GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
2020-03-18 17:23:45 +00:00
|
|
|
void onPrePrepare(GrRecordingContext*,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2020-03-18 17:23:45 +00:00
|
|
|
GrAppliedClip*,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView&,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {}
|
2020-03-18 17:23:45 +00:00
|
|
|
|
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) {
|
2019-12-12 13:26:58 +00:00
|
|
|
static const GrColorType kColorType = GrColorType::kAlpha_F16;
|
|
|
|
static const GrSurfaceOrigin kOrigin = kBottomLeft_GrSurfaceOrigin;
|
2018-11-16 20:43:41 +00:00
|
|
|
const GrBackendFormat format =
|
2019-12-12 13:26:58 +00:00
|
|
|
ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
|
2020-01-22 21:58:15 +00:00
|
|
|
GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType);
|
2018-06-16 23:22:59 +00:00
|
|
|
fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
|
2020-03-23 22:32:50 +00:00
|
|
|
[this](GrResourceProvider* rp, const GrSurfaceProxy::LazySurfaceDesc&)
|
|
|
|
-> GrSurfaceProxy::LazyCallbackResult {
|
2019-04-01 16:29:34 +00:00
|
|
|
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
|
|
|
|
fTest->fHasClipTexture = true;
|
|
|
|
fAtlas->instantiate(rp);
|
|
|
|
return sk_ref_sp(fAtlas->peekTexture());
|
|
|
|
},
|
2020-03-27 00:37:01 +00:00
|
|
|
format, GrRenderable::kYes, 1, GrProtected::kNo, *proxyProvider->caps(),
|
|
|
|
GrSurfaceProxy::UseAllocator::kYes);
|
2020-06-17 17:05:00 +00:00
|
|
|
auto atlasEffect = GrTextureEffect::Make({fLazyProxy, kOrigin, readSwizzle},
|
|
|
|
kPremul_SkAlphaType);
|
2020-06-22 18:46:36 +00:00
|
|
|
this->registerChild(std::move(atlasEffect));
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name() const override { return "LazyProxyTest::ClipFP"; }
|
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
2019-12-11 15:45:01 +00:00
|
|
|
return std::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas);
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
2021-08-09 15:23:04 +00:00
|
|
|
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
|
2021-02-23 15:07:05 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2021-08-06 19:33:58 +00:00
|
|
|
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
|
2017-11-30 05:01:06 +00:00
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Clip : public GrClip {
|
|
|
|
public:
|
|
|
|
Clip(LazyProxyTest* test, GrTextureProxy* atlas)
|
|
|
|
: fTest(test)
|
|
|
|
, fAtlas(atlas) {}
|
|
|
|
|
|
|
|
private:
|
2020-06-11 14:29:00 +00:00
|
|
|
SkIRect getConservativeBounds() const final {
|
|
|
|
return SkIRect::MakeSize(fAtlas->dimensions());
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
Effect apply(GrRecordingContext* rContext,
|
|
|
|
skgpu::v1::SurfaceDrawContext*,
|
|
|
|
GrDrawOp*,
|
|
|
|
GrAAType,
|
|
|
|
GrAppliedClip* out,
|
|
|
|
SkRect* bounds) const override {
|
|
|
|
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
|
|
|
|
out->addCoverageFP(std::make_unique<ClipFP>(rContext, proxyProvider, fTest, fAtlas));
|
2020-06-30 15:12:46 +00:00
|
|
|
return Effect::kClipped;
|
2017-11-30 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LazyProxyTest* const fTest;
|
|
|
|
GrTextureProxy* fAtlas;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
skiatest::Reporter* fReporter;
|
|
|
|
bool fHasOpTexture;
|
|
|
|
bool fHasClipTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GPUTEST(LazyProxyTest, reporter, /* options */) {
|
|
|
|
GrMockOptions mockOptions;
|
2019-07-09 16:34:38 +00:00
|
|
|
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability =
|
2018-02-03 01:32:49 +00:00
|
|
|
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
|
2019-07-09 16:34:38 +00:00
|
|
|
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true;
|
2020-07-13 20:13:31 +00:00
|
|
|
sk_sp<GrDirectContext> ctx = GrDirectContext::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);
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(ctx.get(), GrColorType::kRGBA_8888, nullptr,
|
|
|
|
SkBackingFit::kExact, {100, 100},
|
|
|
|
SkSurfaceProps());
|
|
|
|
REPORTER_ASSERT(reporter, sdc);
|
|
|
|
auto mockAtlas = skgpu::v1::SurfaceDrawContext::Make(ctx.get(), GrColorType::kAlpha_F16,
|
|
|
|
nullptr, SkBackingFit::kExact,
|
|
|
|
{10, 10}, SkSurfaceProps());
|
2017-11-30 05:01:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, mockAtlas);
|
2020-05-29 13:54:07 +00:00
|
|
|
LazyProxyTest::Clip clip(&test, mockAtlas->asTextureProxy());
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->addDrawOp(&clip,
|
2020-11-30 19:33:58 +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;
|
2020-07-13 20:13:31 +00:00
|
|
|
sk_sp<GrDirectContext> ctx = GrDirectContext::MakeMock(&mockOptions, GrContextOptions());
|
2019-02-04 18:26:26 +00:00
|
|
|
auto proxyProvider = ctx->priv().proxyProvider();
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrCaps* caps = ctx->priv().caps();
|
2018-01-16 21:14:41 +00:00
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kNo);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
auto tex = ctx->priv().resourceProvider()->createTexture({kSize, kSize}, format,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrRenderable::kNo, 1, GrMipmapped::kNo,
|
2020-02-07 19:17:25 +00:00
|
|
|
SkBudgeted::kNo, GrProtected::kNo);
|
2019-08-30 20:19:42 +00:00
|
|
|
using LazyInstantiationResult = GrSurfaceProxy::LazyCallbackResult;
|
2018-01-16 21:14:41 +00:00
|
|
|
for (bool doInstantiate : {true, false}) {
|
2019-08-30 20:19:42 +00:00
|
|
|
for (bool releaseCallback : {false, true}) {
|
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:
|
2019-08-30 20:19:42 +00:00
|
|
|
TestCallback(int* value, bool releaseCallback, sk_sp<GrTexture> tex)
|
|
|
|
: fValue(value)
|
|
|
|
, fReleaseCallback(releaseCallback)
|
|
|
|
, fTexture(std::move(tex)) {}
|
2019-02-14 18:05:25 +00:00
|
|
|
TestCallback(const TestCallback& that) { SkASSERT(0); }
|
2019-08-30 20:19:42 +00:00
|
|
|
TestCallback(TestCallback&& that)
|
|
|
|
: fValue(that.fValue)
|
|
|
|
, fReleaseCallback(that.fReleaseCallback)
|
|
|
|
, fTexture(std::move(that.fTexture)) {
|
|
|
|
that.fValue = nullptr;
|
|
|
|
}
|
2019-02-14 18:05:25 +00:00
|
|
|
|
|
|
|
~TestCallback() { fValue ? (void)(*fValue = -1) : void(); }
|
|
|
|
|
|
|
|
TestCallback& operator=(TestCallback&& that) {
|
2020-04-30 01:11:14 +00:00
|
|
|
fValue = std::exchange(that.fValue, nullptr);
|
2019-02-14 18:05:25 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
TestCallback& operator=(const TestCallback& that) = delete;
|
|
|
|
|
2020-03-23 22:32:50 +00:00
|
|
|
LazyInstantiationResult operator()(GrResourceProvider*,
|
|
|
|
const GrSurfaceProxy::LazySurfaceDesc&) const {
|
2019-02-14 18:05:25 +00:00
|
|
|
*fValue = 1;
|
2019-08-30 20:19:42 +00:00
|
|
|
return {fTexture, fReleaseCallback};
|
2019-02-14 18:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int* fValue = nullptr;
|
2019-08-30 20:19:42 +00:00
|
|
|
bool fReleaseCallback;
|
|
|
|
sk_sp<GrTexture> fTexture;
|
2019-02-14 18:05:25 +00:00
|
|
|
};
|
2018-02-08 20:05:44 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
|
2020-02-07 19:17:25 +00:00
|
|
|
TestCallback(&testCount, releaseCallback, tex), format, {kSize, kSize},
|
2020-08-26 17:28:22 +00:00
|
|
|
GrMipmapped::kNo, GrMipmapStatus::kNotAllocated, GrInternalSurfaceFlags::kNone,
|
|
|
|
SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo,
|
|
|
|
GrSurfaceProxy::UseAllocator::kYes);
|
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());
|
2019-08-30 20:19:42 +00:00
|
|
|
if (releaseCallback) {
|
|
|
|
// We will call the cleanup and delete the callback in the
|
2018-02-08 20:05:44 +00:00
|
|
|
// 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
|
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* rContext,
|
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
int* testExecuteValue,
|
|
|
|
bool shouldFailInstantiation) {
|
|
|
|
return GrOp::Make<LazyFailedInstantiationTestOp>(rContext,
|
|
|
|
rContext->priv().caps(),
|
|
|
|
proxyProvider,
|
|
|
|
testExecuteValue,
|
|
|
|
shouldFailInstantiation);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 13:23:58 +00:00
|
|
|
void visitProxies(const GrVisitProxyFunc& func) const override {
|
2020-07-21 13:27:25 +00:00
|
|
|
func(fLazyProxy.get(), GrMipmapped::kNo);
|
2018-06-07 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-10-07 20:46:15 +00:00
|
|
|
friend class GrOp; // for ctor
|
2018-06-12 14:11:12 +00:00
|
|
|
|
2020-07-22 13:35:49 +00:00
|
|
|
LazyFailedInstantiationTestOp(const GrCaps* caps, GrProxyProvider* proxyProvider,
|
2018-11-16 20:43:41 +00:00
|
|
|
int* testExecuteValue, bool shouldFailInstantiation)
|
2018-01-29 15:34:25 +00:00
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fTestExecuteValue(testExecuteValue) {
|
2020-03-23 22:32:50 +00:00
|
|
|
SkISize dims = {kSize, kSize};
|
2020-07-22 13:35:49 +00:00
|
|
|
GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
|
|
|
|
GrRenderable::kNo);
|
2018-01-29 15:34:25 +00:00
|
|
|
|
|
|
|
fLazyProxy = proxyProvider->createLazyProxy(
|
2020-03-23 22:32:50 +00:00
|
|
|
[testExecuteValue, shouldFailInstantiation](
|
|
|
|
GrResourceProvider* rp, const GrSurfaceProxy::LazySurfaceDesc& desc)
|
|
|
|
-> GrSurfaceProxy::LazyCallbackResult {
|
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
|
|
|
}
|
2020-03-23 22:32:50 +00:00
|
|
|
return {rp->createTexture(desc.fDimensions, desc.fFormat, desc.fRenderable,
|
2020-07-21 14:32:07 +00:00
|
|
|
desc.fSampleCnt, desc.fMipmapped, desc.fBudgeted,
|
2020-03-23 22:32:50 +00:00
|
|
|
desc.fProtected),
|
2019-08-30 20:19:42 +00:00
|
|
|
true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
|
2018-03-04 03:43:43 +00:00
|
|
|
},
|
2020-08-26 17:28:22 +00:00
|
|
|
format, dims, GrMipmapped::kNo, GrMipmapStatus::kNotAllocated,
|
|
|
|
GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
|
2018-01-29 15:34:25 +00:00
|
|
|
|
2018-04-12 20:50:17 +00:00
|
|
|
SkASSERT(fLazyProxy.get());
|
|
|
|
|
2020-03-23 22:32:50 +00:00
|
|
|
this->setBounds(SkRect::Make(dims), HasAABloat::kNo, IsHairline::kNo);
|
2018-01-29 15:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "LazyFailedInstantiationTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2021-04-22 18:57:28 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override {
|
2019-01-15 18:53:00 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
2018-01-29 15:34:25 +00:00
|
|
|
}
|
2020-03-18 17:23:45 +00:00
|
|
|
void onPrePrepare(GrRecordingContext*,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2020-03-18 17:23:45 +00:00
|
|
|
GrAppliedClip*,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView&,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {}
|
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;
|
2019-08-27 18:30:21 +00:00
|
|
|
sk_sp<GrTextureProxy> fLazyProxy;
|
2018-01-29 15:34:25 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrDrawOp;
|
2018-01-29 15:34:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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;
|
2020-07-13 20:13:31 +00:00
|
|
|
sk_sp<GrDirectContext> ctx = GrDirectContext::MakeMock(&mockOptions, GrContextOptions());
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
|
2018-01-29 15:34:25 +00:00
|
|
|
for (bool failInstantiation : {false, true}) {
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(ctx.get(), GrColorType::kRGBA_8888, nullptr,
|
|
|
|
SkBackingFit::kExact, {100, 100},
|
|
|
|
SkSurfaceProps());
|
|
|
|
REPORTER_ASSERT(reporter, sdc);
|
2018-01-29 15:34:25 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(SkPMColor4f::FromBytes_RGBA(0xbaaaaaad));
|
2018-01-29 15:34:25 +00:00
|
|
|
|
|
|
|
int executeTestValue = 0;
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->addDrawOp(LazyFailedInstantiationTestOp::Make(ctx.get(), proxyProvider,
|
2020-11-30 19:33:58 +00:00
|
|
|
&executeTestValue, failInstantiation));
|
2020-05-14 19:45:44 +00:00
|
|
|
ctx->flushAndSubmit();
|
2018-01-29 15:34:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|