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

Side by Side Diff: src/gpu/GrPaint.cpp

Issue 22558003: Add blend optimization helpers and use to convert rect draws to clears. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: suppress warning Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrPaint.h" 9 #include "GrPaint.h"
10 10
11 #include "GrBlend.h"
11 #include "effects/GrSimpleTextureEffect.h" 12 #include "effects/GrSimpleTextureEffect.h"
12 13
13 void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { 14 void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
14 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); 15 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
15 this->addColorEffect(effect)->unref(); 16 this->addColorEffect(effect)->unref();
16 } 17 }
17 18
18 void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matri x) { 19 void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matri x) {
19 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); 20 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
20 this->addCoverageEffect(effect)->unref(); 21 this->addCoverageEffect(effect)->unref();
21 } 22 }
22 23
23 void GrPaint::addColorTextureEffect(GrTexture* texture, 24 void GrPaint::addColorTextureEffect(GrTexture* texture,
24 const SkMatrix& matrix, 25 const SkMatrix& matrix,
25 const GrTextureParams& params) { 26 const GrTextureParams& params) {
26 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params) ; 27 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params) ;
27 this->addColorEffect(effect)->unref(); 28 this->addColorEffect(effect)->unref();
28 } 29 }
29 30
30 void GrPaint::addCoverageTextureEffect(GrTexture* texture, 31 void GrPaint::addCoverageTextureEffect(GrTexture* texture,
31 const SkMatrix& matrix, 32 const SkMatrix& matrix,
32 const GrTextureParams& params) { 33 const GrTextureParams& params) {
33 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params) ; 34 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params) ;
34 this->addCoverageEffect(effect)->unref(); 35 this->addCoverageEffect(effect)->unref();
35 } 36 }
37
38 bool GrPaint::isOpaque() const {
39 return this->getOpaqueAndKnownColor(NULL, NULL);
40 }
41
42 bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
43 GrColor tempColor;
44 uint32_t colorComps;
45 if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
46 if (kRGBA_GrColorComponentFlags == colorComps) {
47 *color = tempColor;
48 return true;
49 }
50 }
51 return false;
52 }
53
54 bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
55 uint32_t* solidColorKnownComponents) const {
56
57 // TODO: Share this implementation with GrDrawState
58
59 // Since fColorFilterXfermode is going away soon, we aren't attempting to ha ndle anything but
60 // the default setting.
61 if (SkXfermode::kDst_Mode != fColorFilterXfermode) {
62 return false;
63 }
64
65 GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverag e);
66 uint32_t coverageComps = kRGBA_GrColorComponentFlags;
67 int count = fCoverageStages.count();
68 for (int i = 0; i < count; ++i) {
69 (*fCoverageStages[i].getEffect())->getConstantColorComponents(&coverage, &coverageComps);
70 }
71 if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) {
72 return false;
73 }
74
75 GrColor color = fColor;
76 uint32_t colorComps = kRGBA_GrColorComponentFlags;
77 count = fColorStages.count();
78 for (int i = 0; i < count; ++i) {
79 (*fColorStages[i].getEffect())->getConstantColorComponents(&color, &colo rComps);
80 }
81
82 GrAssert((NULL == solidColor) == (NULL == solidColorKnownComponents));
83
84 GrBlendCoeff srcCoeff = fSrcBlendCoeff;
85 GrBlendCoeff dstCoeff = fDstBlendCoeff;
86 GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0);
87
88 bool opaque = kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoef f);
89 if (NULL != solidColor) {
90 if (opaque) {
91 switch (srcCoeff) {
92 case kZero_GrBlendCoeff:
93 *solidColor = 0;
94 *solidColorKnownComponents = kRGBA_GrColorComponentFlags;
95 break;
96
97 case kOne_GrBlendCoeff:
98 *solidColor = color;
99 *solidColorKnownComponents = colorComps;
100 break;
101
102 // The src coeff should never refer to the src and if it refers to dst then opaque
103 // should have been false.
104 case kSC_GrBlendCoeff:
105 case kISC_GrBlendCoeff:
106 case kDC_GrBlendCoeff:
107 case kIDC_GrBlendCoeff:
108 case kSA_GrBlendCoeff:
109 case kISA_GrBlendCoeff:
110 case kDA_GrBlendCoeff:
111 case kIDA_GrBlendCoeff:
112 default:
113 GrCrash("srcCoeff should not refer to src or dst.");
114 break;
115
116 // TODO: update this once GrPaint actually has a const color.
117 case kConstC_GrBlendCoeff:
118 case kIConstC_GrBlendCoeff:
119 case kConstA_GrBlendCoeff:
120 case kIConstA_GrBlendCoeff:
121 *solidColorKnownComponents = 0;
122 break;
123 }
124 } else {
125 solidColorKnownComponents = 0;
126 }
127 }
128 return opaque;
129 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698