aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-01-20 12:44:06 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-20 18:18:18 +0000
commit67c18d6b5188a0497f6912a73d964c763d2f8f84 (patch)
treed32888c6b13589c2718fc6673f29acf2bb546c38
parent41398f430dc501d450e04540a83b6aa5baf87cd7 (diff)
Continue making Ganesh use absolute texture coordinates - take 2
The idea here is that the GrCoordTransform will actually hold a GrTextureProxy (rather than a GrTexture) and then, in GrGLSLPrimitiveProcessor::GetTransformMatrix, use the instantiated width & height (when uploading the transform matrix) Relanding of: https://skia-review.googlesource.com/c/6977/ Change-Id: Ibc9b9e354f7fc23b1a6e6e4fe7c9fe3cef771c02 Reviewed-on: https://skia-review.googlesource.com/7265 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp8
-rw-r--r--gm/image_pict.cpp3
-rw-r--r--gm/texdata.cpp5
-rw-r--r--gm/texturedomaineffect.cpp11
-rw-r--r--gm/yuvtorgbeffect.cpp12
-rw-r--r--include/gpu/GrCoordTransform.h64
-rw-r--r--include/gpu/SkGr.h14
-rw-r--r--src/core/SkGpuBlurUtils.cpp15
-rw-r--r--src/core/SkImageCacherator.cpp10
-rw-r--r--src/core/SkImageCacherator.h6
-rw-r--r--src/core/SkMatrix.cpp2
-rw-r--r--src/core/SkSpecialImage.cpp8
-rw-r--r--src/effects/GrAlphaThresholdFragmentProcessor.cpp12
-rw-r--r--src/effects/SkArithmeticImageFilter.cpp12
-rw-r--r--src/effects/SkBlurMaskFilter.cpp5
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp5
-rw-r--r--src/effects/SkLightingImageFilter.cpp2
-rw-r--r--src/effects/SkMagnifierImageFilter.cpp3
-rw-r--r--src/effects/SkPerlinNoiseShader.cpp7
-rw-r--r--src/effects/SkTableColorFilter.cpp2
-rw-r--r--src/effects/SkXfermodeImageFilter.cpp12
-rw-r--r--src/effects/gradients/SkGradientShader.cpp10
-rw-r--r--src/gpu/GrBlurUtils.cpp6
-rw-r--r--src/gpu/GrContext.cpp10
-rw-r--r--src/gpu/GrCoordTransform.cpp10
-rw-r--r--src/gpu/GrFragmentProcessor.cpp2
-rw-r--r--src/gpu/GrGpu.cpp6
-rw-r--r--src/gpu/GrGpu.h12
-rw-r--r--src/gpu/GrSWMaskHelper.cpp6
-rw-r--r--src/gpu/GrTextureAdjuster.cpp11
-rw-r--r--src/gpu/GrTextureAdjuster.h3
-rw-r--r--src/gpu/GrTextureMaker.cpp15
-rw-r--r--src/gpu/GrTextureMaker.h6
-rw-r--r--src/gpu/GrTextureProducer.cpp9
-rw-r--r--src/gpu/GrTextureToYUVPlanes.cpp4
-rw-r--r--src/gpu/GrYUVProvider.cpp2
-rw-r--r--src/gpu/SkGpuDevice.cpp25
-rw-r--r--src/gpu/SkGr.cpp9
-rw-r--r--src/gpu/effects/Gr1DKernelEffect.h2
-rw-r--r--src/gpu/effects/GrBicubicEffect.cpp3
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp2
-rw-r--r--src/gpu/effects/GrMatrixConvolutionEffect.cpp2
-rw-r--r--src/gpu/effects/GrYUVEffect.cpp23
-rw-r--r--src/gpu/gl/GrGLGpu.cpp3
-rw-r--r--src/gpu/gl/GrGLGpu.h3
-rw-r--r--src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp5
-rw-r--r--src/image/SkImageShader.cpp12
-rw-r--r--src/image/SkImage_Base.h2
-rw-r--r--src/image/SkImage_Generator.cpp7
-rw-r--r--src/image/SkImage_Gpu.cpp5
-rw-r--r--src/image/SkImage_Gpu.h2
-rw-r--r--src/image/SkImage_Raster.cpp11
-rw-r--r--tests/ImageNewShaderTest.cpp33
-rw-r--r--tests/IntTextureTest.cpp5
-rw-r--r--tests/RectangleTextureTest.cpp6
-rw-r--r--tests/SRGBMipMapTest.cpp2
56 files changed, 248 insertions, 244 deletions
diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
index 6050a5c5c0..95152fadd6 100644
--- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
+++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
@@ -1323,10 +1323,10 @@ sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA
GrSamplerParams::FilterMode::kNone_FilterMode);
sk_sp<GrTexture> permutationsTexture(
GrRefCachedBitmapTexture(args.fContext, paintingData->getImprovedPermutationsBitmap(),
- textureParams));
+ textureParams, nullptr));
sk_sp<GrTexture> gradientTexture(
GrRefCachedBitmapTexture(args.fContext, paintingData->getGradientBitmap(),
- textureParams));
+ textureParams, nullptr));
return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, paintingData,
permutationsTexture.get(),
gradientTexture.get(), m);
@@ -1350,10 +1350,10 @@ sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA
sk_sp<GrTexture> permutationsTexture(
GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBitmap(),
- GrSamplerParams::ClampNoFilter()));
+ GrSamplerParams::ClampNoFilter(), nullptr));
sk_sp<GrTexture> noiseTexture(
GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(),
- GrSamplerParams::ClampNoFilter()));
+ GrSamplerParams::ClampNoFilter(), nullptr));
if ((permutationsTexture) && (noiseTexture)) {
sk_sp<GrFragmentProcessor> inner(
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index 1fdff21e3f..5394f6a656 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -347,7 +347,8 @@ protected:
sk_sp<SkColorSpace> texColorSpace;
sk_sp<GrTexture> texture(
cache->lockAsTexture(canvas->getGrContext(), GrSamplerParams::ClampBilerp(),
- canvas->imageInfo().colorSpace(), &texColorSpace, nullptr));
+ canvas->imageInfo().colorSpace(), &texColorSpace,
+ nullptr, nullptr));
if (!texture) {
// show placeholder if we have no texture
SkPaint paint;
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index 8520d28b12..372ff5dc11 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -97,10 +97,7 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
} else {
vm.reset();
}
- SkMatrix tm;
- tm = vm;
- tm.postIDiv(2*S, 2*S);
- paint.addColorTextureProcessor(texture, nullptr, tm);
+ paint.addColorTextureProcessor(texture, nullptr, vm);
renderTargetContext->drawRect(clip, GrPaint(paint), GrAA::kNo, vm,
SkRect::MakeWH(2 * S, 2 * S));
diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp
index 32042aab84..0bebd8c97d 100644
--- a/gm/texturedomaineffect.cpp
+++ b/gm/texturedomaineffect.cpp
@@ -83,17 +83,16 @@ protected:
}
sk_sp<GrTexture> texture(
- GrRefCachedBitmapTexture(context, fBmp, GrSamplerParams::ClampNoFilter()));
+ GrRefCachedBitmapTexture(context, fBmp, GrSamplerParams::ClampNoFilter(), nullptr));
if (!texture) {
return;
}
SkTArray<SkMatrix> textureMatrices;
- textureMatrices.push_back().setIDiv(texture->width(), texture->height());
- textureMatrices.push_back() = textureMatrices[0];
- textureMatrices.back().postScale(1.5f, 0.85f);
- textureMatrices.push_back() = textureMatrices[0];
- textureMatrices.back().preRotate(45.f, texture->width() / 2.f, texture->height() / 2.f);
+ textureMatrices.push_back() = SkMatrix::I();
+ textureMatrices.push_back() = SkMatrix::MakeScale(1.5f, 0.85f);
+ textureMatrices.push_back();
+ textureMatrices.back().setRotate(45.f, texture->width() / 2.f, texture->height() / 2.f);
const SkIRect texelDomains[] = {
fBmp.bounds(),
diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp
index 8d78f132cf..324446392d 100644
--- a/gm/yuvtorgbeffect.cpp
+++ b/gm/yuvtorgbeffect.cpp
@@ -82,11 +82,11 @@ protected:
sk_sp<GrTexture> texture[3];
texture[0].reset(
- GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp()));
+ GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp(), nullptr));
texture[1].reset(
- GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp()));
+ GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp(), nullptr));
texture[2].reset(
- GrRefCachedBitmapTexture(context, fBmp[2], GrSamplerParams::ClampBilerp()));
+ GrRefCachedBitmapTexture(context, fBmp[2], GrSamplerParams::ClampBilerp(), nullptr));
if (!texture[0] || !texture[1] || !texture[2]) {
return;
@@ -204,11 +204,11 @@ protected:
sk_sp<GrTexture> texture[3];
texture[0].reset(
- GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp()));
+ GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp(), nullptr));
texture[1].reset(
- GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp()));
+ GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp(), nullptr));
texture[2].reset(
- GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp()));
+ GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp(), nullptr));
if (!texture[0] || !texture[1] || !texture[2]) {
return;
diff --git a/include/gpu/GrCoordTransform.h b/include/gpu/GrCoordTransform.h
index 1f1cac7505..5c16c89679 100644
--- a/include/gpu/GrCoordTransform.h
+++ b/include/gpu/GrCoordTransform.h
@@ -20,7 +20,11 @@
*/
class GrCoordTransform : SkNoncopyable {
public:
- GrCoordTransform() { SkDEBUGCODE(fInProcessor = false); }
+ GrCoordTransform()
+ : fTexture(nullptr)
+ , fNormalize(false) {
+ SkDEBUGCODE(fInProcessor = false);
+ }
/**
* Create a transformation that maps [0, 1] to a texture's boundaries. The precision is inferred
@@ -30,7 +34,7 @@ public:
GrCoordTransform(const GrTexture* texture, GrSamplerParams::FilterMode filter) {
SkASSERT(texture);
SkDEBUGCODE(fInProcessor = false);
- this->reset(texture, filter);
+ this->reset(SkMatrix::I(), texture, filter);
}
/**
@@ -52,18 +56,23 @@ public:
this->reset(m, precision);
}
- void reset(const GrTexture* texture, GrSamplerParams::FilterMode filter) {
+ void reset(const SkMatrix&, const GrTexture*, GrSamplerParams::FilterMode filter,
+ bool normalize = true);
+
+ void reset(const SkMatrix& m, GrSLPrecision precision = kDefault_GrSLPrecision) {
SkASSERT(!fInProcessor);
- SkASSERT(texture);
- this->reset(MakeDivByTextureWHMatrix(texture), texture, filter);
+ fMatrix = m;
+ fTexture = nullptr;
+ fNormalize = false;
+ fReverseY = false;
+ fPrecision = precision;
}
- void reset(const SkMatrix&, const GrTexture*, GrSamplerParams::FilterMode filter);
- void reset(const SkMatrix& m, GrSLPrecision precision = kDefault_GrSLPrecision);
-
GrCoordTransform& operator= (const GrCoordTransform& that) {
SkASSERT(!fInProcessor);
fMatrix = that.fMatrix;
+ fTexture = that.fTexture;
+ fNormalize = that.fNormalize;
fReverseY = that.fReverseY;
fPrecision = that.fPrecision;
return *this;
@@ -78,29 +87,38 @@ public:
return &fMatrix;
}
- bool operator==(const GrCoordTransform& that) const {
- return fMatrix.cheapEqualTo(that.fMatrix) &&
- fReverseY == that.fReverseY &&
- fPrecision == that.fPrecision;
+ bool hasSameEffectAs(const GrCoordTransform& that) const {
+ if (fNormalize != that.fNormalize ||
+ fReverseY != that.fReverseY ||
+ fPrecision != that.fPrecision ||
+ !fMatrix.cheapEqualTo(that.fMatrix)) {
+ return false;
+ }
+
+ if (fNormalize) {
+ SkASSERT(fTexture && that.fTexture);
+ return fTexture->width() == that.fTexture->width() &&
+ fTexture->height() == that.fTexture->height();
+ }
+
+ return true;
}
- bool operator!=(const GrCoordTransform& that) const { return !(*this == that); }
-
const SkMatrix& getMatrix() const { return fMatrix; }
+ const GrTexture* texture() const { return fTexture; }
+ bool normalize() const { return fNormalize; }
bool reverseY() const { return fReverseY; }
GrSLPrecision precision() const { return fPrecision; }
- /** Useful for effects that want to insert a texture matrix that is implied by the texture
- dimensions */
- static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) {
- SkASSERT(texture);
- SkMatrix mat;
- (void)mat.setIDiv(texture->width(), texture->height());
- return mat;
- }
-
private:
+ // The textures' effect is to optionally normalize the final matrix, so a blind
+ // equality check could be misleading
+ bool operator==(const GrCoordTransform& that) const;
+ bool operator!=(const GrCoordTransform& that) const;
+
SkMatrix fMatrix;
+ const GrTexture* fTexture;
+ bool fNormalize;
bool fReverseY;
GrSLPrecision fPrecision;
typedef SkNoncopyable INHERITED;
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index e2f09e5ac2..3f72fa134d 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -77,11 +77,17 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) {
////////////////////////////////////////////////////////////////////////////////
/** Returns a texture representing the bitmap that is compatible with the GrSamplerParams. The
- texture is inserted into the cache (unless the bitmap is marked volatile) and can be
- retrieved again via this function. */
-GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&);
+ * texture is inserted into the cache (unless the bitmap is marked volatile) and can be
+ * retrieved again via this function.
+ * The 'scaleAdjust' in/out parameter will be updated to hold any rescaling that needs to be
+ * performed on the absolute texture coordinates (e.g., if the texture is resized out to
+ * the next power of two). It can be null if the caller is sure the bitmap won't be resized.
+ */
+GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&,
+ const GrSamplerParams&, SkScalar scaleAdjust[2]);
-sk_sp<GrTexture> GrMakeCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&);
+sk_sp<GrTexture> GrMakeCachedBitmapTexture(GrContext*, const SkBitmap&,
+ const GrSamplerParams&, SkScalar scaleAdjust[2]);
// TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses).
GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps);
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index b3b523a498..6ac5abe49c 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -262,10 +262,6 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
paint.setGammaCorrect(dstRenderTargetContext->isGammaCorrect());
- // TODO: this matrix relies on the final instantiated size of the texture. This
- // will have to be deferred for TextureProxys
- SkMatrix matrix;
- matrix.setIDiv(srcTexture->width(), srcTexture->height());
SkIRect dstRect(srcRect);
if (srcBounds && i == 1) {
SkRect domain = SkRect::Make(*srcBounds);
@@ -274,7 +270,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
sk_sp<GrFragmentProcessor> fp(GrTextureDomainEffect::Make(
srcTexture.get(),
nullptr,
- matrix,
+ SkMatrix::I(),
domain,
GrTextureDomain::kDecal_Mode,
GrSamplerParams::kBilerp_FilterMode));
@@ -283,7 +279,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcOffset.set(0, 0);
} else {
GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode);
- paint.addColorTextureProcessor(srcTexture.get(), nullptr, matrix, params);
+ paint.addColorTextureProcessor(srcTexture.get(), nullptr, SkMatrix::I(), params);
}
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY);
@@ -369,12 +365,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
return nullptr;
}
- // TODO: this matrix relies on the final instantiated size of the texture. This
- // will have to be deferred for TextureProxys
- SkMatrix matrix;
- matrix.setIDiv(tex->width(), tex->height());
-
- paint.addColorTextureProcessor(tex.get(), nullptr, matrix, params);
+ paint.addColorTextureProcessor(tex.get(), nullptr, SkMatrix::I(), params);
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkIRect dstRect(srcRect);
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index ff3e226417..1556683456 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -606,13 +606,16 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams& params,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace,
- const SkImage* client, SkImage::CachingHint chint) {
+ const SkImage* client,
+ SkScalar scaleAdjust[2],
+ SkImage::CachingHint chint) {
if (!ctx) {
return nullptr;
}
return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, dstColorSpace,
- texColorSpace);
+ texColorSpace,
+ scaleAdjust);
}
#else
@@ -620,7 +623,8 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParam
GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams&,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace,
- const SkImage* client, SkImage::CachingHint) {
+ const SkImage* client,
+ SkScalar scaleAdjust[2], SkImage::CachingHint) {
return nullptr;
}
diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h
index 0e37efa9d3..c5c3e9777a 100644
--- a/src/core/SkImageCacherator.h
+++ b/src/core/SkImageCacherator.h
@@ -59,9 +59,15 @@ public:
* added to the cache on its behalf.
*
* The caller is responsible for calling texture->unref() when they are done.
+ *
+ * The scaleAdjust in/out parameter will return any scale adjustment that needs
+ * to be applied to the absolute texture coordinates in the case where the image
+ * was resized to meet the sampling requirements (e.g., resized out to the next power of 2).
+ * It can be null if the caller knows resizing will not be required.
*/
GrTexture* lockAsTexture(GrContext*, const GrSamplerParams&, SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace, const SkImage* client,
+ SkScalar scaleAdjust[2],
SkImage::CachingHint = SkImage::kAllow_CachingHint);
/**
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index a05ae0a177..390ebe08de 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1038,7 +1038,7 @@ void SkMatrix::Affine_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[]
const SkMatrix::MapPtsProc SkMatrix::gMapPtsProcs[] = {
SkMatrix::Identity_pts, SkMatrix::Trans_pts,
- SkMatrix::Scale_pts, SkMatrix::Scale_pts,
+ SkMatrix::Scale_pts, SkMatrix::Scale_pts,
SkMatrix::Affine_vpts, SkMatrix::Affine_vpts,
SkMatrix::Affine_vpts, SkMatrix::Affine_vpts,
// repeat the persp proc 8 times
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 4f48f7862b..8b2801ebb7 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -103,7 +103,7 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) {
}
sk_sp<GrTexture> resultTex(
- GrRefCachedBitmapTexture(context, bmp, GrSamplerParams::ClampNoFilter()));
+ GrRefCachedBitmapTexture(context, bmp, GrSamplerParams::ClampNoFilter(), nullptr));
if (!resultTex) {
return nullptr;
}
@@ -241,8 +241,8 @@ public:
#if SK_SUPPORT_GPU
sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override {
if (context) {
- return sk_ref_sp(
- GrRefCachedBitmapTexture(context, fBitmap, GrSamplerParams::ClampNoFilter()));
+ return sk_ref_sp(GrRefCachedBitmapTexture(context, fBitmap,
+ GrSamplerParams::ClampNoFilter(), nullptr));
}
return nullptr;
@@ -251,7 +251,7 @@ public:
sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const override {
if (context) {
sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture(
- context, fBitmap, GrSamplerParams::ClampNoFilter())));
+ context, fBitmap, GrSamplerParams::ClampNoFilter(), nullptr)));
sk_sp<GrSurfaceProxy> sProxy = GrSurfaceProxy::MakeWrapped(std::move(tex));
return sk_ref_sp(sProxy->asTextureProxy());
}
diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.cpp b/src/effects/GrAlphaThresholdFragmentProcessor.cpp
index afafe08279..a259607444 100644
--- a/src/effects/GrAlphaThresholdFragmentProcessor.cpp
+++ b/src/effects/GrAlphaThresholdFragmentProcessor.cpp
@@ -32,12 +32,6 @@ sk_sp<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::Make(
bounds));
}
-static SkMatrix make_div_and_translate_matrix(GrTexture* texture, int x, int y) {
- SkMatrix matrix = GrCoordTransform::MakeDivByTextureWHMatrix(texture);
- matrix.preTranslate(SkIntToScalar(x), SkIntToScalar(y));
- return matrix;
-}
-
GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor(
GrTexture* texture,
sk_sp<GrColorSpaceXform> colorSpaceXform,
@@ -47,11 +41,11 @@ GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor(
const SkIRect& bounds)
: fInnerThreshold(innerThreshold)
, fOuterThreshold(outerThreshold)
- , fImageCoordTransform(GrCoordTransform::MakeDivByTextureWHMatrix(texture), texture,
- GrSamplerParams::kNone_FilterMode)
+ , fImageCoordTransform(SkMatrix::I(), texture, GrSamplerParams::kNone_FilterMode)
, fImageTextureSampler(texture)
, fColorSpaceXform(std::move(colorSpaceXform))
- , fMaskCoordTransform(make_div_and_translate_matrix(maskTexture, -bounds.x(), -bounds.y()),
+ , fMaskCoordTransform(SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()),
+ SkIntToScalar(-bounds.y())),
maskTexture,
GrSamplerParams::kNone_FilterMode)
, fMaskTextureSampler(maskTexture) {
diff --git a/src/effects/SkArithmeticImageFilter.cpp b/src/effects/SkArithmeticImageFilter.cpp
index 3e4d48fe65..d33a9dc562 100644
--- a/src/effects/SkArithmeticImageFilter.cpp
+++ b/src/effects/SkArithmeticImageFilter.cpp
@@ -348,10 +348,8 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
sk_sp<GrFragmentProcessor> bgFP;
if (backgroundTex) {
- SkMatrix backgroundMatrix;
- backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height());
- backgroundMatrix.preTranslate(-SkIntToScalar(backgroundOffset.fX),
- -SkIntToScalar(backgroundOffset.fY));
+ SkMatrix backgroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX),
+ -SkIntToScalar(backgroundOffset.fY));
sk_sp<GrColorSpaceXform> bgXform =
GrColorSpaceXform::Make(background->getColorSpace(), outputProperties.colorSpace());
bgFP = GrTextureDomainEffect::Make(
@@ -364,10 +362,8 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
}
if (foregroundTex) {
- SkMatrix foregroundMatrix;
- foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height());
- foregroundMatrix.preTranslate(-SkIntToScalar(foregroundOffset.fX),
- -SkIntToScalar(foregroundOffset.fY));
+ SkMatrix foregroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(foregroundOffset.fX),
+ -SkIntToScalar(foregroundOffset.fY));
sk_sp<GrColorSpaceXform> fgXform =
GrColorSpaceXform::Make(foreground->getColorSpace(), outputProperties.colorSpace());
sk_sp<GrFragmentProcessor> foregroundFP;
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index aff0a32009..b53fc41dea 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -1516,10 +1516,9 @@ sk_sp<GrTextureProxy> SkBlurMaskFilterImpl::filterMaskGPU(GrContext* context,
if (!isNormalBlur) {
GrPaint paint;
- SkMatrix matrix;
- matrix.setIDiv(src->width(), src->height());
// Blend pathTexture over blurTexture.
- paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(src, nullptr, matrix));
+ paint.addCoverageFragmentProcessor(
+ GrSimpleTextureEffect::Make(src, nullptr, SkMatrix::I()));
if (kInner_SkBlurStyle == fBlurStyle) {
// inner: dst = dst * src
paint.setCoverageSetOpXPFactory(SkRegion::kIntersect_Op);
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 28483bd57a..0d3940317f 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -336,9 +336,8 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
return nullptr;
}
- SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displTexture.get());
- offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displOffset.fX),
- SkIntToScalar(colorOffset.fY - displOffset.fY));
+ SkMatrix offsetMatrix = SkMatrix::MakeTrans(SkIntToScalar(colorOffset.fX - displOffset.fX),
+ SkIntToScalar(colorOffset.fY - displOffset.fY));
SkColorSpace* colorSpace = ctx.outputProperties().colorSpace();
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(color->getColorSpace(),
colorSpace);
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 53c85bd864..da4dcb8bdf 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -1702,7 +1702,7 @@ GrLightingEffect::GrLightingEffect(GrTexture* texture,
const SkMatrix& matrix,
BoundaryMode boundaryMode,
const SkIRect* srcBounds)
- : INHERITED(texture, nullptr, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
+ : INHERITED(texture, nullptr, SkMatrix::I())
, fLight(light)
, fSurfaceScale(surfaceScale)
, fFilterMatrix(matrix)
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 2b045322eb..c8b32aee70 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -71,8 +71,7 @@ private:
float yInvZoom,
float xInvInset,
float yInvInset)
- : INHERITED(texture, std::move(colorSpaceXform),
- GrCoordTransform::MakeDivByTextureWHMatrix(texture))
+ : INHERITED(texture, std::move(colorSpaceXform), SkMatrix::I())
, fBounds(bounds)
, fXOffset(xOffset)
, fYOffset(yOffset)
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index dc3d9a690d..90a3531291 100644
--- a/src/effects/SkPerlinNoiseShader.cpp
+++ b/src/effects/SkPerlinNoiseShader.cpp
@@ -515,7 +515,6 @@ public:
bool stitchTiles() const { return fStitchTiles; }
const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency; }
int numOctaves() const { return fNumOctaves; }
- const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); }
private:
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
@@ -546,6 +545,7 @@ private:
GrTexture* permutationsTexture, GrTexture* noiseTexture,
const SkMatrix& matrix)
: fType(type)
+ , fCoordTransform(matrix)
, fNumOctaves(numOctaves)
, fStitchTiles(stitchTiles)
, fPermutationsSampler(permutationsTexture)
@@ -554,7 +554,6 @@ private:
this->initClassID<GrPerlinNoiseEffect>();
this->addTextureSampler(&fPermutationsSampler);
this->addTextureSampler(&fNoiseSampler);
- fCoordTransform.reset(matrix);
this->addCoordTransform(&fCoordTransform);
}
@@ -926,10 +925,10 @@ sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor(const AsFPAr
new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
sk_sp<GrTexture> permutationsTexture(
GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBitmap(),
- GrSamplerParams::ClampNoFilter()));
+ GrSamplerParams::ClampNoFilter(), nullptr));
sk_sp<GrTexture> noiseTexture(
GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(),
- GrSamplerParams::ClampNoFilter()));
+ GrSamplerParams::ClampNoFilter(), nullptr));
SkMatrix m = *args.fViewMatrix;
m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 9c74634f96..6934a3ea56 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -474,7 +474,7 @@ sk_sp<GrFragmentProcessor> ColorTableEffect::Make(GrContext* context, SkBitmap b
if (-1 == row) {
atlas = nullptr;
texture.reset(
- GrRefCachedBitmapTexture(context, bitmap, GrSamplerParams::ClampNoFilter()));
+ GrRefCachedBitmapTexture(context, bitmap, GrSamplerParams::ClampNoFilter(), nullptr));
} else {
texture.reset(SkRef(atlas->getTexture()));
}
diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp
index 7f91df3ab5..c52eebadc6 100644
--- a/src/effects/SkXfermodeImageFilter.cpp
+++ b/src/effects/SkXfermodeImageFilter.cpp
@@ -249,10 +249,8 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
sk_sp<GrFragmentProcessor> bgFP;
if (backgroundTex) {
- SkMatrix backgroundMatrix;
- backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height());
- backgroundMatrix.preTranslate(-SkIntToScalar(backgroundOffset.fX),
- -SkIntToScalar(backgroundOffset.fY));
+ SkMatrix backgroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX),
+ -SkIntToScalar(backgroundOffset.fY));
sk_sp<GrColorSpaceXform> bgXform = GrColorSpaceXform::Make(background->getColorSpace(),
outputProperties.colorSpace());
bgFP = GrTextureDomainEffect::Make(
@@ -266,10 +264,8 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
}
if (foregroundTex) {
- SkMatrix foregroundMatrix;
- foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height());
- foregroundMatrix.preTranslate(-SkIntToScalar(foregroundOffset.fX),
- -SkIntToScalar(foregroundOffset.fY));
+ SkMatrix foregroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(foregroundOffset.fX),
+ -SkIntToScalar(foregroundOffset.fY));
sk_sp<GrColorSpaceXform> fgXform = GrColorSpaceXform::Make(foreground->getColorSpace(),
outputProperties.colorSpace());
sk_sp<GrFragmentProcessor> foregroundFP;
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index ca64cb77e1..b1d3e13a46 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -1659,14 +1659,18 @@ GrGradientEffect::GrGradientEffect(const CreateArgs& args) {
fRow = fAtlas->lockRow(bitmap);
if (-1 != fRow) {
fYCoord = fAtlas->getYOffset(fRow)+SK_ScalarHalf*fAtlas->getNormalizedTexelHeight();
- fCoordTransform.reset(*args.fMatrix, fAtlas->getTexture(), params.filterMode());
+ // This is 1/2 places where auto-normalization is disabled
+ fCoordTransform.reset(*args.fMatrix, fAtlas->getTexture(),
+ params.filterMode(), false);
fTextureSampler.reset(fAtlas->getTexture(), params);
} else {
- sk_sp<GrTexture> texture(GrRefCachedBitmapTexture(args.fContext, bitmap, params));
+ sk_sp<GrTexture> texture(GrRefCachedBitmapTexture(args.fContext, bitmap,
+ params, nullptr));
if (!texture) {
return;
}
- fCoordTransform.reset(*args.fMatrix, texture.get(), params.filterMode());
+ // This is 2/2 places where auto-normalization is disabled
+ fCoordTransform.reset(*args.fMatrix, texture.get(), params.filterMode(), false);
fTextureSampler.reset(texture.get(), params);
fYCoord = SK_ScalarHalf;
}
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 66abadbf98..7a8a252cff 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -47,10 +47,8 @@ static bool draw_mask(GrRenderTargetContext* renderTargetContext,
return false;
}
- SkMatrix matrix;
- matrix.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
- // TODO: this divide relies on the instantiated texture's size!
- matrix.postIDiv(maskTex->width(), maskTex->height());
+ SkMatrix matrix = SkMatrix::MakeTrans(-SkIntToScalar(maskRect.fLeft),
+ -SkIntToScalar(maskRect.fTop));
matrix.preConcat(viewMatrix);
paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(maskTex, nullptr, matrix));
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 5543dff09a..1322e2569a 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -308,10 +308,8 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
if (tempTexture) {
sk_sp<GrFragmentProcessor> fp;
- SkMatrix textureMatrix;
- textureMatrix.setIDiv(tempTexture->width(), tempTexture->height());
if (applyPremulToSrc) {
- fp = this->createUPMToPMEffect(tempTexture.get(), tempDrawInfo.fSwizzle, textureMatrix);
+ fp = this->createUPMToPMEffect(tempTexture.get(), tempDrawInfo.fSwizzle, SkMatrix::I());
// If premultiplying was the only reason for the draw, fall back to a straight write.
if (!fp) {
if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) {
@@ -325,7 +323,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface, SkColorSpace* dstColorSpa
if (!fp) {
fp = GrConfigConversionEffect::Make(tempTexture.get(), tempDrawInfo.fSwizzle,
GrConfigConversionEffect::kNone_PMConversion,
- textureMatrix);
+ SkMatrix::I());
if (!fp) {
return false;
}
@@ -463,9 +461,7 @@ bool GrContext::readSurfacePixels(GrSurface* src, SkColorSpace* srcColorSpace,
tempDrawInfo.fTempSurfaceDesc.fSampleCnt,
tempDrawInfo.fTempSurfaceDesc.fOrigin);
if (tempRTC) {
- SkMatrix textureMatrix;
- textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
- textureMatrix.postIDiv(src->width(), src->height());
+ SkMatrix textureMatrix = SkMatrix::MakeTrans(SkIntToScalar(left), SkIntToScalar(top));
sk_sp<GrFragmentProcessor> fp;
if (unpremul) {
fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fSwizzle,
diff --git a/src/gpu/GrCoordTransform.cpp b/src/gpu/GrCoordTransform.cpp
index 63d91a810f..4afd0efbce 100644
--- a/src/gpu/GrCoordTransform.cpp
+++ b/src/gpu/GrCoordTransform.cpp
@@ -11,11 +11,13 @@
#include "GrGpu.h"
void GrCoordTransform::reset(const SkMatrix& m, const GrTexture* texture,
- GrSamplerParams::FilterMode filter) {
+ GrSamplerParams::FilterMode filter, bool normalize) {
SkASSERT(texture);
SkASSERT(!fInProcessor);
fMatrix = m;
+ fTexture = texture;
+ fNormalize = normalize;
fReverseY = kBottomLeft_GrSurfaceOrigin == texture->origin();
// Always start at kDefault. Then if precisions differ we see if the precision needs to be
@@ -52,9 +54,3 @@ void GrCoordTransform::reset(const SkMatrix& m, const GrTexture* texture,
}
}
-void GrCoordTransform::reset(const SkMatrix& m, GrSLPrecision precision) {
- SkASSERT(!fInProcessor);
- fMatrix = m;
- fReverseY = false;
- fPrecision = precision;
-}
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index eb6a35c4f8..0518966911 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -92,7 +92,7 @@ bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con
}
int count = this->numCoordTransforms();
for (int i = 0; i < count; ++i) {
- if (this->coordTransform(i) != that.coordTransform(i)) {
+ if (!this->coordTransform(i).hasSameEffectAs(that.coordTransform(i))) {
return false;
}
}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 3538b8042f..4880f6c742 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -58,12 +58,16 @@ void GrGpu::disconnect(DisconnectType) {}
////////////////////////////////////////////////////////////////////////////////
bool GrGpu::makeCopyForTextureParams(int width, int height, const GrSamplerParams& textureParams,
- GrTextureProducer::CopyParams* copyParams) const {
+ GrTextureProducer::CopyParams* copyParams,
+ SkScalar scaleAdjust[2]) const {
const GrCaps& caps = *this->caps();
if (textureParams.isTiled() && !caps.npotTextureTileSupport() &&
(!SkIsPow2(width) || !SkIsPow2(height))) {
+ SkASSERT(scaleAdjust);
copyParams->fWidth = GrNextPow2(width);
copyParams->fHeight = GrNextPow2(height);
+ scaleAdjust[0] = ((SkScalar) copyParams->fWidth) / width;
+ scaleAdjust[1] = ((SkScalar) copyParams->fHeight) / height;
switch (textureParams.filterMode()) {
case GrSamplerParams::kNone_FilterMode:
copyParams->fFilter = GrSamplerParams::kNone_FilterMode;
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 39735d2d11..0aed3d2c74 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -473,19 +473,20 @@ public:
// GrSamplerParams. This variation is called when the caller will create a new texture using the
// texture provider from a non-texture src (cpu-backed image, ...).
bool makeCopyForTextureParams(int width, int height, const GrSamplerParams&,
- GrTextureProducer::CopyParams*) const;
+ GrTextureProducer::CopyParams*, SkScalar scaleAdjust[2]) const;
// Like the above but this variation should be called when the caller is not creating the
// original texture but rather was handed the original texture. It adds additional checks
// relevant to original textures that were created external to Skia via
// GrTextureProvider::wrap methods.
bool makeCopyForTextureParams(GrTexture* texture, const GrSamplerParams& params,
- GrTextureProducer::CopyParams* copyParams) const {
+ GrTextureProducer::CopyParams* copyParams,
+ SkScalar scaleAdjust[2]) const {
if (this->makeCopyForTextureParams(texture->width(), texture->height(), params,
- copyParams)) {
+ copyParams, scaleAdjust)) {
return true;
}
- return this->onMakeCopyForTextureParams(texture, params, copyParams);
+ return this->onMakeCopyForTextureParams(texture, params, copyParams, scaleAdjust);
}
// This is only to be used in GL-specific tests.
@@ -549,7 +550,8 @@ private:
virtual gr_instanced::InstancedRendering* onCreateInstancedRendering() = 0;
virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrSamplerParams&,
- GrTextureProducer::CopyParams*) const { return false; }
+ GrTextureProducer::CopyParams*,
+ SkScalar scaleAdjust[2]) const { return false; }
virtual bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight,
size_t rowBytes, GrPixelConfig readConfig, DrawPreference*,
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 2c268990e1..d881888edc 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -172,10 +172,8 @@ void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
// We use device coords to compute the texture coordinates. We take the device coords and apply
// a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
// matrix to normalized coords.
- SkMatrix maskMatrix;
- maskMatrix.setIDiv(texture->width(), texture->height());
- maskMatrix.preTranslate(SkIntToScalar(-textureOriginInDeviceSpace.fX),
- SkIntToScalar(-textureOriginInDeviceSpace.fY));
+ SkMatrix maskMatrix = SkMatrix::MakeTrans(SkIntToScalar(-textureOriginInDeviceSpace.fX),
+ SkIntToScalar(-textureOriginInDeviceSpace.fY));
maskMatrix.preConcat(viewMatrix);
std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFill(paint.getColor(), SkMatrix::I(),
dstRect, nullptr, &invert);
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index 7142ab9bac..2fa5241060 100644
--- a/src/gpu/GrTextureAdjuster.cpp
+++ b/src/gpu/GrTextureAdjuster.cpp
@@ -64,7 +64,8 @@ GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) {
}
GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrSamplerParams& params,
- SkIPoint* outOffset) {
+ SkIPoint* outOffset,
+ SkScalar scaleAdjust[2]) {
GrTexture* texture = this->originalTexture();
GrContext* context = texture->getContext();
CopyParams copyParams;
@@ -81,7 +82,8 @@ GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrSamplerParams& par
copyParams.fWidth = contentArea->width();
copyParams.fHeight = contentArea->height();
copyParams.fFilter = GrSamplerParams::kBilerp_FilterMode;
- } else if (!context->getGpu()->makeCopyForTextureParams(texture, params, &copyParams)) {
+ } else if (!context->getGpu()->makeCopyForTextureParams(texture, params, &copyParams,
+ scaleAdjust)) {
if (outOffset) {
if (contentArea) {
outOffset->set(contentArea->fLeft, contentArea->fRight);
@@ -124,7 +126,8 @@ sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
if (filterOrNullForBicubic) {
params.setFilterMode(*filterOrNullForBicubic);
}
- sk_sp<GrTexture> texture(this->refTextureSafeForParams(params, nullptr));
+ SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
+ sk_sp<GrTexture> texture(this->refTextureSafeForParams(params, nullptr, scaleAdjust));
if (!texture) {
return nullptr;
}
@@ -132,6 +135,7 @@ sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
// content.
if (texture.get() != this->originalTexture()) {
contentArea = nullptr;
+ textureMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
}
DomainMode domainMode =
@@ -156,7 +160,6 @@ sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
}
SkASSERT(kNoDomain_DomainMode == domainMode ||
(domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
- textureMatrix.postIDiv(texture->width(), texture->height());
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(fColorSpace,
dstColorSpace);
return CreateFragmentProcessorForDomainAndFilter(texture.get(), std::move(colorSpaceXform),
diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h
index e437c803e5..1738d60ea8 100644
--- a/src/gpu/GrTextureAdjuster.h
+++ b/src/gpu/GrTextureAdjuster.h
@@ -23,7 +23,8 @@ public:
outOffset will be the top-left corner of the subset if a copy is not made. Otherwise,
the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size
does not match subset's dimensions then the contents are scaled to fit the copy.*/
- GrTexture* refTextureSafeForParams(const GrSamplerParams&, SkIPoint* outOffset);
+ GrTexture* refTextureSafeForParams(const GrSamplerParams&, SkIPoint* outOffset,
+ SkScalar scaleAdjust[2]);
sk_sp<GrFragmentProcessor> createFragmentProcessor(
const SkMatrix& textureMatrix,
diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp
index 37272be4c9..e68703afa1 100644
--- a/src/gpu/GrTextureMaker.cpp
+++ b/src/gpu/GrTextureMaker.cpp
@@ -12,7 +12,8 @@
GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params,
SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace) {
+ sk_sp<SkColorSpace>* texColorSpace,
+ SkScalar scaleAdjust[2]) {
CopyParams copyParams;
bool willBeMipped = params.filterMode() == GrSamplerParams::kMipMap_FilterMode;
@@ -25,7 +26,7 @@ GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params,
}
if (!fContext->getGpu()->makeCopyForTextureParams(this->width(), this->height(), params,
- &copyParams)) {
+ &copyParams, scaleAdjust)) {
return this->refOriginalTexture(willBeMipped, dstColorSpace);
}
GrUniqueKey copyKey;
@@ -77,22 +78,24 @@ sk_sp<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
params.reset(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode);
}
sk_sp<SkColorSpace> texColorSpace;
- sk_sp<GrTexture> texture(this->refTextureForParams(params, dstColorSpace, &texColorSpace));
+ SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
+ sk_sp<GrTexture> texture(this->refTextureForParams(params, dstColorSpace, &texColorSpace,
+ scaleAdjust));
if (!texture) {
return nullptr;
}
+ SkMatrix adjustedMatrix = textureMatrix;
+ adjustedMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
SkRect domain;
DomainMode domainMode =
DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect,
texture->width(), texture->height(),
nullptr, fmForDetermineDomain, &domain);
SkASSERT(kTightCopy_DomainMode != domainMode);
- SkMatrix normalizedTextureMatrix = textureMatrix;
- normalizedTextureMatrix.postIDiv(texture->width(), texture->height());
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(texColorSpace.get(),
dstColorSpace);
return CreateFragmentProcessorForDomainAndFilter(texture.get(), std::move(colorSpaceXform),
- normalizedTextureMatrix, domainMode, domain,
+ adjustedMatrix, domainMode, domain,
filterOrNullForBicubic);
}
diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h
index 0ea5f6d009..767d4ffa3b 100644
--- a/src/gpu/GrTextureMaker.h
+++ b/src/gpu/GrTextureMaker.h
@@ -19,10 +19,12 @@ public:
/**
* Returns a texture that is safe for use with the params. If the size of the returned texture
* does not match width()/height() then the contents of the original must be scaled to fit
- * the texture. Places the color space of the texture in (*texColorSpace).
+ * the texture. Additionally, the 'scaleAdjust' must be applied to the texture matrix
+ * in order to correct the absolute texture coordinates.
+ * Places the color space of the texture in (*texColorSpace).
*/
GrTexture* refTextureForParams(const GrSamplerParams&, SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace);
+ sk_sp<SkColorSpace>* texColorSpace, SkScalar scaleAdjust[2]);
sk_sp<GrFragmentProcessor> createFragmentProcessor(
const SkMatrix& textureMatrix,
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index 0adae8c750..496dbb2d0b 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -52,16 +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;
- localRect.fRight *= sx;
- localRect.fBottom *= sy;
} else {
- localRect = SkRect::MakeWH(1.f, 1.f);
+ localRect = SkRect::MakeWH(inputTexture->width(), inputTexture->height());
}
SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight);
diff --git a/src/gpu/GrTextureToYUVPlanes.cpp b/src/gpu/GrTextureToYUVPlanes.cpp
index b9252fa733..132b680626 100644
--- a/src/gpu/GrTextureToYUVPlanes.cpp
+++ b/src/gpu/GrTextureToYUVPlanes.cpp
@@ -22,8 +22,8 @@ namespace {
static bool convert_texture(GrTexture* src, GrRenderTargetContext* dst, int dstW, int dstH,
SkYUVColorSpace colorSpace, MakeFPProc proc) {
- SkScalar xScale = SkIntToScalar(src->width()) / dstW / src->width();
- SkScalar yScale = SkIntToScalar(src->height()) / dstH / src->height();
+ SkScalar xScale = SkIntToScalar(src->width()) / dstW;
+ SkScalar yScale = SkIntToScalar(src->height()) / dstH;
GrSamplerParams::FilterMode filter;
if (dstW == src->width() && dstW == src->height()) {
filter = GrSamplerParams::kNone_FilterMode;
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index 1330cfea34..2f75d92b46 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -146,7 +146,7 @@ sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth,
- yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
+ yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), r);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 1dec0f6371..85eb671206 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1041,20 +1041,18 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap,
SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() &&
bitmap.height() <= fContext->caps()->maxTileSize());
- sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext.get(), bitmap, params);
+ SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
+ sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext.get(), bitmap,
+ params, scaleAdjust);
if (nullptr == texture) {
return;
}
sk_sp<GrColorSpaceXform> colorSpaceXform =
GrColorSpaceXform::Make(bitmap.colorSpace(), fRenderTargetContext->getColorSpace());
- SkScalar iw = 1.f / texture->width();
- SkScalar ih = 1.f / texture->height();
-
- SkMatrix texMatrix;
// Compute a matrix that maps the rect we will draw to the src rect.
- texMatrix.setRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit);
- texMatrix.postScale(iw, ih);
+ SkMatrix texMatrix = SkMatrix::MakeRectToRect(dstRect, srcRect, SkMatrix::kFill_ScaleToFit);
+ texMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
// Construct a GrPaint by setting the bitmap texture as the first effect and then configuring
// the rest from the SkPaint.
@@ -1122,8 +1120,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
}
// draw sprite neither filters nor tiles.
- texture.reset(
- GrRefCachedBitmapTexture(fContext.get(), bitmap, GrSamplerParams::ClampNoFilter()));
+ texture.reset(GrRefCachedBitmapTexture(fContext.get(), bitmap,
+ GrSamplerParams::ClampNoFilter(), nullptr));
if (!texture) {
return;
}
@@ -1200,10 +1198,7 @@ void SkGpuDevice::drawSpecial(const SkDraw& draw,
SkMatrix::I(),
SkRect::Make(SkIRect::MakeXYWH(
left + offset.fX, top + offset.fY, subset.width(), subset.height())),
- SkRect::MakeXYWH(SkIntToScalar(subset.fLeft) / texture->width(),
- SkIntToScalar(subset.fTop) / texture->height(),
- SkIntToScalar(subset.width()) / texture->width(),
- SkIntToScalar(subset.height()) / texture->height()));
+ SkRect::Make(subset));
}
void SkGpuDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
@@ -1291,8 +1286,8 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
return nullptr;
}
- sk_sp<GrTexture> texture =
- GrMakeCachedBitmapTexture(fContext.get(), bitmap, GrSamplerParams::ClampNoFilter());
+ sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext.get(), bitmap,
+ GrSamplerParams::ClampNoFilter(), nullptr);
if (!texture) {
return nullptr;
}
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 50c7cc25a1..f7949e2120 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -279,16 +279,17 @@ GrTexture* GrUploadMipMapToTexture(GrContext* ctx, const SkImageInfo& info,
}
GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
- const GrSamplerParams& params) {
+ const GrSamplerParams& params, SkScalar scaleAdjust[2]) {
// Caller doesn't care about the texture's color space (they can always get it from the bitmap)
- return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr, nullptr);
+ return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr,
+ nullptr, scaleAdjust);
}
sk_sp<GrTexture> GrMakeCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap,
- const GrSamplerParams& params) {
+ const GrSamplerParams& params, SkScalar scaleAdjust[2]) {
// Caller doesn't care about the texture's color space (they can always get it from the bitmap)
GrTexture* tex = GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr,
- nullptr);
+ nullptr, scaleAdjust);
return sk_sp<GrTexture>(tex);
}
diff --git a/src/gpu/effects/Gr1DKernelEffect.h b/src/gpu/effects/Gr1DKernelEffect.h
index d7402e8c45..29e0e5dec2 100644
--- a/src/gpu/effects/Gr1DKernelEffect.h
+++ b/src/gpu/effects/Gr1DKernelEffect.h
@@ -31,7 +31,7 @@ public:
Gr1DKernelEffect(GrTexture* texture,
Direction direction,
int radius)
- : INHERITED(texture, nullptr, GrCoordTransform::MakeDivByTextureWHMatrix(texture))
+ : INHERITED(texture, nullptr, SkMatrix::I())
, fDirection(direction)
, fRadius(radius) {}
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 50a2a5d3e4..07d1c53011 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -181,8 +181,7 @@ sk_sp<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) {
static const SkShader::TileMode kClampClamp[] =
{ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode };
return GrBicubicEffect::Make(d->fTextures[texIdx], colorSpaceXform,
- GrCoordTransform::MakeDivByTextureWHMatrix(d->fTextures[texIdx]),
- kClampClamp);
+ SkMatrix::I(), kClampClamp);
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 46afb9fbc0..a11be2bb0a 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -219,7 +219,7 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
*upmToPMRule = kConversionRules[i][1];
static const SkRect kDstRect = SkRect::MakeIWH(kSize, kSize);
- static const SkRect kSrcRect = SkRect::MakeIWH(1, 1);
+ static const SkRect kSrcRect = SkRect::MakeIWH(kSize, kSize);
// We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
// from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
// We then verify that two reads produced the same values.
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index 8b98d0b32f..01fc6cec9c 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -156,7 +156,7 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,
const SkIPoint& kernelOffset,
GrTextureDomain::Mode tileMode,
bool convolveAlpha)
- : INHERITED(texture, nullptr, GrCoordTransform::MakeDivByTextureWHMatrix(texture)),
+ : INHERITED(texture, nullptr, SkMatrix::I()),
fKernelSize(kernelSize),
fGain(SkScalarToFloat(gain)),
fBias(SkScalarToFloat(bias) / 255.0f),
diff --git a/src/gpu/effects/GrYUVEffect.cpp b/src/gpu/effects/GrYUVEffect.cpp
index 6d1fac2f32..41bab180ba 100644
--- a/src/gpu/effects/GrYUVEffect.cpp
+++ b/src/gpu/effects/GrYUVEffect.cpp
@@ -66,18 +66,17 @@ public:
GrTexture* vTexture, const SkISize sizes[3],
SkYUVColorSpace colorSpace, bool nv12) {
SkScalar w[3], h[3];
- w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width());
- h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height());
- w[1] = SkIntToScalar(sizes[1].fWidth) / SkIntToScalar(uTexture->width());
- h[1] = SkIntToScalar(sizes[1].fHeight) / SkIntToScalar(uTexture->height());
- w[2] = SkIntToScalar(sizes[2].fWidth) / SkIntToScalar(vTexture->width());
- h[2] = SkIntToScalar(sizes[2].fHeight) / SkIntToScalar(vTexture->height());
- SkMatrix yuvMatrix[3];
- yuvMatrix[0] = GrCoordTransform::MakeDivByTextureWHMatrix(yTexture);
- yuvMatrix[1] = yuvMatrix[0];
- yuvMatrix[1].preScale(w[1] / w[0], h[1] / h[0]);
- yuvMatrix[2] = yuvMatrix[0];
- yuvMatrix[2].preScale(w[2] / w[0], h[2] / h[0]);
+ w[0] = SkIntToScalar(sizes[0].fWidth);
+ h[0] = SkIntToScalar(sizes[0].fHeight);
+ w[1] = SkIntToScalar(sizes[1].fWidth);
+ h[1] = SkIntToScalar(sizes[1].fHeight);
+ w[2] = SkIntToScalar(sizes[2].fWidth);
+ h[2] = SkIntToScalar(sizes[2].fHeight);
+ const SkMatrix yuvMatrix[3] = {
+ SkMatrix::I(),
+ SkMatrix::MakeScale(w[1] / w[0], h[1] / h[0]),
+ SkMatrix::MakeScale(w[2] / w[0], h[2] / h[0])
+ };
GrSamplerParams::FilterMode uvFilterMode =
((sizes[1].fWidth != sizes[0].fWidth) ||
(sizes[1].fHeight != sizes[0].fHeight) ||
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 0e5d8563a4..b9b87a16b5 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -4706,7 +4706,8 @@ GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLG
}
bool GrGLGpu::onMakeCopyForTextureParams(GrTexture* texture, const GrSamplerParams& textureParams,
- GrTextureProducer::CopyParams* copyParams) const {
+ GrTextureProducer::CopyParams* copyParams,
+ SkScalar scaleAdjust[2]) const {
if (textureParams.isTiled() ||
GrSamplerParams::kMipMap_FilterMode == textureParams.filterMode()) {
GrGLTexture* glTexture = static_cast<GrGLTexture*>(texture);
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index c9c3fc4409..fdc2ebbfa9 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -187,7 +187,8 @@ private:
const SkTArray<GrMipLevel>& texels);
bool onMakeCopyForTextureParams(GrTexture*, const GrSamplerParams&,
- GrTextureProducer::CopyParams*) const override;
+ GrTextureProducer::CopyParams*,
+ SkScalar scaleAdjust[2]) const override;
// Checks whether glReadPixels can be called to get pixel values in readConfig from the
// render target.
diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
index 24f21ffe7a..f39fff2a07 100644
--- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
@@ -16,6 +16,11 @@ SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatri
const GrCoordTransform& coordTransform) {
SkMatrix combined;
combined.setConcat(coordTransform.getMatrix(), localMatrix);
+ if (coordTransform.normalize()) {
+ SkASSERT(coordTransform.texture());
+ combined.postIDiv(coordTransform.texture()->width(), coordTransform.texture()->height());
+ }
+
if (coordTransform.reverseY()) {
// combined.postScale(1,-1);
// combined.postTranslate(0,1);
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 5b79fb1d9e..b1fcb0c6f8 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -144,8 +144,6 @@ void SkImageShader::toString(SkString* str) const {
#include "effects/GrSimpleTextureEffect.h"
sk_sp<GrFragmentProcessor> SkImageShader::asFragmentProcessor(const AsFPArgs& args) const {
- SkMatrix matrix;
- matrix.setIDiv(fImage->width(), fImage->height());
SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
@@ -158,7 +156,6 @@ sk_sp<GrFragmentProcessor> SkImageShader::asFragmentProcessor(const AsFPArgs& ar
}
lmInverse.postConcat(inv);
}
- matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = { fTileModeX, fTileModeY };
@@ -172,20 +169,23 @@ sk_sp<GrFragmentProcessor> SkImageShader::asFragmentProcessor(const AsFPArgs& ar
&doBicubic);
GrSamplerParams params(tm, textureFilterMode);
sk_sp<SkColorSpace> texColorSpace;
+ SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
sk_sp<GrTexture> texture(as_IB(fImage)->asTextureRef(args.fContext, params, args.fDstColorSpace,
- &texColorSpace));
+ &texColorSpace, scaleAdjust));
if (!texture) {
return nullptr;
}
+ lmInverse.postScale(scaleAdjust[0], scaleAdjust[1]);
+
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(texColorSpace.get(),
args.fDstColorSpace);
sk_sp<GrFragmentProcessor> inner;
if (doBicubic) {
- inner = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), matrix, tm);
+ inner = GrBicubicEffect::Make(texture.get(), std::move(colorSpaceXform), lmInverse, tm);
} else {
inner = GrSimpleTextureEffect::Make(texture.get(), std::move(colorSpaceXform),
- matrix, params);
+ lmInverse, params);
}
if (GrPixelConfigIsAlphaOnly(texture->config())) {
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index e839a05cd2..e2a4e40410 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -56,7 +56,7 @@ public:
// Caller must call unref when they are done.
virtual GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
- sk_sp<SkColorSpace>*) const = 0;
+ sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const = 0;
virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0;
diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp
index 45f04e4d9a..da9d61a8f0 100644
--- a/src/image/SkImage_Generator.cpp
+++ b/src/image/SkImage_Generator.cpp
@@ -32,7 +32,7 @@ public:
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
- sk_sp<SkColorSpace>*) const override;
+ sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override;
bool onIsLazyGenerated() const override { return true; }
private:
@@ -79,8 +79,9 @@ bool SkImage_Generator::getROPixels(SkBitmap* bitmap, SkColorSpace* dstColorSpac
GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace) const {
- return fCache.lockAsTexture(ctx, params, dstColorSpace, texColorSpace, this);
+ sk_sp<SkColorSpace>* texColorSpace,
+ SkScalar scaleAdjust[2]) const {
+ return fCache.lockAsTexture(ctx, params, dstColorSpace, texColorSpace, this, scaleAdjust);
}
sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 02f53e7104..54c799a3fe 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -97,13 +97,14 @@ sk_sp<GrSurfaceProxy> SkImage_Gpu::refProxy() const {
GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace) const {
+ sk_sp<SkColorSpace>* texColorSpace,
+ SkScalar scaleAdjust[2]) const {
if (texColorSpace) {
*texColorSpace = this->fColorSpace;
}
GrTextureAdjuster adjuster(this->peekTexture(), this->alphaType(), this->bounds(),
this->uniqueID(), this->fColorSpace.get());
- return adjuster.refTextureSafeForParams(params, nullptr);
+ return adjuster.refTextureSafeForParams(params, nullptr, scaleAdjust);
}
static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) {
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 2d6f3bd831..31e268c625 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -40,7 +40,7 @@ public:
bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
GrTexture* asTextureRef(GrContext* ctx, const GrSamplerParams& params, SkColorSpace*,
- sk_sp<SkColorSpace>*) const override;
+ sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
sk_sp<GrSurfaceProxy> refProxy() const;
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index cce1ed20c5..b287789ea8 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -89,7 +89,7 @@ public:
bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*,
- sk_sp<SkColorSpace>*) const override;
+ sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
@@ -173,7 +173,8 @@ bool SkImage_Raster::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace, Cac
GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace) const {
+ sk_sp<SkColorSpace>* texColorSpace,
+ SkScalar scaleAdjust[2]) const {
#if SK_SUPPORT_GPU
if (!ctx) {
return nullptr;
@@ -188,10 +189,10 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrSamplerParams& p
if (tex) {
GrTextureAdjuster adjuster(fPinnedTexture.get(), fBitmap.alphaType(), fBitmap.bounds(),
fPinnedUniqueID, fBitmap.colorSpace());
- return adjuster.refTextureSafeForParams(params, nullptr);
+ return adjuster.refTextureSafeForParams(params, nullptr, scaleAdjust);
}
- return GrRefCachedBitmapTexture(ctx, fBitmap, params);
+ return GrRefCachedBitmapTexture(ctx, fBitmap, params, scaleAdjust);
#endif
return nullptr;
@@ -218,7 +219,7 @@ bool SkImage_Raster::onPinAsTexture(GrContext* ctx) const {
SkASSERT(fPinnedCount == 0);
SkASSERT(fPinnedUniqueID == 0);
fPinnedTexture.reset(
- GrRefCachedBitmapTexture(ctx, fBitmap, GrSamplerParams::ClampNoFilter()));
+ GrRefCachedBitmapTexture(ctx, fBitmap, GrSamplerParams::ClampNoFilter(), nullptr));
if (!fPinnedTexture) {
return false;
}
diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp
index a92a4be4d5..4091db0d9b 100644
--- a/tests/ImageNewShaderTest.cpp
+++ b/tests/ImageNewShaderTest.cpp
@@ -16,7 +16,7 @@
#include "GrContext.h"
#endif
-void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2) {
+static void test_bitmap_equality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& bm2) {
SkAutoLockPixels lockBm1(bm1);
SkAutoLockPixels lockBm2(bm2);
@@ -24,7 +24,7 @@ void testBitmapEquality(skiatest::Reporter* reporter, SkBitmap& bm1, SkBitmap& b
REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.getSize()));
}
-void paintSource(SkSurface* sourceSurface) {
+static void paint_source(SkSurface* sourceSurface) {
SkCanvas* sourceCanvas = sourceSurface->getCanvas();
sourceCanvas->clear(0xFFDEDEDE);
@@ -41,8 +41,9 @@ void paintSource(SkSurface* sourceSurface) {
sourceCanvas->drawRect(rect, paintColor);
}
-void runShaderTest(skiatest::Reporter* reporter, SkSurface* sourceSurface, SkSurface* destinationSurface, SkImageInfo& info) {
- paintSource(sourceSurface);
+static void run_shader_test(skiatest::Reporter* reporter, SkSurface* sourceSurface,
+ SkSurface* destinationSurface, SkImageInfo& info) {
+ paint_source(sourceSurface);
sk_sp<SkImage> sourceImage(sourceSurface->makeImageSnapshot());
sk_sp<SkShader> sourceShader = sourceImage->makeShader(
@@ -65,9 +66,7 @@ void runShaderTest(skiatest::Reporter* reporter, SkSurface* sourceSurface, SkSur
SkBitmap bm;
destinationCanvas->readPixels(rect, &bm);
- testBitmapEquality(reporter, bmOrig, bm);
-
-
+ test_bitmap_equality(reporter, bmOrig, bm);
// Test with a translated shader
SkMatrix matrix;
@@ -107,47 +106,47 @@ DEF_TEST(ImageNewShader, reporter) {
auto sourceSurface(SkSurface::MakeRaster(info));
auto destinationSurface(SkSurface::MakeRaster(info));
- runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
+ run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
#if SK_SUPPORT_GPU
-void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) {
+static void gpu_to_gpu(skiatest::Reporter* reporter, GrContext* context) {
SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
auto sourceSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
auto destinationSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
- runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
+ run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
-void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) {
+static void gpu_to_raster(skiatest::Reporter* reporter, GrContext* context) {
SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
auto sourceSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
auto destinationSurface(SkSurface::MakeRaster(info));
- runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
+ run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
-void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) {
+static void raster_to_gpu(skiatest::Reporter* reporter, GrContext* context) {
SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
auto sourceSurface(SkSurface::MakeRaster(info));
auto destinationSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
- runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
+ run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageNewShader_GPU, reporter, ctxInfo) {
// GPU -> GPU
- gpuToGpu(reporter, ctxInfo.grContext());
+ gpu_to_gpu(reporter, ctxInfo.grContext());
// GPU -> RASTER
- gpuToRaster(reporter, ctxInfo.grContext());
+ gpu_to_raster(reporter, ctxInfo.grContext());
// RASTER -> GPU
- rasterToGpu(reporter, ctxInfo.grContext());
+ raster_to_gpu(reporter, ctxInfo.grContext());
}
#endif
diff --git a/tests/IntTextureTest.cpp b/tests/IntTextureTest.cpp
index a3e17bf644..3edd4cc986 100644
--- a/tests/IntTextureTest.cpp
+++ b/tests/IntTextureTest.cpp
@@ -207,9 +207,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
};
for (auto filter : kNamedFilters) {
- SkMatrix m;
- m.setIDiv(kS, kS);
- sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), nullptr, m,
+ sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), nullptr,
+ SkMatrix::I(),
filter.fMode));
REPORTER_ASSERT(reporter, fp);
if (!fp) {
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index a0c5409142..6d075df203 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -107,14 +107,12 @@ static void test_basic_draw(skiatest::Reporter* reporter, GrContext* context,
context->makeRenderTargetContext(SkBackingFit::kExact, rectangleTexture->width(),
rectangleTexture->height(), rectangleTexture->config(),
nullptr));
- SkMatrix m;
- m.setIDiv(rectangleTexture->width(), rectangleTexture->height());
for (auto filter : {GrSamplerParams::kNone_FilterMode,
GrSamplerParams::kBilerp_FilterMode,
GrSamplerParams::kMipMap_FilterMode}) {
rtContext->clear(nullptr, 0xDDCCBBAA, true);
- sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(rectangleTexture,
- nullptr, m, filter));
+ sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(rectangleTexture, nullptr,
+ SkMatrix::I(), filter));
GrPaint paint;
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
paint.addColorFragmentProcessor(std::move(fp));
diff --git a/tests/SRGBMipMapTest.cpp b/tests/SRGBMipMapTest.cpp
index 79d86911ff..22d68903eb 100644
--- a/tests/SRGBMipMapTest.cpp
+++ b/tests/SRGBMipMapTest.cpp
@@ -132,7 +132,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SRGBMipMaps, reporter, ctxInfo) {
GrPaint paint;
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
GrSamplerParams mipMapParams(SkShader::kRepeat_TileMode, GrSamplerParams::kMipMap_FilterMode);
- paint.addColorTextureProcessor(texture.get(), nullptr, SkMatrix::MakeScale(0.5f), mipMapParams);
+ paint.addColorTextureProcessor(texture.get(), nullptr, SkMatrix::MakeScale(rtS), mipMapParams);
// 1) Draw texture to S32 surface (should generate/use sRGB mips)
paint.setGammaCorrect(true);