diff options
author | 2017-01-09 14:23:59 -0500 | |
---|---|---|
committer | 2017-01-10 16:15:02 +0000 | |
commit | e98234f231d66848e149db683c11b6388e10b233 (patch) | |
tree | 48bbfcde8b5519a3903a1be0e6b28b04dee6b819 | |
parent | 8e619a2b4eb31753e6fcb4a9ec494d31ace755da (diff) |
Start making texture coordinates be absolute
The idea here is that we will pass GrTextureProxys in (where we're currently passing GrTextures) and defer the normalization until the texture is actually instantiated (and possibly move it to the GPU entirely)
This CL does (intentionally) change the texturedomaineffect GM but I believe the new behavior is more correct.
Change-Id: I4e0510b3dfb65ff0d0ee5921f9a6f94151e602d3
Reviewed-on: https://skia-review.googlesource.com/6807
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
-rw-r--r-- | gm/texturedomaineffect.cpp | 8 | ||||
-rw-r--r-- | src/core/SkGpuBlurUtils.cpp | 7 | ||||
-rw-r--r-- | src/effects/SkArithmeticImageFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkLightingImageFilter.cpp | 16 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 6 | ||||
-rw-r--r-- | src/gpu/GrTextureMaker.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrTextureProducer.cpp | 27 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 12 | ||||
-rw-r--r-- | src/gpu/effects/GrBicubicEffect.cpp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrMatrixConvolutionEffect.cpp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomain.cpp | 93 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureDomain.h | 33 |
13 files changed, 104 insertions, 118 deletions
diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp index f2c5fd4652..7313f89a3b 100644 --- a/gm/texturedomaineffect.cpp +++ b/gm/texturedomaineffect.cpp @@ -115,10 +115,10 @@ protected: GrPaint grPaint; grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); sk_sp<GrFragmentProcessor> fp( - GrTextureDomainEffect::Make(texture.get(), nullptr, textureMatrices[tm], - GrTextureDomain::MakeTexelDomain(texture.get(), - texelDomains[d]), - mode, GrSamplerParams::kNone_FilterMode)); + GrTextureDomainEffect::Make( + texture.get(), nullptr, textureMatrices[tm], + GrTextureDomain::MakeTexelDomainForMode(texelDomains[d], mode), + mode, GrSamplerParams::kNone_FilterMode)); if (!fp) { continue; diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp index e3463a4b78..005670a7f9 100644 --- a/src/core/SkGpuBlurUtils.cpp +++ b/src/core/SkGpuBlurUtils.cpp @@ -268,10 +268,9 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context, matrix.setIDiv(srcTexture->width(), srcTexture->height()); SkIRect dstRect(srcRect); if (srcBounds && i == 1) { - SkRect domain; - matrix.mapRect(&domain, SkRect::Make(*srcBounds)); - domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width() : 0.0f, - (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height() : 0.0f); + SkRect domain = SkRect::Make(*srcBounds); + domain.inset((i < scaleFactorX) ? SK_ScalarHalf : 0.0f, + (i < scaleFactorY) ? SK_ScalarHalf : 0.0f); sk_sp<GrFragmentProcessor> fp(GrTextureDomainEffect::Make( srcTexture.get(), nullptr, diff --git a/src/effects/SkArithmeticImageFilter.cpp b/src/effects/SkArithmeticImageFilter.cpp index 984aedc823..dc15254e5d 100644 --- a/src/effects/SkArithmeticImageFilter.cpp +++ b/src/effects/SkArithmeticImageFilter.cpp @@ -356,7 +356,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU( GrColorSpaceXform::Make(background->getColorSpace(), outputProperties.colorSpace()); bgFP = GrTextureDomainEffect::Make( backgroundTex.get(), std::move(bgXform), backgroundMatrix, - GrTextureDomain::MakeTexelDomain(backgroundTex.get(), background->subset()), + GrTextureDomain::MakeTexelDomain(background->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); } else { bgFP = GrConstColorProcessor::Make(GrColor4f::TransparentBlack(), @@ -374,7 +374,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU( foregroundFP = GrTextureDomainEffect::Make( foregroundTex.get(), std::move(fgXform), foregroundMatrix, - GrTextureDomain::MakeTexelDomain(foregroundTex.get(), foreground->subset()), + GrTextureDomain::MakeTexelDomain(foreground->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); paint.addColorFragmentProcessor(std::move(foregroundFP)); diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 7d5a79a72a..bac1b1cea8 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -499,7 +499,7 @@ GrDisplacementMapEffect::GrDisplacementMapEffect( : fDisplacementTransform(offsetMatrix, displacement, GrSamplerParams::kNone_FilterMode) , fDisplacementSampler(displacement) , fColorTransform(color, GrSamplerParams::kNone_FilterMode) - , fDomain(GrTextureDomain::MakeTexelDomain(color, SkIRect::MakeSize(colorDimensions)), + , fDomain(color, GrTextureDomain::MakeTexelDomain(SkIRect::MakeSize(colorDimensions)), GrTextureDomain::kDecal_Mode) , fColorSampler(color) , fColorSpaceXform(std::move(colorSpaceXform)) @@ -651,7 +651,7 @@ void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), colorTex->origin() == kTopLeft_GrSurfaceOrigin ? SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); - fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); + fGLDomain.setData(pdman, displacementMap.domain(), colorTex); if (SkToBool(displacementMap.colorSpaceXform())) { pdman.setSkMatrix44(fColorSpaceXformUni, displacementMap.colorSpaceXform()->srcToDst()); } diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 52c8947cc4..97d593059f 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -1690,20 +1690,16 @@ private: /////////////////////////////////////////////////////////////////////////////// -namespace { - -GrTextureDomain create_domain(GrTexture* texture, const SkIRect* srcBounds, - GrTextureDomain::Mode mode) { +static GrTextureDomain create_domain(GrTexture* texture, const SkIRect* srcBounds, + GrTextureDomain::Mode mode) { if (srcBounds) { - SkRect texelDomain = GrTextureDomain::MakeTexelDomainForMode(texture, *srcBounds, mode); - return GrTextureDomain(texelDomain, mode); + SkRect texelDomain = GrTextureDomain::MakeTexelDomainForMode(*srcBounds, mode); + return GrTextureDomain(texture, texelDomain, mode); } else { - return GrTextureDomain(SkRect::MakeEmpty(), GrTextureDomain::kIgnore_Mode); + return GrTextureDomain::IgnoredDomain(); } } -}; - GrLightingEffect::GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScalar surfaceScale, @@ -1907,7 +1903,7 @@ void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman, pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); sk_sp<SkImageFilterLight> transformedLight( lighting.light()->transform(lighting.filterMatrix())); - fDomain.setData(pdman, lighting.domain(), texture->origin()); + fDomain.setData(pdman, lighting.domain(), texture); fLight->setData(pdman, transformedLight.get()); } diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index 24086197ea..e1627f08a7 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -257,8 +257,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU( outputProperties.colorSpace()); bgFP = GrTextureDomainEffect::Make( backgroundTex.get(), std::move(bgXform), backgroundMatrix, - GrTextureDomain::MakeTexelDomain(backgroundTex.get(), - background->subset()), + GrTextureDomain::MakeTexelDomain(background->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); } else { @@ -277,8 +276,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU( foregroundFP = GrTextureDomainEffect::Make( foregroundTex.get(), std::move(fgXform), foregroundMatrix, - GrTextureDomain::MakeTexelDomain(foregroundTex.get(), - foreground->subset()), + GrTextureDomain::MakeTexelDomain(foreground->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index 7123a66415..37272be4c9 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -84,8 +84,8 @@ sk_sp<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor( SkRect domain; DomainMode domainMode = DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, - texture->width(), texture->height(), nullptr, fmForDetermineDomain, - &domain); + texture->width(), texture->height(), + nullptr, fmForDetermineDomain, &domain); SkASSERT(kTightCopy_DomainMode != domainMode); SkMatrix normalizedTextureMatrix = textureMatrix; normalizedTextureMatrix.postIDiv(texture->width(), texture->height()); diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp index 8b64feaed3..d75aff6e3c 100644 --- a/src/gpu/GrTextureProducer.cpp +++ b/src/gpu/GrTextureProducer.cpp @@ -30,20 +30,13 @@ GrTexture* GrTextureProducer::CopyOnGpu(GrTexture* inputTexture, const SkIRect* GrPaint paint; paint.setGammaCorrect(true); - SkScalar sx SK_INIT_TO_AVOID_WARNING; - SkScalar sy SK_INIT_TO_AVOID_WARNING; - if (subset) { - sx = 1.f / inputTexture->width(); - sy = 1.f / inputTexture->height(); - } - if (copyParams.fFilter != GrSamplerParams::kNone_FilterMode && subset && (subset->width() != copyParams.fWidth || subset->height() != copyParams.fHeight)) { SkRect domain; - domain.fLeft = (subset->fLeft + 0.5f) * sx; - domain.fTop = (subset->fTop + 0.5f)* sy; - domain.fRight = (subset->fRight - 0.5f) * sx; - domain.fBottom = (subset->fBottom - 0.5f) * sy; + domain.fLeft = subset->fLeft + 0.5f; + domain.fTop = subset->fTop + 0.5f; + domain.fRight = subset->fRight - 0.5f; + domain.fBottom = subset->fBottom - 0.5f; // This would cause us to read values from outside the subset. Surely, the caller knows // better! SkASSERT(copyParams.fFilter != GrSamplerParams::kMipMap_FilterMode); @@ -59,6 +52,9 @@ GrTexture* GrTextureProducer::CopyOnGpu(GrTexture* inputTexture, const SkIRect* SkRect localRect; if (subset) { + SkScalar sx = SK_Scalar1 / inputTexture->width(); + SkScalar sy = SK_Scalar1 / inputTexture->height(); + localRect = SkRect::Make(*subset); localRect.fLeft *= sx; localRect.fTop *= sy; @@ -149,10 +145,7 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( // Unless we know the amount of outset and the texture matrix we have to conservatively enforce // the domain. if (restrictFilterToRect) { - domainRect->fLeft = constraintRect.fLeft + kDomainInset; - domainRect->fTop = constraintRect.fTop + kDomainInset; - domainRect->fRight = constraintRect.fRight - kDomainInset; - domainRect->fBottom = constraintRect.fBottom - kDomainInset; + *domainRect = constraintRect.makeInset(kDomainInset, kDomainInset); } else if (textureContentArea) { // If we got here then: there is a textureContentArea, the coords are limited to the // constraint rect, and we're allowed to filter across the constraint rect boundary. So @@ -213,10 +206,6 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( if (domainRect->fTop > domainRect->fBottom) { domainRect->fTop = domainRect->fBottom = SkScalarAve(domainRect->fTop, domainRect->fBottom); } - domainRect->fLeft /= texW; - domainRect->fTop /= texH; - domainRect->fRight /= texW; - domainRect->fBottom /= texH; return kDomain_DomainMode; } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index b08224135b..2230100f4d 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1066,16 +1066,16 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, // Use a constrained texture domain to avoid color bleeding SkRect domain; if (srcRect.width() > SK_Scalar1) { - domain.fLeft = (srcRect.fLeft + 0.5f) * iw; - domain.fRight = (srcRect.fRight - 0.5f) * iw; + domain.fLeft = srcRect.fLeft + 0.5f; + domain.fRight = srcRect.fRight - 0.5f; } else { - domain.fLeft = domain.fRight = srcRect.centerX() * iw; + domain.fLeft = domain.fRight = srcRect.centerX(); } if (srcRect.height() > SK_Scalar1) { - domain.fTop = (srcRect.fTop + 0.5f) * ih; - domain.fBottom = (srcRect.fBottom - 0.5f) * ih; + domain.fTop = srcRect.fTop + 0.5f; + domain.fBottom = srcRect.fBottom - 0.5f; } else { - domain.fTop = domain.fBottom = srcRect.centerY() * ih; + domain.fTop = domain.fBottom = srcRect.centerY(); } if (bicubic) { fp = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), texMatrix, diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp index 9d8e728efc..50a2a5d3e4 100644 --- a/src/gpu/effects/GrBicubicEffect.cpp +++ b/src/gpu/effects/GrBicubicEffect.cpp @@ -124,7 +124,7 @@ void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, imageIncrement[0] = 1.0f / texture->width(); imageIncrement[1] = 1.0f / texture->height(); pdman.set2fv(fImageIncrementUni, 1, imageIncrement); - fDomain.setData(pdman, bicubicEffect.domain(), texture->origin()); + fDomain.setData(pdman, bicubicEffect.domain(), texture); if (SkToBool(bicubicEffect.colorSpaceXform())) { pdman.setSkMatrix44(fColorSpaceXformUni, bicubicEffect.colorSpaceXform()->srcToDst()); } @@ -146,7 +146,7 @@ GrBicubicEffect::GrBicubicEffect(GrTexture* texture, const SkRect& domain) : INHERITED(texture, std::move(colorSpaceXform), matrix, GrSamplerParams(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode)) - , fDomain(domain, GrTextureDomain::kClamp_Mode) { + , fDomain(texture, domain, GrTextureDomain::kClamp_Mode) { this->initClassID<GrBicubicEffect>(); } diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp index 96f7014284..8b98d0b32f 100644 --- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp +++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp @@ -144,7 +144,7 @@ void GrGLMatrixConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdma pdman.set4fv(fKernelUni, arrayCount, conv.kernel()); pdman.set1f(fGainUni, conv.gain()); pdman.set1f(fBiasUni, conv.bias()); - fDomain.setData(pdman, conv.domain(), texture->origin()); + fDomain.setData(pdman, conv.domain(), texture); } GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, @@ -161,7 +161,7 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, fGain(SkScalarToFloat(gain)), fBias(SkScalarToFloat(bias) / 255.0f), fConvolveAlpha(convolveAlpha), - fDomain(GrTextureDomain::MakeTexelDomainForMode(texture, bounds, tileMode), tileMode) { + fDomain(texture, GrTextureDomain::MakeTexelDomainForMode(bounds, tileMode), tileMode) { this->initClassID<GrMatrixConvolutionEffect>(); for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) { fKernel[i] = SkScalarToFloat(kernel[i]); diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index c6ff9f73e4..d6872e1c2e 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -17,29 +17,41 @@ #include "glsl/GrGLSLShaderBuilder.h" #include "glsl/GrGLSLUniformHandler.h" -GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) - : fIndex(index) { +static bool can_ignore_rect(GrTexture* tex, const SkRect& domain) { + // This logic is relying on the instantiated size of 'tex'. In the deferred world it + // will have to change so this logic only fires for kExact texture proxies. This shouldn't + // change the actual behavior of Ganesh since shaders shouldn't be accessing pixels outside + // of the content rectangle. + const SkIRect kFullRect = SkIRect::MakeWH(tex->width(), tex->height()); + + return domain.contains(kFullRect); +} - static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; - if (domain.contains(kFullRect) && kClamp_Mode == mode) { - fMode = kIgnore_Mode; - } else { - fMode = mode; +GrTextureDomain::GrTextureDomain(GrTexture* tex, const SkRect& domain, Mode mode, int index) + : fMode(mode), fIndex(index) { + + if (kIgnore_Mode == fMode) { + return; } - if (fMode != kIgnore_Mode) { - // We don't currently handle domains that are empty or don't intersect the texture. - // It is OK if the domain rect is a line or point, but it should not be inverted. We do not - // handle rects that do not intersect the [0..1]x[0..1] rect. - SkASSERT(domain.fLeft <= domain.fRight); - SkASSERT(domain.fTop <= domain.fBottom); - fDomain.fLeft = SkScalarPin(domain.fLeft, kFullRect.fLeft, kFullRect.fRight); - fDomain.fRight = SkScalarPin(domain.fRight, kFullRect.fLeft, kFullRect.fRight); - fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBottom); - fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect.fBottom); - SkASSERT(fDomain.fLeft <= fDomain.fRight); - SkASSERT(fDomain.fTop <= fDomain.fBottom); + if (kClamp_Mode == mode && can_ignore_rect(tex, domain)) { + fMode = kIgnore_Mode; + return; } + + const SkRect kFullRect = SkRect::MakeIWH(tex->width(), tex->height()); + + // We don't currently handle domains that are empty or don't intersect the texture. + // It is OK if the domain rect is a line or point, but it should not be inverted. We do not + // handle rects that do not intersect the [0..1]x[0..1] rect. + SkASSERT(domain.fLeft <= domain.fRight); + SkASSERT(domain.fTop <= domain.fBottom); + fDomain.fLeft = SkScalarPin(domain.fLeft, 0.0f, kFullRect.fRight); + fDomain.fRight = SkScalarPin(domain.fRight, fDomain.fLeft, kFullRect.fRight); + fDomain.fTop = SkScalarPin(domain.fTop, 0.0f, kFullRect.fBottom); + fDomain.fBottom = SkScalarPin(domain.fBottom, fDomain.fTop, kFullRect.fBottom); + SkASSERT(fDomain.fLeft <= fDomain.fRight); + SkASSERT(fDomain.fTop <= fDomain.fBottom); } ////////////////////////////////////////////////////////////////////////////// @@ -145,17 +157,26 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder, void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomain& textureDomain, - GrSurfaceOrigin textureOrigin) { + GrTexture* tex) { SkASSERT(textureDomain.mode() == fMode); if (kIgnore_Mode != textureDomain.mode()) { + SkScalar wInv = SK_Scalar1 / tex->width(); + SkScalar hInv = SK_Scalar1 / tex->height(); + float values[kPrevDomainCount] = { - SkScalarToFloat(textureDomain.domain().left()), - SkScalarToFloat(textureDomain.domain().top()), - SkScalarToFloat(textureDomain.domain().right()), - SkScalarToFloat(textureDomain.domain().bottom()) + SkScalarToFloat(textureDomain.domain().fLeft * wInv), + SkScalarToFloat(textureDomain.domain().fTop * hInv), + SkScalarToFloat(textureDomain.domain().fRight * wInv), + SkScalarToFloat(textureDomain.domain().fBottom * hInv) }; + + SkASSERT(values[0] >= 0.0f && values[0] <= 1.0f); + SkASSERT(values[1] >= 0.0f && values[1] <= 1.0f); + SkASSERT(values[2] >= 0.0f && values[2] <= 1.0f); + SkASSERT(values[3] >= 0.0f && values[3] <= 1.0f); + // vertical flip if necessary - if (kBottomLeft_GrSurfaceOrigin == textureOrigin) { + if (kBottomLeft_GrSurfaceOrigin == tex->origin()) { values[1] = 1.0f - values[1]; values[3] = 1.0f - values[3]; // The top and bottom were just flipped, so correct the ordering @@ -177,9 +198,8 @@ sk_sp<GrFragmentProcessor> GrTextureDomainEffect::Make(GrTexture* texture, const SkRect& domain, GrTextureDomain::Mode mode, GrSamplerParams::FilterMode filterMode) { - static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; if (GrTextureDomain::kIgnore_Mode == mode || - (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { + (GrTextureDomain::kClamp_Mode == mode && can_ignore_rect(texture, domain))) { return GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXform), matrix, filterMode); } else { return sk_sp<GrFragmentProcessor>( @@ -195,7 +215,7 @@ GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, GrTextureDomain::Mode mode, GrSamplerParams::FilterMode filterMode) : GrSingleTextureEffect(texture, std::move(colorSpaceXform), matrix, filterMode) - , fTextureDomain(domain, mode) { + , fTextureDomain(texture, domain, mode) { SkASSERT(mode != GrTextureDomain::kRepeat_Mode || filterMode == GrSamplerParams::kNone_FilterMode); this->initClassID<GrTextureDomainEffect>(); @@ -235,7 +255,7 @@ GrGLSLFragmentProcessor* GrTextureDomainEffect::onCreateGLSLInstance() const { void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& fp) override { const GrTextureDomainEffect& tde = fp.cast<GrTextureDomainEffect>(); const GrTextureDomain& domain = tde.fTextureDomain; - fGLDomain.setData(pdman, domain, tde.textureSampler(0).texture()->origin()); + fGLDomain.setData(pdman, domain, tde.textureSampler(0).texture()); if (SkToBool(tde.colorSpaceXform())) { pdman.setSkMatrix44(fColorSpaceXformUni, tde.colorSpaceXform()->srcToDst()); } @@ -273,18 +293,19 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrTextureDomainEffect); sk_sp<GrFragmentProcessor> GrTextureDomainEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; + GrTexture* tex = d->fTextures[texIdx]; SkRect domain; - domain.fLeft = d->fRandom->nextUScalar1(); - domain.fRight = d->fRandom->nextRangeScalar(domain.fLeft, SK_Scalar1); - domain.fTop = d->fRandom->nextUScalar1(); - domain.fBottom = d->fRandom->nextRangeScalar(domain.fTop, SK_Scalar1); + domain.fLeft = d->fRandom->nextRangeScalar(0, tex->width()); + domain.fRight = d->fRandom->nextRangeScalar(domain.fLeft, tex->width()); + domain.fTop = d->fRandom->nextRangeScalar(0, tex->height()); + domain.fBottom = d->fRandom->nextRangeScalar(domain.fTop, tex->height()); GrTextureDomain::Mode mode = (GrTextureDomain::Mode) d->fRandom->nextULessThan(GrTextureDomain::kModeCount); const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom); bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool() : false; auto colorSpaceXform = GrTest::TestColorXform(d->fRandom); return GrTextureDomainEffect::Make( - d->fTextures[texIdx], + tex, colorSpaceXform, matrix, domain, @@ -303,7 +324,7 @@ sk_sp<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::Make(GrTe GrDeviceSpaceTextureDecalFragmentProcessor::GrDeviceSpaceTextureDecalFragmentProcessor( GrTexture* texture, const SkIRect& subset, const SkIPoint& deviceSpaceOffset) : fTextureSampler(texture, GrSamplerParams::ClampNoFilter()) - , fTextureDomain(GrTextureDomain::MakeTexelDomain(texture, subset), + , fTextureDomain(texture, GrTextureDomain::MakeTexelDomain(subset), GrTextureDomain::kDecal_Mode) { this->addTextureSampler(&fTextureSampler); fDeviceSpaceOffset.fX = deviceSpaceOffset.fX - subset.fLeft; @@ -342,7 +363,7 @@ GrGLSLFragmentProcessor* GrDeviceSpaceTextureDecalFragmentProcessor::onCreateGLS const GrDeviceSpaceTextureDecalFragmentProcessor& dstdfp = fp.cast<GrDeviceSpaceTextureDecalFragmentProcessor>(); GrTexture* texture = dstdfp.textureSampler(0).texture(); - fGLDomain.setData(pdman, dstdfp.fTextureDomain, texture->origin()); + fGLDomain.setData(pdman, dstdfp.fTextureDomain, texture); float iw = 1.f / texture->width(); float ih = 1.f / texture->height(); float scaleAndTransData[4] = { diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h index 72204b1f8e..66bd2201e3 100644 --- a/src/gpu/effects/GrTextureDomain.h +++ b/src/gpu/effects/GrTextureDomain.h @@ -44,8 +44,7 @@ public: static const int kModeCount = kLastMode + 1; static const GrTextureDomain& IgnoredDomain() { - static const SkRect gDummyRect = {0, 0, 0, 0}; - static const GrTextureDomain gDomain(gDummyRect, kIgnore_Mode); + static const GrTextureDomain gDomain(nullptr, SkRect::MakeEmpty(), kIgnore_Mode); return gDomain; } @@ -53,36 +52,22 @@ public: * @param index Pass a value >= 0 if using multiple texture domains in the same effect. * It is used to keep inserted variables from causing name collisions. */ - GrTextureDomain(const SkRect& domain, Mode, int index = -1); + GrTextureDomain(GrTexture*, const SkRect& domain, Mode, int index = -1); const SkRect& domain() const { return fDomain; } Mode mode() const { return fMode; } /* Computes a domain that bounds all the texels in texelRect. Note that with bilerp enabled texels neighboring the domain may be read. */ - static const SkRect MakeTexelDomain(const GrTexture* texture, const SkIRect& texelRect) { - SkScalar wInv = SK_Scalar1 / texture->width(); - SkScalar hInv = SK_Scalar1 / texture->height(); - SkRect result = { - texelRect.fLeft * wInv, - texelRect.fTop * hInv, - texelRect.fRight * wInv, - texelRect.fBottom * hInv - }; - return result; + static const SkRect MakeTexelDomain(const SkIRect& texelRect) { + return SkRect::Make(texelRect); } - static const SkRect MakeTexelDomainForMode(const GrTexture* texture, const SkIRect& texelRect, Mode mode) { + static const SkRect MakeTexelDomainForMode(const SkIRect& texelRect, Mode mode) { // For Clamp mode, inset by half a texel. - SkScalar wInv = SK_Scalar1 / texture->width(); - SkScalar hInv = SK_Scalar1 / texture->height(); SkScalar inset = (mode == kClamp_Mode && !texelRect.isEmpty()) ? SK_ScalarHalf : 0; - return SkRect::MakeLTRB( - (texelRect.fLeft + inset) * wInv, - (texelRect.fTop + inset) * hInv, - (texelRect.fRight - inset) * wInv, - (texelRect.fBottom - inset) * hInv - ); + return SkRect::MakeLTRB(texelRect.fLeft + inset, texelRect.fTop + inset, + texelRect.fRight - inset, texelRect.fBottom - inset); } bool operator==(const GrTextureDomain& that) const { @@ -130,7 +115,7 @@ public: * origin. */ void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomain& textureDomain, - GrSurfaceOrigin textureOrigin); + GrTexture* texure); enum { kDomainKeyBits = 2, // See DomainKey(). @@ -157,8 +142,6 @@ protected: Mode fMode; SkRect fDomain; int fIndex; - - typedef GrSingleTextureEffect INHERITED; }; /** |