| 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). GrProcessors just define these transformations, and the framework
does the rest of the | 39 * position). GrProcessors just define these transformations, and the framework
does 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 : SkNoncopyable { | 42 class GrCoordTransform : SkNoncopyable { |
| 43 public: | 43 public: |
| 44 GrCoordTransform() { SkDEBUGCODE(fInEffect = false); } | 44 GrCoordTransform() { SkDEBUGCODE(fInProcessor = 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 SkDEBUGCODE(fInProcessor = false); |
| 51 this->reset(sourceCoords, texture); | 51 this->reset(sourceCoords, texture); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * 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 |
| 56 * 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 |
| 57 * coord convention. | 57 * coord convention. |
| 58 */ | 58 */ |
| 59 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); | 60 SkDEBUGCODE(fInProcessor = false); |
| 61 this->reset(sourceCoords, m, texture); | 61 this->reset(sourceCoords, m, texture); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void reset(GrCoordSet sourceCoords, const GrTexture* texture) { | 64 void reset(GrCoordSet sourceCoords, const GrTexture* texture) { |
| 65 SkASSERT(!fInEffect); | 65 SkASSERT(!fInProcessor); |
| 66 SkASSERT(texture); | 66 SkASSERT(texture); |
| 67 this->reset(sourceCoords, MakeDivByTextureWHMatrix(texture), texture); | 67 this->reset(sourceCoords, MakeDivByTextureWHMatrix(texture), texture); |
| 68 } | 68 } |
| 69 | 69 |
| 70 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); | 71 SkASSERT(!fInProcessor); |
| 72 fSourceCoords = sourceCoords; | 72 fSourceCoords = sourceCoords; |
| 73 fMatrix = m; | 73 fMatrix = m; |
| 74 fReverseY = texture && kBottomLeft_GrSurfaceOrigin == texture->origin(); | 74 fReverseY = texture && kBottomLeft_GrSurfaceOrigin == texture->origin(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 GrCoordTransform& operator= (const GrCoordTransform& other) { | 77 GrCoordTransform& operator= (const GrCoordTransform& other) { |
| 78 SkASSERT(!fInEffect); | 78 SkASSERT(!fInProcessor); |
| 79 fSourceCoords = other.fSourceCoords; | 79 fSourceCoords = other.fSourceCoords; |
| 80 fMatrix = other.fMatrix; | 80 fMatrix = other.fMatrix; |
| 81 fReverseY = other.fReverseY; | 81 fReverseY = other.fReverseY; |
| 82 return *this; | 82 return *this; |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * Access the matrix for editing. Note, this must be done before adding the
transform to an | 86 * Access the matrix for editing. Note, this must be done before adding the
transform to an |
| 87 * effect, since effects are immutable. | 87 * effect, since effects are immutable. |
| 88 */ | 88 */ |
| 89 SkMatrix* accessMatrix() { | 89 SkMatrix* accessMatrix() { |
| 90 SkASSERT(!fInEffect); | 90 SkASSERT(!fInProcessor); |
| 91 return &fMatrix; | 91 return &fMatrix; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool operator== (const GrCoordTransform& other) const { | 94 bool operator== (const GrCoordTransform& other) const { |
| 95 return fSourceCoords == other.fSourceCoords && | 95 return fSourceCoords == other.fSourceCoords && |
| 96 fMatrix.cheapEqualTo(other.fMatrix) && | 96 fMatrix.cheapEqualTo(other.fMatrix) && |
| 97 fReverseY == other.fReverseY; | 97 fReverseY == other.fReverseY; |
| 98 } | 98 } |
| 99 | 99 |
| 100 GrCoordSet sourceCoords() const { return fSourceCoords; } | 100 GrCoordSet sourceCoords() const { return fSourceCoords; } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 GrCoordSet fSourceCoords; | 114 GrCoordSet fSourceCoords; |
| 115 SkMatrix fMatrix; | 115 SkMatrix fMatrix; |
| 116 bool fReverseY; | 116 bool fReverseY; |
| 117 | 117 |
| 118 typedef SkNoncopyable INHERITED; | 118 typedef SkNoncopyable INHERITED; |
| 119 | 119 |
| 120 #ifdef SK_DEBUG | 120 #ifdef SK_DEBUG |
| 121 public: | 121 public: |
| 122 void setInEffect() const { fInEffect = true; } | 122 void setInProcessor() const { fInProcessor = true; } |
| 123 private: | 123 private: |
| 124 mutable bool fInEffect; | 124 mutable bool fInProcessor; |
| 125 #endif | 125 #endif |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 #endif | 128 #endif |
| OLD | NEW |