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

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

Issue 656503002: Move willUseInputColor check to computeInvariantOutput (Closed) Base URL: https://skia.googlesource.com/skia.git@addMultFlag
Patch Set: Created 6 years, 2 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
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/core/SkXfermode.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 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 21 matching lines...) Expand all
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 fNonMulStageFound(false), fWillUseInputColor(true) { }
43
44 enum ReadInput {
45 kWill_ReadInput,
46 kWillNot_ReadInput,
47 };
43 48
44 void mulByUnknownOpaqueColor() { 49 void mulByUnknownOpaqueColor() {
45 if (this->isOpaque()) { 50 if (this->isOpaque()) {
46 fValidFlags = kA_GrColorComponentFlag; 51 fValidFlags = kA_GrColorComponentFlag;
47 fIsSingleComponent = false; 52 fIsSingleComponent = false;
48 } else { 53 } else {
49 // Since the current state is not opaque we no longer care if th e color being 54 // Since the current state is not opaque we no longer care if th e color being
50 // multiplied is opaque. 55 // multiplied is opaque.
51 this->mulByUnknownColor(); 56 this->mulByUnknownColor();
52 } 57 }
53 } 58 }
54 59
55 void mulByUnknownColor() { 60 void mulByUnknownColor() {
56 if (this->hasZeroAlpha()) { 61 if (this->hasZeroAlpha()) {
57 this->internalSetToTransparentBlack(); 62 this->internalSetToTransparentBlack();
58 } else { 63 } else {
59 this->internalSetToUnknown(); 64 this->internalSetToUnknown();
60 } 65 }
61 } 66 }
62 67
63 void mulByUnknownAlpha() { 68 void mulByUnknownAlpha() {
64 if (this->hasZeroAlpha()) { 69 if (this->hasZeroAlpha()) {
65 this->internalSetToTransparentBlack(); 70 this->internalSetToTransparentBlack();
66 } else { 71 } else {
67 // We don't need to change fIsSingleComponent in this case 72 // We don't need to change fIsSingleComponent in this case
68 fValidFlags = 0; 73 fValidFlags = 0;
69 } 74 }
70 } 75 }
71 76
72 void invalidateComponents(uint8_t invalidateFlags) { 77 void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) {
73 fValidFlags &= ~invalidateFlags; 78 fValidFlags &= ~invalidateFlags;
74 fIsSingleComponent = false; 79 fIsSingleComponent = false;
80 if (kWillNot_ReadInput == readsInput) {
81 fWillUseInputColor = false;
82 }
75 } 83 }
76 84
77 void setToTransparentBlack() { 85 void setToTransparentBlack(ReadInput readsInput) {
bsalomon 2014/10/15 14:52:42 Does this one need it? Aren't we going to omit the
egdaniel 2014/10/15 18:37:48 Changed function to be mulByKnownAlpha to clear up
78 this->internalSetToTransparentBlack(); 86 this->internalSetToTransparentBlack();
79 fNonMulStageFound = true; 87 fNonMulStageFound = true;
88 if (kWillNot_ReadInput == readsInput) {
89 fWillUseInputColor = false;
90 }
80 } 91 }
81 92
82 void setToOther(uint8_t validFlags, GrColor color) { 93 void setToOther(uint8_t validFlags, GrColor color, ReadInput readsInput) {
83 fValidFlags = validFlags; 94 fValidFlags = validFlags;
84 fColor = color; 95 fColor = color;
85 fIsSingleComponent = false; 96 fIsSingleComponent = false;
86 fNonMulStageFound = true; 97 fNonMulStageFound = true;
98 if (kWillNot_ReadInput == readsInput) {
99 fWillUseInputColor = false;
100 }
87 } 101 }
88 102
89 void setToUnknown() { 103 void setToUnknown(ReadInput readsInput) {
90 this->internalSetToUnknown(); 104 this->internalSetToUnknown();
91 fNonMulStageFound= true; 105 fNonMulStageFound= true;
106 if (kWillNot_ReadInput == readsInput) {
107 fWillUseInputColor = false;
108 }
92 } 109 }
93 110
94 bool isOpaque() const { 111 bool isOpaque() const {
95 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn packA(fColor)); 112 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn packA(fColor));
96 } 113 }
97 114
98 bool isSolidWhite() const { 115 bool isSolidWhite() const {
99 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor); 116 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor);
100 } 117 }
101 118
(...skipping 27 matching lines...) Expand all
129 * If alpha is valid, check that any valid R,G,B values are <= A 146 * If alpha is valid, check that any valid R,G,B values are <= A
130 */ 147 */
131 SkDEBUGCODE(bool validPreMulColor() const;) 148 SkDEBUGCODE(bool validPreMulColor() const;)
132 149
133 // Friended class that have "controller" code which loop over stages cal ling 150 // Friended class that have "controller" code which loop over stages cal ling
134 // computeInvarianteOutput(). These controllers may need to manually adj ust the internal 151 // computeInvarianteOutput(). These controllers may need to manually adj ust the internal
135 // members of InvariantOutput 152 // members of InvariantOutput
136 friend class GrDrawState; 153 friend class GrDrawState;
137 friend class GrOptDrawState; 154 friend class GrOptDrawState;
138 friend class GrPaint; 155 friend class GrPaint;
156 friend class GrProcessor;
139 157
140 GrColor fColor; 158 GrColor fColor;
141 uint32_t fValidFlags; 159 uint32_t fValidFlags;
142 bool fIsSingleComponent; 160 bool fIsSingleComponent;
143 bool fNonMulStageFound; 161 bool fNonMulStageFound;
162 bool fWillUseInputColor;
144 }; 163 };
145 164
146 /** 165 /**
147 * This function is used to perform optimizations. When called the invarient Ouput param 166 * This function is used to perform optimizations. When called the invarient Ouput param
148 * indicate whether the input components to this effect in the FS will have known values. 167 * indicate whether the input components to this effect in the FS will have known values.
149 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th e isSingleComponent 168 * In inout the validFlags member is a bitfield of GrColorComponentFlags. Th e isSingleComponent
150 * member indicates whether the input will be 1 or 4 bytes. The function upd ates the members of 169 * member indicates whether the input will be 1 or 4 bytes. The function upd ates the members of
151 * inout to indicate known values of its output. A component of the color me mber only has 170 * inout to indicate known values of its output. A component of the color me mber only has
152 * meaning if the corresponding bit in validFlags is set. 171 * meaning if the corresponding bit in validFlags is set.
153 */ 172 */
154 void computeInvariantOutput(InvariantOutput* inout) const { 173 void computeInvariantOutput(InvariantOutput* inout) const {
174 inout->fWillUseInputColor = true;
155 this->onComputeInvariantOutput(inout); 175 this->onComputeInvariantOutput(inout);
156 #ifdef SK_DEBUG 176 #ifdef SK_DEBUG
157 inout->validate(); 177 inout->validate();
158 #endif 178 #endif
159 } 179 }
160 180
161 /** This object, besides creating back-end-specific helper objects, is used for run-time-type- 181 /** This object, besides creating back-end-specific helper objects, is used for run-time-type-
162 identification. The factory should be an instance of templated class, 182 identification. The factory should be an instance of templated class,
163 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must 183 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must
164 have a nested type (or typedef) named GLProcessor which will be the subc lass of 184 have a nested type (or typedef) named GLProcessor which will be the subc lass of
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 282 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
263 bool fWillReadFragmentPosition; 283 bool fWillReadFragmentPosition;
264 284
265 typedef GrProgramElement INHERITED; 285 typedef GrProgramElement INHERITED;
266 }; 286 };
267 287
268 class GrFragmentProcessor : public GrProcessor { 288 class GrFragmentProcessor : public GrProcessor {
269 public: 289 public:
270 GrFragmentProcessor() 290 GrFragmentProcessor()
271 : INHERITED() 291 : INHERITED()
272 , fWillReadDstColor(false) 292 , fWillReadDstColor(false) {}
273 , fWillUseInputColor(true) {}
274 293
275 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0; 294 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
276 295
277 int numTransforms() const { return fCoordTransforms.count(); } 296 int numTransforms() const { return fCoordTransforms.count(); }
278 297
279 /** Returns the coordinate transformation at index. index must be valid acco rding to 298 /** Returns the coordinate transformation at index. index must be valid acco rding to
280 numTransforms(). */ 299 numTransforms(). */
281 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; } 300 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran sforms[index]; }
282 301
283 /** Will this effect read the destination pixel value? */ 302 /** Will this effect read the destination pixel value? */
284 bool willReadDstColor() const { return fWillReadDstColor; } 303 bool willReadDstColor() const { return fWillReadDstColor; }
285 304
286 /** Will this effect read the source color value? */
287 bool willUseInputColor() const { return fWillUseInputColor; }
288
289 protected: 305 protected:
290 /** 306 /**
291 * Fragment Processor subclasses call this from their constructor to registe r coordinate 307 * Fragment Processor subclasses call this from their constructor to registe r coordinate
292 * transformations. The processor subclass manages the lifetime of the trans formations (this 308 * transformations. The processor subclass manages the lifetime of the trans formations (this
293 * function only stores a pointer). The GrCoordTransform is typically a memb er field of the 309 * function only stores a pointer). The GrCoordTransform is typically a memb er field of the
294 * GrProcessor subclass. When the matrix has perspective, the transformed co ordinates will have 310 * GrProcessor subclass. When the matrix has perspective, the transformed co ordinates will have
295 * 3 components. Otherwise they'll have 2. This must only be called from the constructor because 311 * 3 components. Otherwise they'll have 2. This must only be called from the constructor because
296 * GrProcessors are immutable. 312 * GrProcessors are immutable.
297 */ 313 */
298 void addCoordTransform(const GrCoordTransform*); 314 void addCoordTransform(const GrCoordTransform*);
299 315
300 /** 316 /**
301 * If the effect subclass will read the destination pixel value then it must call this function 317 * If the effect subclass will read the destination pixel value then it must call this function
302 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts 318 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts
303 * to generate code that reads the destination pixel it will fail. 319 * to generate code that reads the destination pixel it will fail.
304 */ 320 */
305 void setWillReadDstColor() { fWillReadDstColor = true; } 321 void setWillReadDstColor() { fWillReadDstColor = true; }
306 322
307 /**
308 * If the effect will generate a result that does not depend on the input co lor value then it
309 * must call this function from its constructor. Otherwise, when its generat ed backend-specific
310 * code might fail during variable binding due to unused variables.
311 */
312 void setWillNotUseInputColor() { fWillUseInputColor = false; }
313
314 private: 323 private:
315 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; 324 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
316 bool fWillReadDstColor; 325 bool fWillReadDstColor;
317 bool fWillUseInputColor;
318 326
319 typedef GrProcessor INHERITED; 327 typedef GrProcessor INHERITED;
320 }; 328 };
321 329
322 /** 330 /**
323 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called 331 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called
324 * at global destruction time. NAME will be the name of the created GrProcessor. 332 * at global destruction time. NAME will be the name of the created GrProcessor.
325 */ 333 */
326 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \ 334 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \
327 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ 335 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \
328 static GrFragmentProcessor* \ 336 static GrFragmentProcessor* \
329 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \ 337 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \
330 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); 338 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
331 339
332 #endif 340 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698