diff --git a/include/private/GrRecordingContext.h b/include/private/GrRecordingContext.h index 3b587f5b3d..f9a6f44c69 100644 --- a/include/private/GrRecordingContext.h +++ b/include/private/GrRecordingContext.h @@ -86,25 +86,6 @@ protected: */ void addOnFlushCallbackObject(GrOnFlushCallbackObject*); - std::unique_ptr makeWrappedSurfaceContext(sk_sp, - GrColorType, - SkAlphaType, - sk_sp = nullptr, - const SkSurfaceProps* = nullptr); - - /** Create a new surface context backed by a deferred-style GrTextureProxy. */ - std::unique_ptr makeDeferredSurfaceContext( - SkBackingFit, - int width, - int height, - GrColorType, - SkAlphaType, - sk_sp, - GrMipMapped = GrMipMapped::kNo, - GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, - SkBudgeted = SkBudgeted::kYes, - GrProtected = GrProtected::kNo); - /* * Create a new render target context backed by a deferred-style * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp index 5533a9169f..324913df18 100644 --- a/src/core/SkDeferredDisplayListRecorder.cpp +++ b/src/core/SkDeferredDisplayListRecorder.cpp @@ -185,13 +185,17 @@ bool SkDeferredDisplayListRecorder::init() { return false; } - auto c = fContext->priv().makeWrappedSurfaceContext(std::move(proxy), - grColorType, - kPremul_SkAlphaType, - fCharacterization.refColorSpace(), - &fCharacterization.surfaceProps()); - SkASSERT(c->asRenderTargetContext()); - std::unique_ptr rtc(c.release()->asRenderTargetContext()); + const GrSwizzle& readSwizzle = caps->getReadSwizzle(fCharacterization.backendFormat(), + grColorType); + const GrSwizzle& outputSwizzle = caps->getOutputSwizzle(fCharacterization.backendFormat(), + grColorType); + SkASSERT(readSwizzle == proxy->textureSwizzle()); + + auto rtc = std::make_unique(fContext.get(), std::move(proxy), + grColorType, fCharacterization.origin(), + readSwizzle, outputSwizzle, + fCharacterization.refColorSpace(), + &fCharacterization.surfaceProps()); fSurface = SkSurface_Gpu::MakeWrappedRenderTarget(fContext.get(), std::move(rtc)); return SkToBool(fSurface.get()); } diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index b4c3a56a7b..227a0c2f80 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -451,8 +451,8 @@ public: if (!rec) { return false; } - auto sContext = fContext->priv().makeWrappedSurfaceContext(fTextureProxy, fColorType, - this->alphaType(), fColorSpace); + auto sContext = GrSurfaceContext::Make(fContext, fTextureProxy, fColorType, + this->alphaType(), fColorSpace); if (!sContext) { return false; } diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp index 2074f61aa0..a0f5d49379 100644 --- a/src/gpu/GrContextPriv.cpp +++ b/src/gpu/GrContextPriv.cpp @@ -40,32 +40,6 @@ void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBO fContext->addOnFlushCallbackObject(onFlushCBObject); } -std::unique_ptr GrContextPriv::makeWrappedSurfaceContext( - sk_sp proxy, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - const SkSurfaceProps* props) { - return fContext->makeWrappedSurfaceContext(std::move(proxy), colorType, alphaType, - std::move(colorSpace), props); -} - -std::unique_ptr GrContextPriv::makeDeferredSurfaceContext( - SkBackingFit fit, - int width, - int height, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - GrMipMapped mipMapped, - GrSurfaceOrigin origin, - SkBudgeted budgeted, - GrProtected isProtected) { - return fContext->makeDeferredSurfaceContext(fit, width, height, colorType, alphaType, - std::move(colorSpace), mipMapped, origin, budgeted, - isProtected); -} - std::unique_ptr GrContextPriv::makeDeferredRenderTargetContext( SkBackingFit fit, int width, @@ -93,24 +67,6 @@ std::unique_ptr GrContextPriv::makeDeferredRenderTargetCo surfaceProps, budgeted, isProtected); } -std::unique_ptr GrContextPriv::makeBackendTextureContext( - const GrBackendTexture& tex, - GrSurfaceOrigin origin, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace) { - ASSERT_SINGLE_OWNER - - sk_sp proxy = this->proxyProvider()->wrapBackendTexture( - tex, colorType, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); - if (!proxy) { - return nullptr; - } - - return this->drawingManager()->makeSurfaceContext(std::move(proxy), colorType, alphaType, - std::move(colorSpace)); -} - std::unique_ptr GrContextPriv::makeBackendTextureRenderTargetContext( const GrBackendTexture& tex, GrSurfaceOrigin origin, diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index b454c5602f..31c530bd80 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -67,25 +67,6 @@ public: */ void addOnFlushCallbackObject(GrOnFlushCallbackObject*); - std::unique_ptr makeWrappedSurfaceContext(sk_sp, - GrColorType, - SkAlphaType, - sk_sp = nullptr, - const SkSurfaceProps* = nullptr); - - /** Create a new texture context backed by a deferred-style GrTextureProxy. */ - std::unique_ptr makeDeferredSurfaceContext( - SkBackingFit, - int width, - int height, - GrColorType, - SkAlphaType, - sk_sp, - GrMipMapped = GrMipMapped::kNo, - GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, - SkBudgeted = SkBudgeted::kYes, - GrProtected = GrProtected::kNo); - /* * Create a new render target context backed by a deferred-style * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for @@ -130,12 +111,6 @@ public: */ static sk_sp MakeDDL(const sk_sp&); - std::unique_ptr makeBackendTextureContext(const GrBackendTexture&, - GrSurfaceOrigin, - GrColorType, - SkAlphaType, - sk_sp); - // These match the definitions in SkSurface & GrSurface.h, for whence they came typedef void* ReleaseContext; typedef void (*ReleaseProc)(ReleaseContext); diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 6e24270809..decfdf2557 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -941,22 +941,3 @@ std::unique_ptr GrDrawingManager::makeRenderTargetContext managedOpsTask)); } -std::unique_ptr GrDrawingManager::makeSurfaceContext( - sk_sp sProxy, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace) { - if (this->wasAbandoned() || !sProxy->asTextureProxy()) { - return nullptr; - } - - // GrTextureRenderTargets should always be using a GrRenderTargetContext - SkASSERT(!sProxy->asRenderTargetProxy()); - - GrSurfaceOrigin origin = sProxy->origin(); - GrSwizzle readSwizzle = sProxy->textureSwizzle(); - - return std::unique_ptr(new GrSurfaceContext( - fContext, std::move(sProxy), colorType, alphaType, std::move(colorSpace), origin, - readSwizzle)); -} diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index 1e179dbb3e..102aeb1cb4 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -42,10 +42,6 @@ public: sk_sp, const SkSurfaceProps*, bool managedOpsTask = true); - std::unique_ptr makeSurfaceContext(sk_sp, - GrColorType, - SkAlphaType, - sk_sp); // A managed opsTask is controlled by the drawing manager (i.e., sorted & flushed with the // others). An unmanaged one is created and used by the onFlushCallback. diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp index d1c79f3bb1..425c3f3123 100644 --- a/src/gpu/GrRecordingContext.cpp +++ b/src/gpu/GrRecordingContext.cpp @@ -159,65 +159,6 @@ void GrRecordingContext::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlu this->drawingManager()->addOnFlushCallbackObject(onFlushCBObject); } -std::unique_ptr GrRecordingContext::makeWrappedSurfaceContext( - sk_sp proxy, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - const SkSurfaceProps* props) { - ASSERT_SINGLE_OWNER_PRIV - - SkASSERT(proxy); - - if (proxy->asRenderTargetProxy()) { - SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType); - return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType, - std::move(colorSpace), props); - } else { - SkASSERT(proxy->asTextureProxy()); - SkASSERT(!props); - return this->drawingManager()->makeSurfaceContext(std::move(proxy), colorType, alphaType, - std::move(colorSpace)); - } -} - -std::unique_ptr GrRecordingContext::makeDeferredSurfaceContext( - SkBackingFit fit, - int width, - int height, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - GrMipMapped mipMapped, - GrSurfaceOrigin origin, - SkBudgeted budgeted, - GrProtected isProtected) { - auto format = this->caps()->getDefaultBackendFormat(colorType, GrRenderable::kNo); - if (!format.isValid()) { - return nullptr; - } - auto config = this->caps()->getConfigFromBackendFormat(format, colorType); - if (config == kUnknown_GrPixelConfig) { - return nullptr; - } - - GrSurfaceDesc desc; - desc.fWidth = width; - desc.fHeight = height; - desc.fConfig = config; - - sk_sp texture = this->proxyProvider()->createProxy( - format, desc, GrRenderable::kNo, 1, origin, mipMapped, fit, budgeted, isProtected); - if (!texture) { - return nullptr; - } - - auto drawingManager = this->drawingManager(); - - return drawingManager->makeSurfaceContext(std::move(texture), colorType, alphaType, - std::move(colorSpace)); -} - std::unique_ptr GrRecordingContext::makeDeferredRenderTargetContext( SkBackingFit fit, int width, @@ -330,32 +271,6 @@ void GrRecordingContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* o fContext->addOnFlushCallbackObject(onFlushCBObject); } -std::unique_ptr GrRecordingContextPriv::makeWrappedSurfaceContext( - sk_sp proxy, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - const SkSurfaceProps* props) { - return fContext->makeWrappedSurfaceContext(std::move(proxy), colorType, alphaType, - std::move(colorSpace), props); -} - -std::unique_ptr GrRecordingContextPriv::makeDeferredSurfaceContext( - SkBackingFit fit, - int width, - int height, - GrColorType colorType, - SkAlphaType alphaType, - sk_sp colorSpace, - GrMipMapped mipMapped, - GrSurfaceOrigin origin, - SkBudgeted budgeted, - GrProtected isProtected) { - return fContext->makeDeferredSurfaceContext(fit, width, height, colorType, alphaType, - std::move(colorSpace), mipMapped, origin, budgeted, - isProtected); -} - std::unique_ptr GrRecordingContextPriv::makeDeferredRenderTargetContext( SkBackingFit fit, int width, diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h index d1d54b9c85..5f0bf3a934 100644 --- a/src/gpu/GrRecordingContextPriv.h +++ b/src/gpu/GrRecordingContextPriv.h @@ -66,25 +66,6 @@ public: */ void addOnFlushCallbackObject(GrOnFlushCallbackObject*); - std::unique_ptr makeWrappedSurfaceContext(sk_sp, - GrColorType, - SkAlphaType, - sk_sp = nullptr, - const SkSurfaceProps* = nullptr); - - /** Create a new texture context backed by a deferred-style GrTextureProxy. */ - std::unique_ptr makeDeferredSurfaceContext( - SkBackingFit, - int width, - int height, - GrColorType, - SkAlphaType, - sk_sp, - GrMipMapped = GrMipMapped::kNo, - GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, - SkBudgeted = SkBudgeted::kYes, - GrProtected = GrProtected::kNo); - /* * Create a new render target context backed by a deferred-style * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 9fcbd53ff6..a4a878eb34 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -145,13 +145,13 @@ GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context, sk_sp rtp, GrColorType colorType, GrSurfaceOrigin origin, - GrSwizzle texSwizzle, + GrSwizzle readSwizzle, GrSwizzle outSwizzle, sk_sp colorSpace, const SkSurfaceProps* surfaceProps, bool managedOpsTask) : GrSurfaceContext(context, std::move(rtp), colorType, kPremul_SkAlphaType, - std::move(colorSpace), origin, texSwizzle) + std::move(colorSpace), origin, readSwizzle) , fOutputSwizzle(outSwizzle) , fOpsTask(sk_ref_sp(fSurfaceProxy->getLastOpsTask())) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index 395f4240bf..a8b19961eb 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -27,7 +27,6 @@ class GrBackendSemaphore; class GrClip; class GrColorSpaceXform; class GrCoverageCountingPathRenderer; -class GrDrawingManager; class GrDrawOp; class GrFixedClip; class GrOp; @@ -58,6 +57,10 @@ class SkVertices; */ class GrRenderTargetContext : public GrSurfaceContext { public: + GrRenderTargetContext(GrRecordingContext*, sk_sp, GrColorType, + GrSurfaceOrigin, GrSwizzle readSwizzle, GrSwizzle outSwizzle, + sk_sp, const SkSurfaceProps*, bool managedOpsTask = true); + ~GrRenderTargetContext() override; virtual void drawGlyphRunList(const GrClip&, const SkMatrix& viewMatrix, const SkGlyphRunList&); @@ -523,7 +526,6 @@ private: friend class GrClipStackClip; // for access to getOpsTask friend class GrOnFlushResourceProvider; // for access to getOpsTask (http://skbug.com/9357) - friend class GrDrawingManager; // for ctor friend class GrRenderTargetContextPriv; // All the path renderers currently make their own ops @@ -541,10 +543,6 @@ private: friend class GrFillRectOp; // for access to addDrawOp friend class GrTextureOp; // for access to addDrawOp - GrRenderTargetContext(GrRecordingContext*, sk_sp, GrColorType, - GrSurfaceOrigin, GrSwizzle texSwizzle, GrSwizzle outSwizzle, - sk_sp, const SkSurfaceProps*, bool managedOpsTask = true); - SkDEBUGCODE(void onValidate() const override;) diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index dae12e2ba9..848eee348f 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -27,6 +27,61 @@ SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) #define RETURN_FALSE_IF_ABANDONED if (this->fContext->priv().abandoned()) { return false; } +std::unique_ptr GrSurfaceContext::Make(GrRecordingContext* context, + sk_sp proxy, + GrColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace) { + SkASSERT(proxy && proxy->asTextureProxy()); + + // TODO: These should be passed in directly or as GrSurfaceProxyView + GrSurfaceOrigin origin = proxy->origin(); + GrSwizzle readSwizzle = proxy->textureSwizzle(); + + std::unique_ptr surfaceContext; + if (GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy()) { + SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType); + // Will we ever want a swizzle that is not the default output swizzle for the format and + // colorType here? If so we will need to manually pass that in. + GrSwizzle outSwizzle = context->priv().caps()->getOutputSwizzle(proxy->backendFormat(), + colorType); + surfaceContext.reset(new GrRenderTargetContext(context, sk_ref_sp(rtProxy), colorType, + origin, readSwizzle, outSwizzle, + std::move(colorSpace), nullptr)); + } else { + surfaceContext.reset(new GrSurfaceContext(context, std::move(proxy), colorType, alphaType, + std::move(colorSpace), origin, readSwizzle)); + } + return surfaceContext; +} + +std::unique_ptr GrSurfaceContext::Make( + GrRecordingContext* context, const SkISize& dimensions, const GrBackendFormat& format, + GrRenderable renderable, int renderTargetSampleCnt, GrMipMapped mipMapped, + GrProtected isProtected, GrSurfaceOrigin origin, GrColorType colorType, + SkAlphaType alphaType, sk_sp colorSpace, SkBackingFit fit, + SkBudgeted budgeted) { + auto config = context->priv().caps()->getConfigFromBackendFormat(format, colorType); + if (config == kUnknown_GrPixelConfig) { + return nullptr; + } + GrSurfaceDesc desc; + desc.fWidth = dimensions.width(); + desc.fHeight = dimensions.height(); + desc.fConfig = config; + + sk_sp proxy = context->priv().proxyProvider()->createProxy( + format, desc, renderable, renderTargetSampleCnt, origin, mipMapped, fit, budgeted, + isProtected); + if (!proxy) { + return nullptr; + } + + return GrSurfaceContext::Make(context, std::move(proxy), colorType, alphaType, + std::move(colorSpace)); +} + + // In MDB mode the reffing of the 'getLastOpsTask' call's result allows in-progress // GrOpsTasks to be picked up and added to by renderTargetContexts lower in the call // stack. When this occurs with a closed GrOpsTask, a new one will be allocated @@ -291,6 +346,7 @@ bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* s GrBackendFormat format; SkAlphaType alphaType; + GrSwizzle tempReadSwizzle; if (canvas2DFastPath) { desc.fConfig = kRGBA_8888_GrPixelConfig; colorType = GrColorType::kRGBA_8888; @@ -304,6 +360,7 @@ bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* s return false; } alphaType = this->colorInfo().alphaType(); + tempReadSwizzle = this->readSwizzle(); } // It is more efficient for us to write pixels into a top left origin so we prefer that. @@ -316,15 +373,12 @@ bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* s auto tempProxy = direct->priv().proxyProvider()->createProxy( format, desc, GrRenderable::kNo, 1, tempOrigin, GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo); - if (!tempProxy) { return false; } - auto tempCtx = direct->priv().drawingManager()->makeSurfaceContext( - tempProxy, colorType, alphaType, this->colorInfo().refColorSpace()); - if (!tempCtx) { - return false; - } + SkASSERT(tempProxy->textureSwizzle() == tempReadSwizzle); + GrSurfaceContext tempCtx(direct, tempProxy, colorType, alphaType, + this->colorInfo().refColorSpace(), tempOrigin, tempReadSwizzle); // In the fast path we always write the srcData to the temp context as though it were RGBA. // When the data is really BGRA the write will cause the R and B channels to be swapped in @@ -333,7 +387,7 @@ bool GrSurfaceContext::writePixels(const GrImageInfo& origSrcInfo, const void* s if (canvas2DFastPath) { srcInfo = srcInfo.makeColorType(GrColorType::kRGBA_8888); } - if (!tempCtx->writePixels(srcInfo, src, rowBytes, {0, 0}, direct)) { + if (!tempCtx.writePixels(srcInfo, src, rowBytes, {0, 0}, direct)) { return false; } diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h index 2441e085d8..69edd0040c 100644 --- a/src/gpu/GrSurfaceContext.h +++ b/src/gpu/GrSurfaceContext.h @@ -36,6 +36,23 @@ struct SkIRect; */ class GrSurfaceContext { public: + // If the passed in GrSurfaceProxy is renderable this will return a GrRenderTargetContext, + // otherwise it will return a GrSurfaceContext. + static std::unique_ptr Make(GrRecordingContext*, sk_sp, + GrColorType, SkAlphaType, sk_sp); + + static std::unique_ptr Make(GrRecordingContext*, const SkISize& dimensions, + const GrBackendFormat&, GrRenderable, + int renderTargetSampleCnt, GrMipMapped, + GrProtected, GrSurfaceOrigin, GrColorType, + SkAlphaType, sk_sp, SkBackingFit, + SkBudgeted); + + // If it is known that the GrSurfaceProxy is not renderable, you can directly call the the ctor + // here to make a GrSurfaceContext on the stack. + GrSurfaceContext(GrRecordingContext*, sk_sp, GrColorType, SkAlphaType, + sk_sp, GrSurfaceOrigin, GrSwizzle readSwizzle); + virtual ~GrSurfaceContext() = default; const GrColorInfo& colorInfo() const { return fColorInfo; } @@ -113,10 +130,6 @@ public: protected: friend class GrSurfaceContextPriv; - friend class GrDrawingManager; // For ctor - - GrSurfaceContext(GrRecordingContext*, sk_sp, GrColorType, SkAlphaType, - sk_sp, GrSurfaceOrigin, GrSwizzle readSwizzle); GrDrawingManager* drawingManager(); const GrDrawingManager* drawingManager() const; diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index ef5dc3cfb4..060a97a870 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -308,14 +308,24 @@ sk_sp GrSurfaceProxy::Copy(GrRecordingContext* context, return nullptr; } auto colorType = GrPixelConfigToColorType(src->config()); + auto format = src->backendFormat().makeTexture2D(); + SkASSERT(format.isValid()); + auto config = context->priv().caps()->getConfigFromBackendFormat(format, colorType); + if (config == kUnknown_GrPixelConfig) { + return nullptr; + } + GrSurfaceDesc desc; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; + + GrSurfaceOrigin origin = src->origin(); if (src->backendFormat().textureType() != GrTextureType::kExternal) { - auto dstContext = context->priv().makeDeferredSurfaceContext( - fit, width, height, colorType, kUnknown_SkAlphaType, nullptr, mipMapped, - src->origin(), budgeted, isProtected); - if (!dstContext) { - return nullptr; - } - if (dstContext->copy(src, srcRect, dstPoint)) { + auto dstContext = GrSurfaceContext::Make(context, {width, height}, format, + GrRenderable::kNo, 1, mipMapped, isProtected, + origin, colorType, kUnknown_SkAlphaType, nullptr, + fit, budgeted); + if (dstContext && dstContext->copy(src, srcRect, dstPoint)) { return dstContext->asTextureProxyRef(); } } diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp index ab47187c1c..0beb3d318d 100644 --- a/src/gpu/text/GrAtlasManager.cpp +++ b/src/gpu/text/GrAtlasManager.cpp @@ -96,8 +96,8 @@ static bool save_pixels(GrContext* context, GrSurfaceProxy* sProxy, GrColorType return false; } - auto sContext = context->priv().makeWrappedSurfaceContext(sk_ref_sp(sProxy), colorType, - kUnknown_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, sk_ref_sp(sProxy), colorType, + kUnknown_SkAlphaType, nullptr); if (!sContext || !sContext->asTextureProxy()) { return false; } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 7742fbad17..795c149b68 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -637,20 +637,17 @@ sk_sp SkImage::MakeFromAHardwareBufferWithData(GrContext* context, return nullptr; } - auto surfaceContext = - drawingManager->makeSurfaceContext(proxy, SkColorTypeToGrColorType(pixmap.colorType()), - pixmap.alphaType(), cs); - if (!surfaceContext) { - return nullptr; - } + GrSurfaceContext surfaceContext(context, std::move(proxy), + SkColorTypeToGrColorType(pixmap.colorType()), + pixmap.alphaType(), cs, surfaceOrigin, swizzle); SkImageInfo srcInfo = SkImageInfo::Make(bufferDesc.width, bufferDesc.height, colorType, at, std::move(cs)); - surfaceContext->writePixels(srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0}); + surfaceContext.writePixels(srcInfo, pixmap.addr(0, 0), pixmap.rowBytes(), {0, 0}); GrFlushInfo info; info.fFlags = kSyncCpu_GrFlushFlag; - GrSurfaceProxy* p[1] = {proxy.get()}; + GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()}; drawingManager->flush(p, 1, SkSurface::BackendSurfaceAccess::kNoAccess, info, GrPrepareForExternalIORequests()); diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp index 5e8a079234..b96ad749a3 100644 --- a/src/image/SkImage_GpuBase.cpp +++ b/src/image/SkImage_GpuBase.cpp @@ -119,8 +119,8 @@ bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const { this->colorType(), texProxy->backendFormat()); - auto sContext = direct->priv().makeWrappedSurfaceContext( - std::move(texProxy), grColorType, this->alphaType(), this->refColorSpace()); + auto sContext = GrSurfaceContext::Make(direct, std::move(texProxy), grColorType, + this->alphaType(), this->refColorSpace()); if (!sContext) { return false; } @@ -180,8 +180,8 @@ bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, this->colorType(), texProxy->backendFormat()); - auto sContext = direct->priv().makeWrappedSurfaceContext( - std::move(texProxy), grColorType, this->alphaType(), this->refColorSpace()); + auto sContext = GrSurfaceContext::Make(direct, std::move(texProxy), grColorType, + this->alphaType(), this->refColorSpace()); if (!sContext) { return false; } diff --git a/src/image/SkSurface_GpuMtl.mm b/src/image/SkSurface_GpuMtl.mm index d3e42bd335..f91cb433ee 100644 --- a/src/image/SkSurface_GpuMtl.mm +++ b/src/image/SkSurface_GpuMtl.mm @@ -97,13 +97,15 @@ sk_sp SkSurface::MakeFromCAMetalLayer(GrContext* context, false, GrSurfaceProxy::UseAllocator::kYes); - auto c = context->priv().makeWrappedSurfaceContext(std::move(proxy), - grColorType, - kPremul_SkAlphaType, - colorSpace, - surfaceProps); - SkASSERT(c->asRenderTargetContext()); - std::unique_ptr rtc(c.release()->asRenderTargetContext()); + const GrSwizzle& readSwizzle = caps->getReadSwizzle(backendFormat, grColorType); + const GrSwizzle& outputSwizzle = caps->getOutputSwizzle(backendFormat, grColorType); + + SkASSERT(readSwizzle == proxy->textureSwizzle()); + + auto rtc = std::make_unique(context, std::move(proxy), + grColorType, origin, + readSwizzle, outputSwizzle, + colorSpace, surfaceProps); sk_sp surface = SkSurface_Gpu::MakeWrappedRenderTarget(context, std::move(rtc)); return surface; diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp index c4c9af71d2..1576fa1818 100644 --- a/tests/CopySurfaceTest.cpp +++ b/tests/CopySurfaceTest.cpp @@ -105,10 +105,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) { } GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType()); - auto dstContext = context->priv().makeWrappedSurfaceContext( - std::move(dst), - grColorType, - ii.alphaType()); + auto dstContext = GrSurfaceContext::Make(context, std::move(dst), + grColorType, + ii.alphaType(), nullptr); bool result = false; if (sOrigin == dOrigin) { diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 43838a447a..d27c572701 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -155,11 +155,21 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { // Wrap this texture ID in a GrTexture GrBackendTexture backendTex(kSize, kSize, GrMipMapped::kNo, externalTexture); + GrColorType colorType = GrColorType::kRGBA_8888; + SkAlphaType alphaType = kPremul_SkAlphaType; // TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test // fails on the Nexus5. Why? - auto surfaceContext = context0->priv().makeBackendTextureContext( - backendTex, kBottomLeft_GrSurfaceOrigin, GrColorType::kRGBA_8888, kPremul_SkAlphaType, - nullptr); + GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin; + sk_sp texProxy = context0->priv().proxyProvider()->wrapBackendTexture( + backendTex, colorType, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRW_GrIOType); + if (!texProxy) { + ERRORF(reporter, "Error wrapping external texture in GrTextureProxy."); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); + return; + } + auto surfaceContext = GrSurfaceContext::Make(context0, std::move(texProxy), colorType, + alphaType, nullptr); if (!surfaceContext) { ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext."); @@ -180,7 +190,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { // Should not be able to wrap as a RT { auto temp = context0->priv().makeBackendTextureRenderTargetContext( - backendTex, kBottomLeft_GrSurfaceOrigin, 1, GrColorType::kRGBA_8888, nullptr); + backendTex, origin, 1, colorType, nullptr); if (temp) { ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT."); } @@ -194,7 +204,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { // Only test RT-config // TODO: why do we always need to draw to copy from an external texture? TestCopyFromSurface(reporter, context0, surfaceContext->asSurfaceProxy(), - GrColorType::kRGBA_8888, pixels.get(), "EGLImageTest-copy"); + colorType, pixels.get(), "EGLImageTest-copy"); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); } diff --git a/tests/FloatingPointTextureTest.cpp b/tests/FloatingPointTextureTest.cpp index 3645b30860..e302c819de 100644 --- a/tests/FloatingPointTextureTest.cpp +++ b/tests/FloatingPointTextureTest.cpp @@ -56,8 +56,8 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context, T min, T max, T continue; } - auto sContext = context->priv().makeWrappedSurfaceContext(std::move(fpProxy), colorType, - kPremul_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, std::move(fpProxy), colorType, + kPremul_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, sContext); bool result = sContext->readPixels({colorType, kPremul_SkAlphaType, nullptr, DEV_W, DEV_H}, diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index cbe814a076..804508c9d5 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -303,8 +303,9 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) { {kSize, kSize}, combo.fColorType, combo.fFormat, renderable, 1, kTopLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes, GrProtected::kNo); if (proxy) { - auto texCtx = context->priv().makeWrappedSurfaceContext( - std::move(proxy), combo.fColorType, kPremul_SkAlphaType); + auto texCtx = GrSurfaceContext::Make(context, std::move(proxy), + combo.fColorType, + kPremul_SkAlphaType, nullptr); readback.erase(kClearColor); if (texCtx->readPixels(readback.info(), readback.writable_addr(), @@ -328,10 +329,11 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) { fit, desc.fWidth, desc.fHeight, combo.fColorType, nullptr, 1, GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin, nullptr); } else { - surfCtx = context->priv().makeDeferredSurfaceContext( - fit, desc.fWidth, desc.fHeight, combo.fColorType, - kUnknown_SkAlphaType, nullptr, GrMipMapped::kNo, - kTopLeft_GrSurfaceOrigin); + surfCtx = GrSurfaceContext::Make( + context, {desc.fWidth, desc.fHeight}, combo.fFormat, + GrRenderable::kNo, 1, GrMipMapped::kNo, GrProtected::kNo, + kTopLeft_GrSurfaceOrigin, combo.fColorType, + kUnknown_SkAlphaType, nullptr, fit, SkBudgeted::kYes); } if (!surfCtx) { continue; @@ -398,8 +400,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { kTopLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, ioType); - auto surfContext = context->priv().makeWrappedSurfaceContext(proxy, GrColorType::kRGBA_8888, - kPremul_SkAlphaType); + auto surfContext = GrSurfaceContext::Make(context, proxy, GrColorType::kRGBA_8888, + kPremul_SkAlphaType, nullptr); // Read pixels should work with a read-only texture. { diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp index 3d26aaa780..de9aededf0 100644 --- a/tests/GrTestingBackendTextureUploadTest.cpp +++ b/tests/GrTestingBackendTextureUploadTest.cpp @@ -72,8 +72,8 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, } REPORTER_ASSERT(reporter, wrappedProxy); - auto surfaceContext = context->priv().makeWrappedSurfaceContext(std::move(wrappedProxy), grCT, - kPremul_SkAlphaType); + auto surfaceContext = GrSurfaceContext::Make(context, std::move(wrappedProxy), grCT, + kPremul_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, surfaceContext); bool result = surfaceContext->readPixels({grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, diff --git a/tests/GrUploadPixelsTests.cpp b/tests/GrUploadPixelsTests.cpp index 9662ea57b1..001bdb1d28 100644 --- a/tests/GrUploadPixelsTests.cpp +++ b/tests/GrUploadPixelsTests.cpp @@ -35,8 +35,8 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColo {grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0); REPORTER_ASSERT(reporter, proxy); if (proxy) { - auto sContext = context->priv().makeWrappedSurfaceContext( - proxy, SkColorTypeToGrColorType(ct), kPremul_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, proxy, SkColorTypeToGrColorType(ct), + kPremul_SkAlphaType, nullptr); SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); @@ -62,8 +62,8 @@ void basic_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColo {grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, srcBuffer, 0); REPORTER_ASSERT(reporter, proxy); if (proxy) { - auto sContext = context->priv().makeWrappedSurfaceContext( - proxy, SkColorTypeToGrColorType(ct), kPremul_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, proxy, SkColorTypeToGrColorType(ct), + kPremul_SkAlphaType, nullptr); SkImageInfo dstInfo = SkImageInfo::Make(kWidth, kHeight, ct, kPremul_SkAlphaType); diff --git a/tests/PackedConfigsTextureTest.cpp b/tests/PackedConfigsTextureTest.cpp index 56136b13dd..df26fb6f67 100644 --- a/tests/PackedConfigsTextureTest.cpp +++ b/tests/PackedConfigsTextureTest.cpp @@ -120,10 +120,13 @@ static void run_test(skiatest::Reporter* reporter, GrContext* context, int array controlPixelData.begin(), 0); SkASSERT(proxy); - auto sContext = context->priv().makeWrappedSurfaceContext(std::move(proxy), grColorType, - kPremul_SkAlphaType); + GrSwizzle readSwizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(), + grColorType); - if (!sContext->readPixels(dstInfo, readBuffer.begin(), 0, {0, 0})) { + GrSurfaceContext sContext(context, std::move(proxy), grColorType, kPremul_SkAlphaType, + nullptr, origin, readSwizzle); + + if (!sContext.readPixels(dstInfo, readBuffer.begin(), 0, {0, 0})) { // We only require this to succeed if the format is renderable. REPORTER_ASSERT(reporter, !context->colorTypeSupportedAsSurface(colorType)); return; diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp index e7a650bcc6..0dd5c8f4de 100644 --- a/tests/ProcessorTest.cpp +++ b/tests/ProcessorTest.cpp @@ -338,8 +338,8 @@ bool log_pixels(GrColor* pixels, int widthHeight, SkString* dst) { } bool log_texture_proxy(GrContext* context, sk_sp src, SkString* dst) { - auto sContext = - context->priv().makeWrappedSurfaceContext(src, GrColorType::kRGBA_8888, kLogAlphaType); + auto sContext = GrSurfaceContext::Make(context, src, GrColorType::kRGBA_8888, kLogAlphaType, + nullptr); SkImageInfo ii = SkImageInfo::Make(src->dimensions(), kRGBA_8888_SkColorType, kLogAlphaType); SkBitmap bm; SkAssertResult(bm.tryAllocPixels(ii)); diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 00e3dd9aea..e87d9af925 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -426,9 +426,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) { for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) { sk_sp proxy = sk_gpu_test::MakeTextureProxyFromData( context, renderable, origin, bmp.info(), bmp.getPixels(), bmp.rowBytes()); - auto sContext = context->priv().makeWrappedSurfaceContext( - std::move(proxy), SkColorTypeToGrColorType(bmp.colorType()), - kPremul_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, std::move(proxy), + SkColorTypeToGrColorType(bmp.colorType()), kPremul_SkAlphaType, nullptr); auto info = SkImageInfo::Make(DEV_W, DEV_H, kN32_SkColorType, kPremul_SkAlphaType); test_readpixels_texture(reporter, std::move(sContext), info); } diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp index c9a69019cc..31db04cb46 100644 --- a/tests/ReadWriteAlphaTest.cpp +++ b/tests/ReadWriteAlphaTest.cpp @@ -74,8 +74,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { ERRORF(reporter, "Could not create alpha texture."); return; } - auto sContext = context->priv().makeWrappedSurfaceContext( - std::move(proxy), GrColorType::kAlpha_8, kPremul_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, std::move(proxy), GrColorType::kAlpha_8, + kPremul_SkAlphaType, nullptr); sk_sp surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii)); @@ -193,8 +193,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { continue; } - auto sContext = context->priv().makeWrappedSurfaceContext( - std::move(proxy), info.fColorType, kPremul_SkAlphaType); + auto sContext = GrSurfaceContext::Make(context, std::move(proxy), info.fColorType, + kPremul_SkAlphaType, nullptr); for (auto rowBytes : kRowBytes) { size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index 547ba24636..88ecfb41c2 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -192,8 +192,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { TestCopyFromSurface(reporter, context, rectProxy.get(), GrColorType::kRGBA_8888, refPixels, "RectangleTexture-copy-from"); - auto rectContext = context->priv().makeWrappedSurfaceContext( - std::move(rectProxy), GrColorType::kRGBA_8888, kPremul_SkAlphaType); + auto rectContext = GrSurfaceContext::Make(context, std::move(rectProxy), + GrColorType::kRGBA_8888, kPremul_SkAlphaType, + nullptr); SkASSERT(rectContext); TestReadPixels(reporter, rectContext.get(), refPixels, "RectangleTexture-read"); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 12fb2fb4b4..55b76a0a05 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -783,9 +783,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { sk_sp i(surface->makeImageSnapshot()); SkImage_Gpu* gpuImage = (SkImage_Gpu*)as_IB(i); sk_sp proxy = gpuImage->asTextureProxyRef(context); - return context->priv().makeWrappedSurfaceContext( - std::move(proxy), SkColorTypeToGrColorType(i->colorType()), kPremul_SkAlphaType, - gpuImage->refColorSpace()); + return GrSurfaceContext::Make(context, std::move(proxy), + SkColorTypeToGrColorType(i->colorType()), kPremul_SkAlphaType, + gpuImage->refColorSpace()); }; // Test that non-wrapped RTs are created clear. diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp index cf8767a614..3d8b11ff67 100644 --- a/tests/TestUtils.cpp +++ b/tests/TestUtils.cpp @@ -84,8 +84,8 @@ void TestCopyFromSurface(skiatest::Reporter* reporter, SkBackingFit::kExact, SkBudgeted::kYes); SkASSERT(dstProxy); - auto dstContext = context->priv().makeWrappedSurfaceContext(std::move(dstProxy), colorType, - kPremul_SkAlphaType); + auto dstContext = GrSurfaceContext::Make(context, std::move(dstProxy), colorType, + kPremul_SkAlphaType, nullptr); SkASSERT(dstContext); TestReadPixels(reporter, dstContext.get(), expectedPixelValues, testName); diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp index 09465e1845..e42d2847a2 100644 --- a/tools/gpu/ProxyUtils.cpp +++ b/tools/gpu/ProxyUtils.cpp @@ -46,9 +46,8 @@ sk_sp MakeTextureProxyFromData(GrContext* context, if (!proxy) { return nullptr; } - auto sContext = context->priv().makeWrappedSurfaceContext(proxy, imageInfo.colorType(), - imageInfo.alphaType(), - imageInfo.refColorSpace(), nullptr); + auto sContext = GrSurfaceContext::Make(context, proxy, imageInfo.colorType(), + imageInfo.alphaType(), imageInfo.refColorSpace()); if (!sContext) { return nullptr; }