Make fully lazy proxies possess an origin

Change-Id: Icd3d68bce78568562aa12167a58b6d6e5064b124
Reviewed-on: https://skia-review.googlesource.com/106901
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2018-02-13 11:13:51 -05:00 committed by Skia Commit-Bot
parent 6a46fb210b
commit ce5209a8a5
8 changed files with 39 additions and 50 deletions

View File

@ -361,8 +361,7 @@ protected:
// Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
}
using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*,
GrSurfaceOrigin* outOrigin)>;
using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*)>;
// Lazy-callback version
GrSurfaceProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,

View File

@ -136,7 +136,7 @@ sk_sp<GrTextureProxy> GrBackendTextureImageGenerator::onGenerateTexture(
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
[refHelper, releaseProcHelper, semaphore, backendTexture]
(GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
(GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
return sk_sp<GrTexture>();
}

View File

@ -221,7 +221,7 @@ sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(sk_sp<SkImage> srcImag
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
[desc, budgeted, srcImage, fit]
(GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
(GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
// Nothing to clean up here. Once the proxy (and thus lambda) is deleted the ref
// on srcImage will be released.
@ -322,7 +322,7 @@ sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxyFromBitmap(const SkBitma
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
[desc, baseLevel, mipmaps, mipColorMode]
(GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
(GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
return sk_sp<GrTexture>();
}
@ -409,7 +409,7 @@ sk_sp<GrTextureProxy> GrProxyProvider::createWrappedTextureProxy(
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
[backendTex, ownership, releaseHelper]
(GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
(GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
// If this had a releaseHelper it will get unrefed when we delete this lambda
// and will call the release proc so that the client knows they can free the
@ -540,12 +540,13 @@ sk_sp<GrRenderTargetProxy> GrProxyProvider::createLazyRenderTargetProxy(
sk_sp<GrTextureProxy> GrProxyProvider::createFullyLazyProxy(LazyInstantiateCallback&& callback,
Renderable renderable,
GrSurfaceOrigin origin,
GrPixelConfig config) {
GrSurfaceDesc desc;
if (Renderable::kYes == renderable) {
desc.fFlags = kRenderTarget_GrSurfaceFlag;
}
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
desc.fOrigin = origin;
desc.fWidth = -1;
desc.fHeight = -1;
desc.fConfig = config;

View File

@ -141,8 +141,7 @@ public:
GrSurfaceOrigin origin,
int sampleCnt);
using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*,
GrSurfaceOrigin* outOrigin)>;
using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(GrResourceProvider*)>;
enum class Textureable : bool {
kNo = false,
kYes = true
@ -166,8 +165,12 @@ public:
sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
GrMipMapped, SkBackingFit, SkBudgeted);
/**
* Fully lazy proxies have unspecified width and height. Methods that rely on those values
* (e.g., width, height, getBoundsRect) should be avoided.
*/
sk_sp<GrTextureProxy> createFullyLazyProxy(LazyInstantiateCallback&&,
Renderable, GrPixelConfig);
Renderable, GrSurfaceOrigin, GrPixelConfig);
sk_sp<GrRenderTargetProxy> createLazyRenderTargetProxy(LazyInstantiateCallback&&,
const GrSurfaceDesc&, Textureable,

View File

@ -87,7 +87,7 @@ GrSurfaceProxy::~GrSurfaceProxy() {
if (fLazyInstantiateCallback) {
// We call the callback with a null GrResourceProvider to signal that the lambda should
// clean itself up if it is holding onto any captured objects.
this->fLazyInstantiateCallback(nullptr, nullptr);
this->fLazyInstantiateCallback(nullptr);
}
// For this to be deleted the opList that held a ref on it (if there was one) must have been
// deleted. Which would have cleared out this back pointer.
@ -353,26 +353,14 @@ void GrSurfaceProxyPriv::exactify() {
bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvider) {
SkASSERT(GrSurfaceProxy::LazyState::kNot != fProxy->lazyInstantiationState());
GrSurfaceOrigin* outOrigin;
if (GrSurfaceProxy::LazyState::kPartially == fProxy->lazyInstantiationState()) {
// In the partially instantiated case, we set the origin on the SurfaceProxy at creation
// time (via a GrSurfaceDesc). In the lambda, the creation of the texture never needs to
// know the origin, and it also can't change or have any effect on it. Thus we just pass in
// nullptr in this case since it should never be set.
outOrigin = nullptr;
} else {
outOrigin = &fProxy->fOrigin;
}
sk_sp<GrSurface> surface = fProxy->fLazyInstantiateCallback(resourceProvider, outOrigin);
sk_sp<GrSurface> surface = fProxy->fLazyInstantiateCallback(resourceProvider);
if (GrSurfaceProxy::LazyInstantiationType::kSingleUse == fProxy->fLazyInstantiationType) {
fProxy->fLazyInstantiateCallback(nullptr, nullptr);
fProxy->fLazyInstantiateCallback(nullptr);
fProxy->fLazyInstantiateCallback = nullptr;
}
if (!surface) {
fProxy->fWidth = 0;
fProxy->fHeight = 0;
fProxy->fOrigin = kTopLeft_GrSurfaceOrigin;
return false;
}

View File

@ -138,6 +138,8 @@ sk_sp<GrRenderTargetContext> GrCCAtlas::finalize(GrOnFlushResourceProvider* onFl
SkASSERT(!fTextureProxy);
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
desc.fWidth = fWidth;
desc.fHeight = fHeight;
desc.fConfig = kAlpha_half_GrPixelConfig;

View File

@ -229,7 +229,7 @@ void CCPR::ClipPath::init(GrProxyProvider* proxyProvider,
SkASSERT(this->isUninitialized());
fAtlasLazyProxy = proxyProvider->createFullyLazyProxy(
[this](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) {
[this](GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
return sk_sp<GrTexture>();
}
@ -243,19 +243,16 @@ void CCPR::ClipPath::init(GrProxyProvider* proxyProvider,
return sk_sp<GrTexture>();
}
SkASSERT(kTopLeft_GrSurfaceOrigin == textureProxy->origin());
fAtlasScale = {1.f / textureProxy->width(), 1.f / textureProxy->height()};
fAtlasTranslate = {fAtlasOffsetX * fAtlasScale.x(),
fAtlasOffsetY * fAtlasScale.y()};
if (kBottomLeft_GrSurfaceOrigin == textureProxy->origin()) {
fAtlasScale.fY = -fAtlasScale.y();
fAtlasTranslate.fY = 1 - fAtlasTranslate.y();
}
SkDEBUGCODE(fHasAtlasTransform = true);
*outOrigin = textureProxy->origin();
return sk_ref_sp(textureProxy->priv().peekTexture());
},
GrProxyProvider::Renderable::kYes, kAlpha_half_GrPixelConfig);
GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, kAlpha_half_GrPixelConfig);
const SkRect& pathDevBounds = deviceSpacePath.getBounds();
if (SkTMax(pathDevBounds.height(), pathDevBounds.width()) > kPathCropThreshold) {

View File

@ -58,13 +58,12 @@ public:
Op(GrProxyProvider* proxyProvider, LazyProxyTest* test, bool nullTexture)
: GrDrawOp(ClassID()), fTest(test) {
fProxy = proxyProvider->createFullyLazyProxy([this, nullTexture](
GrResourceProvider* rp, GrSurfaceOrigin* origin) {
GrResourceProvider* rp) {
if (!rp) {
return sk_sp<GrTexture>();
}
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
fTest->fHasOpTexture = true;
*origin = kTopLeft_GrSurfaceOrigin;
if (nullTexture) {
return sk_sp<GrTexture>();
} else {
@ -77,7 +76,7 @@ public:
REPORTER_ASSERT(fTest->fReporter, texture);
return texture;
}
}, GrProxyProvider::Renderable::kNo, kRGB_565_GrPixelConfig);
}, GrProxyProvider::Renderable::kNo, kTopLeft_GrSurfaceOrigin, kRGB_565_GrPixelConfig);
this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo, GrOp::IsZeroArea::kNo);
}
@ -112,17 +111,19 @@ public:
, fProxyProvider(proxyProvider)
, fTest(test)
, fAtlas(atlas) {
fLazyProxy = proxyProvider->createFullyLazyProxy([this](GrResourceProvider* rp,
GrSurfaceOrigin* origin) {
if (!rp) {
return sk_sp<GrTexture>();
}
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
fTest->fHasClipTexture = true;
*origin = kBottomLeft_GrSurfaceOrigin;
fAtlas->instantiate(rp);
return sk_ref_sp(fAtlas->priv().peekTexture());
}, GrProxyProvider::Renderable::kYes, kAlpha_half_GrPixelConfig);
fLazyProxy = proxyProvider->createFullyLazyProxy(
[this](GrResourceProvider* rp) {
if (!rp) {
return sk_sp<GrTexture>();
}
REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
fTest->fHasClipTexture = true;
fAtlas->instantiate(rp);
return sk_ref_sp(fAtlas->priv().peekTexture());
},
GrProxyProvider::Renderable::kYes,
kBottomLeft_GrSurfaceOrigin,
kAlpha_half_GrPixelConfig);
fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest,
GrSamplerState::WrapMode::kClamp, kFragment_GrShaderFlag);
this->addTextureSampler(&fAccess);
@ -220,8 +221,7 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
int testCount = 0;
int* testCountPtr = &testCount;
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
[testCountPtr](GrResourceProvider* resourceProvider,
GrSurfaceOrigin* /*outOrigin*/) {
[testCountPtr](GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
*testCountPtr = -1;
return sk_sp<GrTexture>();
@ -267,8 +267,7 @@ public:
desc.fConfig = kRGBA_8888_GrPixelConfig;
fLazyProxy = proxyProvider->createLazyProxy(
[testExecuteValue, shouldFailInstantiation, desc] (
GrResourceProvider* rp, GrSurfaceOrigin* /*origin*/) {
[testExecuteValue, shouldFailInstantiation, desc] (GrResourceProvider* rp) {
if (!rp) {
return sk_sp<GrTexture>();
}