aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu
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 /include/gpu
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>
Diffstat (limited to 'include/gpu')
-rw-r--r--include/gpu/GrCoordTransform.h64
-rw-r--r--include/gpu/SkGr.h14
2 files changed, 51 insertions, 27 deletions
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);