diff options
author | robertphillips <robertphillips@google.com> | 2016-04-27 10:47:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-27 10:47:51 -0700 |
commit | 6c7e325236b7fbb9c9b14ebb4715f88a59718695 (patch) | |
tree | 892db20f12b2f02968a3d67b54719aca3a84a8df | |
parent | b4bb7d825566042ed64697be49457dbac060e6c4 (diff) |
Bring sk_sp to GrDrawContext
This is split out of: https://codereview.chromium.org/1914883002/ (Refactor drawContext/RenderTarget creation)
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1918003003
Review-Url: https://codereview.chromium.org/1918003003
39 files changed, 179 insertions, 164 deletions
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 61d3795225..015450895b 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -109,7 +109,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } @@ -248,7 +248,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } @@ -465,7 +465,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } diff --git a/gm/bigrrectaaeffect.cpp b/gm/bigrrectaaeffect.cpp index f4a1252368..b852961826 100644 --- a/gm/bigrrectaaeffect.cpp +++ b/gm/bigrrectaaeffect.cpp @@ -56,7 +56,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp index 37295c78cc..cfc03398f6 100644 --- a/gm/constcolorprocessor.cpp +++ b/gm/constcolorprocessor.cpp @@ -57,7 +57,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index 28a4d5e97b..0c4c94b3aa 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -163,7 +163,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } diff --git a/gm/rrects.cpp b/gm/rrects.cpp index d8b5e388eb..57c11ada56 100644 --- a/gm/rrects.cpp +++ b/gm/rrects.cpp @@ -66,14 +66,14 @@ protected: #if SK_SUPPORT_GPU GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); context = rt ? rt->getContext() : nullptr; - SkAutoTUnref<GrDrawContext> drawContext; + sk_sp<GrDrawContext> drawContext; if (kEffect_Type == fType) { if (!context) { skiagm::GM::DrawGpuOnlyMessage(canvas); return; } - drawContext.reset(context->drawContext(rt)); + drawContext = context->drawContext(sk_ref_sp(rt)); if (!drawContext) { return; } diff --git a/gm/texdata.cpp b/gm/texdata.cpp index 8e29b2389f..20cad0c739 100644 --- a/gm/texdata.cpp +++ b/gm/texdata.cpp @@ -21,7 +21,7 @@ static const int S = 200; DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget(); GrContext* ctx = canvas->getGrContext(); - SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext(target) : nullptr); + sk_sp<GrDrawContext> drawContext(ctx ? ctx->drawContext(sk_ref_sp(target)) : nullptr); if (drawContext && target) { SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S)); static const int stride = 2 * S; diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp index 89d3b44b7f..e4a02c15d9 100644 --- a/gm/texturedomaineffect.cpp +++ b/gm/texturedomaineffect.cpp @@ -80,7 +80,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp index 996e473e44..09c61765fb 100644 --- a/gm/yuvtorgbeffect.cpp +++ b/gm/yuvtorgbeffect.cpp @@ -79,7 +79,7 @@ protected: return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt))); if (!drawContext) { return; } diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index d59b2a28f0..087d821beb 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -192,7 +192,7 @@ public: * * @return a draw context */ - GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps = NULL); + sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps* = nullptr); /////////////////////////////////////////////////////////////////////////// // Misc. diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index 61b39079b0..7bb9aafc78 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -278,14 +278,18 @@ public: int numColorSamples() const { return fRenderTarget->numColorSamples(); } bool isGammaCorrect() const { return fSurfaceProps.isGammaCorrect(); } - GrRenderTarget* accessRenderTarget() { return fRenderTarget; } + GrRenderTarget* accessRenderTarget() { return fRenderTarget.get(); } + + sk_sp<GrRenderTarget> renderTarget() { return fRenderTarget; } + + sk_sp<GrTexture> asTexture() { return sk_ref_sp(fRenderTarget->asTexture()); } // Provides access to functions that aren't part of the public API. GrDrawContextPriv drawContextPriv(); const GrDrawContextPriv drawContextPriv() const; protected: - GrDrawContext(GrContext*, GrDrawingManager*, GrRenderTarget*, + GrDrawContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>, const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*); GrDrawingManager* drawingManager() { return fDrawingManager; } @@ -323,7 +327,7 @@ private: GrDrawTarget* getDrawTarget(); GrDrawingManager* fDrawingManager; - GrRenderTarget* fRenderTarget; + sk_sp<GrRenderTarget> fRenderTarget; // In MDB-mode the drawTarget can be closed by some other drawContext that has picked // it up. For this reason, the drawTarget should only ever be accessed via 'getDrawTarget'. diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index fdd78f8f73..935ce77d5f 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -301,7 +301,7 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context, return nullptr; } - sk_sp<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index bf2a3fda1c..bfbcfd21f8 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -111,7 +111,8 @@ sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* contex return nullptr; } - sk_sp<GrDrawContext> drawContext(context->drawContext(maskTexture->asRenderTarget())); + sk_sp<GrDrawContext> drawContext( + context->drawContext(sk_ref_sp(maskTexture->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 2afb42f0fa..6eb8474a2e 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -1276,7 +1276,8 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src, paint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op); } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext((*result)->asRenderTarget())); + sk_sp<GrDrawContext> drawContext( + context->drawContext(sk_ref_sp((*result)->asRenderTarget()))); if (!drawContext) { return false; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index a8f0b81d73..797bd972dd 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -346,7 +346,7 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou SkMatrix matrix; matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y())); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp index 0ecc5010c3..c3681faca5 100644 --- a/src/effects/SkGpuBlurUtils.cpp +++ b/src/effects/SkGpuBlurUtils.cpp @@ -228,7 +228,7 @@ GrTexture* GaussianBlur(GrContext* context, return nullptr; } - SkAutoTUnref<GrDrawContext> srcDrawContext; + sk_sp<GrDrawContext> srcDrawContext; for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { GrPaint paint; @@ -258,8 +258,8 @@ GrTexture* GaussianBlur(GrContext* context, scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, i < scaleFactorY ? 0.5f : 1.0f); - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(dstTexture->asRenderTarget())); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()))); if (!dstDrawContext) { return nullptr; } @@ -283,12 +283,12 @@ GrTexture* GaussianBlur(GrContext* context, // We shouldn't be scaling because this is a small size blur SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(dstTexture->asRenderTarget(), &props)); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); if (!dstDrawContext) { return nullptr; } - convolve_gaussian_2d(dstDrawContext, clip, srcRect, srcOffset, + convolve_gaussian_2d(dstDrawContext.get(), clip, srcRect, srcOffset, srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBounds); srcDrawContext.swap(dstDrawContext); @@ -304,7 +304,7 @@ GrTexture* GaussianBlur(GrContext* context, if (scaleFactorX > 1) { // TODO: if we pass in the source draw context we don't need this here if (!srcDrawContext) { - srcDrawContext.reset(context->drawContext(srcTexture->asRenderTarget())); + srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget())); if (!srcDrawContext) { return nullptr; } @@ -317,12 +317,12 @@ GrTexture* GaussianBlur(GrContext* context, srcDrawContext->clear(&clearRect, 0x0, false); } - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(dstTexture->asRenderTarget(), &props)); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); if (!dstDrawContext) { return nullptr; } - convolve_gaussian(dstDrawContext, clip, srcRect, + convolve_gaussian(dstDrawContext.get(), clip, srcRect, srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, srcBounds, srcOffset); srcDrawContext.swap(dstDrawContext); @@ -337,7 +337,7 @@ GrTexture* GaussianBlur(GrContext* context, if (scaleFactorY > 1 || sigmaX > 0.0f) { // TODO: if we pass in the source draw context we don't need this here if (!srcDrawContext) { - srcDrawContext.reset(context->drawContext(srcTexture->asRenderTarget())); + srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget())); if (!srcDrawContext) { return nullptr; } @@ -350,12 +350,12 @@ GrTexture* GaussianBlur(GrContext* context, srcDrawContext->clear(&clearRect, 0x0, false); } - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(dstTexture->asRenderTarget(), &props)); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props)); if (!dstDrawContext) { return nullptr; } - convolve_gaussian(dstDrawContext, clip, srcRect, + convolve_gaussian(dstDrawContext.get(), clip, srcRect, srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY, srcBounds, srcOffset); @@ -391,8 +391,8 @@ GrTexture* GaussianBlur(GrContext* context, SkRect dstRect(srcRect); scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(dstTexture->asRenderTarget())); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()))); if (!dstDrawContext) { return nullptr; } diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 4252831c1b..7223ae5a1e 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -418,7 +418,7 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(SkSpecialIma return nullptr; } - sk_sp<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 810d0e13e4..9e87fe04a4 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -496,13 +496,13 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, if (!scratch) { return nullptr; } - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(scratch->asRenderTarget())); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(scratch->asRenderTarget()))); if (!dstDrawContext) { return nullptr; } - apply_morphology_pass(dstDrawContext, clip, srcTexture.get(), + apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), srcRect, dstRect, radius.fWidth, morphType, Gr1DKernelEffect::kX_Direction); SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, @@ -520,13 +520,13 @@ static sk_sp<SkSpecialImage> apply_morphology(GrContext* context, if (!scratch) { return nullptr; } - SkAutoTUnref<GrDrawContext> dstDrawContext( - context->drawContext(scratch->asRenderTarget())); + sk_sp<GrDrawContext> dstDrawContext( + context->drawContext(sk_ref_sp(scratch->asRenderTarget()))); if (!dstDrawContext) { return nullptr; } - apply_morphology_pass(dstDrawContext, clip, srcTexture.get(), + apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(), srcRect, dstRect, radius.fHeight, morphType, Gr1DKernelEffect::kY_Direction); diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index f4e896ece6..b1ac1c32e0 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -248,7 +248,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* sour paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp index 8edc6b3977..6827c83421 100644 --- a/src/gpu/GrBlurUtils.cpp +++ b/src/gpu/GrBlurUtils.cpp @@ -124,7 +124,7 @@ static GrTexture* create_mask_GPU(GrContext* context, SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height()); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(mask->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(mask->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp index 7418e76449..f0d6faf1ff 100644 --- a/src/gpu/GrClipMaskManager.cpp +++ b/src/gpu/GrClipMaskManager.cpp @@ -632,7 +632,7 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context, texture->resourcePriv().setUniqueKey(key); - SkAutoTUnref<GrDrawContext> dc(context->drawContext(texture->asRenderTarget())); + sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(texture->asRenderTarget()))); if (!dc) { return nullptr; } @@ -682,7 +682,7 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context, 0xffff, 0xffff, 0xffff) - if (!stencil_element(dc, &maskSpaceIBounds, kStencilInElement, + if (!stencil_element(dc.get(), &maskSpaceIBounds, kStencilInElement, translate, element)) { texture->resourcePriv().removeUniqueKey(); return nullptr; @@ -709,7 +709,7 @@ GrTexture* GrClipMaskManager::CreateAlphaClipMask(GrContext* context, paint.setAntiAlias(element->isAA()); paint.setCoverageSetOpXPFactory(op, false); - draw_element(dc, GrClip::WideOpen(), paint, translate, element); + draw_element(dc.get(), GrClip::WideOpen(), paint, translate, element); } } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index c223a60213..5ebb2e95fb 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -362,7 +362,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, } SkMatrix matrix; matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); - SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarget)); + sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderTarget))); if (!drawContext) { return false; } @@ -484,7 +484,8 @@ bool GrContext::readSurfacePixels(GrSurface* src, paint.addColorFragmentProcessor(fp); paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); - SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->asRenderTarget())); + sk_sp<GrDrawContext> drawContext( + this->drawContext(sk_ref_sp(temp->asRenderTarget()))); drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, nullptr); surfaceToRead.reset(SkRef(temp.get())); left = 0; @@ -569,7 +570,7 @@ bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe src->flushWrites(); return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); } - SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTarget()))); if (!drawContext) { return false; } @@ -608,9 +609,10 @@ int GrContext::getRecommendedSampleCount(GrPixelConfig config, } -GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) { +sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt, + const SkSurfaceProps* surfaceProps) { ASSERT_SINGLE_OWNER - return fDrawingManager->drawContext(rt, surfaceProps); + return fDrawingManager->drawContext(std::move(rt), surfaceProps); } bool GrContext::abandoned() const { diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index 2e4b13f03e..af04f74fcf 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -57,13 +57,13 @@ private: // when the drawContext attempts to use it (via getDrawTarget). GrDrawContext::GrDrawContext(GrContext* context, GrDrawingManager* drawingMgr, - GrRenderTarget* rt, + sk_sp<GrRenderTarget> rt, const SkSurfaceProps* surfaceProps, GrAuditTrail* auditTrail, GrSingleOwner* singleOwner) : fDrawingManager(drawingMgr) - , fRenderTarget(rt) - , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) + , fRenderTarget(std::move(rt)) + , fDrawTarget(SkSafeRef(fRenderTarget->getLastDrawTarget())) , fContext(context) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) , fAuditTrail(auditTrail) @@ -95,7 +95,7 @@ GrDrawTarget* GrDrawContext::getDrawTarget() { SkDEBUGCODE(this->validate();) if (!fDrawTarget || fDrawTarget->isClosed()) { - fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget); + fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget.get()); } return fDrawTarget; @@ -107,7 +107,7 @@ bool GrDrawContext::copySurface(GrSurface* src, const SkIRect& srcRect, const Sk SkDEBUGCODE(this->validate();) GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::copySurface"); - return this->getDrawTarget()->copySurface(fRenderTarget, src, srcRect, dstPoint); + return this->getDrawTarget()->copySurface(fRenderTarget.get(), src, srcRect, dstPoint); } void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint, @@ -173,7 +173,7 @@ void GrDrawContext::discard() { GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::discard"); AutoCheckFlush acf(fDrawingManager); - this->getDrawTarget()->discard(fRenderTarget); + this->getDrawTarget()->discard(fRenderTarget.get()); } void GrDrawContext::clear(const SkIRect* rect, @@ -185,7 +185,7 @@ void GrDrawContext::clear(const SkIRect* rect, GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); AutoCheckFlush acf(fDrawingManager); - this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget); + this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget.get()); } @@ -235,7 +235,7 @@ void GrDrawContext::drawPaint(const GrClip& clip, SkAutoTUnref<GrDrawBatch> batch( GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix::I(), r, nullptr, &localMatrix)); - GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } } @@ -258,7 +258,7 @@ GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, const SkRect& rect) { GrDrawBatch* batch = nullptr; - if (should_apply_coverage_aa(paint, fRenderTarget)) { + if (should_apply_coverage_aa(paint, fRenderTarget.get())) { // The fill path can handle rotation but not skew. if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { SkRect devBoundRect; @@ -319,7 +319,7 @@ void GrDrawContext::drawRect(const GrClip& clip, // Will it blend? GrColor clearColor; if (paint.isConstantBlendedColor(&clearColor)) { - this->getDrawTarget()->clear(nullptr, clearColor, true, fRenderTarget); + this->getDrawTarget()->clear(nullptr, clearColor, true, fRenderTarget.get()); return; } } @@ -333,7 +333,7 @@ void GrDrawContext::drawRect(const GrClip& clip, } else { GrColor color = paint.getColor(); - if (should_apply_coverage_aa(paint, fRenderTarget)) { + if (should_apply_coverage_aa(paint, fRenderTarget.get())) { // The stroke path needs the rect to remain axis aligned (no rotation or skew). if (viewMatrix.rectStaysRect()) { batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect, @@ -353,7 +353,7 @@ void GrDrawContext::drawRect(const GrClip& clip, } if (batch) { - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); if (snapToPixelCenters) { pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, @@ -391,7 +391,9 @@ bool GrDrawContextPriv::drawAndStencilRect(const SkIRect* scissorRect, SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMatrix, rect)); if (batch) { - GrPipelineBuilder pipelineBuilder(paint, fDrawContext->fRenderTarget, GrClip::WideOpen()); + GrPipelineBuilder pipelineBuilder(paint, + fDrawContext->accessRenderTarget(), + GrClip::WideOpen()); pipelineBuilder.setStencil(ss); fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch, scissorRect); @@ -417,7 +419,7 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); SkAutoTUnref<GrDrawBatch> batch; - if (should_apply_coverage_aa(paint, fRenderTarget) && + if (should_apply_coverage_aa(paint, fRenderTarget.get()) && view_matrix_ok_for_aa_fill_rect(viewMatrix)) { batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, rectToDraw, localRect)); @@ -427,7 +429,7 @@ void GrDrawContext::fillRectToRect(const GrClip& clip, } if (batch) { - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->drawBatch(&pipelineBuilder, batch); } } @@ -445,7 +447,7 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); SkAutoTUnref<GrDrawBatch> batch; - if (should_apply_coverage_aa(paint, fRenderTarget) && + if (should_apply_coverage_aa(paint, fRenderTarget.get()) && view_matrix_ok_for_aa_fill_rect(viewMatrix)) { batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix, rectToDraw)); @@ -454,7 +456,7 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, nullptr, &localMatrix)); } - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -499,7 +501,7 @@ void GrDrawContext::drawVertices(const GrClip& clip, indexCount, colors, texCoords, bounds)); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -524,7 +526,7 @@ void GrDrawContext::drawAtlas(const GrClip& clip, SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xform, texRect, colors)); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -548,7 +550,7 @@ void GrDrawContext::drawRRect(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - if (should_apply_coverage_aa(paint, fRenderTarget)) { + if (should_apply_coverage_aa(paint, fRenderTarget.get())) { GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.getColor(), @@ -557,7 +559,7 @@ void GrDrawContext::drawRRect(const GrClip& clip, strokeInfo, shaderCaps)); if (batch) { - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -651,7 +653,7 @@ void GrDrawContext::drawDRRect(const GrClip& clip, path.addRRect(outer); path.setFillType(SkPath::kEvenOdd_FillType); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->internalDrawPath(clip, paint, viewMatrix, path, GrStrokeInfo::FillInfo()); } @@ -675,7 +677,7 @@ void GrDrawContext::drawOval(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - if (should_apply_coverage_aa(paint, fRenderTarget)) { + if (should_apply_coverage_aa(paint, fRenderTarget.get())) { GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(), viewMatrix, @@ -683,7 +685,7 @@ void GrDrawContext::drawOval(const GrClip& clip, strokeInfo, shaderCaps)); if (batch) { - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -713,7 +715,7 @@ void GrDrawContext::drawImageNine(const GrClip& clip, imageWidth, imageHeight, center, dst)); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -777,7 +779,7 @@ void GrDrawContext::drawBatch(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); } @@ -812,7 +814,7 @@ void GrDrawContext::drawPath(const GrClip& clip, AutoCheckFlush acf(fDrawingManager); - if (should_apply_coverage_aa(paint, fRenderTarget) && !strokeInfo.isDashed()) { + if (should_apply_coverage_aa(paint, fRenderTarget.get()) && !strokeInfo.isDashed()) { if (strokeInfo.getWidth() < 0 && !path.isConvex()) { // Concave AA paths are expensive - try to avoid them for special cases SkRect rects[2]; @@ -821,7 +823,7 @@ void GrDrawContext::drawPath(const GrClip& clip, SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFillNestedRects( paint.getColor(), viewMatrix, rects)); - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -837,7 +839,7 @@ void GrDrawContext::drawPath(const GrClip& clip, strokeInfo, shaderCaps)); if (batch) { - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); this->getDrawTarget()->drawBatch(pipelineBuilder, batch); return; } @@ -866,8 +868,8 @@ bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, if (path.isEmpty() && path.isInverseFillType()) { this->drawAndStencilRect(scissorRect, ss, op, invert, false, SkMatrix::I(), - SkRect::MakeIWH(fDrawContext->fRenderTarget->width(), - fDrawContext->fRenderTarget->height())); + SkRect::MakeIWH(fDrawContext->width(), + fDrawContext->height())); return true; } @@ -910,7 +912,7 @@ bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, clip.setIRect(*scissorRect); } - GrPipelineBuilder pipelineBuilder(paint, fDrawContext->fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fDrawContext->accessRenderTarget(), clip); pipelineBuilder.setStencil(ss); GrPathRenderer::DrawPathArgs args; @@ -940,7 +942,7 @@ void GrDrawContext::internalDrawPath(const GrClip& clip, // the src color (either the input alpha or in the frag shader) to implement // aa. If we have some future driver-mojo path AA that can do the right // thing WRT to the blend then we'll need some query on the PR. - bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget); + bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); const bool isStencilDisabled = true; bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); @@ -1015,7 +1017,7 @@ void GrDrawContext::internalDrawPath(const GrClip& clip, return; } - GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); + GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); GrPathRenderer::DrawPathArgs args; args.fTarget = this->getDrawTarget(); diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 976fbb62a4..4b035bc863 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -159,8 +159,8 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP return pr; } -GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt, - const SkSurfaceProps* surfaceProps) { +sk_sp<GrDrawContext> GrDrawingManager::drawContext(sk_sp<GrRenderTarget> rt, + const SkSurfaceProps* surfaceProps) { if (this->abandoned()) { return nullptr; } @@ -173,13 +173,16 @@ GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt, if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() && rt->isStencilBufferMultisampled()) { - GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt); + GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt.get()); if (sb) { - return new GrPathRenderingDrawContext(fContext, this, rt, surfaceProps, - fContext->getAuditTrail(), fSingleOwner); + return sk_sp<GrDrawContext>(new GrPathRenderingDrawContext( + fContext, this, std::move(rt), + surfaceProps, + fContext->getAuditTrail(), fSingleOwner)); } } - return new GrDrawContext(fContext, this, rt, surfaceProps, fContext->getAuditTrail(), - fSingleOwner); + return sk_sp<GrDrawContext>(new GrDrawContext(fContext, this, std::move(rt), surfaceProps, + fContext->getAuditTrail(), + fSingleOwner)); } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index f011b4194b..72db2aec6e 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -31,7 +31,7 @@ public: bool abandoned() const { return fAbandoned; } void freeGpuResources(); - GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps*); + sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps*); // The caller automatically gets a ref on the returned drawTarget. It must // be balanced by an unref call. diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp index 3c7ab88735..8bdc3fb1f1 100644 --- a/src/gpu/GrLayerCache.cpp +++ b/src/gpu/GrLayerCache.cpp @@ -468,8 +468,8 @@ void GrLayerCache::purgeAll() { SkASSERT(0 == fPictureHash.count()); if (fAtlas->getTextureOrNull()) { - SkAutoTUnref<GrDrawContext> drawContext( - fContext->drawContext(fAtlas->getTexture()->asRenderTarget())); + sk_sp<GrDrawContext> drawContext( + fContext->drawContext(sk_ref_sp(fAtlas->getTexture()->asRenderTarget()))); if (drawContext) { drawContext->discard(); diff --git a/src/gpu/GrPathRenderingDrawContext.h b/src/gpu/GrPathRenderingDrawContext.h index 49a0e1d3c5..5d1893cf90 100644 --- a/src/gpu/GrPathRenderingDrawContext.h +++ b/src/gpu/GrPathRenderingDrawContext.h @@ -26,10 +26,10 @@ public: SkScalar x, SkScalar y, SkDrawFilter*, const SkIRect& clipBounds) override; protected: - GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, GrRenderTarget* rt, + GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, sk_sp<GrRenderTarget> rt, const SkSurfaceProps* surfaceProps, GrAuditTrail* at, GrSingleOwner* so) - : INHERITED(ctx, mgr, rt, surfaceProps, at, so) {} + : INHERITED(ctx, mgr, std::move(rt), surfaceProps, at, so) {} private: SkAutoTDelete<GrStencilAndCoverTextContext> fStencilAndCoverTextContext; diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp index ae44071976..a6736403fc 100644 --- a/src/gpu/GrRenderTarget.cpp +++ b/src/gpu/GrRenderTarget.cpp @@ -29,7 +29,7 @@ void GrRenderTarget::discard() { return; } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this)); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(this))); if (!drawContext) { return; } diff --git a/src/gpu/GrTextureParamsAdjuster.cpp b/src/gpu/GrTextureParamsAdjuster.cpp index 429a63affa..8868309a80 100644 --- a/src/gpu/GrTextureParamsAdjuster.cpp +++ b/src/gpu/GrTextureParamsAdjuster.cpp @@ -112,7 +112,7 @@ static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset, localRect = SkRect::MakeWH(1.f, 1.f); } - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(copy->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/src/gpu/GrTextureToYUVPlanes.cpp b/src/gpu/GrTextureToYUVPlanes.cpp index 6a8d7b6676..a8eec6365c 100644 --- a/src/gpu/GrTextureToYUVPlanes.cpp +++ b/src/gpu/GrTextureToYUVPlanes.cpp @@ -117,49 +117,49 @@ bool GrTextureToYUVPlanes(GrTexture* texture, const SkISize sizes[3], void* cons // Do all the draws before any readback. if (yuvTex) { - SkAutoTUnref<GrDrawContext> dc(context->drawContext(yuvTex->asRenderTarget())); + sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(yuvTex->asRenderTarget()))); if (!dc) { return false; } - if (!convert_texture(texture, dc, sizes[0].fWidth, sizes[0].fHeight, colorSpace, + if (!convert_texture(texture, dc.get(), sizes[0].fWidth, sizes[0].fHeight, colorSpace, GrYUVEffect::CreateRGBToYUV)) { return false; } } else { SkASSERT(yTex); - SkAutoTUnref<GrDrawContext> dc(context->drawContext(yTex->asRenderTarget())); + sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(yTex->asRenderTarget()))); if (!dc) { return false; } - if (!convert_texture(texture, dc, sizes[0].fWidth, sizes[0].fHeight, colorSpace, + if (!convert_texture(texture, dc.get(), sizes[0].fWidth, sizes[0].fHeight, colorSpace, GrYUVEffect::CreateRGBToY)) { return false; } if (uvTex) { - dc.reset(context->drawContext(uvTex->asRenderTarget())); + dc = context->drawContext(sk_ref_sp(uvTex->asRenderTarget())); if (!dc) { return false; } - if (!convert_texture(texture, dc, sizes[1].fWidth, sizes[1].fHeight, + if (!convert_texture(texture, dc.get(), sizes[1].fWidth, sizes[1].fHeight, colorSpace, GrYUVEffect::CreateRGBToUV)) { return false; } } else { SkASSERT(uTex && vTex); - dc.reset(context->drawContext(uTex->asRenderTarget())); + dc = context->drawContext(sk_ref_sp(uTex->asRenderTarget())); if (!dc) { return false; } - if (!convert_texture(texture, dc, sizes[1].fWidth, sizes[1].fHeight, + if (!convert_texture(texture, dc.get(), sizes[1].fWidth, sizes[1].fHeight, colorSpace, GrYUVEffect::CreateRGBToU)) { return false; } - dc.reset(context->drawContext(vTex->asRenderTarget())); + dc = context->drawContext(sk_ref_sp(vTex->asRenderTarget())); if (!dc) { return false; } - if (!convert_texture(texture, dc, sizes[2].fWidth, sizes[2].fHeight, + if (!convert_texture(texture, dc.get(), sizes[2].fWidth, sizes[2].fHeight, colorSpace, GrYUVEffect::CreateRGBToV)) { return false; } diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index 3990e887b5..6cd7c959b0 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -137,7 +137,7 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth, yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); - SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); + sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(renderTarget))); if (!drawContext) { return nullptr; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 535d55ee79..3644da4b5a 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -172,7 +172,7 @@ SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, fLegacyBitmap.setInfo(info); fLegacyBitmap.setPixelRef(pr)->unref(); - fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); + fDrawContext = this->context()->drawContext(sk_ref_sp(rt), &this->surfaceProps()); if (flags & kNeedClear_Flag) { this->clearAll(); } @@ -385,7 +385,8 @@ void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); fLegacyBitmap.setPixelRef(pr)->unref(); - fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfaceProps())); + fDrawContext = this->context()->drawContext(sk_ref_sp(fRenderTarget.get()), + &this->surfaceProps()); } /////////////////////////////////////////////////////////////////////////////// @@ -513,7 +514,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint SkPath path; path.setIsVolatile(true); path.addRect(rect); - GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, + GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), fClip, path, paint, *draw.fMatrix, nullptr, draw.fRC->getBounds(), true); @@ -564,7 +565,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, return; } if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext->textureProvider(), - fDrawContext, + fDrawContext.get(), &grPaint, fClip, *draw.fMatrix, @@ -585,7 +586,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, SkPath path; path.setIsVolatile(true); path.addRRect(rect); - GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, + GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), fClip, path, paint, *draw.fMatrix, nullptr, draw.fRC->getBounds(), true); @@ -631,7 +632,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, path.addRRect(inner); path.setFillType(SkPath::kEvenOdd_FillType); - GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, + GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), fClip, path, paint, *draw.fMatrix, nullptr, draw.fRC->getBounds(), true); @@ -701,7 +702,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, CHECK_SHOULD_DRAW(draw); GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext); - GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, + GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(), fClip, origSrcPath, paint, *draw.fMatrix, prePathMatrix, draw.fRC->getBounds(), pathIsMutable); diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index ca0488b66b..1e8d301dc5 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -146,7 +146,7 @@ private: // We want these unreffed in DrawContext, RenderTarget, GrContext order. SkAutoTUnref<GrContext> fContext; SkAutoTUnref<GrRenderTarget> fRenderTarget; - SkAutoTUnref<GrDrawContext> fDrawContext; + sk_sp<GrDrawContext> fDrawContext; SkAutoTUnref<const SkClipStack> fClipStack; SkIPoint fClipOrigin; diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp index 7abe49c77e..9750c96f9d 100644 --- a/src/gpu/SkGpuDevice_drawTexture.cpp +++ b/src/gpu/SkGpuDevice_drawTexture.cpp @@ -228,7 +228,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, SkRRect rrect; rrect.setRect(clippedDstRect); if (mf->directFilterRRectMaskGPU(fContext->textureProvider(), - fDrawContext, + fDrawContext.get(), &grPaint, clip, viewMatrix, @@ -239,7 +239,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, SkPath rectPath; rectPath.addRect(clippedDstRect); rectPath.setIsVolatile(true); - GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fClip, + GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext.get(), fClip, rectPath, &grPaint, viewMatrix, mf, paint.getPathEffect(), GrStrokeInfo::FillInfo(), true); } diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 4743f34692..6b43606bb5 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -225,8 +225,8 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context paint1.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - SkAutoTUnref<GrDrawContext> readDrawContext( - context->drawContext(readTex->asRenderTarget())); + sk_sp<GrDrawContext> readDrawContext( + context->drawContext(sk_ref_sp(readTex->asRenderTarget()))); if (!readDrawContext) { failed = true; break; @@ -243,8 +243,8 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context paint2.addColorFragmentProcessor(upmToPM); paint2.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - SkAutoTUnref<GrDrawContext> tempDrawContext( - context->drawContext(tempTex->asRenderTarget())); + sk_sp<GrDrawContext> tempDrawContext( + context->drawContext(sk_ref_sp(tempTex->asRenderTarget()))); if (!tempDrawContext) { failed = true; break; @@ -258,7 +258,7 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context paint3.addColorFragmentProcessor(pmToUPM2); paint3.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); - readDrawContext.reset(context->drawContext(readTex->asRenderTarget())); + readDrawContext = context->drawContext(sk_ref_sp(readTex->asRenderTarget())); if (!readDrawContext) { failed = true; break; diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 359c775fdb..a66a623638 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -270,7 +270,7 @@ sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), SkIntToScalar(dstDesc.fHeight)); - SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(dst->asRenderTarget())); + sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(dst->asRenderTarget()))); if (!drawContext) { return nullptr; } diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp index 56f2fe17be..1065d940ba 100644 --- a/tests/ClearTest.cpp +++ b/tests/ClearTest.cpp @@ -39,7 +39,7 @@ static bool check_rect(GrDrawContext* dc, const SkIRect& rect, uint32_t expected // We only really need the DC, but currently the DC doesn't own the RT so we also ref it, but that // could be dropped when DC is a proper owner of its RT. -static bool reset_dc(SkAutoTUnref<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* rtKeepAlive, +static bool reset_dc(sk_sp<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* rtKeepAlive, GrContext* context, int w, int h) { SkDEBUGCODE(uint32_t oldID = 0;) if (*dc) { @@ -61,7 +61,7 @@ static bool reset_dc(SkAutoTUnref<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* r } GrRenderTarget* rt = (*rtKeepAlive)->asRenderTarget(); SkASSERT(rt->getUniqueID() != oldID); - dc->reset(context->drawContext(rt)); + *dc = context->drawContext(sk_ref_sp(rt)); return *dc != nullptr; } @@ -71,7 +71,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { static const int kH = 10; SkIRect fullRect = SkIRect::MakeWH(kW, kH); - SkAutoTUnref<GrDrawContext> drawContext; + sk_sp<GrDrawContext> drawContext; SkAutoTUnref<GrSurface> rtKeepAlive; // A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround @@ -102,7 +102,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { } // Check a full clear drawContext->clear(&fullRect, kColor1, false); - if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -114,7 +114,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { // Check two full clears, same color drawContext->clear(&fullRect, kColor1, false); drawContext->clear(&fullRect, kColor1, false); - if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -126,7 +126,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { // Check two full clears, different colors drawContext->clear(&fullRect, kColor1, false); drawContext->clear(&fullRect, kColor2, false); - if (!check_rect(drawContext, fullRect, kColor2, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), fullRect, kColor2, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, failX, failY); } @@ -138,7 +138,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { // Test a full clear followed by a same color inset clear drawContext->clear(&fullRect, kColor1, false); drawContext->clear(&mid1Rect, kColor1, false); - if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -150,7 +150,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { // Test a inset clear followed by same color full clear drawContext->clear(&mid1Rect, kColor1, false); drawContext->clear(&fullRect, kColor1, false); - if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -162,14 +162,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { // Test a full clear followed by a different color inset clear drawContext->clear(&fullRect, kColor1, false); drawContext->clear(&mid1Rect, kColor2, false); - if (!check_rect(drawContext, mid1Rect, kColor2, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, failX, failY); } - if (!check_rect(drawContext, outerLeftEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerTopEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerRightEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -181,7 +181,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { // Test a inset clear followed by a different full clear drawContext->clear(&mid1Rect, kColor2, false); drawContext->clear(&fullRect, kColor1, false); - if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -195,21 +195,21 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { drawContext->clear(&fullRect, kColor1, false); drawContext->clear(&mid1Rect, kColor2, false); drawContext->clear(&mid2Rect, kColor1, false); - if (!check_rect(drawContext, mid2Rect, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), mid2Rect, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } - if (!check_rect(drawContext, innerLeftEdge, kColor2, &actualValue, &failX, &failY) || - !check_rect(drawContext, innerTopEdge, kColor2, &actualValue, &failX, &failY) || - !check_rect(drawContext, innerRightEdge, kColor2, &actualValue, &failX, &failY) || - !check_rect(drawContext, innerBottomEdge, kColor2, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), innerLeftEdge, kColor2, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), innerTopEdge, kColor2, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), innerRightEdge, kColor2, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), innerBottomEdge, kColor2, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, failX, failY); } - if (!check_rect(drawContext, outerLeftEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerTopEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerRightEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } @@ -222,14 +222,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { drawContext->clear(&fullRect, kColor1, false); drawContext->clear(&mid2Rect, kColor1, false); drawContext->clear(&mid1Rect, kColor2, false); - if (!check_rect(drawContext, mid1Rect, kColor2, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, failX, failY); } - if (!check_rect(drawContext, outerLeftEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerTopEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerRightEdge, kColor1, &actualValue, &failX, &failY) || - !check_rect(drawContext, outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { + if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || + !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, failX, failY); } diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 8e7d800814..0d825c6551 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -334,7 +334,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { static const int NUM_TESTS = 1024; for (int t = 0; t < NUM_TESTS; t++) { // setup random render target(can fail) - SkAutoTUnref<GrRenderTarget> rt(random_render_target( + sk_sp<GrRenderTarget> rt(random_render_target( context->textureProvider(), &random, context->caps())); if (!rt.get()) { SkDebugf("Could not allocate render target"); @@ -348,13 +348,13 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); - GrProcessorTestData ptd(&random, context, context->caps(), rt, dummyTextures); + GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures); set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages); set_random_xpf(&pipelineBuilder, &ptd); set_random_state(&pipelineBuilder, &random); set_random_stencil(&pipelineBuilder, &random); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(rt)); if (!drawContext) { SkDebugf("Could not allocate drawContext"); return false; @@ -371,7 +371,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { rtDesc.fHeight = kRenderTargetHeight; rtDesc.fFlags = kRenderTarget_GrSurfaceFlag; rtDesc.fConfig = kRGBA_8888_GrPixelConfig; - SkAutoTUnref<GrRenderTarget> rt( + sk_sp<GrRenderTarget> rt( context->textureProvider()->createTexture(rtDesc, SkBudgeted::kNo)->asRenderTarget()); int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count(); for (int i = 0; i < fpFactoryCnt; ++i) { @@ -379,10 +379,10 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { for (int j = 0; j < 10; ++j) { SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); - GrProcessorTestData ptd(&random, context, context->caps(), rt, dummyTextures); + GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures); GrPipelineBuilder builder; builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); - builder.setRenderTarget(rt); + builder.setRenderTarget(rt.get()); builder.setClip(clip); SkAutoTUnref<const GrFragmentProcessor> fp( @@ -391,7 +391,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { BlockInputFragmentProcessor::Create(fp)); builder.addColorFragmentProcessor(blockFP); - SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt)); + sk_sp<GrDrawContext> drawContext(context->drawContext(rt)); if (!drawContext) { SkDebugf("Could not allocate a drawcontext"); return false; diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp index f8c19e3171..6d4ede1ce9 100644 --- a/tests/PrimitiveProcessorTest.cpp +++ b/tests/PrimitiveProcessorTest.cpp @@ -114,7 +114,7 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { ERRORF(reporter, "Could not create render target."); return; } - SkAutoTUnref<GrDrawContext> dc(context->drawContext(target->asRenderTarget())); + sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(target->asRenderTarget()))); if (!dc) { ERRORF(reporter, "Could not create draw context."); return; diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index 3c2a50d630..8c3bdd6a4a 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -89,7 +89,8 @@ static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* conte static void test_clear(skiatest::Reporter* reporter, GrContext* context, GrTexture* rectangleTexture) { if (rectangleTexture->asRenderTarget()) { - SkAutoTUnref<GrDrawContext> dc(context->drawContext(rectangleTexture->asRenderTarget())); + sk_sp<GrDrawContext> dc( + context->drawContext(sk_ref_sp(rectangleTexture->asRenderTarget()))); if (!dc) { ERRORF(reporter, "Could not get GrDrawContext for rectangle texture."); return; |