OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrCoordTransform_DEFINED | 8 #ifndef GrCoordTransform_DEFINED |
9 #define GrCoordTransform_DEFINED | 9 #define GrCoordTransform_DEFINED |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 kPosition_GrCoordSet | 34 kPosition_GrCoordSet |
35 }; | 35 }; |
36 | 36 |
37 /** | 37 /** |
38 * A class representing a linear transformation from one of the built-in coordin
ate sets (local or | 38 * A class representing a linear transformation from one of the built-in coordin
ate sets (local or |
39 * position). GrEffects just define these transformations, and the framework doe
s the rest of the | 39 * position). GrEffects just define these transformations, and the framework doe
s the rest of the |
40 * work to make the transformed coordinates available in their fragment shader. | 40 * work to make the transformed coordinates available in their fragment shader. |
41 */ | 41 */ |
42 class GrCoordTransform : public SkNoncopyable { | 42 class GrCoordTransform : public SkNoncopyable { |
43 public: | 43 public: |
44 GrCoordTransform() {} | 44 GrCoordTransform() { SkDEBUGCODE(fInEffect = false); } |
45 | 45 |
46 /** | 46 /** |
47 * Create a transformation that maps [0, 1] to a texture's boundaries. | 47 * Create a transformation that maps [0, 1] to a texture's boundaries. |
48 */ | 48 */ |
49 GrCoordTransform(GrCoordSet sourceCoords, const GrTexture* texture) { | 49 GrCoordTransform(GrCoordSet sourceCoords, const GrTexture* texture) { |
| 50 SkDEBUGCODE(fInEffect = false); |
50 this->reset(sourceCoords, texture); | 51 this->reset(sourceCoords, texture); |
51 } | 52 } |
52 | 53 |
53 /** | 54 /** |
54 * Create a transformation from a matrix. The optional texture parameter is
used to infer if the | 55 * Create a transformation from a matrix. The optional texture parameter is
used to infer if the |
55 * framework should internally do a y reversal to account for it being upsid
e down by Skia's | 56 * framework should internally do a y reversal to account for it being upsid
e down by Skia's |
56 * coord convention. | 57 * coord convention. |
57 */ | 58 */ |
58 GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix& m, const GrTexture
* texture = NULL) { | 59 GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix& m, const GrTexture
* texture = NULL) { |
| 60 SkDEBUGCODE(fInEffect = false); |
59 this->reset(sourceCoords, m, texture); | 61 this->reset(sourceCoords, m, texture); |
60 } | 62 } |
61 | 63 |
62 void reset(GrCoordSet sourceCoords, const GrTexture* texture) { | 64 void reset(GrCoordSet sourceCoords, const GrTexture* texture) { |
| 65 SkASSERT(!fInEffect); |
63 SkASSERT(NULL != texture); | 66 SkASSERT(NULL != texture); |
64 this->reset(sourceCoords, GrEffect::MakeDivByTextureWHMatrix(texture), t
exture); | 67 this->reset(sourceCoords, GrEffect::MakeDivByTextureWHMatrix(texture), t
exture); |
65 } | 68 } |
66 | 69 |
67 void reset(GrCoordSet sourceCoords, const SkMatrix& m, const GrTexture* text
ure = NULL) { | 70 void reset(GrCoordSet sourceCoords, const SkMatrix& m, const GrTexture* text
ure = NULL) { |
| 71 SkASSERT(!fInEffect); |
68 fSourceCoords = sourceCoords; | 72 fSourceCoords = sourceCoords; |
69 fMatrix = m; | 73 fMatrix = m; |
70 fReverseY = NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->o
rigin(); | 74 fReverseY = NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->o
rigin(); |
71 } | 75 } |
72 | 76 |
| 77 GrCoordTransform& operator= (const GrCoordTransform& other) { |
| 78 SkASSERT(!fInEffect); |
| 79 fSourceCoords = other.fSourceCoords; |
| 80 fMatrix = other.fMatrix; |
| 81 fReverseY = other.fReverseY; |
| 82 return *this; |
| 83 } |
| 84 |
| 85 /** |
| 86 * Access the matrix for editing. Note, this must be done before adding the
transform to an |
| 87 * effect, since effects are immutable. |
| 88 */ |
| 89 SkMatrix* accessMatrix() { |
| 90 SkASSERT(!fInEffect); |
| 91 return &fMatrix; |
| 92 } |
| 93 |
73 bool operator== (const GrCoordTransform& other) const { | 94 bool operator== (const GrCoordTransform& other) const { |
74 return fSourceCoords == other.fSourceCoords && | 95 return fSourceCoords == other.fSourceCoords && |
75 fMatrix.cheapEqualTo(other.fMatrix) && | 96 fMatrix.cheapEqualTo(other.fMatrix) && |
76 fReverseY == other.fReverseY; | 97 fReverseY == other.fReverseY; |
77 } | 98 } |
78 | 99 |
79 GrCoordSet sourceCoords() const { return fSourceCoords; } | 100 GrCoordSet sourceCoords() const { return fSourceCoords; } |
80 const SkMatrix& getMatrix() const { return fMatrix; } | 101 const SkMatrix& getMatrix() const { return fMatrix; } |
81 bool reverseY() const { return fReverseY; } | 102 bool reverseY() const { return fReverseY; } |
82 | 103 |
83 private: | 104 private: |
84 GrCoordSet fSourceCoords; | 105 GrCoordSet fSourceCoords; |
85 SkMatrix fMatrix; | 106 SkMatrix fMatrix; |
86 bool fReverseY; | 107 bool fReverseY; |
87 | 108 |
88 typedef SkNoncopyable INHERITED; | 109 typedef SkNoncopyable INHERITED; |
| 110 |
| 111 #ifdef SK_DEBUG |
| 112 public: |
| 113 void setInEffect() const { fInEffect = true; } |
| 114 private: |
| 115 mutable bool fInEffect; |
| 116 #endif |
89 }; | 117 }; |
90 | 118 |
91 #endif | 119 #endif |
OLD | NEW |