aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrSurfaceProxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/GrSurfaceProxy.cpp')
-rw-r--r--src/gpu/GrSurfaceProxy.cpp62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 71ff6374ff..a5c2be622b 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -21,6 +21,23 @@
#include "SkMathPriv.h"
#include "SkMipMap.h"
+// 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(kGrUnknownSurfaceOrigin)
+ , fFit(SkBackingFit::kApprox)
+ , fBudgeted(SkBudgeted::kYes)
+ , fFlags(GrResourceProvider::kNoPendingIO_Flag)
+ , fLazyInstantiateCallback(std::move(callback))
+ , fNeedsClear(false)
+ , fGpuMemorySize(kInvalidGpuMemorySize)
+ , fLastOpList(nullptr) {
+ // NOTE: the default fUniqueID ctor pulls a value from the same pool as the GrGpuResources.
+}
+
+// Wrapped version
GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit)
: INHERITED(std::move(surface))
, fConfig(fTarget->config())
@@ -64,6 +81,7 @@ sk_sp<GrSurface> GrSurfaceProxy::createSurfaceImpl(
int sampleCnt, bool needsStencil,
GrSurfaceFlags flags, GrMipMapped mipMapped,
SkDestinationSurfaceColorMode mipColorMode) const {
+ SkASSERT(!this->isPendingLazyInstantiation());
SkASSERT(GrMipMapped::kNo == mipMapped);
GrSurfaceDesc desc;
desc.fFlags = flags;
@@ -96,6 +114,7 @@ sk_sp<GrSurface> GrSurfaceProxy::createSurfaceImpl(
}
void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) {
+ SkASSERT(!this->isPendingLazyInstantiation());
SkASSERT(!fTarget && surface);
fTarget = surface.release();
this->INHERITED::transferRefs();
@@ -111,6 +130,7 @@ bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int s
bool needsStencil, GrSurfaceFlags flags, GrMipMapped mipMapped,
SkDestinationSurfaceColorMode mipColorMode,
const GrUniqueKey* uniqueKey) {
+ SkASSERT(!this->isPendingLazyInstantiation());
if (fTarget) {
if (uniqueKey) {
SkASSERT(fTarget->getUniqueKey() == *uniqueKey);
@@ -135,6 +155,7 @@ bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int s
}
void GrSurfaceProxy::computeScratchKey(GrScratchKey* key) const {
+ SkASSERT(!this->isPendingLazyInstantiation());
const GrRenderTargetProxy* rtp = this->asRenderTargetProxy();
int sampleCount = 0;
if (rtp) {
@@ -377,7 +398,15 @@ sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context,
return GrSurfaceProxy::MakeWrapped(std::move(tex), origin);
}
+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));
+}
+
int GrSurfaceProxy::worstCaseWidth() const {
+ SkASSERT(!this->isPendingLazyInstantiation());
if (fTarget) {
return fTarget->width();
}
@@ -389,6 +418,7 @@ int GrSurfaceProxy::worstCaseWidth() const {
}
int GrSurfaceProxy::worstCaseHeight() const {
+ SkASSERT(!this->isPendingLazyInstantiation());
if (fTarget) {
return fTarget->height();
}
@@ -414,6 +444,7 @@ sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context,
GrMipMapped mipMapped,
SkIRect srcRect,
SkBudgeted budgeted) {
+ SkASSERT(!src->isPendingLazyInstantiation());
if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) {
return nullptr;
}
@@ -442,12 +473,13 @@ sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context,
sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, GrSurfaceProxy* src,
GrMipMapped mipMapped, SkBudgeted budgeted) {
+ SkASSERT(!src->isPendingLazyInstantiation());
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());
sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
dstDesc,
GrMipMapped::kNo,
@@ -465,6 +497,7 @@ sk_sp<GrSurfaceContext> GrSurfaceProxy::TestCopy(GrContext* context, const GrSur
}
void GrSurfaceProxyPriv::exactify() {
+ SkASSERT(!fProxy->isPendingLazyInstantiation());
if (this->isExact()) {
return;
}
@@ -491,3 +524,30 @@ void GrSurfaceProxyPriv::exactify() {
// exact amount.
}
+void GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvider) {
+ SkASSERT(fProxy->fLazyInstantiateCallback);
+ SkASSERT(!fProxy->fTarget);
+
+ sk_sp<GrTexture> texture = fProxy->fLazyInstantiateCallback(resourceProvider, &fProxy->fOrigin);
+
+ // Indicate we are no longer pending lazy instantiation.
+ fProxy->fLazyInstantiateCallback = nullptr;
+
+ if (!texture) {
+ fProxy->fWidth = 0;
+ fProxy->fHeight = 0;
+ fProxy->fOrigin = kTopLeft_GrSurfaceOrigin;
+ return;
+ }
+
+ fProxy->fWidth = texture->width();
+ fProxy->fHeight = texture->height();
+
+ SkASSERT(texture->config() == fProxy->fConfig);
+ SkASSERT(kGrUnknownSurfaceOrigin != fProxy->origin());
+ SkASSERT(kTopLeft_GrSurfaceOrigin == fProxy->fOrigin ||
+ kBottomLeft_GrSurfaceOrigin == fProxy->fOrigin);
+ SkDEBUGCODE(fProxy->validateLazyTexture(texture.get());)
+ this->assign(std::move(texture));
+}
+