OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrProcessor_DEFINED | 8 #ifndef GrProcessor_DEFINED |
9 #define GrProcessor_DEFINED | 9 #define GrProcessor_DEFINED |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 effect must reach 0 before the thread terminates and the pool is destroyed.
To create a static | 31 effect must reach 0 before the thread terminates and the pool is destroyed.
To create a static |
32 effect use the macro GR_CREATE_STATIC_EFFECT declared below. | 32 effect use the macro GR_CREATE_STATIC_EFFECT declared below. |
33 */ | 33 */ |
34 class GrProcessor : public GrProgramElement { | 34 class GrProcessor : public GrProgramElement { |
35 public: | 35 public: |
36 SK_DECLARE_INST_COUNT(GrProcessor) | 36 SK_DECLARE_INST_COUNT(GrProcessor) |
37 | 37 |
38 virtual ~GrProcessor(); | 38 virtual ~GrProcessor(); |
39 | 39 |
40 struct InvariantOutput{ | 40 struct InvariantOutput{ |
41 InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false)
{} | 41 InvariantOutput() : fColor(0), fValidFlags(0), fIsSingleComponent(false)
, |
| 42 fNonMulStageFound(false) {} |
42 | 43 |
43 void mulByUnknownOpaqueColor() { | 44 void mulByUnknownOpaqueColor() { |
44 if (this->isOpaque()) { | 45 if (this->isOpaque()) { |
45 fValidFlags = kA_GrColorComponentFlag; | 46 fValidFlags = kA_GrColorComponentFlag; |
46 fIsSingleComponent = false; | 47 fIsSingleComponent = false; |
47 } else { | 48 } else { |
48 // Since the current state is not opaque we no longer care if th
e color being | 49 // Since the current state is not opaque we no longer care if th
e color being |
49 // multiplied is opaque. | 50 // multiplied is opaque. |
50 this->mulByUnknownColor(); | 51 this->mulByUnknownColor(); |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
54 void mulByUnknownColor() { | 55 void mulByUnknownColor() { |
55 if (this->hasZeroAlpha()) { | 56 if (this->hasZeroAlpha()) { |
56 this->setToTransparentBlack(); | 57 this->internalSetToTransparentBlack(); |
57 } else { | 58 } else { |
58 this->setToUnknown(); | 59 this->internalSetToUnknown(); |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
62 void mulByUnknownAlpha() { | 63 void mulByUnknownAlpha() { |
63 if (this->hasZeroAlpha()) { | 64 if (this->hasZeroAlpha()) { |
64 this->setToTransparentBlack(); | 65 this->internalSetToTransparentBlack(); |
65 } else { | 66 } else { |
66 // We don't need to change fIsSingleComponent in this case | 67 // We don't need to change fIsSingleComponent in this case |
67 fValidFlags = 0; | 68 fValidFlags = 0; |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
71 void invalidateComponents(uint8_t invalidateFlags) { | 72 void invalidateComponents(uint8_t invalidateFlags) { |
72 fValidFlags &= ~invalidateFlags; | 73 fValidFlags &= ~invalidateFlags; |
73 fIsSingleComponent = false; | 74 fIsSingleComponent = false; |
74 } | 75 } |
75 | 76 |
76 void setToTransparentBlack() { | 77 void setToTransparentBlack() { |
77 fValidFlags = kRGBA_GrColorComponentFlags; | 78 this->internalSetToTransparentBlack(); |
78 fColor = 0; | 79 fNonMulStageFound = true; |
79 fIsSingleComponent = true; | |
80 } | 80 } |
81 | 81 |
82 void setToOther(uint8_t validFlags, GrColor color) { | 82 void setToOther(uint8_t validFlags, GrColor color) { |
83 fValidFlags = validFlags; | 83 fValidFlags = validFlags; |
84 fColor = color; | 84 fColor = color; |
85 fIsSingleComponent = false; | 85 fIsSingleComponent = false; |
| 86 fNonMulStageFound = true; |
86 } | 87 } |
87 | 88 |
88 void setToUnknown() { | 89 void setToUnknown() { |
89 fValidFlags = 0; | 90 this->internalSetToUnknown(); |
90 fIsSingleComponent = false; | 91 fNonMulStageFound= true; |
91 } | 92 } |
92 | 93 |
93 bool isOpaque() const { | 94 bool isOpaque() const { |
94 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn
packA(fColor)); | 95 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn
packA(fColor)); |
95 } | 96 } |
96 | 97 |
97 bool isSolidWhite() const { | 98 bool isSolidWhite() const { |
98 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF ==
fColor); | 99 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF ==
fColor); |
99 } | 100 } |
100 | 101 |
101 GrColor color() const { return fColor; } | 102 GrColor color() const { return fColor; } |
102 uint8_t validFlags() const { return fValidFlags; } | 103 uint8_t validFlags() const { return fValidFlags; } |
103 | 104 |
104 /** | 105 /** |
105 * If isSingleComponent is true, then the flag values for r, g, b, and a
must all be the | 106 * If isSingleComponent is true, then the flag values for r, g, b, and a
must all be the |
106 * same. If the flags are all set then all color components must be equa
l. | 107 * same. If the flags are all set then all color components must be equa
l. |
107 */ | 108 */ |
108 SkDEBUGCODE(void validate() const;) | 109 SkDEBUGCODE(void validate() const;) |
109 | 110 |
110 private: | 111 private: |
| 112 void internalSetToTransparentBlack() { |
| 113 fValidFlags = kRGBA_GrColorComponentFlags; |
| 114 fColor = 0; |
| 115 fIsSingleComponent = true; |
| 116 } |
| 117 |
| 118 void internalSetToUnknown() { |
| 119 fValidFlags = 0; |
| 120 fIsSingleComponent = false; |
| 121 } |
| 122 |
111 bool hasZeroAlpha() const { | 123 bool hasZeroAlpha() const { |
112 return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpac
kA(fColor)); | 124 return ((fValidFlags & kA_GrColorComponentFlag) && 0 == GrColorUnpac
kA(fColor)); |
113 } | 125 } |
114 | 126 |
115 SkDEBUGCODE(bool colorComponentsAllEqual() const;) | 127 SkDEBUGCODE(bool colorComponentsAllEqual() const;) |
116 /** | 128 /** |
117 * If alpha is valid, check that any valid R,G,B values are <= A | 129 * If alpha is valid, check that any valid R,G,B values are <= A |
118 */ | 130 */ |
119 SkDEBUGCODE(bool validPreMulColor() const;) | 131 SkDEBUGCODE(bool validPreMulColor() const;) |
120 | 132 |
121 // Friended class that have "controller" code which loop over stages cal
ling | 133 // Friended class that have "controller" code which loop over stages cal
ling |
122 // computeInvarianteOutput(). These controllers may need to manually adj
ust the internal | 134 // computeInvarianteOutput(). These controllers may need to manually adj
ust the internal |
123 // members of InvariantOutput | 135 // members of InvariantOutput |
124 friend class GrDrawState; | 136 friend class GrDrawState; |
125 friend class GrOptDrawState; | 137 friend class GrOptDrawState; |
126 friend class GrPaint; | 138 friend class GrPaint; |
127 | 139 |
128 GrColor fColor; | 140 GrColor fColor; |
129 uint32_t fValidFlags; | 141 uint32_t fValidFlags; |
130 bool fIsSingleComponent; | 142 bool fIsSingleComponent; |
| 143 bool fNonMulStageFound; |
131 }; | 144 }; |
132 | 145 |
133 /** | 146 /** |
134 * This function is used to perform optimizations. When called the invarient
Ouput param | 147 * This function is used to perform optimizations. When called the invarient
Ouput param |
135 * indicate whether the input components to this effect in the FS will have
known values. | 148 * indicate whether the input components to this effect in the FS will have
known values. |
136 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent | 149 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th
e isSingleComponent |
137 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of | 150 * member indicates whether the input will be 1 or 4 bytes. The function upd
ates the members of |
138 * inout to indicate known values of its output. A component of the color me
mber only has | 151 * inout to indicate known values of its output. A component of the color me
mber only has |
139 * meaning if the corresponding bit in validFlags is set. | 152 * meaning if the corresponding bit in validFlags is set. |
140 */ | 153 */ |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called | 324 * This creates an effect outside of the effect memory pool. The effect's destru
ctor will be called |
312 * at global destruction time. NAME will be the name of the created GrProcessor. | 325 * at global destruction time. NAME will be the name of the created GrProcessor. |
313 */ | 326 */ |
314 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ | 327 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS)
\ |
315 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ | 328 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage;
\ |
316 static GrFragmentProcessor*
\ | 329 static GrFragmentProcessor*
\ |
317 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ | 330 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);
\ |
318 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); | 331 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); |
319 | 332 |
320 #endif | 333 #endif |
OLD | NEW |