diff options
author | Brian Osman <brianosman@google.com> | 2017-04-03 16:36:58 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-04 13:19:18 +0000 |
commit | 5869ea99e437aec35d28a153079c37fd2b6def44 (patch) | |
tree | bb13198ce47b72de67032cefaf9c25cb84987857 | |
parent | 8540acc197f982860d1c35c61df27e7ac412b45c (diff) |
Fully remove coord transform precision code
Coord transforms are always computed and interpolated at high precision.
Bug: skia:
Change-Id: I5f7eadc2080df8ad5cbb080835c0dba09c59e63e
Reviewed-on: https://skia-review.googlesource.com/11180
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r-- | include/gpu/GrCoordTransform.h | 38 | ||||
-rw-r--r-- | src/effects/GrAlphaThresholdFragmentProcessor.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 5 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 5 | ||||
-rw-r--r-- | src/gpu/GrCoordTransform.cpp | 50 | ||||
-rw-r--r-- | src/gpu/GrPrimitiveProcessor.cpp | 19 | ||||
-rw-r--r-- | src/gpu/effects/GrSingleTextureEffect.cpp | 6 | ||||
-rw-r--r-- | src/gpu/effects/GrYUVEffect.cpp | 8 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLGeometryProcessor.cpp | 3 |
9 files changed, 33 insertions, 107 deletions
diff --git a/include/gpu/GrCoordTransform.h b/include/gpu/GrCoordTransform.h index 5725a69433..54c21b7472 100644 --- a/include/gpu/GrCoordTransform.h +++ b/include/gpu/GrCoordTransform.h @@ -8,12 +8,10 @@ #ifndef GrCoordTransform_DEFINED #define GrCoordTransform_DEFINED -#include "GrProcessor.h" #include "SkMatrix.h" #include "GrTexture.h" -#include "GrTypes.h" -#include "GrShaderVar.h" +class GrResourceProvider; class GrTextureProxy; /** @@ -25,52 +23,47 @@ public: GrCoordTransform() : fTexture(nullptr) , fNormalize(false) - , fReverseY(false) - , fPrecision(kDefault_GrSLPrecision) { + , fReverseY(false) { SkDEBUGCODE(fInProcessor = false); } /** - * Create a transformation that maps [0, 1] to a proxy's boundaries. The precision is inferred - * from the proxy size and filter. The proxy origin also implies whether a y-reversal should - * be performed. + * Create a transformation that maps [0, 1] to a proxy's boundaries. The proxy origin also + * implies whether a y-reversal should be performed. */ - GrCoordTransform(GrResourceProvider* resourceProvider, GrTextureProxy* proxy, - GrSamplerParams::FilterMode filter) { + GrCoordTransform(GrResourceProvider* resourceProvider, GrTextureProxy* proxy) { SkASSERT(proxy); SkDEBUGCODE(fInProcessor = false); - this->reset(resourceProvider, SkMatrix::I(), proxy, filter); + this->reset(resourceProvider, SkMatrix::I(), proxy); } /** - * Create a transformation from a matrix. The precision is inferred from the proxy size and - * filter. The proxy origin also implies whether a y-reversal should be performed. + * Create a transformation from a matrix. The proxy origin also implies whether a y-reversal + * should be performed. */ GrCoordTransform(GrResourceProvider* resourceProvider, const SkMatrix& m, - GrTextureProxy* proxy, GrSamplerParams::FilterMode filter) { + GrTextureProxy* proxy) { SkASSERT(proxy); SkDEBUGCODE(fInProcessor = false); - this->reset(resourceProvider, m, proxy, filter); + this->reset(resourceProvider, m, proxy); } /** * Create a transformation that applies the matrix to a coord set. */ - GrCoordTransform(const SkMatrix& m, GrSLPrecision precision = kDefault_GrSLPrecision) { + GrCoordTransform(const SkMatrix& m) { SkDEBUGCODE(fInProcessor = false); - this->reset(m, precision); + this->reset(m); } - void reset(GrResourceProvider*, const SkMatrix&, GrTextureProxy*, - GrSamplerParams::FilterMode filter, bool normalize = true); + void reset(GrResourceProvider*, const SkMatrix&, GrTextureProxy*, bool normalize = true); - void reset(const SkMatrix& m, GrSLPrecision precision = kDefault_GrSLPrecision) { + void reset(const SkMatrix& m) { SkASSERT(!fInProcessor); fMatrix = m; fTexture = nullptr; fNormalize = false; fReverseY = false; - fPrecision = precision; } GrCoordTransform& operator= (const GrCoordTransform& that) { @@ -79,7 +72,6 @@ public: fTexture = that.fTexture; fNormalize = that.fNormalize; fReverseY = that.fReverseY; - fPrecision = that.fPrecision; return *this; } @@ -112,7 +104,6 @@ public: const GrTexture* texture() const { return fTexture; } bool normalize() const { return fNormalize; } bool reverseY() const { return fReverseY; } - GrSLPrecision precision() const { return kHigh_GrSLPrecision; } private: // The textures' effect is to optionally normalize the final matrix, so a blind @@ -124,7 +115,6 @@ private: const GrTexture* fTexture; bool fNormalize; bool fReverseY; - GrSLPrecision fPrecision; typedef SkNoncopyable INHERITED; #ifdef SK_DEBUG diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.cpp b/src/effects/GrAlphaThresholdFragmentProcessor.cpp index b4ad0ccd2f..be890c48db 100644 --- a/src/effects/GrAlphaThresholdFragmentProcessor.cpp +++ b/src/effects/GrAlphaThresholdFragmentProcessor.cpp @@ -37,15 +37,13 @@ GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor( : INHERITED(OptFlags(outerThreshold)) , fInnerThreshold(innerThreshold) , fOuterThreshold(outerThreshold) - , fImageCoordTransform(resourceProvider, SkMatrix::I(), proxy.get(), - GrSamplerParams::kNone_FilterMode) + , fImageCoordTransform(resourceProvider, SkMatrix::I(), proxy.get()) , fImageTextureSampler(resourceProvider, std::move(proxy)) , fColorSpaceXform(std::move(colorSpaceXform)) , fMaskCoordTransform( resourceProvider, SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y())), - maskProxy.get(), - GrSamplerParams::kNone_FilterMode) + maskProxy.get()) , fMaskTextureSampler(resourceProvider, maskProxy) { this->initClassID<GrAlphaThresholdFragmentProcessor>(); this->addCoordTransform(&fImageCoordTransform); diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 9bd159d40b..bdf9cd5160 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -496,10 +496,9 @@ GrDisplacementMapEffect::GrDisplacementMapEffect( const SkISize& colorDimensions) : INHERITED(GrPixelConfigIsOpaque(color->config()) ? kPreservesOpaqueInput_OptimizationFlag : kNone_OptimizationFlags) - , fDisplacementTransform(resourceProvider, offsetMatrix, displacement.get(), - GrSamplerParams::kNone_FilterMode) + , fDisplacementTransform(resourceProvider, offsetMatrix, displacement.get()) , fDisplacementSampler(resourceProvider, displacement) - , fColorTransform(resourceProvider, color.get(), GrSamplerParams::kNone_FilterMode) + , fColorTransform(resourceProvider, color.get()) , fDomain(color.get(), GrTextureDomain::MakeTexelDomain(SkIRect::MakeSize(colorDimensions)), GrTextureDomain::kDecal_Mode) , fColorSampler(resourceProvider, color) diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index be60dee15e..b178467f9c 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -1696,8 +1696,7 @@ GrGradientEffect::GrGradientEffect(const CreateArgs& args, bool isOpaque) fYCoord = fAtlas->getYOffset(fRow)+SK_ScalarHalf*fAtlas->getNormalizedTexelHeight(); // This is 1/2 places where auto-normalization is disabled fCoordTransform.reset(args.fContext->resourceProvider(), *args.fMatrix, - fAtlas->asTextureProxyRef().get(), - params.filterMode(), false); + fAtlas->asTextureProxyRef().get(), false); fTextureSampler.reset(args.fContext->resourceProvider(), fAtlas->asTextureProxyRef(), params); } else { @@ -1716,7 +1715,7 @@ GrGradientEffect::GrGradientEffect(const CreateArgs& args, bool isOpaque) } // This is 2/2 places where auto-normalization is disabled fCoordTransform.reset(args.fContext->resourceProvider(), *args.fMatrix, - proxy.get(), params.filterMode(), false); + proxy.get(), false); fTextureSampler.reset(args.fContext->resourceProvider(), std::move(proxy), params); fYCoord = SK_ScalarHalf; diff --git a/src/gpu/GrCoordTransform.cpp b/src/gpu/GrCoordTransform.cpp index b22f3258fc..79d9e98b76 100644 --- a/src/gpu/GrCoordTransform.cpp +++ b/src/gpu/GrCoordTransform.cpp @@ -6,53 +6,11 @@ */ #include "GrCoordTransform.h" -#include "GrCaps.h" -#include "GrContext.h" -#include "GrGpu.h" #include "GrResourceProvider.h" #include "GrTextureProxy.h" -static GrSLPrecision compute_precision(const GrShaderCaps* caps, - int width, int height, - GrSamplerParams::FilterMode filter) { - // Always start at kDefault. Then if precisions differ we see if the precision needs to be - // increased. Our rule is that we want at least 4 subpixel values in the representation for - // coords between 0 to 1 when bi- or tri-lerping and 1 value when nearest filtering. Note that - // this still might not be enough when drawing with repeat or mirror-repeat modes but that case - // can be arbitrarily bad. - int subPixelThresh = filter > GrSamplerParams::kNone_FilterMode ? 4 : 1; - GrSLPrecision precision = kDefault_GrSLPrecision; - if (caps) { - if (caps->floatPrecisionVaries()) { - int maxD = SkTMax(width, height); - const GrShaderCaps::PrecisionInfo* info; - info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, precision); - do { - SkASSERT(info->supported()); - // Make sure there is at least 2 bits of subpixel precision in the range of - // texture coords from 0.5 to 1.0. - if ((2 << info->fBits) / maxD > subPixelThresh) { - break; - } - if (kHigh_GrSLPrecision == precision) { - break; - } - GrSLPrecision nextP = static_cast<GrSLPrecision>(precision + 1); - info = &caps->getFloatShaderPrecisionInfo(kFragment_GrShaderType, nextP); - if (!info->supported()) { - break; - } - precision = nextP; - } while (true); - } - } - - return precision; -} - void GrCoordTransform::reset(GrResourceProvider* resourceProvider, const SkMatrix& m, - GrTextureProxy* proxy, - GrSamplerParams::FilterMode filter, bool normalize) { + GrTextureProxy* proxy, bool normalize) { SkASSERT(proxy); SkASSERT(!fInProcessor); @@ -63,10 +21,4 @@ void GrCoordTransform::reset(GrResourceProvider* resourceProvider, const SkMatri fTexture = proxy->instantiate(resourceProvider); fNormalize = normalize; fReverseY = kBottomLeft_GrSurfaceOrigin == proxy->origin(); - - const GrCaps* caps = resourceProvider->caps(); - fPrecision = compute_precision(caps->shaderCaps(), - proxy->worstCaseWidth(*caps), - proxy->worstCaseHeight(*caps), filter); } - diff --git a/src/gpu/GrPrimitiveProcessor.cpp b/src/gpu/GrPrimitiveProcessor.cpp index 2aaaa0474f..b981977af3 100644 --- a/src/gpu/GrPrimitiveProcessor.cpp +++ b/src/gpu/GrPrimitiveProcessor.cpp @@ -10,23 +10,15 @@ #include "GrCoordTransform.h" /** - * The key for an individual coord transform is made up of a matrix type, a precision, and a bit - * that indicates the source of the input coords. + * The key for an individual coord transform is made up of a matrix type, and a bit that indicates + * the source of the input coords. */ enum { kMatrixTypeKeyBits = 1, - kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, - - kPrecisionBits = 2, - kPrecisionShift = kMatrixTypeKeyBits, - - kPositionCoords_Flag = (1 << (kPrecisionShift + kPrecisionBits)), - - kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 2, + kPositionCoords_Flag = 1 << kMatrixTypeKeyBits, + kTransformKeyBits = kMatrixTypeKeyBits + 1, }; -GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits)); - /** * We specialize the vertex code for each of these matrix types. */ @@ -52,9 +44,6 @@ GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, tr key |= kPositionCoords_Flag; } - GR_STATIC_ASSERT(kGrSLPrecisionCount <= (1 << kPrecisionBits)); - key |= (coordTransform->precision() << kPrecisionShift); - key <<= kTransformKeyBits * t; SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to overlap diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp index ee6a31b019..f5d70003e6 100644 --- a/src/gpu/effects/GrSingleTextureEffect.cpp +++ b/src/gpu/effects/GrSingleTextureEffect.cpp @@ -15,7 +15,7 @@ GrSingleTextureEffect::GrSingleTextureEffect(GrResourceProvider* resourceProvide sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& m) : INHERITED(optFlags) - , fCoordTransform(resourceProvider, m, proxy.get(), GrSamplerParams::kNone_FilterMode) + , fCoordTransform(resourceProvider, m, proxy.get()) , fTextureSampler(resourceProvider, std::move(proxy)) , fColorSpaceXform(std::move(colorSpaceXform)) { this->addCoordTransform(&fCoordTransform); @@ -29,7 +29,7 @@ GrSingleTextureEffect::GrSingleTextureEffect(GrResourceProvider* resourceProvide const SkMatrix& m, GrSamplerParams::FilterMode filterMode) : INHERITED(optFlags) - , fCoordTransform(resourceProvider, m, proxy.get(), filterMode) + , fCoordTransform(resourceProvider, m, proxy.get()) , fTextureSampler(resourceProvider, std::move(proxy), filterMode) , fColorSpaceXform(std::move(colorSpaceXform)) { this->addCoordTransform(&fCoordTransform); @@ -42,7 +42,7 @@ GrSingleTextureEffect::GrSingleTextureEffect(GrResourceProvider* resourceProvide sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& m, const GrSamplerParams& params) : INHERITED(optFlags) - , fCoordTransform(resourceProvider, m, proxy.get(), params.filterMode()) + , fCoordTransform(resourceProvider, m, proxy.get()) , fTextureSampler(resourceProvider, std::move(proxy), params) , fColorSpaceXform(std::move(colorSpaceXform)) { this->addCoordTransform(&fCoordTransform); diff --git a/src/gpu/effects/GrYUVEffect.cpp b/src/gpu/effects/GrYUVEffect.cpp index 14fa8c0524..f43f60a29f 100644 --- a/src/gpu/effects/GrYUVEffect.cpp +++ b/src/gpu/effects/GrYUVEffect.cpp @@ -158,10 +158,9 @@ private: sk_sp<GrTextureProxy> vProxy, const SkMatrix yuvMatrix[3], GrSamplerParams::FilterMode uvFilterMode, SkYUVColorSpace colorSpace, bool nv12) : INHERITED(kPreservesOpaqueInput_OptimizationFlag) - , fYTransform(resourceProvider, yuvMatrix[0], yProxy.get(), - GrSamplerParams::kNone_FilterMode) + , fYTransform(resourceProvider, yuvMatrix[0], yProxy.get()) , fYSampler(resourceProvider, std::move(yProxy)) - , fUTransform(resourceProvider, yuvMatrix[1], uProxy.get(), uvFilterMode) + , fUTransform(resourceProvider, yuvMatrix[1], uProxy.get()) , fUSampler(resourceProvider, std::move(uProxy), uvFilterMode) , fVSampler(resourceProvider, vProxy, uvFilterMode) , fColorSpace(colorSpace) @@ -172,8 +171,7 @@ private: this->addCoordTransform(&fUTransform); this->addTextureSampler(&fUSampler); if (!fNV12) { - fVTransform = GrCoordTransform(resourceProvider, yuvMatrix[2], vProxy.get(), - uvFilterMode); + fVTransform = GrCoordTransform(resourceProvider, yuvMatrix[2], vProxy.get()); this->addCoordTransform(&fVTransform); this->addTextureSampler(&fVSampler); } diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp index f13024878f..9dd1cba418 100644 --- a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp +++ b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp @@ -41,7 +41,8 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb, varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSLType : kVec2f_GrSLType; - GrSLPrecision precision = coordTransform->precision(); + // Coord transforms are always handled at high precision + const GrSLPrecision precision = kHigh_GrSLPrecision; const char* uniName; |