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

Side by Side Diff: src/gpu/GrDrawState.h

Issue 766653008: Revert of Make all blending up to GrOptDrawState be handled by the xp/xp factory. (Closed) Base URL: https://skia.googlesource.com/skia.git@xferFactorySolo
Patch Set: Created 6 years 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 | « src/gpu/GrDistanceFieldTextContext.cpp ('k') | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 11
12 #include "GrBlend.h" 12 #include "GrBlend.h"
13 #include "GrDrawTargetCaps.h" 13 #include "GrDrawTargetCaps.h"
14 #include "GrGeometryProcessor.h" 14 #include "GrGeometryProcessor.h"
15 #include "GrGpuResourceRef.h" 15 #include "GrGpuResourceRef.h"
16 #include "GrFragmentStage.h" 16 #include "GrFragmentStage.h"
17 #include "GrProcOptInfo.h" 17 #include "GrProcOptInfo.h"
18 #include "GrRenderTarget.h" 18 #include "GrRenderTarget.h"
19 #include "GrStencil.h" 19 #include "GrStencil.h"
20 #include "GrXferProcessor.h"
21 #include "SkMatrix.h" 20 #include "SkMatrix.h"
22 #include "effects/GrPorterDuffXferProcessor.h"
23 #include "effects/GrSimpleTextureEffect.h" 21 #include "effects/GrSimpleTextureEffect.h"
24 22
25 class GrDrawTargetCaps; 23 class GrDrawTargetCaps;
26 class GrPaint; 24 class GrPaint;
27 class GrTexture; 25 class GrTexture;
28 26
29 class GrDrawState { 27 class GrDrawState {
30 public: 28 public:
31 GrDrawState() { 29 GrDrawState() {
32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 30 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } 207 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); }
210 208
211 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id x]; } 209 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id x]; }
212 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta ges[idx]; } 210 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta ges[idx]; }
213 211
214 /** 212 /**
215 * Checks whether any of the effects will read the dst pixel color. 213 * Checks whether any of the effects will read the dst pixel color.
216 */ 214 */
217 bool willEffectReadDstColor() const; 215 bool willEffectReadDstColor() const;
218 216
219 /**
220 * The xfer processor factory.
221 */
222 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) {
223 fXPFactory.reset(SkRef(xpFactory));
224 return xpFactory;
225 }
226
227 void setPorterDuffXPFactory(SkXfermode::Mode mode) {
228 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode));
229 }
230
231 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) {
232 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst));
233 }
234
235 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe ct) { 217 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe ct) {
236 SkASSERT(effect); 218 SkASSERT(effect);
237 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); 219 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect));
238 fColorProcInfoValid = false; 220 fColorProcInfoValid = false;
239 return effect; 221 return effect;
240 } 222 }
241 223
242 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e ffect) { 224 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e ffect) {
243 SkASSERT(effect); 225 SkASSERT(effect);
244 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); 226 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect));
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 GrDrawState* fDrawState; 325 GrDrawState* fDrawState;
344 GrStencilSettings fStencilSettings; 326 GrStencilSettings fStencilSettings;
345 }; 327 };
346 328
347 /// @} 329 /// @}
348 330
349 /////////////////////////////////////////////////////////////////////////// 331 ///////////////////////////////////////////////////////////////////////////
350 /// @name Blending 332 /// @name Blending
351 //// 333 ////
352 334
335 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; }
336 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; }
337
338 /**
339 * Retrieves the last value set by setBlendConstant()
340 * @return the blending constant value
341 */
342 GrColor getBlendConstant() const { return fBlendConstant; }
343
353 /** 344 /**
354 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional 345 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional
355 * coverage before the blend will give the correct final destination color. In general it 346 * coverage before the blend will give the correct final destination color. In general it
356 * will not as coverage is applied after blending. 347 * will not as coverage is applied after blending.
357 */ 348 */
358 bool canTweakAlphaForCoverage() const; 349 bool canTweakAlphaForCoverage() const;
359 350
351 /**
352 * Sets the blending function coefficients.
353 *
354 * The blend function will be:
355 * D' = sat(S*srcCoef + D*dstCoef)
356 *
357 * where D is the existing destination color, S is the incoming source
358 * color, and D' is the new destination color that will be written. sat()
359 * is the saturation function.
360 *
361 * @param srcCoef coefficient applied to the src color.
362 * @param dstCoef coefficient applied to the dst color.
363 */
364 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
365 fSrcBlend = srcCoeff;
366 fDstBlend = dstCoeff;
367 #ifdef SK_DEBUG
368 if (GrBlendCoeffRefsDst(dstCoeff)) {
369 SkDebugf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n");
370 }
371 if (GrBlendCoeffRefsSrc(srcCoeff)) {
372 SkDebugf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n");
373 }
374 #endif
375 }
376
377 /**
378 * Sets the blending function constant referenced by the following blending
379 * coefficients:
380 * kConstC_GrBlendCoeff
381 * kIConstC_GrBlendCoeff
382 * kConstA_GrBlendCoeff
383 * kIConstA_GrBlendCoeff
384 *
385 * @param constant the constant to set
386 */
387 void setBlendConstant(GrColor constant) { fBlendConstant = constant; }
388
360 /// @} 389 /// @}
361 390
362 /////////////////////////////////////////////////////////////////////////// 391 ///////////////////////////////////////////////////////////////////////////
363 /// @name View Matrix 392 /// @name View Matrix
364 //// 393 ////
365 394
366 /** 395 /**
367 * Retrieves the current view matrix 396 * Retrieves the current view matrix
368 * @return the current view matrix. 397 * @return the current view matrix.
369 */ 398 */
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 630
602 /// @} 631 /// @}
603 632
604 /////////////////////////////////////////////////////////////////////////// 633 ///////////////////////////////////////////////////////////////////////////
605 634
606 GrDrawState& operator= (const GrDrawState& that); 635 GrDrawState& operator= (const GrDrawState& that);
607 636
608 private: 637 private:
609 bool isEqual(const GrDrawState& that) const; 638 bool isEqual(const GrDrawState& that) const;
610 639
640 /**
641 * Optimizations for blending / coverage to that can be applied based on the current state.
642 */
643 enum BlendOpt {
644 /**
645 * No optimization
646 */
647 kNone_BlendOpt,
648 /**
649 * Don't draw at all
650 */
651 kSkipDraw_BlendOpt,
652 /**
653 * The coverage value does not have to be computed separately from alpha , the the output
654 * color can be the modulation of the two.
655 */
656 kCoverageAsAlpha_BlendOpt,
657 /**
658 * Instead of emitting a src color, emit coverage in the alpha channel a nd r,g,b are
659 * "don't cares".
660 */
661 kEmitCoverage_BlendOpt,
662 /**
663 * Emit transparent black instead of the src color, no need to compute c overage.
664 */
665 kEmitTransBlack_BlendOpt
666 };
667
668 /**
669 * Determines what optimizations can be applied based on the blend. The coef ficients may have
670 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional
671 * params that receive the tweaked coefficients. Normally the function looks at the current
672 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
673 * determine the blend optimizations that would be used if there was partial pixel coverage.
674 *
675 * This is used internally and when constructing a GrOptDrawState.
676 */
677 BlendOpt getBlendOpt(bool forceCoverage = false,
678 GrBlendCoeff* srcCoeff = NULL,
679 GrBlendCoeff* dstCoeff = NULL) const;
680
611 const GrProcOptInfo& colorProcInfo() const { 681 const GrProcOptInfo& colorProcInfo() const {
612 this->calcColorInvariantOutput(); 682 this->calcColorInvariantOutput();
613 return fColorProcInfo; 683 return fColorProcInfo;
614 } 684 }
615 685
616 const GrProcOptInfo& coverageProcInfo() const { 686 const GrProcOptInfo& coverageProcInfo() const {
617 this->calcCoverageInvariantOutput(); 687 this->calcCoverageInvariantOutput();
618 return fCoverageProcInfo; 688 return fCoverageProcInfo;
619 } 689 }
620 690
(...skipping 18 matching lines...) Expand all
639 709
640 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. 710 // Some of the auto restore objects assume that no effects are removed durin g their lifetime.
641 // This is used to assert that this condition holds. 711 // This is used to assert that this condition holds.
642 SkDEBUGCODE(int fBlockEffectRemovalCnt;) 712 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
643 713
644 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; 714 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
645 715
646 SkAutoTUnref<GrRenderTarget> fRenderTarget; 716 SkAutoTUnref<GrRenderTarget> fRenderTarget;
647 GrColor fColor; 717 GrColor fColor;
648 SkMatrix fViewMatrix; 718 SkMatrix fViewMatrix;
719 GrColor fBlendConstant;
649 uint32_t fFlagBits; 720 uint32_t fFlagBits;
650 GrStencilSettings fStencilSettings; 721 GrStencilSettings fStencilSettings;
651 uint8_t fCoverage; 722 uint8_t fCoverage;
652 DrawFace fDrawFace; 723 DrawFace fDrawFace;
724 GrBlendCoeff fSrcBlend;
725 GrBlendCoeff fDstBlend;
653 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; 726 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
654 SkAutoTUnref<const GrXPFactory> fXPFactory; 727 SkAutoTUnref<const GrXPFactory> fXPFactory;
655 FragmentStageArray fColorStages; 728 FragmentStageArray fColorStages;
656 FragmentStageArray fCoverageStages; 729 FragmentStageArray fCoverageStages;
657 uint32_t fHints; 730 uint32_t fHints;
658 731
659 mutable GrProcOptInfo fColorProcInfo; 732 mutable GrProcOptInfo fColorProcInfo;
660 mutable GrProcOptInfo fCoverageProcInfo; 733 mutable GrProcOptInfo fCoverageProcInfo;
661 mutable bool fColorProcInfoValid; 734 mutable bool fColorProcInfoValid;
662 mutable bool fCoverageProcInfoValid; 735 mutable bool fCoverageProcInfoValid;
663 736
664 friend class GrOptDrawState; 737 friend class GrOptDrawState;
665 }; 738 };
666 739
667 #endif 740 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.cpp ('k') | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698