diff options
author | Chris Dalton <csmartdalton@google.com> | 2017-11-29 22:01:06 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-30 15:37:12 +0000 |
commit | 706a6ff60c55bee85cff06fc9f8f3764f6e5154b (patch) | |
tree | ce416111dc4101cf58ee12bd7c35007317f33819 /include/private/GrSurfaceProxy.h | |
parent | de2f1dfebd9d28787cdfd77496f365ed3eb6894d (diff) |
Add "lazy" texture proxies
Adds ultra-deferred proxies that are instantiated by a user-supplied
callback during flush.
Bug: skia:7190
Change-Id: I75a7ac6dba953c3b0a99febc203a7f4d2f3789fc
Reviewed-on: https://skia-review.googlesource.com/76461
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'include/private/GrSurfaceProxy.h')
-rw-r--r-- | include/private/GrSurfaceProxy.h | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h index 23f62195c2..387aecd428 100644 --- a/include/private/GrSurfaceProxy.h +++ b/include/private/GrSurfaceProxy.h @@ -212,15 +212,34 @@ public: static sk_sp<GrTextureProxy> MakeWrappedBackend(GrContext*, GrBackendTexture&, GrSurfaceOrigin); + using LazyInstantiateCallback = std::function<sk_sp<GrTexture>(GrResourceProvider*, + GrSurfaceOrigin* outOrigin)>; + + enum class Renderable : bool { + kNo = false, + kYes = true + }; + + /** + * Creates a texture proxy that will be instantiated by a user-supplied callback during flush. + * (Mipmapping, MSAA, and stencil are not supported by this method.) + */ + static sk_sp<GrTextureProxy> MakeLazy(LazyInstantiateCallback&&, Renderable, GrPixelConfig); + + GrPixelConfig config() const { return fConfig; } + int width() const { SkASSERT(!this->isPendingLazyInstantiation()); return fWidth; } + int height() const { SkASSERT(!this->isPendingLazyInstantiation()); return fHeight; } + int worstCaseWidth() const; + int worstCaseHeight() const; GrSurfaceOrigin origin() const { + SkASSERT(!this->isPendingLazyInstantiation()); SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin); return fOrigin; } - int width() const { return fWidth; } - int height() const { return fHeight; } - int worstCaseWidth() const; - int worstCaseHeight() const; - GrPixelConfig config() const { return fConfig; } + + // If the client gave us a LazyInstantiateCallback (via MakeLazy), then we will invoke that + // callback during flush. fWidth, fHeight, and fOrigin will be undefined until that time. + bool isPendingLazyInstantiation() const { return SkToBool(fLazyInstantiateCallback); } class UniqueID { public: @@ -230,7 +249,7 @@ public: // wrapped explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { } - // deferred + // deferred and lazy-callback UniqueID() : fID(GrGpuResource::CreateUniqueID()) { } uint32_t asUInt() const { return fID; } @@ -281,7 +300,10 @@ public: /** * Helper that gets the width and height of the surface as a bounding rectangle. */ - SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); } + SkRect getBoundsRect() const { + SkASSERT(!this->isPendingLazyInstantiation()); + return SkRect::MakeIWH(this->width(), this->height()); + } /** * @return the texture proxy associated with the surface proxy, may be NULL. @@ -314,6 +336,7 @@ public: * @return the amount of GPU memory used in bytes */ size_t gpuMemorySize() const { + SkASSERT(!this->isPendingLazyInstantiation()); if (fTarget) { return fTarget->gpuMemorySize(); } @@ -363,6 +386,9 @@ protected: // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources } + // Lazy-callback version + GrSurfaceProxy(LazyInstantiateCallback&& callback, GrPixelConfig config); + // Wrapped version GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit); @@ -392,23 +418,28 @@ protected: GrSurfaceFlags flags, GrMipMapped mipMapped, SkDestinationSurfaceColorMode mipColorMode, const GrUniqueKey*); +private: // For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in // from the wrapped resource. GrPixelConfig fConfig; int fWidth; int fHeight; GrSurfaceOrigin fOrigin; - SkBackingFit fFit; // always exact for wrapped resources - mutable SkBudgeted fBudgeted; // set from the backing resource for wrapped resources + SkBackingFit fFit; // always kApprox for lazy-callback resources + // always kExact for wrapped resources + mutable SkBudgeted fBudgeted; // always kYes for lazy-callback resources + // set from the backing resource for wrapped resources // mutable bc of SkSurface/SkImage wishy-washiness const uint32_t fFlags; const UniqueID fUniqueID; // set from the backing resource for wrapped resources + LazyInstantiateCallback fLazyInstantiateCallback; + SkDEBUGCODE(virtual void validateLazyTexture(const GrTexture*) = 0;) + static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; }) -private: virtual size_t onUninstantiatedGpuMemorySize() const = 0; bool fNeedsClear; |