diff options
author | 2016-11-10 17:03:43 -0500 | |
---|---|---|
committer | 2016-11-14 15:08:23 +0000 | |
commit | 7f6cd90f0c8f6e8dd658cb1b1c587b833adfc364 (patch) | |
tree | c2d015925ce8d90e0996d58b4030f4bec0e7f21f | |
parent | 4fea663af4f0d5dabb6e784072264abcbad29461 (diff) |
Start plumbing deferral of GPU resources in the image filters
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4688
Change-Id: I904d999ea87a55bee73765aa96a2f8aef7a0d61c
Reviewed-on: https://skia-review.googlesource.com/4688
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r-- | src/core/SkSpecialImage.cpp | 10 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 21 | ||||
-rw-r--r-- | src/effects/SkLightingImageFilter.cpp | 18 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 95 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 19 |
5 files changed, 95 insertions, 68 deletions
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index f4577df849..f18878175b 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -391,13 +391,19 @@ public: // TODO: add GrTextureProxy-backed SkImage_Gpus GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider()); - auto img = sk_sp<SkImage>(new SkImage_Gpu(fSurfaceProxy->width(), fSurfaceProxy->height(), + // TODO: In this instance we know we're going to draw a sub-portion of the backing + // texture into the canvas so it is okay to wrap it in an SkImage. This poses + // some problems for full deferral however in that when the deferred SkImage_Gpu + // instantiates itself it is going to have to either be okay with having a larger + // than expected backing texture (unlikely) or the 'fit' of the SurfaceProxy needs + // to be tightened (if it is deferred). + auto img = sk_sp<SkImage>(new SkImage_Gpu(surf->width(), surf->height(), this->uniqueID(), fAlphaType, sk_ref_sp(surf->asTexture()), fColorSpace, SkBudgeted::kNo)); canvas->drawImageRect(img, this->subset(), - dst, paint, SkCanvas::kStrict_SrcRectConstraint); + dst, paint, SkCanvas::kStrict_SrcRectConstraint); } GrContext* onGetContext() const override { return fContext; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index d73b440a75..8cb610e3b1 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -15,9 +15,11 @@ #include "SkColorPriv.h" #if SK_SUPPORT_GPU #include "GrContext.h" -#include "GrRenderTargetContext.h" #include "GrCoordTransform.h" #include "GrInvariantOutput.h" +#include "GrRenderTargetContext.h" +#include "GrTextureProxy.h" + #include "SkGr.h" #include "SkGrPriv.h" #include "effects/GrTextureDomain.h" @@ -349,9 +351,10 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou SkColorSpace* colorSpace = ctx.outputProperties().colorSpace(); sk_sp<GrRenderTargetContext> renderTargetContext( - context->makeRenderTargetContext(SkBackingFit::kApprox, bounds.width(), bounds.height(), - GrRenderableConfigForColorSpace(colorSpace), - sk_ref_sp(colorSpace))); + context->makeDeferredRenderTargetContext(SkBackingFit::kApprox, + bounds.width(), bounds.height(), + GrRenderableConfigForColorSpace(colorSpace), + sk_ref_sp(colorSpace))); if (!renderTargetContext) { return nullptr; } @@ -361,10 +364,12 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou offset->fX = bounds.left(); offset->fY = bounds.top(); - return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), - kNeedNewImageUniqueID_SpecialImage, - renderTargetContext->asTexture(), - sk_ref_sp(renderTargetContext->getColorSpace())); + return SkSpecialImage::MakeDeferredFromGpu( + context, + SkIRect::MakeWH(bounds.width(), bounds.height()), + kNeedNewImageUniqueID_SpecialImage, + sk_ref_sp(renderTargetContext->asDeferredTexture()), + sk_ref_sp(renderTargetContext->getColorSpace())); } #endif diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 703930d6e7..da6210c7d1 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -16,11 +16,13 @@ #if SK_SUPPORT_GPU #include "GrContext.h" -#include "GrRenderTargetContext.h" #include "GrFixedClip.h" #include "GrFragmentProcessor.h" #include "GrInvariantOutput.h" #include "GrPaint.h" +#include "GrRenderTargetContext.h" +#include "GrTextureProxy.h" + #include "SkGr.h" #include "SkGrPriv.h" #include "effects/GrSingleTextureEffect.h" @@ -413,10 +415,10 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU( sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); SkASSERT(inputTexture); - sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext( - SkBackingFit::kApprox,offsetBounds.width(), offsetBounds.height(), - GrRenderableConfigForColorSpace(outputProperties.colorSpace()), - sk_ref_sp(outputProperties.colorSpace()))); + sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext( + SkBackingFit::kApprox, offsetBounds.width(), offsetBounds.height(), + GrRenderableConfigForColorSpace(outputProperties.colorSpace()), + sk_ref_sp(outputProperties.colorSpace()))); if (!renderTargetContext) { return nullptr; } @@ -458,9 +460,11 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU( this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomRight, kBottomRight_BoundaryMode, pSrcBounds, offsetBounds); - return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()), + return SkSpecialImage::MakeDeferredFromGpu( + context, + SkIRect::MakeWH(offsetBounds.width(), offsetBounds.height()), kNeedNewImageUniqueID_SpecialImage, - renderTargetContext->asTexture(), + sk_ref_sp(renderTargetContext->asDeferredTexture()), sk_ref_sp(renderTargetContext->getColorSpace())); } #endif diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 630f782f90..cd35d655c4 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -17,10 +17,12 @@ #if SK_SUPPORT_GPU #include "GrContext.h" -#include "GrRenderTargetContext.h" #include "GrFixedClip.h" #include "GrInvariantOutput.h" +#include "GrRenderTargetContext.h" #include "GrTexture.h" +#include "GrTextureProxy.h" + #include "SkGr.h" #include "SkGrPriv.h" #include "effects/Gr1DKernelEffect.h" @@ -151,7 +153,7 @@ public: } static sk_sp<GrFragmentProcessor> Make(GrTexture* tex, Direction dir, int radius, - MorphologyType type, float bounds[2]) { + MorphologyType type, const float bounds[2]) { return sk_sp<GrFragmentProcessor>(new GrMorphologyEffect(tex, dir, radius, type, bounds)); } @@ -179,8 +181,7 @@ private: void onComputeInvariantOutput(GrInvariantOutput* inout) const override; GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); - GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType, - float bounds[2]); + GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType, const float bounds[2]); GR_DECLARE_FRAGMENT_PROCESSOR_TEST; @@ -310,10 +311,11 @@ void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, if (m.useRange()) { const float* range = m.range(); - if (m.direction() && texture.origin() == kBottomLeft_GrSurfaceOrigin) { - pdman.set2f(fRangeUni, 1.0f - range[1], 1.0f - range[0]); + if (Gr1DKernelEffect::kY_Direction == m.direction() && + texture.origin() == kBottomLeft_GrSurfaceOrigin) { + pdman.set2f(fRangeUni, 1.0f - (range[1]*pixelSize), 1.0f - (range[0]*pixelSize)); } else { - pdman.set2f(fRangeUni, range[0], range[1]); + pdman.set2f(fRangeUni, range[0] * pixelSize, range[1] * pixelSize); } } } @@ -334,7 +336,7 @@ GrMorphologyEffect::GrMorphologyEffect(GrTexture* texture, Direction direction, int radius, MorphologyType type, - float range[2]) + const float range[2]) : INHERITED(texture, direction, radius) , fType(type) , fUseRange(true) { @@ -385,18 +387,19 @@ sk_sp<GrFragmentProcessor> GrMorphologyEffect::TestCreate(GrProcessorTestData* d } -static void apply_morphology_rect(GrRenderTargetContext* renderTargetContext, +static void apply_morphology_rect(GrTextureProvider* provider, + GrRenderTargetContext* renderTargetContext, const GrClip& clip, - GrTexture* texture, + GrTextureProxy* textureProxy, const SkIRect& srcRect, const SkIRect& dstRect, int radius, GrMorphologyEffect::MorphologyType morphType, - float bounds[2], + const float bounds[2], Gr1DKernelEffect::Direction direction) { GrPaint paint; paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); - paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture, + paint.addColorFragmentProcessor(GrMorphologyEffect::Make(textureProxy->instantiate(provider), direction, radius, morphType, @@ -406,9 +409,10 @@ static void apply_morphology_rect(GrRenderTargetContext* renderTargetContext, SkRect::Make(srcRect)); } -static void apply_morphology_rect_no_bounds(GrRenderTargetContext* renderTargetContext, +static void apply_morphology_rect_no_bounds(GrTextureProvider* provider, + GrRenderTargetContext* renderTargetContext, const GrClip& clip, - GrTexture* texture, + GrTextureProxy* textureProxy, const SkIRect& srcRect, const SkIRect& dstRect, int radius, @@ -416,16 +420,18 @@ static void apply_morphology_rect_no_bounds(GrRenderTargetContext* renderTargetC Gr1DKernelEffect::Direction direction) { GrPaint paint; paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); - paint.addColorFragmentProcessor(GrMorphologyEffect::Make(texture, direction, radius, + paint.addColorFragmentProcessor(GrMorphologyEffect::Make(textureProxy->instantiate(provider), + direction, radius, morphType)); paint.setPorterDuffXPFactory(SkBlendMode::kSrc); renderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(), SkRect::Make(dstRect), SkRect::Make(srcRect)); } -static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, +static void apply_morphology_pass(GrTextureProvider* provider, + GrRenderTargetContext* renderTargetContext, const GrClip& clip, - GrTexture* texture, + GrTextureProxy* textureProxy, const SkIRect& srcRect, const SkIRect& dstRect, int radius, @@ -436,8 +442,8 @@ static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, SkIRect middleSrcRect = srcRect, middleDstRect = dstRect; SkIRect upperSrcRect = srcRect, upperDstRect = dstRect; if (direction == Gr1DKernelEffect::kX_Direction) { - bounds[0] = (SkIntToScalar(srcRect.left()) + 0.5f) / texture->width(); - bounds[1] = (SkIntToScalar(srcRect.right()) - 0.5f) / texture->width(); + bounds[0] = SkIntToScalar(srcRect.left()) + 0.5f; + bounds[1] = SkIntToScalar(srcRect.right()) - 0.5f; lowerSrcRect.fRight = srcRect.left() + radius; lowerDstRect.fRight = dstRect.left() + radius; upperSrcRect.fLeft = srcRect.right() - radius; @@ -445,8 +451,8 @@ static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, middleSrcRect.inset(radius, 0); middleDstRect.inset(radius, 0); } else { - bounds[0] = (SkIntToScalar(srcRect.top()) + 0.5f) / texture->height(); - bounds[1] = (SkIntToScalar(srcRect.bottom()) - 0.5f) / texture->height(); + bounds[0] = SkIntToScalar(srcRect.top()) + 0.5f; + bounds[1] = SkIntToScalar(srcRect.bottom()) - 0.5f; lowerSrcRect.fBottom = srcRect.top() + radius; lowerDstRect.fBottom = dstRect.top() + radius; upperSrcRect.fTop = srcRect.bottom() - radius; @@ -456,16 +462,16 @@ static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, } if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) { // radius covers srcRect; use bounds over entire draw - apply_morphology_rect(renderTargetContext, clip, texture, srcRect, dstRect, radius, - morphType, bounds, direction); + apply_morphology_rect(provider, renderTargetContext, clip, textureProxy, + srcRect, dstRect, radius, morphType, bounds, direction); } else { // Draw upper and lower margins with bounds; middle without. - apply_morphology_rect(renderTargetContext, clip, texture, lowerSrcRect, lowerDstRect, - radius, morphType, bounds, direction); - apply_morphology_rect(renderTargetContext, clip, texture, upperSrcRect, upperDstRect, - radius, morphType, bounds, direction); - apply_morphology_rect_no_bounds(renderTargetContext, clip, texture, middleSrcRect, - middleDstRect, radius, morphType, direction); + apply_morphology_rect(provider, renderTargetContext, clip, textureProxy, + lowerSrcRect, lowerDstRect, radius, morphType, bounds, direction); + apply_morphology_rect(provider, renderTargetContext, clip, textureProxy, + upperSrcRect, upperDstRect, radius, morphType, bounds, direction); + apply_morphology_rect_no_bounds(provider, renderTargetContext, clip, textureProxy, + middleSrcRect, middleDstRect, radius, morphType, direction); } } @@ -476,7 +482,7 @@ static sk_sp<SkSpecialImage> apply_morphology( GrMorphologyEffect::MorphologyType morphType, SkISize radius, const SkImageFilter::OutputProperties& outputProperties) { - sk_sp<GrTexture> srcTexture(input->asTextureRef(context)); + sk_sp<GrTextureProxy> srcTexture(input->asTextureProxy(context)); SkASSERT(srcTexture); sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace()); GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get()); @@ -490,13 +496,14 @@ static sk_sp<SkSpecialImage> apply_morphology( SkASSERT(radius.width() > 0 || radius.height() > 0); if (radius.fWidth > 0) { - sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeRenderTargetContext( + sk_sp<GrRenderTargetContext> dstRTContext(context->makeDeferredRenderTargetContext( SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace)); - if (!dstRenderTargetContext) { + if (!dstRTContext) { return nullptr; } - apply_morphology_pass(dstRenderTargetContext.get(), clip, srcTexture.get(), + apply_morphology_pass(context->textureProvider(), + dstRTContext.get(), clip, srcTexture.get(), srcRect, dstRect, radius.fWidth, morphType, Gr1DKernelEffect::kX_Direction); SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, @@ -504,29 +511,31 @@ static sk_sp<SkSpecialImage> apply_morphology( GrColor clearColor = GrMorphologyEffect::kErode_MorphologyType == morphType ? SK_ColorWHITE : SK_ColorTRANSPARENT; - dstRenderTargetContext->clear(&clearRect, clearColor, false); + dstRTContext->clear(&clearRect, clearColor, false); - srcTexture = dstRenderTargetContext->asTexture(); + srcTexture = sk_ref_sp(dstRTContext->asDeferredTexture()); srcRect = dstRect; } if (radius.fHeight > 0) { - sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeRenderTargetContext( + sk_sp<GrRenderTargetContext> dstRTContext(context->makeDeferredRenderTargetContext( SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace)); - if (!dstRenderTargetContext) { + if (!dstRTContext) { return nullptr; } - apply_morphology_pass(dstRenderTargetContext.get(), clip, srcTexture.get(), + apply_morphology_pass(context->textureProvider(), + dstRTContext.get(), clip, srcTexture.get(), srcRect, dstRect, radius.fHeight, morphType, Gr1DKernelEffect::kY_Direction); - srcTexture = dstRenderTargetContext->asTexture(); + srcTexture = sk_ref_sp(dstRTContext->asDeferredTexture()); } - return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(rect.width(), rect.height()), - kNeedNewImageUniqueID_SpecialImage, - std::move(srcTexture), std::move(colorSpace), - &input->props()); + return SkSpecialImage::MakeDeferredFromGpu(context, + SkIRect::MakeWH(rect.width(), rect.height()), + kNeedNewImageUniqueID_SpecialImage, + std::move(srcTexture), std::move(colorSpace), + &input->props()); } #endif diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index 5963f09199..840f652514 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -18,6 +18,8 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrRenderTargetContext.h" +#include "GrTextureProxy.h" + #include "effects/GrConstColorProcessor.h" #include "effects/GrTextureDomain.h" #include "effects/GrSimpleTextureEffect.h" @@ -291,10 +293,10 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU( paint.setPorterDuffXPFactory(SkBlendMode::kSrc); - sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext( - SkBackingFit::kApprox, bounds.width(), bounds.height(), - GrRenderableConfigForColorSpace(outputProperties.colorSpace()), - sk_ref_sp(outputProperties.colorSpace()))); + sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext( + SkBackingFit::kApprox, bounds.width(), bounds.height(), + GrRenderableConfigForColorSpace(outputProperties.colorSpace()), + sk_ref_sp(outputProperties.colorSpace()))); if (!renderTargetContext) { return nullptr; } @@ -304,10 +306,11 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU( matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())); renderTargetContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds)); - return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()), - kNeedNewImageUniqueID_SpecialImage, - renderTargetContext->asTexture(), - sk_ref_sp(renderTargetContext->getColorSpace())); + return SkSpecialImage::MakeDeferredFromGpu(context, + SkIRect::MakeWH(bounds.width(), bounds.height()), + kNeedNewImageUniqueID_SpecialImage, + sk_ref_sp(renderTargetContext->asDeferredTexture()), + sk_ref_sp(renderTargetContext->getColorSpace())); } sk_sp<GrFragmentProcessor> |