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

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

Issue 1734163002: Replace fWillReadFragmentPosition with a bitfield (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | src/effects/GrCircleBlurFragmentProcessor.cpp » ('j') | src/gpu/GrPipeline.cpp » ('J')
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 int numTextures() const { return fTextureAccesses.count(); } 73 int numTextures() const { return fTextureAccesses.count(); }
74 74
75 /** Returns the access pattern for the texture at index. index must be valid according to 75 /** Returns the access pattern for the texture at index. index must be valid according to
76 numTextures(). */ 76 numTextures(). */
77 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; } 77 const GrTextureAccess& textureAccess(int index) const { return *fTextureAcce sses[index]; }
78 78
79 /** Shortcut for textureAccess(index).texture(); */ 79 /** Shortcut for textureAccess(index).texture(); */
80 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); } 80 GrTexture* texture(int index) const { return this->textureAccess(index).getT exture(); }
81 81
82 /** Will this processor read the fragment position? */ 82 /**
83 bool willReadFragmentPosition() const { return fWillReadFragmentPosition; } 83 * Platform specific built-in state that a processor can include in the frag ment shader. A
84 * processor must enable this state before using it.
85 */
86 enum BuiltInState {
87 kNone_BuiltInState = 0,
88 kFragmentPosition_BuiltInState = 1
89 };
90
91 GR_DECL_BITFIELD_OPS_FRIENDS(BuiltInState);
92
93 BuiltInState builtInState() const { return fBuiltInState; }
84 94
85 void* operator new(size_t size); 95 void* operator new(size_t size);
86 void operator delete(void* target); 96 void operator delete(void* target);
87 97
88 void* operator new(size_t size, void* placement) { 98 void* operator new(size_t size, void* placement) {
89 return ::operator new(size, placement); 99 return ::operator new(size, placement);
90 } 100 }
91 void operator delete(void* target, void* placement) { 101 void operator delete(void* target, void* placement) {
92 ::operator delete(target, placement); 102 ::operator delete(target, placement);
93 } 103 }
94 104
95 /** 105 /**
96 * Helper for down-casting to a GrProcessor subclass 106 * Helper for down-casting to a GrProcessor subclass
97 */ 107 */
98 template <typename T> const T& cast() const { return *static_cast<const T*>( this); } 108 template <typename T> const T& cast() const { return *static_cast<const T*>( this); }
99 109
100 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r eturn fClassID; } 110 uint32_t classID() const { SkASSERT(kIllegalProcessorClassID != fClassID); r eturn fClassID; }
101 111
102 protected: 112 protected:
103 GrProcessor() : fClassID(kIllegalProcessorClassID), fWillReadFragmentPositio n(false) {} 113 GrProcessor() : fClassID(kIllegalProcessorClassID), fBuiltInState(kNone_Buil tInState) {}
104 114
105 /** 115 /**
106 * Subclasses call this from their constructor to register GrTextureAccesses . The processor 116 * Subclasses call this from their constructor to register GrTextureAccesses . The processor
107 * subclass manages the lifetime of the accesses (this function only stores a pointer). The 117 * subclass manages the lifetime of the accesses (this function only stores a pointer). The
108 * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be 118 * GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be
109 * called from the constructor because GrProcessors are immutable. 119 * called from the constructor because GrProcessors are immutable.
110 */ 120 */
111 virtual void addTextureAccess(const GrTextureAccess* textureAccess); 121 virtual void addTextureAccess(const GrTextureAccess* textureAccess);
112 122
113 bool hasSameTextureAccesses(const GrProcessor&) const; 123 bool hasSameTextureAccesses(const GrProcessor&) const;
114 124
115 /** 125 void enableBuiltInState(BuiltInState state) { fBuiltInState |= state; }
joshualitt 2016/02/25 19:21:29 This is more a question for Brian / Robert, but do
Chris Dalton 2016/02/25 19:45:30 So, willRead isn't very needed anymore on this cla
Chris Dalton 2016/02/25 20:38:37 Also, FWIW, this feels pretty similar to "fsBuilde
bsalomon 2016/02/25 21:11:03 I find the setWillFoo() a bit more readable than e
Chris Dalton 2016/02/25 22:24:24 Ok, brought back "setWillFoo()". For children FPs
116 * If the prcoessor will generate a backend-specific processor that will rea d the fragment
117 * position in the FS then it must call this method from its constructor. Ot herwise, the
118 * request to access the fragment position will be denied.
119 */
120 void setWillReadFragmentPosition() { fWillReadFragmentPosition = true; }
121 126
122 template <typename PROC_SUBCLASS> void initClassID() { 127 template <typename PROC_SUBCLASS> void initClassID() {
123 static uint32_t kClassID = GenClassID(); 128 static uint32_t kClassID = GenClassID();
124 fClassID = kClassID; 129 fClassID = kClassID;
125 } 130 }
126 131
127 uint32_t fClassID; 132 uint32_t fClassID;
128 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; 133 SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
129 134
130 private: 135 private:
131 static uint32_t GenClassID() { 136 static uint32_t GenClassID() {
132 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The 137 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The
133 // atomic inc returns the old value not the incremented value. So we add 138 // atomic inc returns the old value not the incremented value. So we add
134 // 1 to the returned value. 139 // 1 to the returned value.
135 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID )) + 1; 140 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrProcessorClassID )) + 1;
136 if (!id) { 141 if (!id) {
137 SkFAIL("This should never wrap as it should only be called once for each GrProcessor " 142 SkFAIL("This should never wrap as it should only be called once for each GrProcessor "
138 "subclass."); 143 "subclass.");
139 } 144 }
140 return id; 145 return id;
141 } 146 }
142 147
143 enum { 148 enum {
144 kIllegalProcessorClassID = 0, 149 kIllegalProcessorClassID = 0,
145 }; 150 };
146 static int32_t gCurrProcessorClassID; 151 static int32_t gCurrProcessorClassID;
147 152
148 bool fWillReadFragmentPosition; 153 BuiltInState fBuiltInState;
149 154
150 typedef GrProgramElement INHERITED; 155 typedef GrProgramElement INHERITED;
151 }; 156 };
152 157
158 GR_MAKE_BITFIELD_OPS(GrProcessor::BuiltInState);
159
153 #endif 160 #endif
OLDNEW
« no previous file with comments | « no previous file | src/effects/GrCircleBlurFragmentProcessor.cpp » ('j') | src/gpu/GrPipeline.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698