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

Side by Side Diff: src/gpu/gl/GrGLProgramDataManager.cpp

Issue 367643004: Implement NVPR on GLES (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: rebase Created 6 years, 4 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
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 "gl/GrGLShaderBuilder.h" 8 #include "gl/GrGLShaderBuilder.h"
9 #include "gl/GrGLPathRendering.h"
9 #include "gl/GrGLProgram.h" 10 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLUniformHandle.h" 11 #include "gl/GrGLUniformHandle.h"
11 #include "gl/GrGpuGL.h" 12 #include "gl/GrGpuGL.h"
12 #include "SkMatrix.h" 13 #include "SkMatrix.h"
13 14
14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \ 15 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
15 SkASSERT(arrayCount <= uni.fArrayCount || \ 16 SkASSERT(arrayCount <= uni.fArrayCount || \
16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCoun t)) 17 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCoun t))
17 18
18 GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu, 19 GrGLProgramDataManager::GrGLProgramDataManager(GrGpuGL* gpu,
19 GrGLProgram*, 20 GrGLProgram* program,
20 const GrGLShaderBuilder& builder) 21 const GrGLShaderBuilder& builder)
21 : fGpu(gpu) { 22 : fGpu(gpu)
23 , fProgram(program) {
22 int count = builder.getUniformInfos().count(); 24 int count = builder.getUniformInfos().count();
23 fUniforms.push_back_n(count); 25 fUniforms.push_back_n(count);
24 for (int i = 0; i < count; i++) { 26 for (int i = 0; i < count; i++) {
25 Uniform& uniform = fUniforms[i]; 27 Uniform& uniform = fUniforms[i];
26 const GrGLShaderBuilder::UniformInfo& builderUniform = builder.getUnifor mInfos()[i]; 28 const GrGLShaderBuilder::UniformInfo& builderUniform = builder.getUnifor mInfos()[i];
27 SkASSERT(GrGLShaderVar::kNonArray == builderUniform.fVariable.getArrayCo unt() || 29 SkASSERT(GrGLShaderVar::kNonArray == builderUniform.fVariable.getArrayCo unt() ||
28 builderUniform.fVariable.getArrayCount() > 0); 30 builderUniform.fVariable.getArrayCount() > 0);
29 SkDEBUGCODE( 31 SkDEBUGCODE(
30 uniform.fArrayCount = builderUniform.fVariable.getArrayCount(); 32 uniform.fArrayCount = builderUniform.fVariable.getArrayCount();
31 uniform.fType = builderUniform.fVariable.getType(); 33 uniform.fType = builderUniform.fVariable.getType();
32 ); 34 );
33 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he re. 35 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he re.
34 36
35 if (GrGLShaderBuilder::kVertex_Visibility & builderUniform.fVisibility) { 37 if (GrGLShaderBuilder::kVertex_Visibility & builderUniform.fVisibility) {
36 uniform.fVSLocation = builderUniform.fLocation; 38 uniform.fVSLocation = builderUniform.fLocation;
37 } else { 39 } else {
38 uniform.fVSLocation = kUnusedUniform; 40 uniform.fVSLocation = kUnusedUniform;
39 } 41 }
40 if (GrGLShaderBuilder::kFragment_Visibility & builderUniform.fVisibility ) { 42 if (GrGLShaderBuilder::kFragment_Visibility & builderUniform.fVisibility ) {
41 uniform.fFSLocation = builderUniform.fLocation; 43 uniform.fFSLocation = builderUniform.fLocation;
42 } else { 44 } else {
43 uniform.fFSLocation = kUnusedUniform; 45 uniform.fFSLocation = kUnusedUniform;
44 } 46 }
45 } 47 }
48
49 count = builder.getSeparableVaryingInfos().count();
50 fVaryings.push_back_n(count);
51 for (int i = 0; i < count; i++) {
52 Varying& varying = fVaryings[i];
53 const GrGLShaderBuilder::SeparableVaryingInfo& builderVarying =
54 builder.getSeparableVaryingInfos()[i];
55 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo unt());
56 SkDEBUGCODE(
57 varying.fType = builderVarying.fVariable.getType();
58 );
59 varying.fLocation = builderVarying.fLocation;
60 }
46 } 61 }
47 62
48 void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const { 63 void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const {
49 const Uniform& uni = fUniforms[u.toProgramDataIndex()]; 64 const Uniform& uni = fUniforms[u.toProgramDataIndex()];
50 SkASSERT(uni.fType == kSampler2D_GrSLType); 65 SkASSERT(uni.fType == kSampler2D_GrSLType);
51 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 66 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
52 // FIXME: We still insert a single sampler uniform for every stage. If the s hader does not 67 // FIXME: We still insert a single sampler uniform for every stage. If the s hader does not
53 // reference the sampler then the compiler may have optimized it out. Uncomm ent this assert 68 // reference the sampler then the compiler may have optimized it out. Uncomm ent this assert
54 // once stages insert their own samplers. 69 // once stages insert their own samplers.
55 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo cation); 70 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo cation);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 matrix.get(SkMatrix::kMPersp0), 269 matrix.get(SkMatrix::kMPersp0),
255 matrix.get(SkMatrix::kMSkewX), 270 matrix.get(SkMatrix::kMSkewX),
256 matrix.get(SkMatrix::kMScaleY), 271 matrix.get(SkMatrix::kMScaleY),
257 matrix.get(SkMatrix::kMPersp1), 272 matrix.get(SkMatrix::kMPersp1),
258 matrix.get(SkMatrix::kMTransX), 273 matrix.get(SkMatrix::kMTransX),
259 matrix.get(SkMatrix::kMTransY), 274 matrix.get(SkMatrix::kMTransY),
260 matrix.get(SkMatrix::kMPersp2), 275 matrix.get(SkMatrix::kMPersp2),
261 }; 276 };
262 this->setMatrix3f(u, mt); 277 this->setMatrix3f(u, mt);
263 } 278 }
279
280 void GrGLProgramDataManager::setProgramPathFragmentInputTransform(VaryingHandle i,
281 unsigned compo nents,
282 const SkMatrix & matrix) const {
283 const Varying& fragmentInput = fVaryings[i.toProgramDataIndex()];
284
285 GrGLfloat coefficients[3 * 3];
286 SkASSERT(components >= 1 && components <= 3);
287
288 coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]);
289 coefficients[1] = SkScalarToFloat(matrix[SkMatrix::kMSkewX]);
290 coefficients[2] = SkScalarToFloat(matrix[SkMatrix::kMTransX]);
291
292 if (components >= 2) {
293 coefficients[3] = SkScalarToFloat(matrix[SkMatrix::kMSkewY]);
294 coefficients[4] = SkScalarToFloat(matrix[SkMatrix::kMScaleY]);
295 coefficients[5] = SkScalarToFloat(matrix[SkMatrix::kMTransY]);
296 }
297
298 if (components >= 3) {
299 coefficients[6] = SkScalarToFloat(matrix[SkMatrix::kMPersp0]);
300 coefficients[7] = SkScalarToFloat(matrix[SkMatrix::kMPersp1]);
301 coefficients[8] = SkScalarToFloat(matrix[SkMatrix::kMPersp2]);
302 }
303 fGpu->pathRendering()->programPathFragmentInputGen(fProgram->programID(),
304 fragmentInput.fLocation,
305 GR_GL_OBJECT_LINEAR,
306 components,
307 coefficients);
308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698