diff options
author | Robert Phillips <robertphillips@google.com> | 2017-02-15 14:19:01 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-15 20:17:29 +0000 |
commit | 63c67461ed07b5fca35182ac62657b2cb16afbb4 (patch) | |
tree | 461c958cfca8c01c1fba552438a6c05f9da2bb45 | |
parent | ca4c60f5413ba2af4ddfce7160ddd226e8738e02 (diff) |
Tighten up GrSurfaceProxy typing
This may reduce the number of "why not GrTextureProxy" issues
Change-Id: I9e0e5042f5801ba9a933b697a380cb0cb54b4522
Reviewed-on: https://skia-review.googlesource.com/8510
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | gm/etc1.cpp | 2 | ||||
-rw-r--r-- | include/gpu/GrProcessorUnitTest.h | 6 | ||||
-rw-r--r-- | include/private/GrSurfaceProxy.h | 9 | ||||
-rw-r--r-- | src/core/SkSpecialImage.cpp | 61 | ||||
-rw-r--r-- | src/core/SkSpecialImage.h | 2 | ||||
-rw-r--r-- | src/gpu/GrSurfaceProxy.cpp | 21 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 14 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 7 | ||||
-rw-r--r-- | tests/SpecialImageTest.cpp | 6 |
9 files changed, 65 insertions, 63 deletions
diff --git a/gm/etc1.cpp b/gm/etc1.cpp index 8111860bf9..09ef7d867a 100644 --- a/gm/etc1.cpp +++ b/gm/etc1.cpp @@ -79,7 +79,7 @@ protected: desc.fWidth = kTexWidth; desc.fHeight = kTexHeight; - sk_sp<GrSurfaceProxy> proxy = GrTextureProxy::MakeDeferred(*context->caps(), + sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*context->caps(), context->textureProvider(), desc, SkBudgeted::kYes, fETC1Data.get(), 0); diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h index 748a522c57..0f7e8e8d7c 100644 --- a/include/gpu/GrProcessorUnitTest.h +++ b/include/gpu/GrProcessorUnitTest.h @@ -64,12 +64,10 @@ struct GrProcessorTestData { GrContext* context() { return fContext; } GrTexture* texture(int index) { return fTextures[index]; } - sk_sp<GrTextureProxy> textureProxy(int index) { - return sk_ref_sp(fProxies[index]->asTextureProxy()); - } + sk_sp<GrTextureProxy> textureProxy(int index) { return fProxies[index]; } private: - sk_sp<GrSurfaceProxy> fProxies[2]; + sk_sp<GrTextureProxy> fProxies[2]; }; #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h index a08cb2654a..16220e06ba 100644 --- a/include/private/GrSurfaceProxy.h +++ b/include/private/GrSurfaceProxy.h @@ -168,6 +168,7 @@ private: class GrSurfaceProxy : public GrIORefProxy { public: static sk_sp<GrSurfaceProxy> MakeWrapped(sk_sp<GrSurface>); + static sk_sp<GrTextureProxy> MakeWrapped(sk_sp<GrTexture>); static sk_sp<GrSurfaceProxy> MakeDeferred(const GrCaps&, const GrSurfaceDesc&, SkBackingFit, SkBudgeted); @@ -282,14 +283,12 @@ public: } // Helper function that creates a temporary SurfaceContext to perform the copy - static sk_sp<GrSurfaceProxy> Copy(GrContext*, GrSurfaceProxy* src, + static sk_sp<GrTextureProxy> Copy(GrContext*, GrSurfaceProxy* src, SkIRect srcRect, SkBudgeted); // Copy the entire 'src' - static sk_sp<GrSurfaceProxy> Copy(GrContext* context, GrSurfaceProxy* src, - SkBudgeted budgeted) { - return Copy(context, src, SkIRect::MakeWH(src->width(), src->height()), budgeted); - } + static sk_sp<GrTextureProxy> Copy(GrContext* context, GrSurfaceProxy* src, + SkBudgeted budgeted); // Test-only entry point - should decrease in use as proxies propagate static sk_sp<GrSurfaceContext> TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc, diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index f44d011c05..cef87b75be 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -263,12 +263,7 @@ public: if (context) { sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture( context, fBitmap, GrSamplerParams::ClampNoFilter(), nullptr))); - sk_sp<GrSurfaceProxy> sProxy = GrSurfaceProxy::MakeWrapped(std::move(tex)); - if (!sProxy) { - return nullptr; - } - - return sk_ref_sp(sProxy->asTextureProxy()); + return GrSurfaceProxy::MakeWrapped(std::move(tex)); } return nullptr; @@ -361,17 +356,17 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset, /////////////////////////////////////////////////////////////////////////////// #include "GrTexture.h" -static sk_sp<SkImage> wrap_proxy_in_image(GrContext* context, GrSurfaceProxy* proxy, +static sk_sp<SkImage> wrap_proxy_in_image(GrContext* context, GrTextureProxy* proxy, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) { // TODO: add GrTextureProxy-backed SkImage_Gpus - GrSurface* surf = proxy->instantiate(context->textureProvider()); - if (!surf) { + GrTexture* tex = proxy->instantiate(context->textureProvider()); + if (!tex) { return nullptr; } return sk_make_sp<SkImage_Gpu>(proxy->width(), proxy->height(), kNeedNewImageUniqueID, alphaType, - sk_ref_sp(surf->asTexture()), + sk_ref_sp(tex), std::move(colorSpace), SkBudgeted::kYes); } @@ -382,18 +377,18 @@ public: sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) : INHERITED(subset, uniqueID, props) , fContext(tex->getContext()) + , fTextureProxy(GrSurfaceProxy::MakeWrapped(std::move(tex))) , fAlphaType(at) , fColorSpace(std::move(colorSpace)) , fAddedRasterVersionToCache(false) { - fSurfaceProxy = GrSurfaceProxy::MakeWrapped(std::move(tex)); } SkSpecialImage_Gpu(GrContext* context, const SkIRect& subset, - uint32_t uniqueID, sk_sp<GrSurfaceProxy> proxy, SkAlphaType at, + uint32_t uniqueID, sk_sp<GrTextureProxy> proxy, SkAlphaType at, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) : INHERITED(subset, uniqueID, props) , fContext(context) - , fSurfaceProxy(std::move(proxy)) + , fTextureProxy(std::move(proxy)) , fAlphaType(at) , fColorSpace(std::move(colorSpace)) , fAddedRasterVersionToCache(false) { @@ -407,15 +402,15 @@ public: SkAlphaType alphaType() const override { return fAlphaType; } - size_t getSize() const override { return fSurfaceProxy->gpuMemorySize(); } + size_t getSize() const override { return fTextureProxy->gpuMemorySize(); } void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override { SkRect dst = SkRect::MakeXYWH(x, y, this->subset().width(), this->subset().height()); // TODO: add GrTextureProxy-backed SkImage_Gpus - GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider()); - if (!surf) { + GrTexture* tex = fTextureProxy->instantiate(fContext->textureProvider()); + if (!tex) { return; } @@ -423,11 +418,11 @@ public: // texture into the canvas so it is okay to wrap it in an SkImage. This poses // some problems for full deferral however in that when the deferred SkImage_Gpu // instantiates itself it is going to have to either be okay with having a larger - // than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs + // than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs // to be tightened (if it is deferred). - auto img = sk_sp<SkImage>(new SkImage_Gpu(surf->width(), surf->height(), + auto img = sk_sp<SkImage>(new SkImage_Gpu(tex->width(), tex->height(), this->uniqueID(), fAlphaType, - sk_ref_sp(surf->asTexture()), + sk_ref_sp(tex), fColorSpace, SkBudgeted::kNo)); canvas->drawImageRect(img, this->subset(), @@ -438,15 +433,11 @@ public: // This entry point should go away in favor of asTextureProxy sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { - GrSurface* surf = fSurfaceProxy->instantiate(context->textureProvider()); - if (!surf) { - return nullptr; - } - return sk_ref_sp(surf->asTexture()); + return sk_ref_sp(fTextureProxy->instantiate(context->textureProvider())); } sk_sp<GrTextureProxy> onAsTextureProxy(GrContext*) const override { - return sk_ref_sp(fSurfaceProxy->asTextureProxy()); + return fTextureProxy; } bool onGetROPixels(SkBitmap* dst) const override { @@ -465,12 +456,12 @@ public: } // Reading back to an SkBitmap ends deferral - GrSurface* surface = fSurfaceProxy->instantiate(fContext->textureProvider()); - if (!surface) { + GrTexture* texture = fTextureProxy->instantiate(fContext->textureProvider()); + if (!texture) { return false; } - if (!surface->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig, + if (!texture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig, dst->getPixels(), dst->rowBytes())) { return false; } @@ -501,7 +492,7 @@ public: return SkSpecialImage::MakeDeferredFromGpu(fContext, subset, this->uniqueID(), - fSurfaceProxy, + fTextureProxy, fColorSpace, &this->props(), fAlphaType); @@ -511,14 +502,14 @@ public: sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override { // TODO: this is problematic since the surfaceProxy could be loose if (0 == subset.fLeft && 0 == subset.fTop && - fSurfaceProxy->width() == subset.width() && - fSurfaceProxy->height() == subset.height()) { + fTextureProxy->width() == subset.width() && + fTextureProxy->height() == subset.height()) { // The existing GrTexture is already tight so reuse it in the SkImage - return wrap_proxy_in_image(fContext, fSurfaceProxy.get(), + return wrap_proxy_in_image(fContext, fTextureProxy.get(), fAlphaType, fColorSpace); } - sk_sp<GrSurfaceProxy> subsetProxy(GrSurfaceProxy::Copy(fContext, fSurfaceProxy.get(), + sk_sp<GrTextureProxy> subsetProxy(GrSurfaceProxy::Copy(fContext, fTextureProxy.get(), subset, SkBudgeted::kYes)); return wrap_proxy_in_image(fContext, subsetProxy.get(), fAlphaType, fColorSpace); @@ -536,7 +527,7 @@ public: private: GrContext* fContext; - sk_sp<GrSurfaceProxy> fSurfaceProxy; + sk_sp<GrTextureProxy> fTextureProxy; const SkAlphaType fAlphaType; sk_sp<SkColorSpace> fColorSpace; mutable SkAtomic<bool> fAddedRasterVersionToCache; @@ -558,7 +549,7 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset, sk_sp<SkSpecialImage> SkSpecialImage::MakeDeferredFromGpu(GrContext* context, const SkIRect& subset, uint32_t uniqueID, - sk_sp<GrSurfaceProxy> proxy, + sk_sp<GrTextureProxy> proxy, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props, SkAlphaType at) { diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index bf168f02af..1c9c5a1b4c 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -89,7 +89,7 @@ public: static sk_sp<SkSpecialImage> MakeDeferredFromGpu(GrContext*, const SkIRect& subset, uint32_t uniqueID, - sk_sp<GrSurfaceProxy>, + sk_sp<GrTextureProxy>, sk_sp<SkColorSpace>, const SkSurfaceProps* = nullptr, SkAlphaType at = kPremul_SkAlphaType); diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index a032f693e7..bd60aa9fb9 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -131,6 +131,18 @@ sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeWrapped(sk_sp<GrSurface> surf) { } } +sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrapped(sk_sp<GrTexture> tex) { + if (!tex) { + return nullptr; + } + + if (tex->asRenderTarget()) { + return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex))); + } else { + return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex))); + } +} + sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeDeferred(const GrCaps& caps, const GrSurfaceDesc& desc, SkBackingFit fit, @@ -217,7 +229,7 @@ void GrSurfaceProxy::validate(GrContext* context) const { } #endif -sk_sp<GrSurfaceProxy> GrSurfaceProxy::Copy(GrContext* context, +sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, GrSurfaceProxy* src, SkIRect srcRect, SkBudgeted budgeted) { @@ -241,7 +253,12 @@ sk_sp<GrSurfaceProxy> GrSurfaceProxy::Copy(GrContext* context, return nullptr; } - return dstContext->asSurfaceProxyRef(); + return dstContext->asTextureProxyRef(); +} + +sk_sp<GrTextureProxy> GrSurfaceProxy::Copy(GrContext* context, GrSurfaceProxy* src, + SkBudgeted budgeted) { + return Copy(context, src, SkIRect::MakeWH(src->width(), src->height()), budgeted); } sk_sp<GrSurfaceContext> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc, diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 4314b450fd..0197a6e663 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1315,15 +1315,15 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) { } sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { - sk_sp<GrSurfaceProxy> sProxy(this->accessRenderTargetContext()->asTextureProxyRef()); - if (!sProxy) { + sk_sp<GrTextureProxy> proxy(this->accessRenderTargetContext()->asTextureProxyRef()); + if (!proxy) { // When the device doesn't have a texture, we create a temporary texture. // TODO: we should actually only copy the portion of the source needed to apply the image // filter - sProxy = GrSurfaceProxy::Copy(fContext.get(), - this->accessRenderTargetContext()->asSurfaceProxy(), - SkBudgeted::kYes); - if (!sProxy) { + proxy = GrSurfaceProxy::Copy(fContext.get(), + this->accessRenderTargetContext()->asSurfaceProxy(), + SkBudgeted::kYes); + if (!proxy) { return nullptr; } } @@ -1334,7 +1334,7 @@ sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), srcRect, kNeedNewImageUniqueID_SpecialImage, - sProxy, + std::move(proxy), ii.refColorSpace(), &this->surfaceProps()); } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 98a7101e6b..05caf867a3 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -94,12 +94,7 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace, } sk_sp<GrTextureProxy> SkImage_Gpu::asTextureProxyRef() const { - sk_sp<GrSurfaceProxy> sProxy = GrSurfaceProxy::MakeWrapped(fTexture); - if (!sProxy) { - return nullptr; - } - - return sk_ref_sp(sProxy->asTextureProxy()); + return GrSurfaceProxy::MakeWrapped(fTexture); } GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrSamplerParams& params, diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp index 94683a0cdf..e2e4990d12 100644 --- a/tests/SpecialImageTest.cpp +++ b/tests/SpecialImageTest.cpp @@ -324,7 +324,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_DeferredGpu, reporter, ctxInfo) context, SkIRect::MakeWH(kFullSize, kFullSize), kNeedNewImageUniqueID_SpecialImage, - proxy, nullptr)); + sk_ref_sp(proxy->asTextureProxy()), + nullptr)); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); @@ -333,7 +334,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_DeferredGpu, reporter, ctxInfo) context, subset, kNeedNewImageUniqueID_SpecialImage, - proxy, nullptr)); + sk_ref_sp(proxy->asTextureProxy()), + nullptr)); test_image(subSImg1, reporter, context, true, kPad, kFullSize); } |