Updating lazy proxys to support the case where we know a lot more info about the texture.
This is needed for future DDL texture work.
Bug: skia:
Change-Id: I07e0b9c67509e63b9cac00adc355254d03784df8
Reviewed-on: https://skia-review.googlesource.com/91500
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 420c43b..7a7e0a3 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -146,7 +146,7 @@
// handle resource allocation & usage on their own. (No deferred or lazy proxies!)
onFlushOpList->visitProxies_debugOnly([](GrSurfaceProxy* p) {
SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred());
- SkASSERT(!p->isPendingLazyInstantiation());
+ SkASSERT(GrSurfaceProxy::LazyState::kNot == p->lazyInstantiationState());
});
#endif
onFlushOpList->makeClosed(*fContext->caps());
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index dea47e6..d1b77d2 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -35,11 +35,15 @@
}
// Lazy-callback version
-GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback, GrPixelConfig config)
- : INHERITED(std::move(callback), config)
- , fSampleCnt(0)
+GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback,
+ const GrSurfaceDesc& desc,
+ SkBackingFit fit, SkBudgeted budgeted,
+ uint32_t flags)
+ : INHERITED(std::move(callback), desc, fit, budgeted, flags)
+ , fSampleCnt(desc.fSampleCnt)
, fNeedsStencil(false)
, fRenderTargetFlags(GrRenderTargetFlags::kNone) {
+ SkASSERT(SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags));
}
// Wrapped version
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index 5f40a92..d346a7e 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -81,7 +81,7 @@
#ifdef SK_DISABLE_EXPLICIT_GPU_RESOURCE_ALLOCATION
// FIXME: remove this once we can do the lazy instantiation from assign instead.
- if (proxy->isPendingLazyInstantiation()) {
+ if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
proxy->priv().doLazyInstantiation(fResourceProvider);
}
#endif
@@ -236,7 +236,7 @@
continue;
}
- if (cur->proxy()->isPendingLazyInstantiation()) {
+ if (GrSurfaceProxy::LazyState::kNot != cur->proxy()->lazyInstantiationState()) {
cur->proxy()->priv().doLazyInstantiation(fResourceProvider);
} else if (sk_sp<GrSurface> surface = this->findSurfaceFor(cur->proxy(), needsStencil)) {
// TODO: make getUniqueKey virtual on GrSurfaceProxy
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 1090d0d..e505a9c 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -21,20 +21,49 @@
#include "SkMathPriv.h"
#include "SkMipMap.h"
+#ifdef SK_DEBUG
+static bool is_valid_fully_lazy(const GrSurfaceDesc& desc, SkBackingFit fit) {
+ return desc.fWidth <= 0 &&
+ desc.fHeight <= 0 &&
+ desc.fConfig != kUnknown_GrPixelConfig &&
+ desc.fSampleCnt == 0 &&
+ SkBackingFit::kApprox == fit;
+}
+
+static bool is_valid_partially_lazy(const GrSurfaceDesc& desc) {
+ return ((desc.fWidth > 0 && desc.fHeight > 0) ||
+ (desc.fWidth <= 0 && desc.fHeight <= 0)) &&
+ desc.fConfig != kUnknown_GrPixelConfig;
+}
+
+static bool is_valid_non_lazy(const GrSurfaceDesc& desc) {
+ return desc.fWidth > 0 &&
+ desc.fHeight > 0 &&
+ desc.fConfig != kUnknown_GrPixelConfig;
+}
+#endif
+
// Lazy-callback version
-GrSurfaceProxy::GrSurfaceProxy(LazyInstantiateCallback&& callback, GrPixelConfig config)
- : fConfig(config)
- , fWidth(-1) // Width, height, and origin will be initialized upon lazy instantiation.
- , fHeight(-1)
- , fOrigin(kTopLeft_GrSurfaceOrigin)
- , fFit(SkBackingFit::kApprox)
- , fBudgeted(SkBudgeted::kYes)
- , fFlags(GrResourceProvider::kNoPendingIO_Flag)
+GrSurfaceProxy::GrSurfaceProxy(LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc,
+ SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
+ : fConfig(desc.fConfig)
+ , fWidth(desc.fWidth)
+ , fHeight(desc.fHeight)
+ , fOrigin(desc.fOrigin)
+ , fFit(fit)
+ , fBudgeted(budgeted)
+ , fFlags(flags)
, fLazyInstantiateCallback(std::move(callback))
- , fNeedsClear(false)
+ , fNeedsClear(SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag))
, fGpuMemorySize(kInvalidGpuMemorySize)
, fLastOpList(nullptr) {
// NOTE: the default fUniqueID ctor pulls a value from the same pool as the GrGpuResources.
+ if (fLazyInstantiateCallback) {
+ SkASSERT(is_valid_fully_lazy(desc, fit) || is_valid_partially_lazy(desc));
+ } else {
+ SkASSERT(is_valid_non_lazy(desc));
+ }
+
}
// Wrapped version
@@ -81,7 +110,7 @@
int sampleCnt, bool needsStencil,
GrSurfaceFlags flags, GrMipMapped mipMapped,
SkDestinationSurfaceColorMode mipColorMode) const {
- SkASSERT(!this->isPendingLazyInstantiation());
+ SkASSERT(GrSurfaceProxy::LazyState::kNot == this->lazyInstantiationState());
SkASSERT(GrMipMapped::kNo == mipMapped);
GrSurfaceDesc desc;
desc.fFlags = flags;
@@ -114,7 +143,7 @@
}
void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) {
- SkASSERT(!this->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kNot == this->lazyInstantiationState());
SkASSERT(!fTarget && surface);
fTarget = surface.release();
this->INHERITED::transferRefs();
@@ -130,7 +159,7 @@
bool needsStencil, GrSurfaceFlags flags, GrMipMapped mipMapped,
SkDestinationSurfaceColorMode mipColorMode,
const GrUniqueKey* uniqueKey) {
- SkASSERT(!this->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kNot == this->lazyInstantiationState());
if (fTarget) {
if (uniqueKey) {
SkASSERT(fTarget->getUniqueKey() == *uniqueKey);
@@ -155,7 +184,7 @@
}
void GrSurfaceProxy::computeScratchKey(GrScratchKey* key) const {
- SkASSERT(!this->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kFully != this->lazyInstantiationState());
const GrRenderTargetProxy* rtp = this->asRenderTargetProxy();
int sampleCount = 0;
if (rtp) {
@@ -392,14 +421,38 @@
}
sk_sp<GrTextureProxy> GrSurfaceProxy::MakeLazy(LazyInstantiateCallback&& callback,
- Renderable renderable, GrPixelConfig config) {
- return sk_sp<GrTextureProxy>(Renderable::kYes == renderable ?
- new GrTextureRenderTargetProxy(std::move(callback), config) :
- new GrTextureProxy(std::move(callback), config));
+ const GrSurfaceDesc& desc,
+ GrMipMapped mipMapped,
+ SkBackingFit fit,
+ SkBudgeted budgeted) {
+ SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) ||
+ (desc.fWidth > 0 && desc.fHeight > 0));
+ uint32_t flags = GrResourceProvider::kNoPendingIO_Flag;
+ return sk_sp<GrTextureProxy>(SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags) ?
+ new GrTextureRenderTargetProxy(std::move(callback), desc,
+ mipMapped, fit, budgeted, flags) :
+ new GrTextureProxy(std::move(callback), desc, mipMapped, fit,
+ budgeted, flags));
+}
+
+sk_sp<GrTextureProxy> GrSurfaceProxy::MakeFullyLazy(LazyInstantiateCallback&& callback,
+ Renderable renderable, GrPixelConfig config) {
+ GrSurfaceDesc desc;
+ if (Renderable::kYes == renderable) {
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ }
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ desc.fWidth = -1;
+ desc.fHeight = -1;
+ desc.fConfig = config;
+ desc.fSampleCnt = 0;
+
+ return MakeLazy(std::move(callback), desc, GrMipMapped::kNo, SkBackingFit::kApprox,
+ SkBudgeted::kYes);
}
int GrSurfaceProxy::worstCaseWidth() const {
- SkASSERT(!this->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kFully != this->lazyInstantiationState());
if (fTarget) {
return fTarget->width();
}
@@ -411,7 +464,7 @@
}
int GrSurfaceProxy::worstCaseHeight() const {
- SkASSERT(!this->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kFully != this->lazyInstantiationState());
if (fTarget) {
return fTarget->height();
}
@@ -437,7 +490,7 @@
GrMipMapped mipMapped,
SkIRect srcRect,
SkBudgeted budgeted) {
- SkASSERT(!src->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kFully != src->lazyInstantiationState());
if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) {
return nullptr;
}
@@ -466,13 +519,13 @@
sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, GrSurfaceProxy* src,
GrMipMapped mipMapped, SkBudgeted budgeted) {
- SkASSERT(!src->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kFully != src->lazyInstantiationState());
return Copy(context, src, mipMapped, SkIRect::MakeWH(src->width(), src->height()), budgeted);
}
sk_sp<GrSurfaceContext> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
GrSurfaceProxy* srcProxy) {
- SkASSERT(!srcProxy->isPendingLazyInstantiation());
+ SkASSERT(LazyState::kFully != srcProxy->lazyInstantiationState());
sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
dstDesc,
GrMipMapped::kNo,
@@ -490,7 +543,7 @@
}
void GrSurfaceProxyPriv::exactify() {
- SkASSERT(!fProxy->isPendingLazyInstantiation());
+ SkASSERT(GrSurfaceProxy::LazyState::kFully != fProxy->lazyInstantiationState());
if (this->isExact()) {
return;
}
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index c42df8b..68153dd 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -26,9 +26,11 @@
}
// Lazy-callback version
-GrTextureProxy::GrTextureProxy(LazyInstantiateCallback&& callback, GrPixelConfig config)
- : INHERITED(std::move(callback), config)
- , fMipMapped(GrMipMapped::kNo)
+GrTextureProxy::GrTextureProxy(LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc,
+ GrMipMapped mipMapped, SkBackingFit fit, SkBudgeted budgeted,
+ uint32_t flags)
+ : INHERITED(std::move(callback), desc, fit, budgeted, flags)
+ , fMipMapped(mipMapped)
, fMipColorMode(SkDestinationSurfaceColorMode::kLegacy)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {
diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp
index 9435231..fe12a0a 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -7,6 +7,7 @@
#include "GrTextureRenderTargetProxy.h"
+#include "GrCaps.h"
#include "GrTexture.h"
#include "GrRenderTarget.h"
#include "GrSurfaceProxyPriv.h"
@@ -27,12 +28,16 @@
// Lazy-callback version
GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(LazyInstantiateCallback&& callback,
- GrPixelConfig config)
- : GrSurfaceProxy(std::move(callback), config)
+ const GrSurfaceDesc& desc,
+ GrMipMapped mipMapped,
+ SkBackingFit fit,
+ SkBudgeted budgeted,
+ uint32_t flags)
+ : GrSurfaceProxy(std::move(callback), desc, fit, budgeted, flags)
// Since we have virtual inheritance, we initialize GrSurfaceProxy directly. Send null
// callbacks to the texture and RT proxies simply to route to the appropriate constructors.
- , GrTextureProxy(LazyInstantiateCallback(), config)
- , GrRenderTargetProxy(LazyInstantiateCallback(), config) {
+ , GrTextureProxy(LazyInstantiateCallback(), desc, mipMapped, fit, budgeted, flags)
+ , GrRenderTargetProxy(LazyInstantiateCallback(), desc, fit, budgeted, flags) {
}
// Wrapped version
diff --git a/src/gpu/GrTextureRenderTargetProxy.h b/src/gpu/GrTextureRenderTargetProxy.h
index 5719366..739f797 100644
--- a/src/gpu/GrTextureRenderTargetProxy.h
+++ b/src/gpu/GrTextureRenderTargetProxy.h
@@ -30,7 +30,8 @@
SkBackingFit, SkBudgeted, uint32_t flags);
// Lazy-callback version
- GrTextureRenderTargetProxy(LazyInstantiateCallback&&, GrPixelConfig);
+ GrTextureRenderTargetProxy(LazyInstantiateCallback&&, const GrSurfaceDesc& desc, GrMipMapped,
+ SkBackingFit, SkBudgeted, uint32_t flags);
// Wrapped version
GrTextureRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
index 62d3a06..67098cc 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
@@ -225,7 +225,7 @@
int rtHeight) {
SkASSERT(this->isUninitialized());
- fAtlasLazyProxy = GrSurfaceProxy::MakeLazy(
+ fAtlasLazyProxy = GrSurfaceProxy::MakeFullyLazy(
[this](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) {
SkASSERT(fHasAtlas);
SkASSERT(!fHasAtlasTransform);