| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrRODrawState_DEFINED | 8 #ifndef GrRODrawState_DEFINED |
| 9 #define GrRODrawState_DEFINED | 9 #define GrRODrawState_DEFINED |
| 10 | 10 |
| 11 #include "GrEffectStage.h" | 11 #include "GrEffectStage.h" |
| 12 #include "GrRenderTarget.h" | 12 #include "GrRenderTarget.h" |
| 13 #include "GrStencil.h" | 13 #include "GrStencil.h" |
| 14 #include "SkMatrix.h" | 14 #include "SkMatrix.h" |
| 15 | 15 |
| 16 class GrDrawState; |
| 16 class GrDrawTargetCaps; | 17 class GrDrawTargetCaps; |
| 17 class GrPaint; | 18 class GrPaint; |
| 18 class GrTexture; | 19 class GrTexture; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * Read-only base class for GrDrawState. This class contains all the necessary d
ata to represent a | 22 * Read-only base class for GrDrawState. This class contains all the necessary d
ata to represent a |
| 22 * canonical DrawState. All methods in the class are const, thus once created th
e data in the class | 23 * canonical DrawState. All methods in the class are const, thus once created th
e data in the class |
| 23 * cannot be changed. | 24 * cannot be changed. |
| 24 */ | 25 */ |
| 25 class GrRODrawState : public SkRefCnt { | 26 class GrRODrawState : public SkRefCnt { |
| 26 public: | 27 public: |
| 27 SK_DECLARE_INST_COUNT(GrRODrawState) | 28 SK_DECLARE_INST_COUNT(GrRODrawState) |
| 28 | 29 |
| 30 GrRODrawState() {} |
| 31 |
| 32 GrRODrawState& operator= (const GrRODrawState& that); |
| 33 |
| 29 /////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////// |
| 30 /// @name Vertex Attributes | 35 /// @name Vertex Attributes |
| 31 //// | 36 //// |
| 32 | 37 |
| 33 enum { | 38 enum { |
| 34 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, | 39 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, |
| 35 }; | 40 }; |
| 36 | 41 |
| 37 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } | 42 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } |
| 38 int getVertexAttribCount() const { return fVACount; } | 43 int getVertexAttribCount() const { return fVACount; } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 61 bool hasLocalCoordAttribute() const { | 66 bool hasLocalCoordAttribute() const { |
| 62 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri
bBinding]; | 67 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri
bBinding]; |
| 63 } | 68 } |
| 64 bool hasColorVertexAttribute() const { | 69 bool hasColorVertexAttribute() const { |
| 65 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind
ing]; | 70 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind
ing]; |
| 66 } | 71 } |
| 67 bool hasCoverageVertexAttribute() const { | 72 bool hasCoverageVertexAttribute() const { |
| 68 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB
inding]; | 73 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB
inding]; |
| 69 } | 74 } |
| 70 | 75 |
| 76 const int* getFixedFunctionVertexAttribIndices() const { |
| 77 return fFixedFunctionVertexAttribIndices; |
| 78 } |
| 79 |
| 71 bool validateVertexAttribs() const; | 80 bool validateVertexAttribs() const; |
| 72 | 81 |
| 73 /// @} | 82 /// @} |
| 74 | 83 |
| 75 /** | 84 /** |
| 76 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. | 85 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. |
| 77 */ | 86 */ |
| 78 bool hasSolidCoverage() const; | 87 bool hasSolidCoverage() const; |
| 79 | 88 |
| 80 /// @} | 89 /// @} |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 *dstBlendCoeff = fDstBlend; | 160 *dstBlendCoeff = fDstBlend; |
| 152 } | 161 } |
| 153 | 162 |
| 154 /** | 163 /** |
| 155 * Retrieves the last value set by setBlendConstant() | 164 * Retrieves the last value set by setBlendConstant() |
| 156 * @return the blending constant value | 165 * @return the blending constant value |
| 157 */ | 166 */ |
| 158 GrColor getBlendConstant() const { return fBlendConstant; } | 167 GrColor getBlendConstant() const { return fBlendConstant; } |
| 159 | 168 |
| 160 /** | 169 /** |
| 170 * We don't use supplied vertex color attributes if our blend mode is EmitCo
verage or |
| 171 * EmitTransBlack |
| 172 */ |
| 173 bool canIgnoreColorAttribute() const; |
| 174 |
| 175 /** |
| 161 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 176 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 162 * coverage before the blend will give the correct final destination color.
In general it | 177 * coverage before the blend will give the correct final destination color.
In general it |
| 163 * will not as coverage is applied after blending. | 178 * will not as coverage is applied after blending. |
| 164 */ | 179 */ |
| 165 bool canTweakAlphaForCoverage() const; | 180 bool canTweakAlphaForCoverage() const; |
| 166 | 181 |
| 167 /** | 182 /** |
| 168 * Optimizations for blending / coverage to that can be applied based on the
current state. | 183 * Optimizations for blending / coverage to that can be applied based on the
current state. |
| 169 */ | 184 */ |
| 170 enum BlendOptFlags { | 185 enum BlendOptFlags { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 191 */ | 206 */ |
| 192 kEmitTransBlack_BlendOptFlag = 0x8, | 207 kEmitTransBlack_BlendOptFlag = 0x8, |
| 193 /** | 208 /** |
| 194 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op
tDstCoeff cached by | 209 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op
tDstCoeff cached by |
| 195 * the get BlendOpts function. | 210 * the get BlendOpts function. |
| 196 */ | 211 */ |
| 197 kInvalid_BlendOptFlag = 1 << 31, | 212 kInvalid_BlendOptFlag = 1 << 31, |
| 198 }; | 213 }; |
| 199 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | 214 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
| 200 | 215 |
| 216 /** |
| 217 * Determines what optimizations can be applied based on the blend. The coef
ficients may have |
| 218 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional |
| 219 * params that receive the tweaked coefficients. Normally the function looks
at the current |
| 220 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively |
| 221 * determine the blend optimizations that would be used if there was partial
pixel coverage. |
| 222 * |
| 223 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
ust buffer for |
| 224 * playback) must call this function and respect the flags that replace the
output color. |
| 225 * |
| 226 * If the cached BlendOptFlags does not have the invalidate bit set, then ge
tBlendOpts will |
| 227 * simply returned the cached flags and coefficients. Otherwise it will calc
ulate the values. |
| 228 */ |
| 229 BlendOptFlags getBlendOpts(bool forceCoverage = false, |
| 230 GrBlendCoeff* srcCoeff = NULL, |
| 231 GrBlendCoeff* dstCoeff = NULL) const; |
| 201 /// @} | 232 /// @} |
| 202 | 233 |
| 203 /////////////////////////////////////////////////////////////////////////// | 234 /////////////////////////////////////////////////////////////////////////// |
| 204 /// @name View Matrix | 235 /// @name View Matrix |
| 205 //// | 236 //// |
| 206 | 237 |
| 207 /** | 238 /** |
| 208 * Retrieves the current view matrix | 239 * Retrieves the current view matrix |
| 209 * @return the current view matrix. | 240 * @return the current view matrix. |
| 210 */ | 241 */ |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 * control over the blend coeffs. When set, there will be a single blend
step controlled by | 325 * control over the blend coeffs. When set, there will be a single blend
step controlled by |
| 295 * setBlendFunc() which will use coverage*color as the src color. | 326 * setBlendFunc() which will use coverage*color as the src color. |
| 296 */ | 327 */ |
| 297 kCoverageDrawing_StateBit = 0x10, | 328 kCoverageDrawing_StateBit = 0x10, |
| 298 | 329 |
| 299 // Users of the class may add additional bits to the vector | 330 // Users of the class may add additional bits to the vector |
| 300 kDummyStateBit, | 331 kDummyStateBit, |
| 301 kLastPublicStateBit = kDummyStateBit-1, | 332 kLastPublicStateBit = kDummyStateBit-1, |
| 302 }; | 333 }; |
| 303 | 334 |
| 335 uint32_t getFlagBits() const { return fFlagBits; } |
| 336 |
| 304 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f
FlagBits); } | 337 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f
FlagBits); } |
| 305 | 338 |
| 306 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } | 339 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } |
| 307 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat
eBit); } | 340 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat
eBit); } |
| 308 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } | 341 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
| 309 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } | 342 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } |
| 310 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } | 343 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } |
| 311 | 344 |
| 312 /// @} | 345 /// @} |
| 313 | 346 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 326 /** | 359 /** |
| 327 * Gets whether the target is drawing clockwise, counterclockwise, | 360 * Gets whether the target is drawing clockwise, counterclockwise, |
| 328 * or both faces. | 361 * or both faces. |
| 329 * @return the current draw face(s). | 362 * @return the current draw face(s). |
| 330 */ | 363 */ |
| 331 DrawFace getDrawFace() const { return fDrawFace; } | 364 DrawFace getDrawFace() const { return fDrawFace; } |
| 332 | 365 |
| 333 /// @} | 366 /// @} |
| 334 | 367 |
| 335 /////////////////////////////////////////////////////////////////////////// | 368 /////////////////////////////////////////////////////////////////////////// |
| 369 /// @name Hints |
| 370 /// Hints that when provided can enable optimizations. |
| 371 //// |
| 372 |
| 373 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; |
| 374 |
| 375 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } |
| 376 |
| 377 /// @} |
| 378 |
| 379 /////////////////////////////////////////////////////////////////////////// |
| 336 | 380 |
| 337 /** Return type for CombineIfPossible. */ | 381 /** Return type for CombineIfPossible. */ |
| 338 enum CombinedState { | 382 enum CombinedState { |
| 339 /** The GrDrawStates cannot be combined. */ | 383 /** The GrDrawStates cannot be combined. */ |
| 340 kIncompatible_CombinedState, | 384 kIncompatible_CombinedState, |
| 341 /** Either draw state can be used in place of the other. */ | 385 /** Either draw state can be used in place of the other. */ |
| 342 kAOrB_CombinedState, | 386 kAOrB_CombinedState, |
| 343 /** Use the first draw state. */ | 387 /** Use the first draw state. */ |
| 344 kA_CombinedState, | 388 kA_CombinedState, |
| 345 /** Use the second draw state. */ | 389 /** Use the second draw state. */ |
| 346 kB_CombinedState, | 390 kB_CombinedState, |
| 347 }; | 391 }; |
| 348 | 392 |
| 349 protected: | 393 protected: |
| 350 /** | 394 /** |
| 351 * Converts refs on GrGpuResources owned directly or indirectly by this GrRO
DrawState into | 395 * Converts refs on GrGpuResources owned directly or indirectly by this GrRO
DrawState into |
| 352 * pending reads and writes. This should be called when a GrDrawState is rec
orded into | 396 * pending reads and writes. This should be called when a GrDrawState is rec
orded into |
| 353 * a GrDrawTarget for later execution. Subclasses of GrRODrawState may add s
etters. However, | 397 * a GrDrawTarget for later execution. Subclasses of GrRODrawState may add s
etters. However, |
| 354 * once this call has been made the GrRODrawState is immutable. It is also n
o longer copyable. | 398 * once this call has been made the GrRODrawState is immutable. It is also n
o longer copyable. |
| 355 * In the future this conversion will automatically happen when converting a
GrDrawState into | 399 * In the future this conversion will automatically happen when converting a
GrDrawState into |
| 356 * an optimized draw state. | 400 * an optimized draw state. |
| 357 */ | 401 */ |
| 358 void convertToPendingExec(); | 402 void convertToPendingExec(); |
| 359 | 403 |
| 360 friend class GrDrawTarget; | 404 friend class GrDrawTarget; |
| 361 | 405 |
| 406 explicit GrRODrawState(const GrRODrawState& drawState); |
| 407 |
| 362 bool isEqual(const GrRODrawState& that) const; | 408 bool isEqual(const GrRODrawState& that) const; |
| 363 | 409 |
| 364 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== | 410 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== |
| 365 GrProgramResource fRenderTarget; | 411 GrProgramResource fRenderTarget; |
| 366 GrColor fColor; | 412 GrColor fColor; |
| 367 SkMatrix fViewMatrix; | 413 SkMatrix fViewMatrix; |
| 368 GrColor fBlendConstant; | 414 GrColor fBlendConstant; |
| 369 uint32_t fFlagBits; | 415 uint32_t fFlagBits; |
| 370 const GrVertexAttrib* fVAPtr; | 416 const GrVertexAttrib* fVAPtr; |
| 371 int fVACount; | 417 int fVACount; |
| 372 size_t fVAStride; | 418 size_t fVAStride; |
| 373 GrStencilSettings fStencilSettings; | 419 GrStencilSettings fStencilSettings; |
| 374 uint8_t fCoverage; | 420 uint8_t fCoverage; |
| 375 DrawFace fDrawFace; | 421 DrawFace fDrawFace; |
| 376 GrBlendCoeff fSrcBlend; | 422 GrBlendCoeff fSrcBlend; |
| 377 GrBlendCoeff fDstBlend; | 423 GrBlendCoeff fDstBlend; |
| 378 | 424 |
| 379 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 425 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| 380 SkAutoTDelete<GrEffectStage> fGeometryProcessor; | 426 SkAutoTDelete<GrEffectStage> fGeometryProcessor; |
| 381 EffectStageArray fColorStages; | 427 EffectStageArray fColorStages; |
| 382 EffectStageArray fCoverageStages; | 428 EffectStageArray fCoverageStages; |
| 383 | 429 |
| 430 uint32_t fHints; |
| 431 |
| 384 mutable GrBlendCoeff fOptSrcBlend; | 432 mutable GrBlendCoeff fOptSrcBlend; |
| 385 mutable GrBlendCoeff fOptDstBlend; | 433 mutable GrBlendCoeff fOptDstBlend; |
| 386 mutable BlendOptFlags fBlendOptFlags; | 434 mutable BlendOptFlags fBlendOptFlags; |
| 387 | 435 |
| 388 // This is simply a different representation of info in fVertexAttribs and t
hus does | 436 // This is simply a different representation of info in fVertexAttribs and t
hus does |
| 389 // not need to be compared in op==. | 437 // not need to be compared in op==. |
| 390 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; | 438 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; |
| 391 | 439 |
| 392 private: | 440 private: |
| 441 /** |
| 442 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 443 */ |
| 444 bool srcAlphaWillBeOne() const; |
| 445 |
| 446 /** |
| 447 * Helper function for getBlendOpts. |
| 448 */ |
| 449 BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
| 450 GrBlendCoeff* srcCoeff = NULL, |
| 451 GrBlendCoeff* dstCoeff = NULL) const; |
| 452 |
| 393 typedef SkRefCnt INHERITED; | 453 typedef SkRefCnt INHERITED; |
| 394 }; | 454 }; |
| 395 | 455 |
| 396 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); | 456 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); |
| 397 | 457 |
| 398 #endif | 458 #endif |
| OLD | NEW |