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

Side by Side Diff: src/gpu/effects/GrTextureDomain.cpp

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 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 | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrYUVtoRGBEffect.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 #include "GrTextureDomain.h" 8 #include "GrTextureDomain.h"
9 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
10 #include "GrSimpleTextureEffect.h" 10 #include "GrSimpleTextureEffect.h"
11 #include "SkFloatingPoint.h" 11 #include "SkFloatingPoint.h"
12 #include "gl/GrGLContext.h" 12 #include "gl/GrGLContext.h"
13 #include "gl/GrGLFragmentProcessor.h" 13 #include "gl/GrGLFragmentProcessor.h"
14 #include "gl/builders/GrGLProgramBuilder.h" 14 #include "gl/builders/GrGLProgramBuilder.h"
15 #include "glsl/GrGLSLProgramDataManager.h"
15 16
16 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) 17 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index)
17 : fIndex(index) { 18 : fIndex(index) {
18 19
19 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 20 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
20 if (domain.contains(kFullRect) && kClamp_Mode == mode) { 21 if (domain.contains(kFullRect) && kClamp_Mode == mode) {
21 fMode = kIgnore_Mode; 22 fMode = kIgnore_Mode;
22 } else { 23 } else {
23 fMode = mode; 24 fMode = mode;
24 } 25 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 136
136 builder->codeAppendf("%s = ", outColor); 137 builder->codeAppendf("%s = ", outColor);
137 builder->appendTextureLookupAndModulate(inModulateColor, sampler, 138 builder->appendTextureLookupAndModulate(inModulateColor, sampler,
138 clampedCoords.c_str()); 139 clampedCoords.c_str());
139 builder->codeAppend(";"); 140 builder->codeAppend(";");
140 break; 141 break;
141 } 142 }
142 } 143 }
143 } 144 }
144 145
145 void GrTextureDomain::GLDomain::setData(const GrGLProgramDataManager& pdman, 146 void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman,
146 const GrTextureDomain& textureDomain, 147 const GrTextureDomain& textureDomain,
147 GrSurfaceOrigin textureOrigin) { 148 GrSurfaceOrigin textureOrigin) {
148 SkASSERT(textureDomain.mode() == fMode); 149 SkASSERT(textureDomain.mode() == fMode);
149 if (kIgnore_Mode != textureDomain.mode()) { 150 if (kIgnore_Mode != textureDomain.mode()) {
150 GrGLfloat values[kPrevDomainCount] = { 151 float values[kPrevDomainCount] = {
151 SkScalarToFloat(textureDomain.domain().left()), 152 SkScalarToFloat(textureDomain.domain().left()),
152 SkScalarToFloat(textureDomain.domain().top()), 153 SkScalarToFloat(textureDomain.domain().top()),
153 SkScalarToFloat(textureDomain.domain().right()), 154 SkScalarToFloat(textureDomain.domain().right()),
154 SkScalarToFloat(textureDomain.domain().bottom()) 155 SkScalarToFloat(textureDomain.domain().bottom())
155 }; 156 };
156 // vertical flip if necessary 157 // vertical flip if necessary
157 if (kBottomLeft_GrSurfaceOrigin == textureOrigin) { 158 if (kBottomLeft_GrSurfaceOrigin == textureOrigin) {
158 values[1] = 1.0f - values[1]; 159 values[1] = 1.0f - values[1];
159 values[3] = 1.0f - values[3]; 160 values[3] = 1.0f - values[3];
160 // The top and bottom were just flipped, so correct the ordering 161 // The top and bottom were just flipped, so correct the ordering
161 // of elements so that values = (l, t, r, b). 162 // of elements so that values = (l, t, r, b).
162 SkTSwap(values[1], values[3]); 163 SkTSwap(values[1], values[3]);
163 } 164 }
164 if (0 != memcmp(values, fPrevDomain, kPrevDomainCount * sizeof(GrGLfloat ))) { 165 if (0 != memcmp(values, fPrevDomain, kPrevDomainCount * sizeof(float))) {
165 pdman.set4fv(fDomainUni, 1, values); 166 pdman.set4fv(fDomainUni, 1, values);
166 memcpy(fPrevDomain, values, kPrevDomainCount * sizeof(GrGLfloat)); 167 memcpy(fPrevDomain, values, kPrevDomainCount * sizeof(float));
167 } 168 }
168 } 169 }
169 } 170 }
170 171
171 172
172 ////////////////////////////////////////////////////////////////////////////// 173 //////////////////////////////////////////////////////////////////////////////
173 174
174 class GrGLTextureDomainEffect : public GrGLFragmentProcessor { 175 class GrGLTextureDomainEffect : public GrGLFragmentProcessor {
175 public: 176 public:
176 GrGLTextureDomainEffect(const GrProcessor&); 177 GrGLTextureDomainEffect(const GrProcessor&);
177 178
178 virtual void emitCode(EmitArgs&) override; 179 virtual void emitCode(EmitArgs&) override;
179 180
180 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*); 181 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder*);
181 182
182 protected: 183 protected:
183 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; 184 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
184 185
185 private: 186 private:
186 GrTextureDomain::GLDomain fGLDomain; 187 GrTextureDomain::GLDomain fGLDomain;
187 typedef GrGLFragmentProcessor INHERITED; 188 typedef GrGLFragmentProcessor INHERITED;
188 }; 189 };
189 190
190 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { 191 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) {
191 } 192 }
192 193
193 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { 194 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) {
194 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo mainEffect>(); 195 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo mainEffect>();
195 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); 196 const GrTextureDomain& domain = textureDomainEffect.textureDomain();
196 197
197 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); 198 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
198 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 199 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
199 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, coords2D, args .fSamplers[0], 200 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, coords2D, args .fSamplers[0],
200 args.fInputColor); 201 args.fInputColor);
201 } 202 }
202 203
203 void GrGLTextureDomainEffect::onSetData(const GrGLProgramDataManager& pdman, 204 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman,
204 const GrProcessor& processor) { 205 const GrProcessor& processor) {
205 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD omainEffect>(); 206 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD omainEffect>();
206 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); 207 const GrTextureDomain& domain = textureDomainEffect.textureDomain();
207 fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); 208 fGLDomain.setData(pdman, domain, processor.texture(0)->origin());
208 } 209 }
209 210
210 void GrGLTextureDomainEffect::GenKey(const GrProcessor& processor, const GrGLSLC aps&, 211 void GrGLTextureDomainEffect::GenKey(const GrProcessor& processor, const GrGLSLC aps&,
211 GrProcessorKeyBuilder* b) { 212 GrProcessorKeyBuilder* b) {
212 const GrTextureDomain& domain = processor.cast<GrTextureDomainEffect>().text ureDomain(); 213 const GrTextureDomain& domain = processor.cast<GrTextureDomainEffect>().text ureDomain();
213 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); 214 b->add32(GrTextureDomain::GLDomain::DomainKey(domain));
214 } 215 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool() : false; 291 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool() : false;
291 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC oordSet; 292 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC oordSet;
292 return GrTextureDomainEffect::Create( 293 return GrTextureDomainEffect::Create(
293 d->fTextures[texIdx], 294 d->fTextures[texIdx],
294 matrix, 295 matrix,
295 domain, 296 domain,
296 mode, 297 mode,
297 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi lterMode, 298 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi lterMode,
298 coords); 299 coords);
299 } 300 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrYUVtoRGBEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698