OLD | NEW |
(Empty) | |
| 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 "GrEffect.h" |
| 12 #include "SkMatrix.h" |
| 13 #include "GrTexture.h" |
| 14 #include "GrTypes.h" |
| 15 |
| 16 /** |
| 17 * Coordinates available to GrEffect subclasses for requesting transformations.
Transformed |
| 18 * coordinates are made available in the the portion of fragment shader emitted
by the effect. |
| 19 */ |
| 20 enum GrCoordSet { |
| 21 /** |
| 22 * The user-space coordinates that map to the fragment being rendered. These
coords account for |
| 23 * any change of coordinate system done on the CPU by GrContext before rende
ring, and also are |
| 24 * correct for draws that take explicit local coords rather than inferring t
hem from the |
| 25 * primitive's positions (e.g. drawVertices). These are usually the coords a
GrEffect wants. |
| 26 */ |
| 27 kLocal_GrCoordSet, |
| 28 |
| 29 /** |
| 30 * The actual vertex position. Note that GrContext may not draw using the or
iginal view matrix |
| 31 * specified by the caller, as it may have transformed vertices into another
space. These are |
| 32 * usually not the coordinates a GrEffect wants. |
| 33 */ |
| 34 kPosition_GrCoordSet |
| 35 }; |
| 36 |
| 37 /** |
| 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 |
| 40 * work to make the transformed coordinates available in their fragment shader. |
| 41 */ |
| 42 class GrCoordTransform : public SkNoncopyable { |
| 43 public: |
| 44 GrCoordTransform() {} |
| 45 |
| 46 /** |
| 47 * Create a transformation that maps [0, 1] to a texture's boundaries. |
| 48 */ |
| 49 GrCoordTransform(GrCoordSet sourceCoords, const GrTexture* texture) { |
| 50 this->reset(sourceCoords, texture); |
| 51 } |
| 52 |
| 53 /** |
| 54 * 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 * coord convention. |
| 57 */ |
| 58 GrCoordTransform(GrCoordSet sourceCoords, const SkMatrix& m, const GrTexture
* texture = NULL) { |
| 59 this->reset(sourceCoords, m, texture); |
| 60 } |
| 61 |
| 62 void reset(GrCoordSet sourceCoords, const GrTexture* texture) { |
| 63 SkASSERT(NULL != texture); |
| 64 this->reset(sourceCoords, GrEffect::MakeDivByTextureWHMatrix(texture), t
exture); |
| 65 } |
| 66 |
| 67 void reset(GrCoordSet sourceCoords, const SkMatrix& m, const GrTexture* text
ure = NULL) { |
| 68 fSourceCoords = sourceCoords; |
| 69 fMatrix = m; |
| 70 fReverseY = NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->o
rigin(); |
| 71 } |
| 72 |
| 73 bool operator== (const GrCoordTransform& other) const { |
| 74 return fSourceCoords == other.fSourceCoords && |
| 75 fMatrix.cheapEqualTo(other.fMatrix) && |
| 76 fReverseY == other.fReverseY; |
| 77 } |
| 78 |
| 79 GrCoordSet sourceCoords() const { return fSourceCoords; } |
| 80 const SkMatrix& getMatrix() const { return fMatrix; } |
| 81 bool reverseY() const { return fReverseY; } |
| 82 |
| 83 private: |
| 84 GrCoordSet fSourceCoords; |
| 85 SkMatrix fMatrix; |
| 86 bool fReverseY; |
| 87 |
| 88 typedef SkNoncopyable INHERITED; |
| 89 }; |
| 90 |
| 91 #endif |
OLD | NEW |