OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 /** | 47 /** |
48 * Copies another draw state with a preconcat to the view matrix. | 48 * Copies another draw state with a preconcat to the view matrix. |
49 **/ | 49 **/ |
50 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); | 50 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); |
51 | 51 |
52 virtual ~GrDrawState(); | 52 virtual ~GrDrawState(); |
53 | 53 |
54 /** | 54 /** |
55 * Resets to the default state. GrEffects will be removed from all stages. | 55 * Resets to the default state. GrProcessors will be removed from all stages
. |
56 */ | 56 */ |
57 void reset() { this->onReset(NULL); } | 57 void reset() { this->onReset(NULL); } |
58 | 58 |
59 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } | 59 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } |
60 | 60 |
61 /** | 61 /** |
62 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that | 62 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that |
63 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 63 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint |
64 * equivalents are set to default values with the exception of vertex attrib
ute state which | 64 * equivalents are set to default values with the exception of vertex attrib
ute state which |
65 * is unmodified by this function and clipping which will be enabled. | 65 * is unmodified by this function and clipping which will be enabled. |
66 */ | 66 */ |
67 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); | 67 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); |
68 | 68 |
69 /////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////// |
70 /// @name Vertex Attributes | 70 /// @name Vertex Attributes |
71 //// | 71 //// |
72 | 72 |
73 /** | 73 /** |
74 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing | 74 * The format of vertices is represented as an array of GrVertexAttribs, wit
h each representing |
75 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in | 75 * the type of the attribute, its offset, and semantic binding (see GrVertex
Attrib in |
76 * GrTypesPriv.h). | 76 * GrTypesPriv.h). |
77 * | 77 * |
78 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe
cified when | 78 * The mapping of attributes with kEffect bindings to GrProcessor inputs is
specified when |
79 * setEffect is called. | 79 * setEffect is called. |
80 */ | 80 */ |
81 | 81 |
82 /** | 82 /** |
83 * Sets vertex attributes for next draw. The object driving the templatizat
ion | 83 * Sets vertex attributes for next draw. The object driving the templatizat
ion |
84 * should be a global GrVertexAttrib array that is never changed. | 84 * should be a global GrVertexAttrib array that is never changed. |
85 * | 85 * |
86 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | 86 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
87 * @param stride the number of bytes between successive vertex data. | 87 * @param stride the number of bytes between successive vertex data. |
88 */ | 88 */ |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 | 173 |
174 /// @} | 174 /// @} |
175 | 175 |
176 /** | 176 /** |
177 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, | 177 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, |
178 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader | 178 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader |
179 * but is never put in the color processing pipeline. | 179 * but is never put in the color processing pipeline. |
180 */ | 180 */ |
181 | 181 |
182 const GrEffect* setGeometryProcessor(const GrEffect* effect) { | 182 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g
eometryProcessor) { |
183 SkASSERT(effect); | 183 SkASSERT(geometryProcessor); |
184 SkASSERT(effect->requiresVertexShader()); | |
185 SkASSERT(!this->hasGeometryProcessor()); | 184 SkASSERT(!this->hasGeometryProcessor()); |
186 fGeometryProcessor.reset(new GrEffectStage(effect)); | 185 fGeometryProcessor.reset(new GrGeometryStage(geometryProcessor)); |
187 this->invalidateOptState(); | 186 this->invalidateOptState(); |
188 return effect; | 187 return geometryProcessor; |
189 } | 188 } |
190 | 189 |
191 /////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////// |
192 /// @name Effect Stages | 191 /// @name Effect Stages |
193 /// Each stage hosts a GrEffect. The effect produces an output color or cove
rage in the fragment | 192 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the |
194 /// shader. Its inputs are the output from the previous stage as well as som
e variables | 193 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables |
195 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | 194 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, |
196 /// the fragment position, local coordinates). | 195 /// the fragment position, local coordinates). |
197 /// | 196 /// |
198 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final | 197 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final |
199 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly | 198 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly |
200 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional | 199 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional |
201 /// pixel coverage rather than as input to the src/dst color blend step. | 200 /// pixel coverage rather than as input to the src/dst color blend step. |
202 /// | 201 /// |
203 /// The input color to the first color-stage is either the constant color or
interpolated | 202 /// The input color to the first color-stage is either the constant color or
interpolated |
204 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | 203 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage |
205 /// (usually full-coverage) or interpolated per-vertex coverage. | 204 /// (usually full-coverage) or interpolated per-vertex coverage. |
206 /// | 205 /// |
207 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 206 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
208 /// the color / coverage distinction. | 207 /// the color / coverage distinction. |
209 //// | 208 //// |
210 | 209 |
211 const GrEffect* addColorEffect(const GrEffect* effect) { | 210 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
212 SkASSERT(effect); | 211 SkASSERT(effect); |
213 SkASSERT(!effect->requiresVertexShader()); | 212 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
214 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect)); | |
215 this->invalidateOptState(); | 213 this->invalidateOptState(); |
216 return effect; | 214 return effect; |
217 } | 215 } |
218 | 216 |
219 const GrEffect* addCoverageEffect(const GrEffect* effect) { | 217 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
220 SkASSERT(effect); | 218 SkASSERT(effect); |
221 SkASSERT(!effect->requiresVertexShader()); | 219 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
222 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect)); | |
223 this->invalidateOptState(); | 220 this->invalidateOptState(); |
224 return effect; | 221 return effect; |
225 } | 222 } |
226 | 223 |
227 /** | 224 /** |
228 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. | 225 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. |
229 */ | 226 */ |
230 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 227 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
231 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un
ref(); | 228 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))-
>unref(); |
232 } | 229 } |
233 | 230 |
234 void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 231 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix)
{ |
235 this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix))-
>unref(); | 232 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix
))->unref(); |
236 } | 233 } |
237 | 234 |
238 void addColorTextureEffect(GrTexture* texture, | 235 void addColorTextureProcessor(GrTexture* texture, |
239 const SkMatrix& matrix, | 236 const SkMatrix& matrix, |
240 const GrTextureParams& params) { | 237 const GrTextureParams& params) { |
241 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix, para
ms))->unref(); | 238 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p
arams))->unref(); |
242 } | 239 } |
243 | 240 |
244 void addCoverageTextureEffect(GrTexture* texture, | 241 void addCoverageTextureProcessor(GrTexture* texture, |
245 const SkMatrix& matrix, | 242 const SkMatrix& matrix, |
246 const GrTextureParams& params) { | 243 const GrTextureParams& params) { |
247 this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix, p
arams))->unref(); | 244 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix
, params))->unref(); |
248 } | 245 } |
249 | 246 |
250 /** | 247 /** |
251 * When this object is destroyed it will remove any color/coverage effects f
rom the draw state | 248 * When this object is destroyed it will remove any color/coverage effects f
rom the draw state |
252 * that were added after its constructor. | 249 * that were added after its constructor. |
253 * | 250 * |
254 * This class has strange behavior around geometry processor. If there is a
GP on the draw state | 251 * This class has strange behavior around geometry processor. If there is a
GP on the draw state |
255 * it will assert that the GP is not modified until after the destructor of
the ARE. If the | 252 * it will assert that the GP is not modified until after the destructor of
the ARE. If the |
256 * draw state has a NULL GP when the ARE is constructed then it will reset i
t to null in the | 253 * draw state has a NULL GP when the ARE is constructed then it will reset i
t to null in the |
257 * destructor. | 254 * destructor. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 377 |
381 void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); | 378 void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); |
382 | 379 |
383 /** Sets the draw state's matrix to identity. This can fail because the
current view matrix | 380 /** Sets the draw state's matrix to identity. This can fail because the
current view matrix |
384 is not invertible. */ | 381 is not invertible. */ |
385 bool setIdentity(GrDrawState* drawState); | 382 bool setIdentity(GrDrawState* drawState); |
386 | 383 |
387 private: | 384 private: |
388 void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); | 385 void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); |
389 | 386 |
390 GrDrawState* fDrawState; | 387 GrDrawState* fDrawState; |
391 SkMatrix fViewMatrix; | 388 SkMatrix fViewMatrix; |
392 int fNumColorStages; | 389 int fNumColorStages; |
393 bool fHasGeometryProcesso
r; | 390 bool fHasGeometryProce
ssor; |
394 SkAutoSTArray<8, GrEffectStage::SavedCoordChange> fSavedCoordChanges; | 391 SkAutoSTArray<8, GrProcessorStage::SavedCoordChange> fSavedCoordChange
s; |
395 }; | 392 }; |
396 | 393 |
397 /// @} | 394 /// @} |
398 | 395 |
399 /////////////////////////////////////////////////////////////////////////// | 396 /////////////////////////////////////////////////////////////////////////// |
400 /// @name Render Target | 397 /// @name Render Target |
401 //// | 398 //// |
402 | 399 |
403 /** | 400 /** |
404 * Sets the render-target used at the next drawing call | 401 * Sets the render-target used at the next drawing call |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 558 |
562 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); | 559 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); |
563 | 560 |
564 mutable GrOptDrawState* fCachedOptState; | 561 mutable GrOptDrawState* fCachedOptState; |
565 mutable uint32_t fCachedCapsID; | 562 mutable uint32_t fCachedCapsID; |
566 | 563 |
567 typedef GrRODrawState INHERITED; | 564 typedef GrRODrawState INHERITED; |
568 }; | 565 }; |
569 | 566 |
570 #endif | 567 #endif |
OLD | NEW |