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

Side by Side Diff: include/gpu/GrInvariantOutput.h

Issue 699943003: Move GrInvariantOutput out of GrProcessor and into its own class. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Cleanup Created 6 years, 1 month 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 | « gyp/gpu.gypi ('k') | include/gpu/GrProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrInvariantOutput_DEFINED
9 #define GrInvariantOutput_DEFINED
10
11 #include "GrColor.h"
12
13 class GrInvariantOutput {
14 public:
15 GrInvariantOutput(GrColor color, GrColorComponentFlags flags, bool isSingleC omponent)
16 : fColor(color), fValidFlags(flags), fIsSingleComponent(isSingleComponen t),
17 fNonMulStageFound(false), fWillUseInputColor(true) {}
18
19 virtual ~GrInvariantOutput() {}
20
21 enum ReadInput {
22 kWill_ReadInput,
23 kWillNot_ReadInput,
24 };
25
26 void mulByUnknownOpaqueColor() {
27 if (this->isOpaque()) {
28 fValidFlags = kA_GrColorComponentFlag;
29 fIsSingleComponent = false;
30 } else {
31 // Since the current state is not opaque we no longer care if the co lor being
32 // multiplied is opaque.
33 this->mulByUnknownColor();
34 }
35 }
36
37 void mulByUnknownColor() {
38 if (this->hasZeroAlpha()) {
39 this->internalSetToTransparentBlack();
40 } else {
41 this->internalSetToUnknown();
42 }
43 }
44
45 void mulByUnknownAlpha() {
46 if (this->hasZeroAlpha()) {
47 this->internalSetToTransparentBlack();
48 } else {
49 // We don't need to change fIsSingleComponent in this case
50 fValidFlags = 0;
51 }
52 }
53
54 void mulByKnownAlpha(uint8_t alpha) {
55 if (this->hasZeroAlpha() || 0 == alpha) {
56 this->internalSetToTransparentBlack();
57 } else {
58 if (alpha != 255) {
59 // Multiply color by alpha
60 fColor = GrColorPackRGBA(SkMulDiv255Round(GrColorUnpackR(fColor) , alpha),
61 SkMulDiv255Round(GrColorUnpackG(fColor) , alpha),
62 SkMulDiv255Round(GrColorUnpackB(fColor) , alpha),
63 SkMulDiv255Round(GrColorUnpackA(fColor) , alpha));
64 }
65 }
66 }
67
68 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) {
69 fValidFlags &= ~invalidateFlags;
70 fIsSingleComponent = false;
71 fNonMulStageFound = true;
72 if (kWillNot_ReadInput == readsInput) {
73 fWillUseInputColor = false;
74 }
75 }
76
77 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) {
78 fValidFlags = validFlags;
79 fColor = color;
80 fIsSingleComponent = false;
81 fNonMulStageFound = true;
82 if (kWillNot_ReadInput == readsInput) {
83 fWillUseInputColor = false;
84 }
85 }
86
87 void setToUnknown(ReadInput readsInput) {
88 this->internalSetToUnknown();
89 fNonMulStageFound= true;
90 if (kWillNot_ReadInput == readsInput) {
91 fWillUseInputColor = false;
92 }
93 }
94
95 bool isOpaque() const {
96 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpack A(fColor));
97 }
98
99 bool isSolidWhite() const {
100 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fCol or);
101 }
102
103 GrColor color() const { return fColor; }
104 uint8_t validFlags() const { return fValidFlags; }
105
106 bool willUseInputColor() const { return fWillUseInputColor; }
107 void resetWillUseInputColor() { fWillUseInputColor = true; }
108
109 void resetNonMulStageFound() { fNonMulStageFound = false; }
110
111 /**
112 * If isSingleComponent is true, then the flag values for r, g, b, and a mus t all be the
113 * same. If the flags are all set then all color components must be equal.
114 */
115 SkDEBUGCODE(void validate() const;)
116
117 protected:
118 GrColor fColor;
119 uint32_t fValidFlags;
120 bool fIsSingleComponent;
121 bool fNonMulStageFound;
122 bool fWillUseInputColor;
123
124 private:
125 void internalSetToTransparentBlack() {
126 fValidFlags = kRGBA_GrColorComponentFlags;
127 fColor = 0;
128 fIsSingleComponent = true;
129 }
130
131 void internalSetToUnknown() {
132 fValidFlags = 0;
133 fIsSingleComponent = false;
134 }
135
136 bool hasZeroAlpha() const {
137 return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpackA(f Color));
138 }
139
140 SkDEBUGCODE(bool colorComponentsAllEqual() const;)
141 /**
142 * If alpha is valid, check that any valid R,G,B values are <= A
143 */
144 SkDEBUGCODE(bool validPreMulColor() const;)
145 };
146
147 #endif
148
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698