From a0ca909142ba4fd33a1b2750f551e7edbb4b98f1 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 10 May 2018 22:04:08 +0000 Subject: Revert "Remove GrBackendObject and all related functions from Skia." This reverts commit ccd4cfc23ebbbecbc6b292359352aad335ad7b73. Reason for revert: Fuchsia not building again. (Flutter roll may have been reverted?) Original change's description: > Remove GrBackendObject and all related functions from Skia. > > Bug: skia: > Change-Id: I59434b7477c0bc26fd982bd81eb97ab94bbba073 > Reviewed-on: https://skia-review.googlesource.com/125822 > Reviewed-by: Brian Salomon > Commit-Queue: Greg Daniel TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: Ie2c518b84b0c9513c0c622082de2831088b1ad8d No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/127480 Reviewed-by: Brian Osman Commit-Queue: Brian Osman --- src/image/SkImage.cpp | 11 +++++++++++ src/image/SkImage_Base.h | 6 ++++++ src/image/SkImage_Gpu.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/image/SkImage_Gpu.h | 4 ++++ src/image/SkSurface.cpp | 10 ++++++++++ src/image/SkSurface_Base.h | 10 ++++++++++ src/image/SkSurface_Gpu.cpp | 23 +++++++++++++++++++++++ src/image/SkSurface_Gpu.h | 5 +++++ 8 files changed, 109 insertions(+) (limited to 'src/image') diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 72285bd698..3be804fca8 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -163,6 +163,13 @@ GrTexture* SkImage::getTexture() const { bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekProxy()); } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS +GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const { + return as_IB(this)->onGetTextureHandle(flushPendingGrContextIO, origin); +} +#endif + GrBackendTexture SkImage::getBackendTexture(bool flushPendingGrContextIO, GrSurfaceOrigin* origin) const { return as_IB(this)->onGetBackendTexture(flushPendingGrContextIO, origin); @@ -181,6 +188,10 @@ GrTexture* SkImage::getTexture() const { return nullptr; } bool SkImage::isTextureBacked() const { return false; } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS +GrBackendObject SkImage::getTextureHandle(bool, GrSurfaceOrigin*) const { return 0; } +#endif + GrBackendTexture SkImage::getBackendTexture(bool flushPendingGrContextIO, GrSurfaceOrigin* origin) const { return GrBackendTexture(); // invalid diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 9cf70fb1d3..c74a7b97e0 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -55,6 +55,12 @@ public: virtual sk_sp refPinnedTextureProxy(uint32_t* uniqueID) const { return nullptr; } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS + virtual GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const { + return 0; + } +#endif virtual GrTexture* onGetTexture() const { return nullptr; } #endif diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 08c9010228..17a0a25f5a 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -162,6 +162,46 @@ static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) } } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS +GrBackendObject SkImage_Gpu::onGetTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const { + SkASSERT(fProxy); + + if (!fContext->contextPriv().resourceProvider() && !fProxy->priv().isInstantiated()) { + // This image was created with a DDL context and cannot be instantiated. Thus we return 0 + // here which is considered invalid for all backends. + return 0; + } + + if (GrSurfaceProxy::LazyState::kNot != fProxy->lazyInstantiationState()) { + SkASSERT(fContext->contextPriv().resourceProvider()); + fProxy->priv().doLazyInstantiation(fContext->contextPriv().resourceProvider()); + if (!fProxy->priv().isInstantiated()) { + // We failed to instantiate the lazy proxy. Thus we return 0 here which is considered + // invalid for all backends. + return 0; + } + } + + if (!fProxy->instantiate(fContext->contextPriv().resourceProvider())) { + return 0; + } + + GrTexture* texture = fProxy->priv().peekTexture(); + + if (texture) { + if (flushPendingGrContextIO) { + fContext->contextPriv().prepareSurfaceForExternalIO(fProxy.get()); + } + if (origin) { + *origin = fProxy->origin(); + } + return texture->getTextureHandle(); + } + return 0; +} +#endif + GrBackendTexture SkImage_Gpu::onGetBackendTexture(bool flushPendingGrContextIO, GrSurfaceOrigin* origin) const { SkASSERT(fProxy); diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index cb9a7c7a9f..1425c875ce 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -50,6 +50,10 @@ public: return fProxy; } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS + GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const override; +#endif GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO, GrSurfaceOrigin* origin) const override; diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index 1a3eb4312e..73f3175ab9 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -218,6 +218,16 @@ void SkSurface::writePixels(const SkBitmap& src, int x, int y) { } } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS +GrBackendObject SkSurface::getTextureHandle(BackendHandleAccess access) { + return asSB(this)->onGetTextureHandle(access); +} + +bool SkSurface::getRenderTargetHandle(GrBackendObject* obj, BackendHandleAccess access) { + return asSB(this)->onGetRenderTargetHandle(obj, access); +} +#endif + GrBackendTexture SkSurface::getBackendTexture(BackendHandleAccess access) { return asSB(this)->onGetBackendTexture(access); } diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h index 67d330f9bb..90bcdff1dd 100644 --- a/src/image/SkSurface_Base.h +++ b/src/image/SkSurface_Base.h @@ -19,6 +19,16 @@ public: SkSurface_Base(const SkImageInfo&, const SkSurfaceProps*); virtual ~SkSurface_Base(); +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS + virtual GrBackendObject onGetTextureHandle(BackendHandleAccess) { + return 0; + } + + virtual bool onGetRenderTargetHandle(GrBackendObject*, BackendHandleAccess) { + return false; + } +#endif + virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess); virtual GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess); diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index d86b316ef6..c81fc28417 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -52,6 +52,29 @@ static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface, return rtc->accessRenderTarget(); } +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS +GrBackendObject SkSurface_Gpu::onGetTextureHandle(BackendHandleAccess access) { + GrRenderTarget* rt = prepare_rt_for_external_access(this, access); + if (!rt) { + return 0; + } + GrTexture* texture = rt->asTexture(); + if (texture) { + return texture->getTextureHandle(); + } + return 0; +} + +bool SkSurface_Gpu::onGetRenderTargetHandle(GrBackendObject* obj, BackendHandleAccess access) { + GrRenderTarget* rt = prepare_rt_for_external_access(this, access); + if (!rt) { + return false; + } + *obj = rt->getRenderTargetHandle(); + return true; +} +#endif + GrBackendTexture SkSurface_Gpu::onGetBackendTexture(BackendHandleAccess access) { GrRenderTarget* rt = prepare_rt_for_external_access(this, access); if (!rt) { diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h index 97fe5e5d5a..fc014c2cd2 100644 --- a/src/image/SkSurface_Gpu.h +++ b/src/image/SkSurface_Gpu.h @@ -23,6 +23,11 @@ public: // This is an internal-only factory static sk_sp MakeWrappedRenderTarget(GrContext*, sk_sp); +#ifdef SK_SUPPORT_LEGACY_BACKEND_OBJECTS + GrBackendObject onGetTextureHandle(BackendHandleAccess) override; + bool onGetRenderTargetHandle(GrBackendObject*, BackendHandleAccess) override; +#endif + GrBackendTexture onGetBackendTexture(BackendHandleAccess) override; GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess) override; -- cgit v1.2.3