diff options
-rw-r--r-- | src/core/SkImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/core/SkMatrixImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/core/SkSpecialImage.cpp | 65 | ||||
-rw-r--r-- | src/core/SkSpecialImage.h | 11 | ||||
-rw-r--r-- | src/effects/SkColorFilterImageFilter.cpp | 3 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 13 | ||||
-rw-r--r-- | src/effects/SkDropShadowImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkImageSource.cpp | 6 | ||||
-rwxr-xr-x | src/effects/SkMergeImageFilter.cpp | 5 | ||||
-rw-r--r-- | src/effects/SkOffsetImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkPaintImageFilter.cpp | 5 | ||||
-rw-r--r-- | src/effects/SkPictureImageFilter.cpp | 9 | ||||
-rw-r--r-- | src/effects/SkTileImageFilter.cpp | 12 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 4 | ||||
-rw-r--r-- | tests/SpecialImageTest.cpp | 11 |
15 files changed, 70 insertions, 92 deletions
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 9373dc1a1d..be48ca17ba 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -348,9 +348,9 @@ bool SkImageFilter::applyCropRect(const Context& ctx, const SkIRect& srcBounds, // around it. static sk_sp<SkSpecialImage> pad_image(SkSpecialImage* src, int newWidth, int newHeight, int offX, int offY) { - // We explicitly want to operate in the source's color space here - SkImageFilter::OutputProperties outProps(src->getColorSpace()); - sk_sp<SkSpecialSurface> surf(src->makeSurface(outProps, SkISize::Make(newWidth, newHeight))); + + SkImageInfo info = SkImageInfo::MakeN32Premul(newWidth, newHeight); + sk_sp<SkSpecialSurface> surf(src->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/core/SkMatrixImageFilter.cpp b/src/core/SkMatrixImageFilter.cpp index 12efc64683..2e827d82a6 100644 --- a/src/core/SkMatrixImageFilter.cpp +++ b/src/core/SkMatrixImageFilter.cpp @@ -70,7 +70,9 @@ sk_sp<SkSpecialImage> SkMatrixImageFilter::onFilterImage(SkSpecialImage* source, SkIRect dstBounds; dstRect.roundOut(&dstBounds); - sk_sp<SkSpecialSurface> surf(input->makeSurface(ctx.outputProperties(), dstBounds.size())); + const SkImageInfo info = SkImageInfo::MakeN32Premul(dstBounds.width(), dstBounds.height()); + + sk_sp<SkSpecialSurface> surf(input->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 5d62c6bc62..240d469219 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -52,13 +52,11 @@ public: virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; - virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const = 0; + virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const = 0; virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0; - virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const = 0; + virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const = 0; private: typedef SkSpecialImage INHERITED; @@ -153,14 +151,12 @@ sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { } #endif -sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const { - return as_SIB(this)->onMakeSurface(outProps, size, at); +sk_sp<SkSpecialSurface> SkSpecialImage::makeSurface(const SkImageInfo& info) const { + return as_SIB(this)->onMakeSurface(info); } -sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const { - return as_SIB(this)->onMakeTightSurface(outProps, size, at); +sk_sp<SkSurface> SkSpecialImage::makeTightSurface(const SkImageInfo& info) const { + return as_SIB(this)->onMakeTightSurface(info); } sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const { @@ -256,22 +252,7 @@ public: } #endif -// TODO: The raster implementations of image filters all currently assume that the pixels are -// legacy N32. Until they actually check the format and operate on sRGB or F16 data appropriately, -// we can't enable this. (They will continue to produce incorrect results, but less-so). -#define RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 0 - - sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const override { -#if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 - SkColorSpace* colorSpace = outProps.colorSpace(); -#else - SkColorSpace* colorSpace = nullptr; -#endif - SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() - ? kRGBA_F16_SkColorType : kN32_SkColorType; - SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at, - sk_ref_sp(colorSpace)); + sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override { return SkSpecialSurface::MakeRaster(info, nullptr); } @@ -297,17 +278,7 @@ public: return SkImage::MakeFromBitmap(subsetBM); } - sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const override { -#if RASTER_IMAGE_FILTERS_SUPPORT_SRGB_AND_F16 - SkColorSpace* colorSpace = outProps.colorSpace(); -#else - SkColorSpace* colorSpace = nullptr; -#endif - SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() - ? kRGBA_F16_SkColorType : kN32_SkColorType; - SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at, - sk_ref_sp(colorSpace)); + sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override { return SkSurface::MakeRaster(info); } @@ -411,16 +382,16 @@ public: return fColorSpace.get(); } - sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const override { + sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override { if (!fTexture->getContext()) { return nullptr; } - SkColorSpace* colorSpace = outProps.colorSpace(); - return SkSpecialSurface::MakeRenderTarget( - fTexture->getContext(), size.width(), size.height(), - GrRenderableConfigForColorSpace(colorSpace), sk_ref_sp(colorSpace)); + GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps()); + + return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), + info.width(), info.height(), + config, sk_ref_sp(info.colorSpace())); } sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const override { @@ -457,13 +428,7 @@ public: fAlphaType, subTx.get(), fColorSpace, SkBudgeted::kYes); } - sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, SkAlphaType at) const override { - SkColorSpace* colorSpace = outProps.colorSpace(); - SkColorType colorType = colorSpace && colorSpace->gammaIsLinear() - ? kRGBA_F16_SkColorType : kRGBA_8888_SkColorType; - SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType, at, - sk_ref_sp(colorSpace)); + sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override { return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::kYes, info); } diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index c1f3791edf..cd8c3141fb 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -12,8 +12,7 @@ #include "SkRefCnt.h" #include "SkSurfaceProps.h" -#include "SkImageFilter.h" // for OutputProperties -#include "SkImageInfo.h" // for SkAlphaType +#include "SkImageInfo.h" // for SkAlphaType class GrContext; class GrTexture; @@ -87,17 +86,13 @@ public: /** * Create a new special surface with a backend that is compatible with this special image. */ - sk_sp<SkSpecialSurface> makeSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, - SkAlphaType at = kPremul_SkAlphaType) const; + sk_sp<SkSpecialSurface> makeSurface(const SkImageInfo&) const; /** * Create a new surface with a backend that is compatible with this special image. * TODO: switch this to makeSurface once we resolved the naming issue */ - sk_sp<SkSurface> makeTightSurface(const SkImageFilter::OutputProperties& outProps, - const SkISize& size, - SkAlphaType at = kPremul_SkAlphaType) const; + sk_sp<SkSurface> makeTightSurface(const SkImageInfo&) const; /** * Extract a subset of this special image and return it as a special image. diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index d6b23d5038..63d5942f6a 100644 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -79,7 +79,8 @@ sk_sp<SkSpecialImage> SkColorFilterImageFilter::onFilterImage(SkSpecialImage* so return nullptr; } - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPremul_SkAlphaType); + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 4f6386d92e..8d068072a7 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -279,18 +279,7 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou } SkIPoint displOffset = SkIPoint::Make(0, 0); - // Creation of the displacement map should happen in a non-colorspace aware context. This - // texture is a purely mathematical construct, so we want to just operate on the stored - // values. Consider: - // User supplies an sRGB displacement map. If we're rendering to a wider gamut, then we could - // end up filtering the displacement map into that gamut, which has the effect of reducing - // the amount of displacement that it represents (as encoded values move away from the - // primaries). - // With a more complex DAG attached to this input, it's not clear that working in ANY specific - // color space makes sense, so we ignore color spaces (and gamma) entirely. This may not be - // ideal, but it's at least consistent and predictable. - Context displContext(ctx.ctm(), ctx.clipBounds(), ctx.cache(), OutputProperties(nullptr)); - sk_sp<SkSpecialImage> displ(this->filterInput(0, source, displContext, &displOffset)); + sk_sp<SkSpecialImage> displ(this->filterInput(0, source, ctx, &displOffset)); if (!displ) { return nullptr; } diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp index b4b8cac4f0..5befe71194 100644 --- a/src/effects/SkDropShadowImageFilter.cpp +++ b/src/effects/SkDropShadowImageFilter.cpp @@ -77,7 +77,9 @@ sk_sp<SkSpecialImage> SkDropShadowImageFilter::onFilterImage(SkSpecialImage* sou return nullptr; } - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + const SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), + kPremul_SkAlphaType); + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkImageSource.cpp b/src/effects/SkImageSource.cpp index f434de4aa0..f3fc05491e 100644 --- a/src/effects/SkImageSource.cpp +++ b/src/effects/SkImageSource.cpp @@ -93,7 +93,11 @@ sk_sp<SkSpecialImage> SkImageSource::onFilterImage(SkSpecialImage* source, const const SkIRect dstIRect = dstRect.roundOut(); - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dstIRect.size())); + // SRGBTODO: Propagate SkColorType? + const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.height(), + kPremul_SkAlphaType); + + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkMergeImageFilter.cpp b/src/effects/SkMergeImageFilter.cpp index cc7e336a3d..2dd02ee529 100755 --- a/src/effects/SkMergeImageFilter.cpp +++ b/src/effects/SkMergeImageFilter.cpp @@ -113,7 +113,10 @@ sk_sp<SkSpecialImage> SkMergeImageFilter::onFilterImage(SkSpecialImage* source, const int x0 = bounds.left(); const int y0 = bounds.top(); - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), + kPremul_SkAlphaType); + + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp index 1c99154f16..af60164d99 100644 --- a/src/effects/SkOffsetImageFilter.cpp +++ b/src/effects/SkOffsetImageFilter.cpp @@ -49,7 +49,9 @@ sk_sp<SkSpecialImage> SkOffsetImageFilter::onFilterImage(SkSpecialImage* source, return nullptr; } - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), + kPremul_SkAlphaType); + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkPaintImageFilter.cpp b/src/effects/SkPaintImageFilter.cpp index 0a0e4e92ed..8833629eed 100644 --- a/src/effects/SkPaintImageFilter.cpp +++ b/src/effects/SkPaintImageFilter.cpp @@ -43,7 +43,10 @@ sk_sp<SkSpecialImage> SkPaintImageFilter::onFilterImage(SkSpecialImage* source, return nullptr; } - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), + kPremul_SkAlphaType); + + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp index 6539104a30..bfe26b62c5 100644 --- a/src/effects/SkPictureImageFilter.cpp +++ b/src/effects/SkPictureImageFilter.cpp @@ -118,7 +118,8 @@ sk_sp<SkSpecialImage> SkPictureImageFilter::onFilterImage(SkSpecialImage* source SkASSERT(!bounds.isEmpty()); - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPremul_SkAlphaType); + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } @@ -166,8 +167,10 @@ void SkPictureImageFilter::drawPictureAtLocalResolution(SkSpecialImage* source, sk_sp<SkSpecialImage> localImg; { - sk_sp<SkSpecialSurface> localSurface(source->makeSurface(ctx.outputProperties(), - localIBounds.size())); + const SkImageInfo info = SkImageInfo::MakeN32(localIBounds.width(), localIBounds.height(), + kPremul_SkAlphaType); + + sk_sp<SkSpecialSurface> localSurface(source->makeSurface(info)); if (!localSurface) { return; } diff --git a/src/effects/SkTileImageFilter.cpp b/src/effects/SkTileImageFilter.cpp index 46c4d9af67..c098bc2955 100644 --- a/src/effects/SkTileImageFilter.cpp +++ b/src/effects/SkTileImageFilter.cpp @@ -55,7 +55,9 @@ sk_sp<SkSpecialImage> SkTileImageFilter::onFilterImage(SkSpecialImage* source, } const SkIRect dstIRect = dstRect.roundOut(); - if (!fSrcRect.width() || !fSrcRect.height() || !dstIRect.width() || !dstIRect.height()) { + int dstWidth = dstIRect.width(); + int dstHeight = dstIRect.height(); + if (!fSrcRect.width() || !fSrcRect.height() || !dstWidth || !dstHeight) { return nullptr; } @@ -78,7 +80,9 @@ sk_sp<SkSpecialImage> SkTileImageFilter::onFilterImage(SkSpecialImage* source, return nullptr; } } else { - sk_sp<SkSurface> surf(input->makeTightSurface(ctx.outputProperties(), srcIRect.size())); + const SkImageInfo info = SkImageInfo::MakeN32(srcIRect.width(), srcIRect.height(), + kPremul_SkAlphaType); + sk_sp<SkSurface> surf(input->makeTightSurface(info)); if (!surf) { return nullptr; } @@ -98,7 +102,9 @@ sk_sp<SkSpecialImage> SkTileImageFilter::onFilterImage(SkSpecialImage* source, SkASSERT(subset->width() == srcIRect.width()); SkASSERT(subset->height() == srcIRect.height()); - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dstIRect.size())); + const SkImageInfo info = SkImageInfo::MakeN32(dstWidth, dstHeight, kPremul_SkAlphaType); + + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index d655c9484f..c7e4143e11 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -95,7 +95,9 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter::onFilterImage(SkSpecialImage* sourc } #endif - sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), bounds.size())); + const SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), + kPremul_SkAlphaType); + sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); if (!surf) { return nullptr; } diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp index e992177430..ba0eb58f4e 100644 --- a/tests/SpecialImageTest.cpp +++ b/tests/SpecialImageTest.cpp @@ -85,9 +85,9 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep //-------------- // Test that draw restricts itself to the subset - SkImageFilter::OutputProperties outProps(img->getColorSpace()); - sk_sp<SkSpecialSurface> surf(img->makeSurface(outProps, SkISize::Make(kFullSize, kFullSize), - kOpaque_SkAlphaType)); + SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlphaType); + + sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); SkCanvas* canvas = surf->getCanvas(); @@ -122,8 +122,9 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels(&tmpPixmap)); } { - SkImageFilter::OutputProperties outProps(img->getColorSpace()); - sk_sp<SkSurface> tightSurf(img->makeTightSurface(outProps, subset.size())); + SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), + kPremul_SkAlphaType); + sk_sp<SkSurface> tightSurf(img->makeTightSurface(info)); REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); |