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

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: Update InvariantOutput validate 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/effects/SkColorFilters.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 fInputIsOnlyModulated(true) {} 42 fInputIsOnlyModulated(true), fWillUseInputColor(true ) {}
43 43
44 void mulByUnknownOpaqueColor() { 44 void mulByUnknownOpaqueColor() {
45 if (this->isOpaque()) { 45 if (this->isOpaque()) {
46 fValidFlags = kA_GrColorComponentFlag; 46 fValidFlags = kA_GrColorComponentFlag;
47 fIsSingleComponent = false; 47 fIsSingleComponent = false;
48 } else { 48 } else {
49 // 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
50 // multiplied is opaque. 50 // multiplied is opaque.
51 this->mulByUnknownColor(); 51 this->mulByUnknownColor();
52 } 52 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 fColor = color; 84 fColor = color;
85 fIsSingleComponent = false; 85 fIsSingleComponent = false;
86 fInputIsOnlyModulated = false; 86 fInputIsOnlyModulated = false;
87 } 87 }
88 88
89 void setToUnknown() { 89 void setToUnknown() {
90 this->setToUnknownPriv(); 90 this->setToUnknownPriv();
91 fInputIsOnlyModulated = false; 91 fInputIsOnlyModulated = false;
92 } 92 }
93 93
94 /**
95 * If the effect will generate a result that does not depend on the inpu t color value then
96 * it must call this function from its onComputeInvariantOutput(). Other wise, when its
97 * generated backend-specific code might fail during variable binding du e to unused
98 * variables.
99 */
100 void setWillNotUseInputColor() {
bsalomon 2014/10/13 20:54:42 Instead of a new setter can we make it be a requir
egdaniel 2014/10/14 17:49:57 Done.
101 fWillUseInputColor = false;
102 }
103
94 bool isOpaque() const { 104 bool isOpaque() const {
95 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn packA(fColor)); 105 return ((fValidFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUn packA(fColor));
96 } 106 }
97 107
98 bool isSolidWhite() const { 108 bool isSolidWhite() const {
99 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor); 109 return (fValidFlags == kRGBA_GrColorComponentFlags && 0xFFFFFFFF == fColor);
100 } 110 }
101 111
102 GrColor color() const { return fColor; } 112 GrColor color() const { return fColor; }
103 uint8_t validFlags() const { return fValidFlags; } 113 uint8_t validFlags() const { return fValidFlags; }
(...skipping 25 matching lines...) Expand all
129 * If alpha is valid, check that any valid R,G,B values are <= A 139 * If alpha is valid, check that any valid R,G,B values are <= A
130 */ 140 */
131 SkDEBUGCODE(bool validPreMulColor() const;) 141 SkDEBUGCODE(bool validPreMulColor() const;)
132 142
133 // Friended class that have "controller" code which loop over stages cal ling 143 // Friended class that have "controller" code which loop over stages cal ling
134 // computeInvarianteOutput(). These controllers may need to manually adj ust the internal 144 // computeInvarianteOutput(). These controllers may need to manually adj ust the internal
135 // members of InvariantOutput 145 // members of InvariantOutput
136 friend class GrDrawState; 146 friend class GrDrawState;
137 friend class GrOptDrawState; 147 friend class GrOptDrawState;
138 friend class GrPaint; 148 friend class GrPaint;
149 friend class GrProcessor;
139 150
140 GrColor fColor; 151 GrColor fColor;
141 uint32_t fValidFlags; 152 uint32_t fValidFlags;
142 bool fIsSingleComponent; 153 bool fIsSingleComponent;
143 bool fInputIsOnlyModulated; 154 bool fInputIsOnlyModulated;
155 bool fWillUseInputColor;
144 }; 156 };
145 157
146 /** 158 /**
147 * This function is used to perform optimizations. When called the invarient Ouput param 159 * 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. 160 * 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 161 * 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 162 * 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 163 * 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. 164 * meaning if the corresponding bit in validFlags is set.
153 */ 165 */
154 void computeInvariantOutput(InvariantOutput* inout) const { 166 void computeInvariantOutput(InvariantOutput* inout) const {
167 inout->fWillUseInputColor = true;
155 this->onComputeInvariantOutput(inout); 168 this->onComputeInvariantOutput(inout);
156 #ifdef SK_DEBUG 169 #ifdef SK_DEBUG
157 inout->validate(); 170 inout->validate();
158 #endif 171 #endif
159 } 172 }
160 173
161 /** This object, besides creating back-end-specific helper objects, is used for run-time-type- 174 /** 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, 175 identification. The factory should be an instance of templated class,
163 GrTBackendEffectFactory. It is templated on the subclass of GrProcessor. The subclass must 176 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 177 have a nested type (or typedef) named GLProcessor which will be the subc lass of
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 293 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
281 bool fWillReadFragmentPosition; 294 bool fWillReadFragmentPosition;
282 295
283 typedef GrProgramElement INHERITED; 296 typedef GrProgramElement INHERITED;
284 }; 297 };
285 298
286 class GrFragmentProcessor : public GrProcessor { 299 class GrFragmentProcessor : public GrProcessor {
287 public: 300 public:
288 GrFragmentProcessor() 301 GrFragmentProcessor()
289 : INHERITED() 302 : INHERITED()
290 , fWillReadDstColor(false) 303 , fWillReadDstColor(false) {}
291 , fWillUseInputColor(true) {}
292 304
293 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0; 305 virtual const GrBackendFragmentProcessorFactory& getFactory() const = 0;
294 306
295 /** Will this effect read the destination pixel value? */ 307 /** Will this effect read the destination pixel value? */
296 bool willReadDstColor() const { return fWillReadDstColor; } 308 bool willReadDstColor() const { return fWillReadDstColor; }
297 309
298 /** Will this effect read the source color value? */
299 bool willUseInputColor() const { return fWillUseInputColor; }
300
301 protected: 310 protected:
302 /** 311 /**
303 * If the effect subclass will read the destination pixel value then it must call this function 312 * If the effect subclass will read the destination pixel value then it must call this function
304 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts 313 * from its constructor. Otherwise, when its generated backend-specific effe ct class attempts
305 * to generate code that reads the destination pixel it will fail. 314 * to generate code that reads the destination pixel it will fail.
306 */ 315 */
307 void setWillReadDstColor() { fWillReadDstColor = true; } 316 void setWillReadDstColor() { fWillReadDstColor = true; }
308 317
309 /**
310 * If the effect will generate a result that does not depend on the input co lor value then it
311 * must call this function from its constructor. Otherwise, when its generat ed backend-specific
312 * code might fail during variable binding due to unused variables.
313 */
314 void setWillNotUseInputColor() { fWillUseInputColor = false; }
315
316 private: 318 private:
317 bool fWillReadDstColor; 319 bool fWillReadDstColor;
318 bool fWillUseInputColor;
319 320
320 typedef GrProcessor INHERITED; 321 typedef GrProcessor INHERITED;
321 }; 322 };
322 323
323 /** 324 /**
324 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called 325 * This creates an effect outside of the effect memory pool. The effect's destru ctor will be called
325 * at global destruction time. NAME will be the name of the created GrProcessor. 326 * at global destruction time. NAME will be the name of the created GrProcessor.
326 */ 327 */
327 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \ 328 #define GR_CREATE_STATIC_FRAGMENT_PROCESSOR(NAME, EFFECT_CLASS, ARGS) \
328 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \ 329 static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \
329 static GrFragmentProcessor* \ 330 static GrFragmentProcessor* \
330 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \ 331 NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \
331 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME); 332 static SkAutoTDestroy<GrFragmentProcessor> NAME##_ad(NAME);
332 333
333 #endif 334 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/effects/SkColorFilters.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698