diff options
author | 2017-03-20 14:37:13 -0400 | |
---|---|---|
committer | 2017-03-21 11:39:41 +0000 | |
commit | 0db235bc0278887c344eb25b4681e9cca4cf892a (patch) | |
tree | 853a3e84db8d689e36ff5e6730ac38d77a621f14 /src/image | |
parent | 53262d0ff466668bfbc76893ba5a581203269572 (diff) |
Make SkImage_Gpu be deferred
This CL removes the GrTexture-based ctor forcing everyone to create deferred SkImage_Gpus.
split out into:
https://skia-review.googlesource.com/c/9106/ (Remove atlas creation from GrResourceProvider)
Change-Id: I266bbe089c242fe54d5b7adcc7895aa5a39440a0
Reviewed-on: https://skia-review.googlesource.com/6680
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage.cpp | 17 | ||||
-rw-r--r-- | src/image/SkImage_Base.h | 7 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 69 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.h | 8 | ||||
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 37 |
5 files changed, 87 insertions, 51 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 6217f4ecda..fe6369ed35 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -169,25 +169,14 @@ sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const { #if SK_SUPPORT_GPU GrTexture* SkImage::getTexture() const { - return as_IB(this)->peekTexture(); + return as_IB(this)->onGetTexture(); } -bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture()); } +bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekProxy()); } GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextIO, GrSurfaceOrigin* origin) const { - GrTexture* texture = as_IB(this)->peekTexture(); - if (texture) { - GrContext* context = texture->getContext(); - if (context && flushPendingGrContextIO) { - context->prepareSurfaceForExternalIO(texture); - } - if (origin) { - *origin = texture->origin(); - } - return texture->getTextureHandle(); - } - return 0; + return as_IB(this)->onGetTextureHandle(flushPendingGrContextIO, origin); } #else diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 284af0d1a6..e0319ddc25 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -47,13 +47,20 @@ public: virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint) const = 0; + // MDB TODO: this entry point needs to go away virtual GrTexture* peekTexture() const { return nullptr; } #if SK_SUPPORT_GPU + virtual GrTextureProxy* peekProxy() const { return nullptr; } virtual sk_sp<GrTextureProxy> asTextureProxyRef() const { return nullptr; } virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerParams&, SkColorSpace*, sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const = 0; virtual sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const { return nullptr; } + virtual GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const { + return 0; + } + virtual GrTexture* onGetTexture() const { return nullptr; } #endif virtual SkImageCacherator* peekCacherator() const { return nullptr; } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index bcd7275279..c9bc2ee9a4 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -36,17 +36,6 @@ #include "SkPixelRef.h" #include "SkReadPixelsRec.h" -SkImage_Gpu::SkImage_Gpu(uint32_t uniqueID, SkAlphaType at, sk_sp<GrTexture> tex, - sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) - : INHERITED(tex->width(), tex->height(), uniqueID) - , fContext(tex->getContext()) - , fProxy(GrSurfaceProxy::MakeWrapped(std::move(tex))) - , fAlphaType(at) - , fBudgeted(budgeted) - , fColorSpace(std::move(colorSpace)) - , fAddedRasterVersionToCache(false) { -} - SkImage_Gpu::SkImage_Gpu(GrContext* context, uint32_t uniqueID, SkAlphaType at, sk_sp<GrTextureProxy> proxy, sk_sp<SkColorSpace> colorSpace, SkBudgeted budgeted) @@ -165,6 +154,33 @@ static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) } } +GrBackendObject SkImage_Gpu::onGetTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const { + GrTextureProxy* proxy = this->peekProxy(); + SkASSERT(proxy); + + GrSurface* surface = proxy->instantiate(fContext->resourceProvider()); + if (surface && surface->asTexture()) { + if (flushPendingGrContextIO) { + fContext->prepareSurfaceForExternalIO(surface); + } + if (origin) { + *origin = surface->origin(); + } + return surface->asTexture()->getTextureHandle(); + } + return 0; +} + +GrTexture* SkImage_Gpu::onGetTexture() const { + GrTextureProxy* proxy = this->peekProxy(); + if (!proxy) { + return nullptr; + } + + return proxy->instantiate(fContext->resourceProvider()); +} + bool SkImage_Gpu::onReadYUV8Planes(const SkISize sizes[3], void* const planes[3], const size_t rowBytes[3], SkYUVColorSpace colorSpace) const { if (GrTextureToYUVPlanes(fContext, fProxy, sizes, planes, rowBytes, colorSpace)) { @@ -251,6 +267,7 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend if (desc.fWidth <= 0 || desc.fHeight <= 0) { return nullptr; } + sk_sp<GrTexture> tex = ctx->resourceProvider()->wrapBackendTexture(desc, ownership); if (!tex) { return nullptr; @@ -261,8 +278,9 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend const SkBudgeted budgeted = (kAdoptAndCache_GrWrapOwnership == ownership) ? SkBudgeted::kYes : SkBudgeted::kNo; - return sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID, - at, std::move(tex), std::move(colorSpace), budgeted); + sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(tex))); + return sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID, + at, std::move(proxy), std::move(colorSpace), budgeted); } sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, @@ -388,7 +406,8 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace std::move(imageColorSpace)); } -static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id, +static sk_sp<SkImage> create_image_from_maker(GrContext* context, + GrTextureMaker* maker, SkAlphaType at, uint32_t id, SkColorSpace* dstColorSpace) { sk_sp<SkColorSpace> texColorSpace; sk_sp<GrTexture> texture(maker->refTextureForParams(GrSamplerParams::ClampNoFilter(), @@ -396,7 +415,8 @@ static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType if (!texture) { return nullptr; } - return sk_make_sp<SkImage_Gpu>(id, at, std::move(texture), + sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(texture)); + return sk_make_sp<SkImage_Gpu>(context, id, at, std::move(proxy), std::move(texColorSpace), SkBudgeted::kNo); } @@ -410,12 +430,14 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstCo if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { GrImageTextureMaker maker(context, cacher, this, kDisallow_CachingHint); - return create_image_from_maker(&maker, this->alphaType(), this->uniqueID(), dstColorSpace); + return create_image_from_maker(context, &maker, this->alphaType(), + this->uniqueID(), dstColorSpace); } if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { GrBitmapTextureMaker maker(context, *bmp); - return create_image_from_maker(&maker, this->alphaType(), this->uniqueID(), dstColorSpace); + return create_image_from_maker(context, &maker, this->alphaType(), + this->uniqueID(), dstColorSpace); } return nullptr; } @@ -824,13 +846,16 @@ sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& if (!ctx) { return nullptr; } - sk_sp<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevelCount, colorMode)); - if (!texture) { + sk_sp<GrTextureProxy> proxy(GrUploadMipMapToTextureProxy(ctx, info, texels, mipLevelCount, + colorMode)); + if (!proxy) { return nullptr; } - return sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID, - info.alphaType(), std::move(texture), - sk_ref_sp(info.colorSpace()), budgeted); + + SkASSERT(proxy->priv().isExact()); + return sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID, + info.alphaType(), std::move(proxy), + info.refColorSpace(), budgeted); } sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> colorSpace) const { diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 53c38dc278..858419156c 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -21,7 +21,6 @@ class SkImage_Gpu : public SkImage_Base { public: - SkImage_Gpu(uint32_t uniqueID, SkAlphaType, sk_sp<GrTexture>, sk_sp<SkColorSpace>, SkBudgeted); SkImage_Gpu(GrContext*, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>, sk_sp<SkColorSpace>, SkBudgeted); ~SkImage_Gpu() override; @@ -34,6 +33,9 @@ public: sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override; sk_sp<SkImage> onMakeSubset(const SkIRect&) const override; + GrTextureProxy* peekProxy() const override { + return fProxy.get(); + } GrTexture* peekTexture() const override { return fProxy->instantiate(fContext->resourceProvider()); } @@ -43,10 +45,14 @@ public: sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerParams&, SkColorSpace*, sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override; + sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override { *uniqueID = this->uniqueID(); return sk_ref_sp(this->peekTexture()); } + GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO, + GrSurfaceOrigin* origin) const override; + GrTexture* onGetTexture() const override; bool onReadYUV8Planes(const SkISize sizes[3], void* const planes[3], const size_t rowBytes[3], SkYUVColorSpace colorSpace) const override; diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index b610c9c9a1..fdbbf82779 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -8,14 +8,15 @@ #include "SkSurface_Gpu.h" #include "GrContextPriv.h" +#include "GrRenderTargetContextPriv.h" #include "GrResourceProvider.h" + #include "SkCanvas.h" #include "SkColorSpace_Base.h" #include "SkGpuDevice.h" #include "SkImage_Base.h" #include "SkImage_Gpu.h" #include "SkImagePriv.h" -#include "GrRenderTargetContextPriv.h" #include "SkSurface_Base.h" #if SK_SUPPORT_GPU @@ -23,6 +24,7 @@ SkSurface_Gpu::SkSurface_Gpu(sk_sp<SkGpuDevice> device) : INHERITED(device->width(), device->height(), &device->surfaceProps()) , fDevice(std::move(device)) { + SkASSERT(fDevice->accessRenderTargetContext()->asSurfaceProxy()->priv().isExact()); } SkSurface_Gpu::~SkSurface_Gpu() { @@ -91,38 +93,45 @@ sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot() { GrContext* ctx = fDevice->context(); - GrSurfaceProxy* srcProxy = rtc->asSurfaceProxy(); - sk_sp<GrSurfaceContext> copyCtx; + if (!rtc->asSurfaceProxy()) { + return nullptr; + } + + SkBudgeted budgeted = rtc->asSurfaceProxy()->isBudgeted(); + + sk_sp<GrTextureProxy> srcProxy = rtc->asTextureProxyRef(); // If the original render target is a buffer originally created by the client, then we don't // want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid // copy-on-write. if (!srcProxy || rtc->priv().refsWrappedObjects()) { + // MDB TODO: replace this with GrSurfaceProxy::Copy? GrSurfaceDesc desc = rtc->desc(); desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag; - copyCtx = ctx->contextPriv().makeDeferredSurfaceContext(desc, + sk_sp<GrSurfaceContext> copyCtx = ctx->contextPriv().makeDeferredSurfaceContext( + desc, SkBackingFit::kExact, - srcProxy->isBudgeted()); + budgeted); if (!copyCtx) { return nullptr; } - if (!copyCtx->copy(srcProxy)) { + if (!copyCtx->copy(rtc->asSurfaceProxy())) { return nullptr; } - srcProxy = copyCtx->asSurfaceProxy(); + srcProxy = copyCtx->asTextureProxyRef(); } - // TODO: add proxy-backed SkImage_Gpu - GrTexture* tex = srcProxy->instantiate(ctx->resourceProvider())->asTexture(); - const SkImageInfo info = fDevice->imageInfo(); sk_sp<SkImage> image; - if (tex) { - image = sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID, - info.alphaType(), sk_ref_sp(tex), - sk_ref_sp(info.colorSpace()), srcProxy->isBudgeted()); + if (srcProxy) { + // The renderTargetContext coming out of SkGpuDevice should always be exact and the + // above copy creates a kExact surfaceContext. + SkASSERT(srcProxy->priv().isExact()); + image = sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID, + info.alphaType(), std::move(srcProxy), + info.refColorSpace(), budgeted); } return image; } |