blob: 63cb9da20b489c7e47fb18f0d6cb66d93bb622a7 [file] [log] [blame]
junov@google.comf93e7172011-03-31 21:26:24 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
junov@google.comf93e7172011-03-31 21:26:24 +00006 */
joshualitt23e280d2014-09-18 12:26:38 -07007
junov@google.comf93e7172011-03-31 21:26:24 +00008#include "GrGLProgram.h"
9
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000010#include "GrAllocator.h"
joshualittb0a8a372014-09-23 09:50:21 -070011#include "GrProcessor.h"
bsalomon@google.com77af6802013-10-02 13:04:56 +000012#include "GrCoordTransform.h"
joshualitta5305a12014-10-10 17:47:00 -070013#include "GrGLGeometryProcessor.h"
joshualittb0a8a372014-09-23 09:50:21 -070014#include "GrGLProcessor.h"
bsalomon@google.com34cccde2013-01-04 18:34:30 +000015#include "GrGpuGL.h"
kkinnunenec56e452014-08-25 22:21:16 -070016#include "GrGLPathRendering.h"
bsalomon@google.com4fa66942011-09-20 19:06:12 +000017#include "GrGLShaderVar.h"
bsalomon@google.com018f1792013-04-18 19:36:09 +000018#include "GrGLSL.h"
egdaniel170f90b2014-09-16 12:54:40 -070019#include "GrOptDrawState.h"
Scroggo97c88c22011-05-11 14:05:25 +000020#include "SkXfermode.h"
21
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000022#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)
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000024
joshualitt47bb3822014-10-07 16:43:25 -070025/**
26 * Retrieves the final matrix that a transform needs to apply to its source coords.
27 */
joshualitt2dd1ae02014-12-03 06:24:10 -080028static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int transformIdx) {
bsalomonae59b772014-11-19 08:23:49 -080029 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransform(transformIdx);
joshualitt47bb3822014-10-07 16:43:25 -070030 SkMatrix combined;
31
32 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
33 // If we have explicit local coords then we shouldn't need a coord change.
joshualitt2dd1ae02014-12-03 06:24:10 -080034 const SkMatrix& ccm = stage.getCoordChangeMatrix();
joshualitt47bb3822014-10-07 16:43:25 -070035 combined.setConcat(coordTransform.getMatrix(), ccm);
kkinnunenec56e452014-08-25 22:21:16 -070036 } else {
joshualitt47bb3822014-10-07 16:43:25 -070037 combined = coordTransform.getMatrix();
kkinnunendddc18a2014-08-03 23:19:46 -070038 }
joshualitt47bb3822014-10-07 16:43:25 -070039 if (coordTransform.reverseY()) {
40 // combined.postScale(1,-1);
41 // combined.postTranslate(0,1);
42 combined.set(SkMatrix::kMSkewY,
43 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
44 combined.set(SkMatrix::kMScaleY,
45 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
46 combined.set(SkMatrix::kMTransY,
47 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000048 }
joshualitt47bb3822014-10-07 16:43:25 -070049 return combined;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000050}
51
joshualitt47bb3822014-10-07 16:43:25 -070052///////////////////////////////////////////////////////////////////////////////////////////////////
53
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000054GrGLProgram::GrGLProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -070055 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -070056 const BuiltinUniformHandles& builtinUniforms,
57 GrGLuint programID,
58 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -070059 GrGLInstalledGeoProc* geometryProcessor,
60 GrGLInstalledFragProcs* fragmentProcessors)
commit-bot@chromium.orga05fa062014-05-30 18:55:03 +000061 : fColor(GrColor_ILLEGAL)
egdaniel37b4d862014-11-03 10:07:07 -080062 , fCoverage(0)
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000063 , fDstCopyTexUnit(-1)
joshualitt47bb3822014-10-07 16:43:25 -070064 , fBuiltinUniformHandles(builtinUniforms)
65 , fProgramID(programID)
joshualitta5305a12014-10-10 17:47:00 -070066 , fGeometryProcessor(geometryProcessor)
67 , fFragmentProcessors(SkRef(fragmentProcessors))
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000068 , fDesc(desc)
69 , fGpu(gpu)
joshualitt47bb3822014-10-07 16:43:25 -070070 , fProgramDataManager(gpu, uniforms) {
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000071 this->initSamplerUniforms();
junov@google.comf93e7172011-03-31 21:26:24 +000072}
73
74GrGLProgram::~GrGLProgram() {
kkinnunendddc18a2014-08-03 23:19:46 -070075 if (fProgramID) {
76 GL_CALL(DeleteProgram(fProgramID));
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000077 }
junov@google.comf93e7172011-03-31 21:26:24 +000078}
79
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000080void GrGLProgram::abandon() {
kkinnunendddc18a2014-08-03 23:19:46 -070081 fProgramID = 0;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000082}
83
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000084void GrGLProgram::initSamplerUniforms() {
kkinnunendddc18a2014-08-03 23:19:46 -070085 GL_CALL(UseProgram(fProgramID));
bsalomon@google.com34cccde2013-01-04 18:34:30 +000086 GrGLint texUnitIdx = 0;
kkinnunendddc18a2014-08-03 23:19:46 -070087 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) {
88 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni, texUnitIdx);
bsalomon@google.com804e9942013-06-06 18:04:38 +000089 fDstCopyTexUnit = texUnitIdx++;
bsalomon@google.com26e18b52013-03-29 19:22:36 +000090 }
bsalomon49f085d2014-09-05 13:34:00 -070091 if (fGeometryProcessor.get()) {
joshualitt47bb3822014-10-07 16:43:25 -070092 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx);
joshualittbd769d02014-09-04 08:56:46 -070093 }
joshualitta5305a12014-10-10 17:47:00 -070094 int numProcs = fFragmentProcessors->fProcs.count();
95 for (int i = 0; i < numProcs; i++) {
96 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx);
joshualitt47bb3822014-10-07 16:43:25 -070097 }
98}
99
joshualitta5305a12014-10-10 17:47:00 -0700100void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) {
101 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
102 int numSamplers = samplers.count();
103 for (int s = 0; s < numSamplers; ++s) {
104 SkASSERT(samplers[s].fUniform.isValid());
105 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx);
106 samplers[s].fTextureUnit = (*texUnitIdx)++;
107 }
108}
109
110void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) {
111 const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
joshualitt47bb3822014-10-07 16:43:25 -0700112 int numSamplers = samplers.count();
113 SkASSERT(numSamplers == processor.numTextures());
114 for (int s = 0; s < numSamplers; ++s) {
115 SkASSERT(samplers[s].fTextureUnit >= 0);
116 const GrTextureAccess& textureAccess = processor.textureAccess(s);
117 fGpu->bindTexture(samplers[s].fTextureUnit,
118 textureAccess.getParams(),
119 static_cast<GrGLTexture*>(textureAccess.getTexture()));
120 }
121}
122
123
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000124///////////////////////////////////////////////////////////////////////////////
junov@google.comf93e7172011-03-31 21:26:24 +0000125
joshualittf78c60c2014-12-04 06:01:45 -0800126void GrGLProgram::setData(const GrOptDrawState& optState, GrGpu::DrawType drawType) {
egdaniel170f90b2014-09-16 12:54:40 -0700127 GrColor color = optState.getColor();
egdaniel37b4d862014-11-03 10:07:07 -0800128 uint8_t coverage = optState.getCoverage();
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000129
joshualitt0e602822014-10-28 10:27:44 -0700130 this->setColor(optState, color);
131 this->setCoverage(optState, coverage);
joshualittf78c60c2014-12-04 06:01:45 -0800132 this->setMatrixAndRenderTargetHeight(drawType, optState);
bsalomon@google.com91207482013-02-12 21:45:24 +0000133
joshualitt9176e2c2014-11-20 07:28:52 -0800134 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
bsalomon49f085d2014-09-05 13:34:00 -0700135 if (dstCopy) {
kkinnunendddc18a2014-08-03 23:19:46 -0700136 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
137 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
kkinnunen7510b222014-07-30 00:04:16 -0700138 static_cast<GrGLfloat>(dstCopy->offset().fX),
139 static_cast<GrGLfloat>(dstCopy->offset().fY));
kkinnunendddc18a2014-08-03 23:19:46 -0700140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
kkinnunen7510b222014-07-30 00:04:16 -0700141 1.f / dstCopy->texture()->width(),
142 1.f / dstCopy->texture()->height());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000143 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
144 static GrTextureParams kParams; // the default is clamp, nearest filtering.
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000145 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000146 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700147 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
148 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000149 }
150 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700151 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
152 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
153 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000154 }
bsalomon@google.comc7818882013-03-20 19:19:53 +0000155
joshualitt47bb3822014-10-07 16:43:25 -0700156 // we set the textures, and uniforms for installed processors in a generic way, but subclasses
157 // of GLProgram determine how to set coord transforms
bsalomon49f085d2014-09-05 13:34:00 -0700158 if (fGeometryProcessor.get()) {
joshualitta5305a12014-10-10 17:47:00 -0700159 SkASSERT(optState.hasGeometryProcessor());
160 const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
joshualitt841a6b52014-12-04 06:00:41 -0800161 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp);
joshualitta5305a12014-10-10 17:47:00 -0700162 this->bindTextures(fGeometryProcessor, gp);
joshualittbd769d02014-09-04 08:56:46 -0700163 }
joshualitta5305a12014-10-10 17:47:00 -0700164 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000165
joshualitt47bb3822014-10-07 16:43:25 -0700166 // Some of GrGLProgram subclasses need to update state here
joshualittf78c60c2014-12-04 06:01:45 -0800167 this->didSetData(drawType);
joshualitt47bb3822014-10-07 16:43:25 -0700168}
169
joshualitta5305a12014-10-10 17:47:00 -0700170void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
171 int numProcessors = fFragmentProcessors->fProcs.count();
172 for (int e = 0; e < numProcessors; ++e) {
bsalomonae59b772014-11-19 08:23:49 -0800173 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
joshualitta5305a12014-10-10 17:47:00 -0700174 const GrProcessor& processor = *stage.getProcessor();
175 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
176 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
177 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
178 }
179}
bsalomonae59b772014-11-19 08:23:49 -0800180void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
181 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700182 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700183 int numTransforms = transforms.count();
184 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
185 for (int t = 0; t < numTransforms; ++t) {
186 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800187 const SkMatrix& matrix = get_transform_matrix(processor, t);
joshualitt47bb3822014-10-07 16:43:25 -0700188 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
189 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
190 transforms[t].fCurrentValue = matrix;
191 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000192 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000193}
bsalomon@google.com91207482013-02-12 21:45:24 +0000194
joshualitt47bb3822014-10-07 16:43:25 -0700195void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
196 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
197}
198
joshualitt0e602822014-10-28 10:27:44 -0700199void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) {
joshualitt79f8fae2014-10-28 17:59:26 -0700200 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700201 switch (header.fColorInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700202 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700203 // Attribute case is handled in GrGpuGL::setupGeometry
204 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700205 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700206 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) {
207 // OpenGL ES doesn't support unsigned byte varieties of glUniform
208 GrGLfloat c[4];
209 GrColorToRGBAFloat(color, c);
210 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c);
211 fColor = color;
212 }
213 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700214 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700215 // Handled by shader creation
216 break;
217 default:
218 SkFAIL("Unexpected color type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000219 }
220}
221
egdaniel37b4d862014-11-03 10:07:07 -0800222void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage) {
joshualitt79f8fae2014-10-28 17:59:26 -0700223 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700224 switch (header.fCoverageInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700225 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700226 // Attribute case is handled in GrGpuGL::setupGeometry
227 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700228 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700229 if (fCoverage != coverage) {
230 // OpenGL ES doesn't support unsigned byte varieties of glUniform
egdaniele27065a2014-11-06 08:00:48 -0800231 GrGLfloat c = GrNormalizeByteToFloat(coverage);
egdaniel37b4d862014-11-03 10:07:07 -0800232 fProgramDataManager.set1f(fBuiltinUniformHandles.fCoverageUni, c);
joshualitt0e602822014-10-28 10:27:44 -0700233 fCoverage = coverage;
234 }
235 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700236 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700237 // Handled by shader creation
238 break;
239 default:
240 SkFAIL("Unexpected coverage type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000241 }
242}
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000243
joshualittf78c60c2014-12-04 06:01:45 -0800244void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
245 const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700246 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
247 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
248 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
249 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
250 SkIntToScalar(optState.getRenderTarget()->height()));
251 }
252
253 // call subclasses to set the actual view matrix
joshualittf78c60c2014-12-04 06:01:45 -0800254 this->onSetMatrixAndRenderTargetHeight(drawType, optState);
joshualitt47bb3822014-10-07 16:43:25 -0700255}
256
joshualittf78c60c2014-12-04 06:01:45 -0800257void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
258 const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700259 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000260 SkISize size;
261 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700262 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
263 fMatrixState.fRenderTargetSize != size ||
264 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700265 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000266
egdaniel170f90b2014-09-16 12:54:40 -0700267 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000268 fMatrixState.fRenderTargetSize = size;
269 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000270
271 GrGLfloat viewMatrix[3 * 3];
272 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700273 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000274
275 GrGLfloat rtAdjustmentVec[4];
276 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700277 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000278 }
279}
joshualitt47bb3822014-10-07 16:43:25 -0700280
281/////////////////////////////////////////////////////////////////////////////////////////
282
283GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700284 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700285 const BuiltinUniformHandles& builtinUniforms,
286 GrGLuint programID,
287 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700288 GrGLInstalledFragProcs* fragmentProcessors)
289 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700290}
291
joshualittf78c60c2014-12-04 06:01:45 -0800292void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
293 const GrOptDrawState& optState) {
294 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
joshualitt47bb3822014-10-07 16:43:25 -0700295 const GrRenderTarget* rt = optState.getRenderTarget();
296 SkISize size;
297 size.set(rt->width(), rt->height());
298 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
299}
300
301/////////////////////////////////////////////////////////////////////////////////////////
302
303GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700304 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700305 const BuiltinUniformHandles& builtinUniforms,
306 GrGLuint programID,
307 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700308 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700309 const SeparableVaryingInfoArray& separableVaryings)
joshualitta5305a12014-10-10 17:47:00 -0700310 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700311 int count = separableVaryings.count();
312 fVaryings.push_back_n(count);
313 for (int i = 0; i < count; i++) {
314 Varying& varying = fVaryings[i];
315 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
316 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
317 SkDEBUGCODE(
318 varying.fType = builderVarying.fVariable.getType();
319 );
320 varying.fLocation = builderVarying.fLocation;
321 }
322}
323
324void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
325 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
326}
327
bsalomonae59b772014-11-19 08:23:49 -0800328void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
329 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700330 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700331 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700332 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700333 for (int t = 0; t < numTransforms; ++t) {
334 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800335 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700336 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
337 continue;
338 }
339 transforms[t].fCurrentValue = transform;
340 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
341 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
342 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
343 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
344 fragmentInput.fLocation,
345 GR_GL_OBJECT_LINEAR,
346 components,
347 transform);
348 }
349}
350
351//////////////////////////////////////////////////////////////////////////////////////
352
353GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700354 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700355 const BuiltinUniformHandles& builtinUniforms,
356 GrGLuint programID,
357 const UniformInfoArray& uniforms,
358 GrGLInstalledFragProcs* fps,
359 int texCoordSetCnt)
360 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700361 , fTexCoordSetCnt(texCoordSetCnt) {
362}
363
364void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
365 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
366 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
367}
368
joshualitta5305a12014-10-10 17:47:00 -0700369void
bsalomonae59b772014-11-19 08:23:49 -0800370GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
371 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700372 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700373 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
374 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700375 for (int t = 0; t < numTransforms; ++t) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800376 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700377 GrGLPathRendering::PathTexGenComponents components =
378 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800379 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700380 components = GrGLPathRendering::kSTR_PathTexGenComponents;
381 }
382 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
383 }
384}