Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: include/gpu/GrEffectStage.h

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/GrEffect.h ('k') | include/gpu/GrEffectUnitTest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10
11 #ifndef GrEffectStage_DEFINED
12 #define GrEffectStage_DEFINED
13
14 #include "GrBackendEffectFactory.h"
15 #include "GrCoordTransform.h"
16 #include "GrEffect.h"
17 #include "GrProgramElementRef.h"
18 #include "SkMatrix.h"
19 #include "SkShader.h"
20
21 // TODO: Make two variations on this class: One for GrDrawState that only owns r egular refs
22 // and supports compatibility checks and changing local coords. The second is fo r GrOptDrawState,
23 // is immutable, and only owns pending execution refs. This requries removing th e common base
24 // class from GrDrawState and GrOptDrawState called GrRODrawState and converting to GrOptDrawState
25 // when draws are enqueued in the GrInOrderDrawBuffer.
26 class GrEffectStage {
27 public:
28 explicit GrEffectStage(const GrEffect* effect)
29 : fEffect(SkRef(effect)) {
30 fCoordChangeMatrixSet = false;
31 }
32
33 GrEffectStage(const GrEffectStage& other) {
34 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet;
35 if (other.fCoordChangeMatrixSet) {
36 fCoordChangeMatrix = other.fCoordChangeMatrix;
37 }
38 fEffect.initAndRef(other.fEffect);
39 }
40
41 static bool AreCompatible(const GrEffectStage& a, const GrEffectStage& b,
42 bool usingExplicitLocalCoords) {
43 SkASSERT(a.fEffect.get());
44 SkASSERT(b.fEffect.get());
45
46 if (!a.getEffect()->isEqual(*b.getEffect())) {
47 return false;
48 }
49
50 // We always track the coord change matrix, but it has no effect when ex plicit local coords
51 // are used.
52 if (usingExplicitLocalCoords) {
53 return true;
54 }
55
56 if (a.fCoordChangeMatrixSet != b.fCoordChangeMatrixSet) {
57 return false;
58 }
59
60 if (!a.fCoordChangeMatrixSet) {
61 return true;
62 }
63
64 return a.fCoordChangeMatrix == b.fCoordChangeMatrix;
65 }
66
67 /**
68 * This is called when the coordinate system in which the geometry is specif ied will change.
69 *
70 * @param matrix The transformation from the old coord system in which ge ometry is specified
71 * to the new one from which it will actually be drawn.
72 */
73 void localCoordChange(const SkMatrix& matrix) {
74 if (fCoordChangeMatrixSet) {
75 fCoordChangeMatrix.preConcat(matrix);
76 } else {
77 fCoordChangeMatrixSet = true;
78 fCoordChangeMatrix = matrix;
79 }
80 }
81
82 class SavedCoordChange {
83 public:
84 SkDEBUGCODE(SavedCoordChange() : fEffectUniqueID(SK_InvalidUniqueID) {})
85 private:
86 bool fCoordChangeMatrixSet;
87 SkMatrix fCoordChangeMatrix;
88 SkDEBUGCODE(mutable uint32_t fEffectUniqueID;)
89
90 friend class GrEffectStage;
91 };
92
93 /**
94 * This gets the current coordinate system change. It is the accumulation of
95 * localCoordChange calls since the effect was installed. It is used when th en caller
96 * wants to temporarily change the source geometry coord system, draw someth ing, and then
97 * restore the previous coord system (e.g. temporarily draw in device coords ).
98 */
99 void saveCoordChange(SavedCoordChange* savedCoordChange) const {
100 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet;
101 if (fCoordChangeMatrixSet) {
102 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
103 }
104 SkASSERT(SK_InvalidUniqueID == savedCoordChange->fEffectUniqueID);
105 SkDEBUGCODE(savedCoordChange->fEffectUniqueID = fEffect->getUniqueID();)
106 }
107
108 /**
109 * This balances the saveCoordChange call.
110 */
111 void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
112 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet;
113 if (fCoordChangeMatrixSet) {
114 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
115 }
116 SkASSERT(savedCoordChange.fEffectUniqueID == fEffect->getUniqueID());
117 SkDEBUGCODE(savedCoordChange.fEffectUniqueID = SK_InvalidUniqueID);
118 }
119
120 /**
121 * Gets the matrix representing all changes of coordinate system since the G rEffect was
122 * installed in the stage.
123 */
124 const SkMatrix& getCoordChangeMatrix() const {
125 if (fCoordChangeMatrixSet) {
126 return fCoordChangeMatrix;
127 } else {
128 return SkMatrix::I();
129 }
130 }
131
132 bool isPerspectiveCoordTransform(int matrixIndex, bool useExplicitLocalCoord s) const {
133 const GrCoordTransform& coordTransform = this->getEffect()->coordTransfo rm(matrixIndex);
134 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType();
135 SkMatrix::TypeMask type1 = SkMatrix::kIdentity_Mask;
136 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
137 type1 = useExplicitLocalCoords ?
138 SkMatrix::kIdentity_Mask : this->getCoordChangeMatrix().getTyp e();
139 }
140
141 int combinedTypes = type0 | type1;
142 if (SkMatrix::kPerspective_Mask & combinedTypes) {
143 return true;
144 } else {
145 return false;
146 }
147 }
148
149 const GrEffect* getEffect() const { return fEffect.get(); }
150
151 void convertToPendingExec() { fEffect.convertToPendingExec(); }
152
153 private:
154 bool fCoordChangeMatrixSet;
155 SkMatrix fCoordChangeMatrix;
156 GrProgramElementRef<const GrEffect> fEffect;
157 };
158
159 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrEffect.h ('k') | include/gpu/GrEffectUnitTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698