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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 years 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/GrXfermodeFragmentProcessor.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 "glsl/GrGLSLFragmentProcessor.h" 12 #include "glsl/GrGLSLFragmentProcessor.h"
13 #include "glsl/GrGLSLProgramBuilder.h" 13 #include "glsl/GrGLSLFragmentShaderBuilder.h"
14 #include "glsl/GrGLSLProgramDataManager.h" 14 #include "glsl/GrGLSLProgramDataManager.h"
15 #include "glsl/GrGLSLShaderBuilder.h"
15 #include "glsl/GrGLSLTextureSampler.h" 16 #include "glsl/GrGLSLTextureSampler.h"
17 #include "glsl/GrGLSLUniformHandler.h"
16 18
17 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) 19 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index)
18 : fIndex(index) { 20 : fIndex(index) {
19 21
20 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 22 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
21 if (domain.contains(kFullRect) && kClamp_Mode == mode) { 23 if (domain.contains(kFullRect) && kClamp_Mode == mode) {
22 fMode = kIgnore_Mode; 24 fMode = kIgnore_Mode;
23 } else { 25 } else {
24 fMode = mode; 26 fMode = mode;
25 } 27 }
26 28
27 if (fMode != kIgnore_Mode) { 29 if (fMode != kIgnore_Mode) {
28 // We don't currently handle domains that are empty or don't intersect t he texture. 30 // We don't currently handle domains that are empty or don't intersect t he texture.
29 // It is OK if the domain rect is a line or point, but it should not be inverted. We do not 31 // It is OK if the domain rect is a line or point, but it should not be inverted. We do not
30 // handle rects that do not intersect the [0..1]x[0..1] rect. 32 // handle rects that do not intersect the [0..1]x[0..1] rect.
31 SkASSERT(domain.fLeft <= domain.fRight); 33 SkASSERT(domain.fLeft <= domain.fRight);
32 SkASSERT(domain.fTop <= domain.fBottom); 34 SkASSERT(domain.fTop <= domain.fBottom);
33 fDomain.fLeft = SkScalarPin(domain.fLeft, kFullRect.fLeft, kFullRect.fRi ght); 35 fDomain.fLeft = SkScalarPin(domain.fLeft, kFullRect.fLeft, kFullRect.fRi ght);
34 fDomain.fRight = SkScalarPin(domain.fRight, kFullRect.fLeft, kFullRect.f Right); 36 fDomain.fRight = SkScalarPin(domain.fRight, kFullRect.fLeft, kFullRect.f Right);
35 fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBotto m); 37 fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBotto m);
36 fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect. fBottom); 38 fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect. fBottom);
37 SkASSERT(fDomain.fLeft <= fDomain.fRight); 39 SkASSERT(fDomain.fLeft <= fDomain.fRight);
38 SkASSERT(fDomain.fTop <= fDomain.fBottom); 40 SkASSERT(fDomain.fTop <= fDomain.fBottom);
39 } 41 }
40 } 42 }
41 43
42 ////////////////////////////////////////////////////////////////////////////// 44 //////////////////////////////////////////////////////////////////////////////
43 45
44 void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder, 46 void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
47 GrGLSLUniformHandler* uniformHandl er,
45 const GrGLSLCaps* glslCaps, 48 const GrGLSLCaps* glslCaps,
46 const GrTextureDomain& textureDoma in, 49 const GrTextureDomain& textureDoma in,
47 const char* outColor, 50 const char* outColor,
48 const SkString& inCoords, 51 const SkString& inCoords,
49 const GrGLSLTextureSampler& sample r, 52 const GrGLSLTextureSampler& sample r,
50 const char* inModulateColor) { 53 const char* inModulateColor) {
51 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); 54 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
52 SkDEBUGCODE(fMode = textureDomain.mode();) 55 SkDEBUGCODE(fMode = textureDomain.mode();)
53 56
54 GrGLSLProgramBuilder* program = builder->getProgramBuilder();
55
56 if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) { 57 if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) {
57 const char* name; 58 const char* name;
58 SkString uniName("TexDom"); 59 SkString uniName("TexDom");
59 if (textureDomain.fIndex >= 0) { 60 if (textureDomain.fIndex >= 0) {
60 uniName.appendS32(textureDomain.fIndex); 61 uniName.appendS32(textureDomain.fIndex);
61 } 62 }
62 fDomainUni = program->addUniform(GrGLSLProgramBuilder::kFragment_Visibil ity, 63 fDomainUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_ Visibility,
63 kVec4f_GrSLType, kDefault_GrSLPrecision , 64 kVec4f_GrSLType, kDefault_GrSLPr ecision,
64 uniName.c_str(), &name); 65 uniName.c_str(), &name);
65 fDomainName = name; 66 fDomainName = name;
66 } 67 }
67 68
68 switch (textureDomain.mode()) { 69 switch (textureDomain.mode()) {
69 case kIgnore_Mode: { 70 case kIgnore_Mode: {
70 builder->codeAppendf("%s = ", outColor); 71 builder->codeAppendf("%s = ", outColor);
71 builder->appendTextureLookupAndModulate(inModulateColor, sampler, 72 builder->appendTextureLookupAndModulate(inModulateColor, sampler,
72 inCoords.c_str()); 73 inCoords.c_str());
73 builder->codeAppend(";"); 74 builder->codeAppend(";");
74 break; 75 break;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { 193 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) {
193 } 194 }
194 195
195 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { 196 void GrGLTextureDomainEffect::emitCode(EmitArgs& args) {
196 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo mainEffect>(); 197 const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDo mainEffect>();
197 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); 198 const GrTextureDomain& domain = textureDomainEffect.textureDomain();
198 199
199 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 200 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
200 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 201 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
201 fGLDomain.sampleTexture(fragBuilder, 202 fGLDomain.sampleTexture(fragBuilder,
203 args.fUniformHandler,
202 args.fGLSLCaps, 204 args.fGLSLCaps,
203 domain, 205 domain,
204 args.fOutputColor, 206 args.fOutputColor,
205 coords2D, 207 coords2D,
206 args.fSamplers[0], 208 args.fSamplers[0],
207 args.fInputColor); 209 args.fInputColor);
208 } 210 }
209 211
210 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman, 212 void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman,
211 const GrProcessor& processor) { 213 const GrProcessor& processor) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool() : false; 299 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool() : false;
298 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC oordSet; 300 GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrC oordSet;
299 return GrTextureDomainEffect::Create( 301 return GrTextureDomainEffect::Create(
300 d->fTextures[texIdx], 302 d->fTextures[texIdx],
301 matrix, 303 matrix,
302 domain, 304 domain,
303 mode, 305 mode,
304 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi lterMode, 306 bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_Fi lterMode,
305 coords); 307 coords);
306 } 308 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrXfermodeFragmentProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698