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 #include "GrInvariantOutput.h" | 8 #include "GrInvariantOutput.h" |
9 | 9 |
10 #ifdef SK_DEBUG | 10 #ifdef SK_DEBUG |
11 | 11 |
12 void GrInvariantOutput::validate() const { | 12 void GrInvariantOutput::validate() const { |
13 if (fIsSingleComponent) { | 13 if (fIsSingleComponent) { |
14 SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags)
; | 14 SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags)
; |
15 if (kRGBA_GrColorComponentFlags == fValidFlags) { | 15 if (kRGBA_GrColorComponentFlags == fValidFlags) { |
16 SkASSERT(this->colorComponentsAllEqual()); | 16 SkASSERT(this->colorComponentsAllEqual()); |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 SkASSERT(this->validPreMulColor()); | |
21 | |
22 // If we claim that we are not using the input color we must not be modulati
ng the input. | 20 // If we claim that we are not using the input color we must not be modulati
ng the input. |
23 SkASSERT(fNonMulStageFound || fWillUseInputColor); | 21 SkASSERT(fNonMulStageFound || fWillUseInputColor); |
24 } | 22 } |
25 | 23 |
26 bool GrInvariantOutput::colorComponentsAllEqual() const { | 24 bool GrInvariantOutput::colorComponentsAllEqual() const { |
27 unsigned colorA = GrColorUnpackA(fColor); | 25 unsigned colorA = GrColorUnpackA(fColor); |
28 return(GrColorUnpackR(fColor) == colorA && | 26 return(GrColorUnpackR(fColor) == colorA && |
29 GrColorUnpackG(fColor) == colorA && | 27 GrColorUnpackG(fColor) == colorA && |
30 GrColorUnpackB(fColor) == colorA); | 28 GrColorUnpackB(fColor) == colorA); |
31 } | 29 } |
32 | 30 |
33 bool GrInvariantOutput::validPreMulColor() const { | |
34 if (kA_GrColorComponentFlag & fValidFlags) { | |
35 float c[4]; | |
36 GrColorToRGBAFloat(fColor, c); | |
37 if (kR_GrColorComponentFlag & fValidFlags) { | |
38 if (c[0] > c[3]) { | |
39 return false; | |
40 } | |
41 } | |
42 if (kG_GrColorComponentFlag & fValidFlags) { | |
43 if (c[1] > c[3]) { | |
44 return false; | |
45 } | |
46 } | |
47 if (kB_GrColorComponentFlag & fValidFlags) { | |
48 if (c[2] > c[3]) { | |
49 return false; | |
50 } | |
51 } | |
52 } | |
53 return true; | |
54 } | |
55 | |
56 #endif // end DEBUG | 31 #endif // end DEBUG |
57 | 32 |
OLD | NEW |