diff options
author | 2016-12-14 12:04:46 +0000 | |
---|---|---|
committer | 2016-12-14 12:05:06 +0000 | |
commit | d316e77c1e1967b439a9a6c11146c54e367bff71 (patch) | |
tree | fbf7d3740c39507cdb2aad0267c2d96cd3d98bec /src/gpu | |
parent | 2e018f548d76b0688f9873c683cffc681fec40ec (diff) |
Revert "Add a deferred copy surface (take 2)"
This reverts commit 398487a850431cf495330d4023607df5305a311f.
Reason for revert: See if this is causing the roll failure
Original change's description:
> Add a deferred copy surface (take 2)
>
> This CL forces all GrSurface copies to go through a GrSurfaceContext (rather than GrContext).
>
> There is a bit of goofiness going on here until read/writePixels is also consolidated in GrSurfaceContext and a proxy-backed SkImage/SkSurface is added.
>
> This is a reland of https://skia-review.googlesource.com/c/5773/ (Add a deferred copy surface)
>
> Change-Id: Ide560f569aede5e622420dc2f30eef76357d69f4
> Reviewed-on: https://skia-review.googlesource.com/5939
> Reviewed-by: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
>
TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I1ef40f0d5fb0bca62031f94f10eb18acd753e913
Reviewed-on: https://skia-review.googlesource.com/6024
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 67 | ||||
-rw-r--r-- | src/gpu/GrContextPriv.h | 7 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 16 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContextPriv.h | 4 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetProxy.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrSurfaceProxy.cpp | 50 | ||||
-rw-r--r-- | src/gpu/GrTextureContext.cpp | 25 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 32 |
8 files changed, 66 insertions, 143 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 2e66c0c404..ff5b0266e6 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -541,6 +541,43 @@ void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { fDrawingManager->prepareSurfaceForExternalIO(surface); } +bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, + const SkIPoint& dstPoint) { + ASSERT_SINGLE_OWNER + RETURN_FALSE_IF_ABANDONED + GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::copySurface"); + + if (!src || !dst) { + return false; + } + ASSERT_OWNED_RESOURCE(src); + ASSERT_OWNED_RESOURCE(dst); + + // We don't allow conversion between integer configs and float/fixed configs. + if (GrPixelConfigIsSint(dst->config()) != GrPixelConfigIsSint(src->config())) { + return false; + } + +#ifndef ENABLE_MDB + // We can't yet fully defer copies to textures, so GrTextureContext::copySurface will + // execute the copy immediately. Ensure the data is ready. + src->flushWrites(); +#endif + + sk_sp<GrSurfaceContext> surfaceContext( + this->contextPriv().makeWrappedSurfaceContext(sk_ref_sp(dst))); + + if (!surfaceContext) { + return false; + } + + if (!surfaceContext->copySurface(src, srcRect, dstPoint)) { + return false; + } + + return true; +} + void GrContext::flushSurfaceWrites(GrSurface* surface) { ASSERT_SINGLE_OWNER RETURN_IF_ABANDONED @@ -602,36 +639,8 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurface } } -sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc, - SkBudgeted isDstBudgeted) { - - sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*fContext->caps(), dstDesc, - SkBackingFit::kExact, isDstBudgeted); - - if (proxy->asRenderTargetProxy()) { - return this->drawingManager()->makeRenderTargetContext(std::move(proxy), nullptr, nullptr); - } else { - SkASSERT(proxy->asTextureProxy()); - return this->drawingManager()->makeTextureContext(std::move(proxy)); - } - - return nullptr; -} - -sk_sp<GrSurfaceContext> GrContextPriv::makeTestSurfaceContext(sk_sp<GrSurfaceProxy> proxy) { - - if (proxy->asRenderTargetProxy()) { - return this->drawingManager()->makeRenderTargetContext(std::move(proxy), nullptr, nullptr); - } else { - SkASSERT(proxy->asTextureProxy()); - return this->drawingManager()->makeTextureContext(std::move(proxy)); - } - - return nullptr; -} - sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext( - const GrBackendTextureDesc& desc, + const GrBackendTextureDesc& desc, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props, GrWrapOwnership ownership) { diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index 2b2a39e009..dcf0807507 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -11,8 +11,6 @@ #include "GrContext.h" #include "GrSurfaceContext.h" -class GrSurfaceProxy; - /** Class that adds methods to GrContext that are only intended for use internal to Skia. This class is purely a privileged window into GrContext. It should never have additional data members or virtual methods. */ @@ -28,11 +26,6 @@ public: // Create a surfaceContext that wraps an existing texture or renderTarget sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex); - sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc, - SkBudgeted isDstBudgeted); - - sk_sp<GrSurfaceContext> makeTestSurfaceContext(sk_sp<GrSurfaceProxy> proxy); - sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext( const GrBackendTextureDesc& desc, sk_sp<SkColorSpace> colorSpace, diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index f32bf8fed2..1a1f6a5835 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -133,20 +133,12 @@ GrRenderTargetOpList* GrRenderTargetContext::getOpList() { return fOpList; } -// TODO: move this (and GrTextContext::copy) to GrSurfaceContext? -bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy, - const SkIRect& srcRect, - const SkIPoint& dstPoint) { +bool GrRenderTargetContext::copySurface(GrSurface* src, const SkIRect& srcRect, + const SkIPoint& dstPoint) { ASSERT_SINGLE_OWNER RETURN_FALSE_IF_ABANDONED SkDEBUGCODE(this->validate();) - GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::copy"); - - // TODO: defer instantiation until flush time - sk_sp<GrSurface> src(sk_ref_sp(srcProxy->instantiate(fContext->textureProvider()))); - if (!src) { - return false; - } + GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::copySurface"); // TODO: this needs to be fixed up since it ends the deferrable of the GrRenderTarget sk_sp<GrRenderTarget> rt( @@ -155,7 +147,7 @@ bool GrRenderTargetContext::onCopy(GrSurfaceProxy* srcProxy, return false; } - return this->getOpList()->copySurface(rt.get(), src.get(), srcRect, dstPoint); + return this->getOpList()->copySurface(rt.get(), src, srcRect, dstPoint); } void GrRenderTargetContext::drawText(const GrClip& clip, const GrPaint& grPaint, diff --git a/src/gpu/GrRenderTargetContextPriv.h b/src/gpu/GrRenderTargetContextPriv.h index f1548cc9fa..b3bd72a563 100644 --- a/src/gpu/GrRenderTargetContextPriv.h +++ b/src/gpu/GrRenderTargetContextPriv.h @@ -114,10 +114,6 @@ public: const GrUserStencilSettings* = nullptr, bool snapToCenters = false); - bool refsWrappedObjects() const { - return fRenderTargetContext->fRenderTargetProxy->refsWrappedObjects(); - } - private: explicit GrRenderTargetContextPriv(GrRenderTargetContext* renderTargetContext) : fRenderTargetContext(renderTargetContext) {} diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp index 882acf660c..03637cf9af 100644 --- a/src/gpu/GrRenderTargetProxy.cpp +++ b/src/gpu/GrRenderTargetProxy.cpp @@ -8,7 +8,6 @@ #include "GrRenderTargetProxy.h" #include "GrCaps.h" -#include "GrGpuResourcePriv.h" #include "GrRenderTargetOpList.h" #include "GrRenderTargetPriv.h" #include "GrTextureProvider.h" @@ -64,10 +63,3 @@ size_t GrRenderTargetProxy::onGpuMemorySize() const { return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit); } -bool GrRenderTargetProxy::refsWrappedObjects() const { - if (!fTarget) { - return false; - } - - return fTarget->resourcePriv().refsWrappedObjects(); -} diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index 24c7cfe29a..4a0c3480a4 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -8,11 +8,8 @@ #include "GrSurfaceProxy.h" #include "GrCaps.h" -#include "GrContext.h" -#include "GrContextPriv.h" #include "GrGpuResourcePriv.h" #include "GrOpList.h" -#include "GrSurfaceContext.h" #include "GrTextureProvider.h" #include "GrTextureRenderTargetProxy.h" @@ -164,50 +161,3 @@ void GrSurfaceProxy::validate(GrContext* context) const { INHERITED::validate(); } #endif - -sk_sp<GrSurfaceProxy> GrSurfaceProxy::Copy(GrContext* context, - GrSurfaceProxy* src, - SkIRect srcRect, - SkBudgeted budgeted) { - if (!srcRect.intersect(SkIRect::MakeWH(src->width(), src->height()))) { - return nullptr; - } - - GrSurfaceDesc dstDesc = src->desc(); - dstDesc.fWidth = srcRect.width(); - dstDesc.fHeight = srcRect.height(); - - sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(dstDesc, - budgeted)); - if (!dstContext) { - return nullptr; - } - - if (!dstContext->copy(src, srcRect, SkIPoint::Make(0, 0))) { - return nullptr; - } - - return sk_ref_sp(dstContext->asDeferredSurface()); -} - -sk_sp<GrSurfaceProxy> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc, - GrTexture* srcTexture, SkBudgeted budgeted) { - - sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext( - dstDesc, - budgeted)); - if (!dstContext) { - return nullptr; - } - - sk_sp<GrSurfaceProxy> srcProxy(GrSurfaceProxy::MakeWrapped(sk_ref_sp(srcTexture))); - if (!srcProxy) { - return nullptr; - } - - if (!dstContext->copy(srcProxy.get())) { - return nullptr; - } - - return sk_ref_sp(dstContext->asDeferredSurface()); -} diff --git a/src/gpu/GrTextureContext.cpp b/src/gpu/GrTextureContext.cpp index 28240f8a79..22620fed0f 100644 --- a/src/gpu/GrTextureContext.cpp +++ b/src/gpu/GrTextureContext.cpp @@ -24,7 +24,8 @@ GrTextureContext::GrTextureContext(GrContext* context, : GrSurfaceContext(context, auditTrail, singleOwner) , fDrawingManager(drawingMgr) , fTextureProxy(std::move(textureProxy)) - , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList())) { + , fOpList(SkSafeRef(fTextureProxy->getLastTextureOpList())) +{ SkDEBUGCODE(this->validate();) } @@ -55,26 +56,12 @@ GrTextureOpList* GrTextureContext::getOpList() { return fOpList; } -// TODO: move this (and GrRenderTargetContext::copy) to GrSurfaceContext? -bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy, - const SkIRect& srcRect, - const SkIPoint& dstPoint) { +bool GrTextureContext::copySurface(GrSurface* src, const SkIRect& srcRect, + const SkIPoint& dstPoint) { ASSERT_SINGLE_OWNER RETURN_FALSE_IF_ABANDONED SkDEBUGCODE(this->validate();) - GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::copy"); - - // TODO: defer instantiation until flush time - sk_sp<GrSurface> src(sk_ref_sp(srcProxy->instantiate(fContext->textureProvider()))); - if (!src) { - return false; - } -
-#ifndef ENABLE_MDB
- // We can't yet fully defer copies to textures, so GrTextureContext::copySurface will
- // execute the copy immediately. Ensure the data is ready.
- src->flushWrites();
-#endif + GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrTextureContext::copySurface"); // TODO: this needs to be fixed up since it ends the deferrable of the GrTexture sk_sp<GrTexture> tex(sk_ref_sp(fTextureProxy->instantiate(fContext->textureProvider()))); @@ -83,7 +70,7 @@ bool GrTextureContext::onCopy(GrSurfaceProxy* srcProxy, } GrTextureOpList* opList = this->getOpList(); - bool result = opList->copySurface(tex.get(), src.get(), srcRect, dstPoint); + bool result = opList->copySurface(tex.get(), src, srcRect, dstPoint); #ifndef ENABLE_MDB GrOpFlushState flushState(fContext->getGpu(), nullptr); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 5738764a5b..3cdc34e982 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -15,7 +15,6 @@ #include "GrRenderTargetContextPriv.h" #include "GrStyle.h" #include "GrTextureAdjuster.h" -#include "GrTextureProxy.h" #include "GrTracing.h" #include "SkCanvasPriv.h" @@ -263,7 +262,9 @@ void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) { if (fRenderTargetContext->wasAbandoned()) { return; } - newRTC->copy(fRenderTargetContext->asDeferredSurface()); + newRTC->copySurface(fRenderTargetContext->asTexture().get(), + SkIRect::MakeWH(this->width(), this->height()), + SkIPoint::Make(0, 0)); } fRenderTargetContext = newRTC; @@ -1331,15 +1332,19 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) { } sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { - sk_sp<GrSurfaceProxy> sProxy(sk_ref_sp(this->accessRenderTargetContext()->asDeferredTexture())); - if (!sProxy) { + sk_sp<GrTexture> texture(this->accessRenderTargetContext()->asTexture()); + if (!texture) { // 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()->asDeferredSurface(), - SkBudgeted::kYes); - if (!sProxy) { + texture.reset(fContext->textureProvider()->createTexture( + this->accessRenderTargetContext()->desc(), SkBudgeted::kYes)); + if (!texture) { + return nullptr; + } + + if (!fContext->copySurface(texture.get(), + this->accessRenderTargetContext()->accessRenderTarget())) { return nullptr; } } @@ -1347,12 +1352,11 @@ sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() { const SkImageInfo ii = this->imageInfo(); const SkIRect srcRect = SkIRect::MakeWH(ii.width(), ii.height()); - return SkSpecialImage::MakeDeferredFromGpu(fContext.get(), - srcRect, - kNeedNewImageUniqueID_SpecialImage, - sProxy, - sk_ref_sp(ii.colorSpace()), - &this->surfaceProps()); + return SkSpecialImage::MakeFromGpu(srcRect, + kNeedNewImageUniqueID_SpecialImage, + std::move(texture), + sk_ref_sp(ii.colorSpace()), + &this->surfaceProps()); } void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |