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

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

Issue 764643004: Create xfer processor backend. (Closed) Base URL: https://skia.googlesource.com/skia.git@xferBlendSolo
Patch Set: Blend off ODS and only on XP Created 6 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/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDesc.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 2011 Google Inc. 2 * Copyright 2011 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 "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
11 #include "GrProcessor.h" 11 #include "GrProcessor.h"
12 #include "GrCoordTransform.h" 12 #include "GrCoordTransform.h"
13 #include "GrGLGeometryProcessor.h" 13 #include "GrGLGeometryProcessor.h"
14 #include "GrGLProcessor.h" 14 #include "GrGLProcessor.h"
15 #include "GrGLXferProcessor.h"
15 #include "GrGpuGL.h" 16 #include "GrGpuGL.h"
16 #include "GrGLPathRendering.h" 17 #include "GrGLPathRendering.h"
17 #include "GrGLShaderVar.h" 18 #include "GrGLShaderVar.h"
18 #include "GrGLSL.h" 19 #include "GrGLSL.h"
19 #include "GrOptDrawState.h" 20 #include "GrOptDrawState.h"
21 #include "GrXferProcessor.h"
20 #include "SkXfermode.h" 22 #include "SkXfermode.h"
21 23
22 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) 24 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
23 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) 25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
24 26
25 /** 27 /**
26 * Retrieves the final matrix that a transform needs to apply to its source coor ds. 28 * Retrieves the final matrix that a transform needs to apply to its source coor ds.
27 */ 29 */
28 static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int tr ansformIdx) { 30 static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int tr ansformIdx) {
29 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor m(transformIdx); 31 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransfor m(transformIdx);
(...skipping 20 matching lines...) Expand all
50 } 52 }
51 53
52 //////////////////////////////////////////////////////////////////////////////// /////////////////// 54 //////////////////////////////////////////////////////////////////////////////// ///////////////////
53 55
54 GrGLProgram::GrGLProgram(GrGpuGL* gpu, 56 GrGLProgram::GrGLProgram(GrGpuGL* gpu,
55 const GrProgramDesc& desc, 57 const GrProgramDesc& desc,
56 const BuiltinUniformHandles& builtinUniforms, 58 const BuiltinUniformHandles& builtinUniforms,
57 GrGLuint programID, 59 GrGLuint programID,
58 const UniformInfoArray& uniforms, 60 const UniformInfoArray& uniforms,
59 GrGLInstalledGeoProc* geometryProcessor, 61 GrGLInstalledGeoProc* geometryProcessor,
62 GrGLInstalledXferProc* xferProcessor,
60 GrGLInstalledFragProcs* fragmentProcessors) 63 GrGLInstalledFragProcs* fragmentProcessors)
61 : fColor(GrColor_ILLEGAL) 64 : fColor(GrColor_ILLEGAL)
62 , fCoverage(0) 65 , fCoverage(0)
63 , fDstCopyTexUnit(-1) 66 , fDstCopyTexUnit(-1)
64 , fBuiltinUniformHandles(builtinUniforms) 67 , fBuiltinUniformHandles(builtinUniforms)
65 , fProgramID(programID) 68 , fProgramID(programID)
66 , fGeometryProcessor(geometryProcessor) 69 , fGeometryProcessor(geometryProcessor)
70 , fXferProcessor(xferProcessor)
67 , fFragmentProcessors(SkRef(fragmentProcessors)) 71 , fFragmentProcessors(SkRef(fragmentProcessors))
68 , fDesc(desc) 72 , fDesc(desc)
69 , fGpu(gpu) 73 , fGpu(gpu)
70 , fProgramDataManager(gpu, uniforms) { 74 , fProgramDataManager(gpu, uniforms) {
71 this->initSamplerUniforms(); 75 this->initSamplerUniforms();
72 } 76 }
73 77
74 GrGLProgram::~GrGLProgram() { 78 GrGLProgram::~GrGLProgram() {
75 if (fProgramID) { 79 if (fProgramID) {
76 GL_CALL(DeleteProgram(fProgramID)); 80 GL_CALL(DeleteProgram(fProgramID));
77 } 81 }
78 } 82 }
79 83
80 void GrGLProgram::abandon() { 84 void GrGLProgram::abandon() {
81 fProgramID = 0; 85 fProgramID = 0;
82 } 86 }
83 87
84 void GrGLProgram::initSamplerUniforms() { 88 void GrGLProgram::initSamplerUniforms() {
85 GL_CALL(UseProgram(fProgramID)); 89 GL_CALL(UseProgram(fProgramID));
86 GrGLint texUnitIdx = 0; 90 GrGLint texUnitIdx = 0;
87 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { 91 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) {
88 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni , texUnitIdx); 92 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni , texUnitIdx);
89 fDstCopyTexUnit = texUnitIdx++; 93 fDstCopyTexUnit = texUnitIdx++;
90 } 94 }
91 if (fGeometryProcessor.get()) { 95 if (fGeometryProcessor.get()) {
92 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx); 96 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx);
93 } 97 }
98 if (fXferProcessor.get()) {
99 this->initSamplers(fXferProcessor.get(), &texUnitIdx);
100 }
94 int numProcs = fFragmentProcessors->fProcs.count(); 101 int numProcs = fFragmentProcessors->fProcs.count();
95 for (int i = 0; i < numProcs; i++) { 102 for (int i = 0; i < numProcs; i++) {
96 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx); 103 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx);
97 } 104 }
98 } 105 }
99 106
100 void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) { 107 void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) {
101 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers; 108 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
102 int numSamplers = samplers.count(); 109 int numSamplers = samplers.count();
103 for (int s = 0; s < numSamplers; ++s) { 110 for (int s = 0; s < numSamplers; ++s) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 162
156 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses 163 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses
157 // of GLProgram determine how to set coord transforms 164 // of GLProgram determine how to set coord transforms
158 if (fGeometryProcessor.get()) { 165 if (fGeometryProcessor.get()) {
159 SkASSERT(optState.hasGeometryProcessor()); 166 SkASSERT(optState.hasGeometryProcessor());
160 const GrGeometryProcessor& gp = *optState.getGeometryProcessor(); 167 const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
161 const GrBatchTracker& bt = optState.getBatchTracker(); 168 const GrBatchTracker& bt = optState.getBatchTracker();
162 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp, bt); 169 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp, bt);
163 this->bindTextures(fGeometryProcessor, gp); 170 this->bindTextures(fGeometryProcessor, gp);
164 } 171 }
172 if (fXferProcessor.get()) {
173 const GrXferProcessor& xp = *optState.getXferProcessor();
174 fXferProcessor->fGLProc->setData(fProgramDataManager, xp);
175 this->bindTextures(fXferProcessor, xp);
176 }
165 this->setFragmentData(optState); 177 this->setFragmentData(optState);
166 178
167 // Some of GrGLProgram subclasses need to update state here 179 // Some of GrGLProgram subclasses need to update state here
168 this->didSetData(optState.drawType()); 180 this->didSetData(optState.drawType());
169 } 181 }
170 182
171 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { 183 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
172 int numProcessors = fFragmentProcessors->fProcs.count(); 184 int numProcessors = fFragmentProcessors->fProcs.count();
173 for (int e = 0; e < numProcessors; ++e) { 185 for (int e = 0; e < numProcessors; ++e) {
174 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); 186 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 289 }
278 } 290 }
279 291
280 //////////////////////////////////////////////////////////////////////////////// ///////// 292 //////////////////////////////////////////////////////////////////////////////// /////////
281 293
282 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, 294 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu,
283 const GrProgramDesc& desc, 295 const GrProgramDesc& desc,
284 const BuiltinUniformHandles& builtinUni forms, 296 const BuiltinUniformHandles& builtinUni forms,
285 GrGLuint programID, 297 GrGLuint programID,
286 const UniformInfoArray& uniforms, 298 const UniformInfoArray& uniforms,
299 GrGLInstalledXferProc* xferProcessor,
287 GrGLInstalledFragProcs* fragmentProcess ors) 300 GrGLInstalledFragProcs* fragmentProcess ors)
288 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP rocessors) { 301 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL,
302 xferProcessor, fragmentProcessors) {
289 } 303 }
290 304
291 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { 305 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
292 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType())); 306 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
293 const GrRenderTarget* rt = optState.getRenderTarget(); 307 const GrRenderTarget* rt = optState.getRenderTarget();
294 SkISize size; 308 SkISize size;
295 size.set(rt->width(), rt->height()); 309 size.set(rt->width(), rt->height());
296 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin()); 310 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
297 } 311 }
298 312
299 //////////////////////////////////////////////////////////////////////////////// ///////// 313 //////////////////////////////////////////////////////////////////////////////// /////////
300 314
301 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, 315 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu,
302 const GrProgramDesc& desc, 316 const GrProgramDesc& desc,
303 const BuiltinUniformHandles& builtinUniforms, 317 const BuiltinUniformHandles& builtinUniforms,
304 GrGLuint programID, 318 GrGLuint programID,
305 const UniformInfoArray& uniforms, 319 const UniformInfoArray& uniforms,
320 GrGLInstalledXferProc* xferProcessor,
306 GrGLInstalledFragProcs* fragmentProcessors, 321 GrGLInstalledFragProcs* fragmentProcessors,
307 const SeparableVaryingInfoArray& separableVaryi ngs) 322 const SeparableVaryingInfoArray& separableVaryi ngs)
308 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcess ors) { 323 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms,
324 xferProcessor, fragmentProcessors) {
309 int count = separableVaryings.count(); 325 int count = separableVaryings.count();
310 fVaryings.push_back_n(count); 326 fVaryings.push_back_n(count);
311 for (int i = 0; i < count; i++) { 327 for (int i = 0; i < count; i++) {
312 Varying& varying = fVaryings[i]; 328 Varying& varying = fVaryings[i];
313 const SeparableVaryingInfo& builderVarying = separableVaryings[i]; 329 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
314 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo unt()); 330 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCo unt());
315 SkDEBUGCODE( 331 SkDEBUGCODE(
316 varying.fType = builderVarying.fVariable.getType(); 332 varying.fType = builderVarying.fVariable.getType();
317 ); 333 );
318 varying.fLocation = builderVarying.fLocation; 334 varying.fLocation = builderVarying.fLocation;
(...skipping 27 matching lines...) Expand all
346 } 362 }
347 } 363 }
348 364
349 //////////////////////////////////////////////////////////////////////////////// ////// 365 //////////////////////////////////////////////////////////////////////////////// //////
350 366
351 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, 367 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu,
352 const GrProgramDesc& desc, 368 const GrProgramDesc& desc,
353 const BuiltinUniformHandles& builti nUniforms, 369 const BuiltinUniformHandles& builti nUniforms,
354 GrGLuint programID, 370 GrGLuint programID,
355 const UniformInfoArray& uniforms, 371 const UniformInfoArray& uniforms,
372 GrGLInstalledXferProc* xp,
356 GrGLInstalledFragProcs* fps, 373 GrGLInstalledFragProcs* fps,
357 int texCoordSetCnt) 374 int texCoordSetCnt)
358 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) 375 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, xp, fps)
359 , fTexCoordSetCnt(texCoordSetCnt) { 376 , fTexCoordSetCnt(texCoordSetCnt) {
360 } 377 }
361 378
362 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { 379 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
363 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); 380 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
364 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); 381 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
365 } 382 }
366 383
367 void 384 void
368 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc, 385 GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
369 GrGLInstalledFragProc* ip) { 386 GrGLInstalledFragProc* ip) {
370 // We've hidden the texcoord index in the first entry of the transforms arra y for each effect 387 // We've hidden the texcoord index in the first entry of the transforms arra y for each effect
371 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); 388 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
372 int numTransforms = proc.getProcessor()->numTransforms(); 389 int numTransforms = proc.getProcessor()->numTransforms();
373 for (int t = 0; t < numTransforms; ++t) { 390 for (int t = 0; t < numTransforms; ++t) {
374 const SkMatrix& transform = get_transform_matrix(proc, t); 391 const SkMatrix& transform = get_transform_matrix(proc, t);
375 GrGLPathRendering::PathTexGenComponents components = 392 GrGLPathRendering::PathTexGenComponents components =
376 GrGLPathRendering::kST_PathTexGenComponents; 393 GrGLPathRendering::kST_PathTexGenComponents;
377 if (proc.isPerspectiveCoordTransform(t)) { 394 if (proc.isPerspectiveCoordTransform(t)) {
378 components = GrGLPathRendering::kSTR_PathTexGenComponents; 395 components = GrGLPathRendering::kSTR_PathTexGenComponents;
379 } 396 }
380 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t ransform); 397 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t ransform);
381 } 398 }
382 } 399 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDesc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698