skia2/tests/LazyProxyTest.cpp

403 lines
18 KiB
C++
Raw Normal View History

/*
* 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 "tests/Test.h"
#include "include/gpu/GrTexture.h"
#include "include/gpu/mock/GrMockTypes.h"
#include "src/core/SkExchange.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/GrSurfaceProxy.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/GrTextureProxyPriv.h"
#include "src/gpu/mock/GrMockGpu.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) override {
REPORTER_ASSERT(fReporter, !fHasOpTexture);
REPORTER_ASSERT(fReporter, !fHasClipTexture);
}
void postFlush(GrDeferredUploadToken, const uint32_t* opsTaskIDs, int numOpsTaskIDs) override {
REPORTER_ASSERT(fReporter, fHasOpTexture);
REPORTER_ASSERT(fReporter, fHasClipTexture);
}
class Op final : public GrDrawOp {
public:
DEFINE_OP_CLASS_ID
static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
GrProxyProvider* proxyProvider,
LazyProxyTest* test,
bool nullTexture) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
return pool->allocate<Op>(context, proxyProvider, test, nullTexture);
}
void visitProxies(const VisitProxyFunc& func) const override {
func(fProxy.get(), GrMipMapped::kNo);
}
void onExecute(GrOpFlushState*, const SkRect& chainBounds) override {
REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture);
REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture);
}
private:
friend class GrOpMemoryPool; // for ctor
Op(GrRecordingContext* ctx, GrProxyProvider* proxyProvider,
LazyProxyTest* test, bool nullTexture)
: GrDrawOp(ClassID()), fTest(test) {
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
const GrBackendFormat format =
ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kBGR_565,
GrRenderable::kNo);
GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(
format, GrColorType::kBGR_565);
fProxy = GrProxyProvider::MakeFullyLazyProxy(
[this, format,
nullTexture](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
fTest->fHasOpTexture = true;
if (nullTexture) {
return {};
} else {
static constexpr SkISize kDimensions = {1234, 567};
sk_sp<GrTexture> texture = rp->createTexture(
kDimensions, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
SkBudgeted::kYes, GrProtected::kNo);
REPORTER_ASSERT(fTest->fReporter, texture);
return texture;
}
},
format, readSwizzle, GrRenderable::kNo, 1, GrProtected::kNo,
*proxyProvider->caps(), GrSurfaceProxy::UseAllocator::kYes);
this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo,
GrOp::IsHairline::kNo);
}
const char* name() const override { return "LazyProxyTest::Op"; }
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip* clip,
bool hasMixedSampledCoverage, GrClampType) override {
return GrProcessorSet::EmptySetAnalysis();
}
void onPrepare(GrOpFlushState*) override {}
LazyProxyTest* const fTest;
sk_sp<GrTextureProxy> fProxy;
};
class ClipFP : public GrFragmentProcessor {
public:
ClipFP(GrRecordingContext* ctx, GrProxyProvider* proxyProvider, LazyProxyTest* test,
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
GrTextureProxy* atlas)
: GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
, fContext(ctx)
, fProxyProvider(proxyProvider)
, fTest(test)
, fAtlas(atlas) {
Reland "Update FragmentProcessor TextureSampler to hold an GrSurfaceProxyView." This reverts commit c5c024791bb7a587223b807e00ffba4a3eb5fdb7. Reason for revert: Doh Original change's description: > Revert "Update FragmentProcessor TextureSampler to hold an GrSurfaceProxyView." > > This reverts commit acf5929ae0addc5188117142fd3fb39828baa8d5. > > Reason for revert: May be blocking Chrome roll > Original change's description: > > Update FragmentProcessor TextureSampler to hold an GrSurfaceProxyView. > > > > In future CLs I will update the Ops that create the TextureSamplers to pass > > the GrSurfaceProxyView in. > > > > Bug: skia:9556 > > Change-Id: I550dab64974d32e4c3047188063efa2d0832328e > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259164 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Michael Ludwig <michaelludwig@google.com> > > TBR=egdaniel@google.com,michaelludwig@google.com > > Change-Id: Ic804a52c5c6d16a13a9cc2d85bb959f305134177 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:9556 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259433 > Reviewed-by: Robert Phillips <robertphillips@google.com> > Commit-Queue: Robert Phillips <robertphillips@google.com> TBR=egdaniel@google.com,robertphillips@google.com,michaelludwig@google.com Change-Id: If2af5b5b323858e59c0c8db3b75477d74d78abfd No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:9556 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259434 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
2019-12-12 13:26:58 +00:00
static const GrColorType kColorType = GrColorType::kAlpha_F16;
static const GrSurfaceOrigin kOrigin = kBottomLeft_GrSurfaceOrigin;
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
const GrBackendFormat format =
Reland "Update FragmentProcessor TextureSampler to hold an GrSurfaceProxyView." This reverts commit c5c024791bb7a587223b807e00ffba4a3eb5fdb7. Reason for revert: Doh Original change's description: > Revert "Update FragmentProcessor TextureSampler to hold an GrSurfaceProxyView." > > This reverts commit acf5929ae0addc5188117142fd3fb39828baa8d5. > > Reason for revert: May be blocking Chrome roll > Original change's description: > > Update FragmentProcessor TextureSampler to hold an GrSurfaceProxyView. > > > > In future CLs I will update the Ops that create the TextureSamplers to pass > > the GrSurfaceProxyView in. > > > > Bug: skia:9556 > > Change-Id: I550dab64974d32e4c3047188063efa2d0832328e > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259164 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Michael Ludwig <michaelludwig@google.com> > > TBR=egdaniel@google.com,michaelludwig@google.com > > Change-Id: Ic804a52c5c6d16a13a9cc2d85bb959f305134177 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:9556 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259433 > Reviewed-by: Robert Phillips <robertphillips@google.com> > Commit-Queue: Robert Phillips <robertphillips@google.com> TBR=egdaniel@google.com,robertphillips@google.com,michaelludwig@google.com Change-Id: If2af5b5b323858e59c0c8db3b75477d74d78abfd No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:9556 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259434 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
2019-12-12 13:26:58 +00:00
ctx->priv().caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(format, kColorType);
fLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
[this](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
fTest->fHasClipTexture = true;
fAtlas->instantiate(rp);
return sk_ref_sp(fAtlas->peekTexture());
},
format, readSwizzle, GrRenderable::kYes, 1, GrProtected::kNo,
*proxyProvider->caps(), GrSurfaceProxy::UseAllocator::kYes);
fAccess.set(GrSurfaceProxyView(fLazyProxy, kOrigin, readSwizzle),
GrSamplerState::Filter::kNearest);
this->setTextureSamplerCnt(1);
}
private:
const char* name() const override { return "LazyProxyTest::ClipFP"; }
std::unique_ptr<GrFragmentProcessor> clone() const override {
return std::make_unique<ClipFP>(fContext, fProxyProvider, fTest, fAtlas);
}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; }
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
const TextureSampler& onTextureSampler(int) const override { return fAccess; }
GrRecordingContext* const fContext;
GrProxyProvider* const fProxyProvider;
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:
bool apply(GrRecordingContext* context, GrRenderTargetContext*, bool useHWAA,
bool hasUserStencilSettings, GrAppliedClip* out, SkRect* bounds) const override {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
out->addCoverageFP(std::make_unique<ClipFP>(context, proxyProvider, fTest, fAtlas));
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->setLTRB(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;
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fRenderability =
GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
mockOptions.fConfigOptions[(int)GrColorType::kAlpha_F16].fTexturable = true;
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
for (bool nullTexture : {false, true}) {
LazyProxyTest test(reporter);
ctx->priv().addOnFlushCallbackObject(&test);
auto rtc = GrRenderTargetContext::Make(
ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100});
REPORTER_ASSERT(reporter, rtc);
auto mockAtlas = GrRenderTargetContext::Make(
ctx.get(), GrColorType::kAlpha_F16, nullptr, SkBackingFit::kExact, {10, 10});
REPORTER_ASSERT(reporter, mockAtlas);
rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()),
LazyProxyTest::Op::Make(ctx.get(), proxyProvider, &test, nullTexture));
ctx->priv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test);
}
}
static const int kSize = 16;
DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
GrMockOptions mockOptions;
sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
auto proxyProvider = ctx->priv().proxyProvider();
const GrCaps* caps = ctx->priv().caps();
GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kNo);
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
auto tex = ctx->priv().resourceProvider()->createTexture({kSize, kSize}, format,
GrRenderable::kNo, 1, GrMipMapped::kNo,
SkBudgeted::kNo, GrProtected::kNo);
using LazyInstantiationResult = GrSurfaceProxy::LazyCallbackResult;
for (bool doInstantiate : {true, false}) {
for (bool releaseCallback : {false, true}) {
int testCount = 0;
// Sets an integer to 1 when the callback is called and -1 when it is deleted.
class TestCallback {
public:
TestCallback(int* value, bool releaseCallback, sk_sp<GrTexture> tex)
: fValue(value)
, fReleaseCallback(releaseCallback)
, fTexture(std::move(tex)) {}
TestCallback(const TestCallback& that) { SkASSERT(0); }
TestCallback(TestCallback&& that)
: fValue(that.fValue)
, fReleaseCallback(that.fReleaseCallback)
, fTexture(std::move(that.fTexture)) {
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;
LazyInstantiationResult operator()(GrResourceProvider* resourceProvider) const {
*fValue = 1;
return {fTexture, fReleaseCallback};
}
private:
int* fValue = nullptr;
bool fReleaseCallback;
sk_sp<GrTexture> fTexture;
};
GrSwizzle readSwizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
TestCallback(&testCount, releaseCallback, tex), format, {kSize, kSize},
readSwizzle, GrRenderable::kNo, 1, GrMipMapped::kNo,
GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone,
SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo,
GrSurfaceProxy::UseAllocator::kYes);
REPORTER_ASSERT(reporter, proxy.get());
REPORTER_ASSERT(reporter, 0 == testCount);
if (doInstantiate) {
proxy->priv().doLazyInstantiation(ctx->priv().resourceProvider());
if (releaseCallback) {
// 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);
}
}
}
}
class LazyFailedInstantiationTestOp : public GrDrawOp {
public:
DEFINE_OP_CLASS_ID
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
GrProxyProvider* proxyProvider,
int* testExecuteValue,
bool shouldFailInstantiation) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
return pool->allocate<LazyFailedInstantiationTestOp>(context, proxyProvider,
testExecuteValue,
shouldFailInstantiation);
}
void visitProxies(const VisitProxyFunc& func) const override {
func(fLazyProxy.get(), GrMipMapped::kNo);
}
private:
friend class GrOpMemoryPool; // for ctor
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider,
int* testExecuteValue, bool shouldFailInstantiation)
: INHERITED(ClassID())
, fTestExecuteValue(testExecuteValue) {
SkISize desc;
desc.fWidth = kSize;
desc.fHeight = kSize;
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
GrBackendFormat format =
ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888,
GrRenderable::kNo);
GrSwizzle readSwizzle = ctx->priv().caps()->getReadSwizzle(
format, GrColorType::kRGBA_8888);
fLazyProxy = proxyProvider->createLazyProxy(
[testExecuteValue, shouldFailInstantiation, desc,
format](GrResourceProvider* rp) -> GrSurfaceProxy::LazyCallbackResult {
if (shouldFailInstantiation) {
*testExecuteValue = 1;
return {};
}
return {rp->createTexture(desc, format, GrRenderable::kNo, 1, GrMipMapped::kNo,
SkBudgeted::kNo, GrProtected::kNo),
true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced};
},
format, desc, readSwizzle, GrRenderable::kNo, 1, GrMipMapped::kNo,
GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
SkBudgeted::kNo, GrProtected::kNo, GrSurfaceProxy::UseAllocator::kYes);
SkASSERT(fLazyProxy.get());
this->setBounds(SkRect::MakeIWH(kSize, kSize),
HasAABloat::kNo, IsHairline::kNo);
}
const char* name() const override { return "LazyFailedInstantiationTestOp"; }
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*,
bool hasMixedSampledCoverage, GrClampType) override {
return GrProcessorSet::EmptySetAnalysis();
}
void onPrepare(GrOpFlushState*) override {}
void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override {
*fTestExecuteValue = 2;
}
int* fTestExecuteValue;
sk_sp<GrTextureProxy> 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());
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
for (bool failInstantiation : {false, true}) {
auto rtc = GrRenderTargetContext::Make(
ctx.get(), GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {100, 100});
REPORTER_ASSERT(reporter, rtc);
rtc->clear(nullptr, SkPMColor4f::FromBytes_RGBA(0xbaaaaaad),
GrRenderTargetContext::CanClearFullscreen::kYes);
int executeTestValue = 0;
rtc->priv().testingOnly_addDrawOp(LazyFailedInstantiationTestOp::Make(
ctx.get(), proxyProvider, &executeTestValue, failInstantiation));
ctx->flush();
if (failInstantiation) {
REPORTER_ASSERT(reporter, 1 == executeTestValue);
} else {
REPORTER_ASSERT(reporter, 2 == executeTestValue);
}
}
}