From a4cb388c0fe83de153806cbe42e4b7d47a069c09 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Thu, 29 Dec 2016 01:24:28 +0000 Subject: Revert "Add ImageToColorSpace helper in SkImageFilter" This reverts commit e02d3caab823728d3106bcb1d4fbb674afc959fb. Reason for revert: New logic triggers out-of-date assert. Reverting until I can fix that, too. Original change's description: > Add ImageToColorSpace helper in SkImageFilter > > Share this logic among a couple filters that need it. This also fixes a > bug that showed up in the morhpology GM for GPU color space configs. > > BUG=skia: > > Change-Id: Ic686b07aff80e58e14a86108703bfbb3cf524979 > Reviewed-on: https://skia-review.googlesource.com/6475 > Reviewed-by: Brian Salomon > Commit-Queue: Brian Osman > TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org BUG=skia: NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I00b444dfaaa9b5981f7b33b34419cf9795b52ddb Reviewed-on: https://skia-review.googlesource.com/6480 Commit-Queue: Brian Osman Reviewed-by: Brian Osman --- src/effects/SkMatrixConvolutionImageFilter.cpp | 32 ++++++++++++++++++++++---- src/effects/SkMorphologyImageFilter.cpp | 32 ++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src/effects') diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index 6af8508b5a..40d09d661a 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -10,6 +10,7 @@ #include "SkColorPriv.h" #include "SkReadBuffer.h" #include "SkSpecialImage.h" +#include "SkSpecialSurface.h" #include "SkWriteBuffer.h" #include "SkRect.h" #include "SkUnPreMultiply.h" @@ -281,6 +282,23 @@ static GrTextureDomain::Mode convert_tilemodes(SkMatrixConvolutionImageFilter::T } return GrTextureDomain::kIgnore_Mode; } + +// Return a copy of 'src' transformed to the output's color space +static sk_sp image_to_color_space(SkSpecialImage* src, + const SkImageFilter::OutputProperties& outProps) { + sk_sp surf(src->makeSurface( + outProps, SkISize::Make(src->width(), src->height()))); + if (!surf) { + return sk_ref_sp(src); + } + + SkCanvas* canvas = surf->getCanvas(); + SkASSERT(canvas); + + src->draw(canvas, 0, 0, nullptr); + + return surf->makeImageSnapshot(); +} #endif sk_sp SkMatrixConvolutionImageFilter::onFilterImage(SkSpecialImage* source, @@ -304,11 +322,15 @@ sk_sp SkMatrixConvolutionImageFilter::onFilterImage(SkSpecialIma fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE) { GrContext* context = source->getContext(); - // Ensure the input is in the destination color space. Typically applyCropRect will have - // called pad_image to account for our dilation of bounds, so the result will already be - // moved to the destination color space. If a filter DAG avoids that, then we use this - // fall-back, which saves us from having to do the xform during the filter itself. - input = ImageToColorSpace(input.get(), ctx.outputProperties()); + // If the input is not yet already in the destination color space, do an explicit up-front + // conversion. This is extremely unlikely (maybe even impossible). Typically, applyCropRect + // will have called pad_image to account for our dilation of bounds, so the result will + // already be moved to the destination color space. If someone makes a filter DAG that + // avoids that, then we use this fall-back, which saves us from having to do the xform + // during the filter itself. + if (input->getColorSpace() != ctx.outputProperties().colorSpace()) { + input = image_to_color_space(input.get(), ctx.outputProperties()); + } sk_sp inputTexture(input->asTextureRef(context)); SkASSERT(inputTexture); diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 0b3a86d69f..42986ce9de 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -13,6 +13,7 @@ #include "SkReadBuffer.h" #include "SkRect.h" #include "SkSpecialImage.h" +#include "SkSpecialSurface.h" #include "SkWriteBuffer.h" #if SK_SUPPORT_GPU @@ -545,6 +546,23 @@ static sk_sp apply_morphology( std::move(srcTexture), std::move(colorSpace), &input->props()); } + +// Return a copy of 'src' transformed to the output's color space +static sk_sp image_to_color_space(SkSpecialImage* src, + const SkImageFilter::OutputProperties& outProps) { + sk_sp surf(src->makeSurface( + outProps, SkISize::Make(src->width(), src->height()))); + if (!surf) { + return sk_ref_sp(src); + } + + SkCanvas* canvas = surf->getCanvas(); + SkASSERT(canvas); + + src->draw(canvas, 0, 0, nullptr); + + return surf->makeImageSnapshot(); +} #endif sk_sp SkMorphologyImageFilter::onFilterImage(SkSpecialImage* source, @@ -585,11 +603,15 @@ sk_sp SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou if (source->isTextureBacked()) { GrContext* context = source->getContext(); - // Ensure the input is in the destination color space. Typically applyCropRect will have - // called pad_image to account for our dilation of bounds, so the result will already be - // moved to the destination color space. If a filter DAG avoids that, then we use this - // fall-back, which saves us from having to do the xform during the filter itself. - input = ImageToColorSpace(input.get(), ctx.outputProperties()); + // If the input is not yet already in the destination color space, do an explicit up-front + // conversion. This is extremely unlikely (maybe even impossible). Typically, applyCropRect + // will have called pad_image to account for our dilation of bounds, so the result will + // already be moved to the destination color space. If someone makes a filter DAG that + // avoids that, then we use this fall-back, which saves us from having to do the xform + // during the filter itself. + if (input->getColorSpace() != ctx.outputProperties().colorSpace()) { + input = image_to_color_space(input.get(), ctx.outputProperties()); + } auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::kDilate_MorphologyType : GrMorphologyEffect::kErode_MorphologyType; -- cgit v1.2.3