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