diff options
author | Brian Osman <brianosman@google.com> | 2017-10-18 10:23:18 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-18 15:24:45 +0000 |
commit | 5e34167d53c06c3c4512592bd1477fcf2df97172 (patch) | |
tree | b8fb506c8e6abf763c84a19d28b74cce2a0f4ffa | |
parent | bd2c653e8aba1077ac1a5d8fed5cfc304e4095a8 (diff) |
Convert more code to use color space xform FP
Special images, image shaders, and all texture producers,
as well as bicubic (which simplifies factory call sites).
Bug: skia:
Change-Id: I3f7c178060f25db8b659fe66e132f5ea066317b1
Reviewed-on: https://skia-review.googlesource.com/61261
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r-- | src/gpu/GrTextureAdjuster.cpp | 9 | ||||
-rw-r--r-- | src/gpu/GrTextureMaker.cpp | 9 | ||||
-rw-r--r-- | src/gpu/GrTextureProducer.cpp | 16 | ||||
-rw-r--r-- | src/gpu/GrTextureProducer.h | 2 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 26 | ||||
-rw-r--r-- | src/gpu/effects/GrBicubicEffect.cpp | 28 | ||||
-rw-r--r-- | src/gpu/effects/GrBicubicEffect.h | 18 | ||||
-rw-r--r-- | src/shaders/SkImageShader.cpp | 11 |
8 files changed, 36 insertions, 83 deletions
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index da3175863c..99716276ec 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -155,10 +155,7 @@ std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor( } SkASSERT(kNoDomain_DomainMode == domainMode || (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom)); - sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(fColorSpace, - dstColorSpace); - return CreateFragmentProcessorForDomainAndFilter(std::move(proxy), - std::move(colorSpaceXform), - textureMatrix, domainMode, domain, - filterOrNullForBicubic); + auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), textureMatrix, + domainMode, domain, filterOrNullForBicubic); + return GrColorSpaceXformEffect::Make(std::move(fp), fColorSpace, dstColorSpace); } diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index 8183188f60..cc3d490d3c 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -117,12 +117,9 @@ std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor( proxy.get(), nullptr, fmForDetermineDomain, &domain); SkASSERT(kTightCopy_DomainMode != domainMode); - sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(texColorSpace.get(), - dstColorSpace); - return CreateFragmentProcessorForDomainAndFilter(std::move(proxy), - std::move(colorSpaceXform), - adjustedMatrix, domainMode, domain, - filterOrNullForBicubic); + auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), adjustedMatrix, + domainMode, domain, filterOrNullForBicubic); + return GrColorSpaceXformEffect::Make(std::move(fp), texColorSpace.get(), dstColorSpace); } sk_sp<GrTextureProxy> GrTextureMaker::generateTextureProxyForParams(const CopyParams& copyParams, diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp index 2b9679a478..f8a0df7937 100644 --- a/src/gpu/GrTextureProducer.cpp +++ b/src/gpu/GrTextureProducer.cpp @@ -221,7 +221,6 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( std::unique_ptr<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorForDomainAndFilter( sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& textureMatrix, DomainMode domainMode, const SkRect& domain, @@ -229,24 +228,21 @@ std::unique_ptr<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorF SkASSERT(kTightCopy_DomainMode != domainMode); if (filterOrNullForBicubic) { if (kDomain_DomainMode == domainMode) { - return GrTextureDomainEffect::Make(std::move(proxy), - std::move(colorSpaceXform), textureMatrix, - domain, GrTextureDomain::kClamp_Mode, + return GrTextureDomainEffect::Make(std::move(proxy), nullptr, textureMatrix, domain, + GrTextureDomain::kClamp_Mode, *filterOrNullForBicubic); } else { GrSamplerState samplerState(GrSamplerState::WrapMode::kClamp, *filterOrNullForBicubic); - return GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform), - textureMatrix, samplerState); + return GrSimpleTextureEffect::Make(std::move(proxy), nullptr, textureMatrix, + samplerState); } } else { if (kDomain_DomainMode == domainMode) { - return GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform), - textureMatrix, domain); + return GrBicubicEffect::Make(std::move(proxy), textureMatrix, domain); } else { static const GrSamplerState::WrapMode kClampClamp[] = { GrSamplerState::WrapMode::kClamp, GrSamplerState::WrapMode::kClamp}; - return GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform), - textureMatrix, kClampClamp); + return GrBicubicEffect::Make(std::move(proxy), textureMatrix, kClampClamp); } } } diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index 24b23b6e17..432e7b35b3 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -13,7 +13,6 @@ #include "SkImageInfo.h" class GrContext; -class GrColorSpaceXform; class GrFragmentProcessor; class GrTexture; class GrTextureProxy; @@ -138,7 +137,6 @@ protected: static std::unique_ptr<GrFragmentProcessor> CreateFragmentProcessorForDomainAndFilter( sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform>, const SkMatrix& textureMatrix, DomainMode, const SkRect& domain, diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index bbc23c2226..447333566a 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -979,8 +979,6 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, if (!proxy) { return; } - sk_sp<GrColorSpaceXform> colorSpaceXform = - GrColorSpaceXform::Make(bitmap.colorSpace(), fRenderTargetContext->getColorSpace()); // Compute a matrix that maps the rect we will draw to the src rect. const SkMatrix texMatrix = SkMatrix::MakeRectToRect(dstRect, srcRect, @@ -1006,23 +1004,21 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, domain.fTop = domain.fBottom = srcRect.centerY(); } if (bicubic) { - fp = GrBicubicEffect::Make(std::move(proxy), - std::move(colorSpaceXform), texMatrix, domain); + fp = GrBicubicEffect::Make(std::move(proxy), texMatrix, domain); } else { - fp = GrTextureDomainEffect::Make(std::move(proxy), std::move(colorSpaceXform), - texMatrix, domain, GrTextureDomain::kClamp_Mode, - samplerState.filter()); + fp = GrTextureDomainEffect::Make(std::move(proxy), nullptr, texMatrix, domain, + GrTextureDomain::kClamp_Mode, samplerState.filter()); } } else if (bicubic) { SkASSERT(GrSamplerState::Filter::kNearest == samplerState.filter()); GrSamplerState::WrapMode wrapMode[2] = {samplerState.wrapModeX(), samplerState.wrapModeY()}; - fp = GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform), texMatrix, - wrapMode); + fp = GrBicubicEffect::Make(std::move(proxy), texMatrix, wrapMode); } else { - fp = GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform), texMatrix, - samplerState); + fp = GrSimpleTextureEffect::Make(std::move(proxy), nullptr, texMatrix, samplerState); } + fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(), + fRenderTargetContext->getColorSpace()); GrPaint grPaint; if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, viewMatrix, std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(), @@ -1086,11 +1082,9 @@ void SkGpuDevice::drawSpecial(SkSpecialImage* special1, int left, int top, const SkPaint tmpUnfiltered(paint); tmpUnfiltered.setImageFilter(nullptr); - sk_sp<GrColorSpaceXform> colorSpaceXform = - GrColorSpaceXform::Make(result->getColorSpace(), fRenderTargetContext->getColorSpace()); - - auto fp = GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform), - SkMatrix::I()); + auto fp = GrSimpleTextureEffect::Make(std::move(proxy), nullptr, SkMatrix::I()); + fp = GrColorSpaceXformEffect::Make(std::move(fp), result->getColorSpace(), + fRenderTargetContext->getColorSpace()); if (GrPixelConfigIsAlphaOnly(config)) { fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp)); } else { diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp index e95b7a43b9..c2cedf291b 100644 --- a/src/gpu/effects/GrBicubicEffect.cpp +++ b/src/gpu/effects/GrBicubicEffect.cpp @@ -8,7 +8,6 @@ #include "GrBicubicEffect.h" #include "GrTexture.h" -#include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" @@ -22,7 +21,6 @@ public: GrProcessorKeyBuilder* b) { const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>(); b->add32(GrTextureDomain::GLDomain::DomainKey(bicubicEffect.domain())); - b->add32(GrColorSpaceXform::XformKey(bicubicEffect.colorSpaceXform())); } protected: @@ -32,7 +30,6 @@ private: typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; UniformHandle fImageIncrementUni; - GrGLSLColorSpaceXformHelper fColorSpaceHelper; GrTextureDomain::GLDomain fDomain; typedef GrGLSLFragmentProcessor INHERITED; @@ -47,8 +44,6 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) { const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); - fColorSpaceHelper.emitCode(uniformHandler, bicubicEffect.colorSpaceXform()); - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); @@ -105,11 +100,6 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) { y); } SkString bicubicColor("(wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3)"); - if (fColorSpaceHelper.isValid()) { - SkString xformedColor; - fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &fColorSpaceHelper); - bicubicColor.swap(xformedColor); - } fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, bicubicColor.c_str(), args.fInputColor); } @@ -125,34 +115,27 @@ void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, imageIncrement[1] = 1.0f / texture->height(); pdman.set2fv(fImageIncrementUni, 1, imageIncrement); fDomain.setData(pdman, bicubicEffect.domain(), proxy); - if (SkToBool(bicubicEffect.colorSpaceXform())) { - fColorSpaceHelper.setData(pdman, bicubicEffect.colorSpaceXform()); - } } GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix, const GrSamplerState::WrapMode wrapModes[2]) : INHERITED{kGrBicubicEffect_ClassID, ModulateByConfigOptimizationFlags(proxy->config())} , fCoordTransform(matrix, proxy.get()) , fDomain(GrTextureDomain::IgnoredDomain()) , fTextureSampler(std::move(proxy), - GrSamplerState(wrapModes, GrSamplerState::Filter::kNearest)) - , fColorSpaceXform(std::move(colorSpaceXform)) { + GrSamplerState(wrapModes, GrSamplerState::Filter::kNearest)) { this->addCoordTransform(&fCoordTransform); this->addTextureSampler(&fTextureSampler); } GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix, const SkRect& domain) : INHERITED(kGrBicubicEffect_ClassID, ModulateByConfigOptimizationFlags(proxy->config())) , fCoordTransform(matrix, proxy.get()) , fDomain(proxy.get(), domain, GrTextureDomain::kClamp_Mode) - , fTextureSampler(std::move(proxy)) - , fColorSpaceXform(std::move(colorSpaceXform)) { + , fTextureSampler(std::move(proxy)) { this->addCoordTransform(&fCoordTransform); this->addTextureSampler(&fTextureSampler); } @@ -161,8 +144,7 @@ GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that) : INHERITED(kGrBicubicEffect_ClassID, that.optimizationFlags()) , fCoordTransform(that.fCoordTransform) , fDomain(that.fDomain) - , fTextureSampler(that.fTextureSampler) - , fColorSpaceXform(that.fColorSpaceXform) { + , fTextureSampler(that.fTextureSampler) { this->addCoordTransform(&fCoordTransform); this->addTextureSampler(&fTextureSampler); } @@ -187,11 +169,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; - sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(d->fRandom); static const GrSamplerState::WrapMode kClampClamp[] = {GrSamplerState::WrapMode::kClamp, GrSamplerState::WrapMode::kClamp}; - return GrBicubicEffect::Make(d->textureProxy(texIdx), std::move(colorSpaceXform), - SkMatrix::I(), kClampClamp); + return GrBicubicEffect::Make(d->textureProxy(texIdx), SkMatrix::I(), kClampClamp); } #endif diff --git a/src/gpu/effects/GrBicubicEffect.h b/src/gpu/effects/GrBicubicEffect.h index b0a28d9b0d..1d70103524 100644 --- a/src/gpu/effects/GrBicubicEffect.h +++ b/src/gpu/effects/GrBicubicEffect.h @@ -28,28 +28,24 @@ public: const GrTextureDomain& domain() const { return fDomain; } - const GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); } - /** * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. */ static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix, const GrSamplerState::WrapMode wrapModes[2]) { - return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect( - std::move(proxy), std::move(colorSpaceXform), matrix, wrapModes)); + return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix, + wrapModes)); } /** * Create a Mitchell filter effect with a texture matrix and a domain. */ static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix, const SkRect& domain) { - return std::unique_ptr<GrFragmentProcessor>( - new GrBicubicEffect(std::move(proxy), std::move(colorSpaceXform), matrix, domain)); + return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix, + domain)); } /** @@ -63,10 +59,9 @@ public: GrSamplerState::Filter* filterMode); private: - GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, + GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix& matrix, const GrSamplerState::WrapMode wrapModes[2]); - GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, - const SkMatrix &matrix, const SkRect& domain); + GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix &matrix, const SkRect& domain); explicit GrBicubicEffect(const GrBicubicEffect&); GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; @@ -78,7 +73,6 @@ private: GrCoordTransform fCoordTransform; GrTextureDomain fDomain; TextureSampler fTextureSampler; - sk_sp<GrColorSpaceXform> fColorSpaceXform; GR_DECLARE_FRAGMENT_PROCESSOR_TEST diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index 29d0a11170..d9c9bf0ff4 100644 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -221,17 +221,14 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor( lmInverse.postScale(scaleAdjust[0], scaleAdjust[1]); - sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(texColorSpace.get(), - args.fDstColorSpace); std::unique_ptr<GrFragmentProcessor> inner; if (doBicubic) { - inner = GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform), lmInverse, - wrapModes); + inner = GrBicubicEffect::Make(std::move(proxy), lmInverse, wrapModes); } else { - inner = GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform), lmInverse, - samplerState); + inner = GrSimpleTextureEffect::Make(std::move(proxy), nullptr, lmInverse, samplerState); } - + inner = GrColorSpaceXformEffect::Make(std::move(inner), texColorSpace.get(), + args.fDstColorSpace); if (isAlphaOnly) { return inner; } |