Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrCoordTransform.h
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrCoordTransform_DEFINED
9 #define GrCoordTransform_DEFINED
10 
11 #include "GrProcessor.h"
12 #include "SkMatrix.h"
13 #include "GrTexture.h"
14 #include "GrTypes.h"
15 #include "GrShaderVar.h"
16 
23 enum GrCoordSet {
30  kLocal_GrCoordSet,
31 
35  kDevice_GrCoordSet,
36 };
37 
43 class GrCoordTransform : SkNoncopyable {
44 public:
45  GrCoordTransform() : fSourceCoords(kLocal_GrCoordSet) { SkDEBUGCODE(fInProcessor = false); }
46 
52  GrCoordTransform(GrCoordSet sourceCoords,
53  const GrTexture* texture,
54  GrTextureParams::FilterMode filter) {
55  SkASSERT(texture);
56  SkDEBUGCODE(fInProcessor = false);
57  this->reset(sourceCoords, texture, filter);
58  }
59 
64  GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix& m,
65  const GrTexture* texture, GrTextureParams::FilterMode filter) {
66  SkDEBUGCODE(fInProcessor = false);
67  SkASSERT(texture);
68  this->reset(sourceCoords, m, texture, filter);
69  }
70 
74  GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix& m,
75  GrSLPrecision precision = kDefault_GrSLPrecision) {
76  SkDEBUGCODE(fInProcessor = false);
77  this->reset(sourceCoords, m, precision);
78  }
79 
80  void reset(GrCoordSet sourceCoords, const GrTexture* texture,
81  GrTextureParams::FilterMode filter) {
82  SkASSERT(!fInProcessor);
83  SkASSERT(texture);
84  this->reset(sourceCoords, MakeDivByTextureWHMatrix(texture), texture, filter);
85  }
86 
87  void reset(GrCoordSet, const SkMatrix&, const GrTexture*, GrTextureParams::FilterMode filter);
88  void reset(GrCoordSet sourceCoords, const SkMatrix& m,
89  GrSLPrecision precision = kDefault_GrSLPrecision);
90 
91  GrCoordTransform& operator= (const GrCoordTransform& that) {
92  SkASSERT(!fInProcessor);
93  fSourceCoords = that.fSourceCoords;
94  fMatrix = that.fMatrix;
95  fReverseY = that.fReverseY;
96  fPrecision = that.fPrecision;
97  return *this;
98  }
99 
105  SkASSERT(!fInProcessor);
106  return &fMatrix;
107  }
108 
109  bool operator==(const GrCoordTransform& that) const {
110  return fSourceCoords == that.fSourceCoords &&
111  fMatrix.cheapEqualTo(that.fMatrix) &&
112  fReverseY == that.fReverseY &&
113  fPrecision == that.fPrecision;
114  }
115 
116  bool operator!=(const GrCoordTransform& that) const { return !(*this == that); }
117 
118  GrCoordSet sourceCoords() const { return fSourceCoords; }
119  const SkMatrix& getMatrix() const { return fMatrix; }
120  bool reverseY() const { return fReverseY; }
121  GrSLPrecision precision() const { return fPrecision; }
122 
125  static inline SkMatrix MakeDivByTextureWHMatrix(const GrTexture* texture) {
126  SkASSERT(texture);
127  SkMatrix mat;
128  (void)mat.setIDiv(texture->width(), texture->height());
129  return mat;
130  }
131 
132 private:
133  GrCoordSet fSourceCoords;
134  SkMatrix fMatrix;
135  bool fReverseY;
136  GrSLPrecision fPrecision;
137  typedef SkNoncopyable INHERITED;
138 
139 #ifdef SK_DEBUG
140 public:
141  void setInProcessor() const { fInProcessor = true; }
142 private:
143  mutable bool fInProcessor;
144 #endif
145 };
146 
147 #endif
bool setIDiv(int divx, int divy)
Set the matrix to scale by 1/divx and 1/divy.
SkMatrix * accessMatrix()
Access the matrix for editing.
Definition: GrCoordTransform.h:104
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:26
static SkMatrix MakeDivByTextureWHMatrix(const GrTexture *texture)
Useful for effects that want to insert a texture matrix that is implied by the texture dimensions...
Definition: GrCoordTransform.h:125
int width() const
Retrieves the width of the surface.
Definition: GrSurface.h:26
A class representing a linear transformation from one of the built-in coordinate sets (local or posit...
Definition: GrCoordTransform.h:43
int height() const
Retrieves the height of the surface.
Definition: GrSurface.h:31
GrCoordTransform(GrCoordSet sourceCoords, const GrTexture *texture, GrTextureParams::FilterMode filter)
Create a transformation that maps [0, 1] to a texture's boundaries.
Definition: GrCoordTransform.h:52
GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix &m, GrSLPrecision precision=kDefault_GrSLPrecision)
Create a transformation that applies the matrix to a coord set.
Definition: GrCoordTransform.h:74
bool cheapEqualTo(const SkMatrix &m) const
Efficient comparison of two matrices.
Definition: SkMatrix.h:619
Definition: GrTexture.h:19
GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix &m, const GrTexture *texture, GrTextureParams::FilterMode filter)
Create a transformation from a matrix.
Definition: GrCoordTransform.h:64