blob: 3456a424d0ee76f76c35cdecef30ae9a4fe52e0b [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 */
joshualitta5305a12014-10-10 17:47:00 -070028static SkMatrix get_transform_matrix(const GrFragmentStage& processorStage,
joshualitt47bb3822014-10-07 16:43:25 -070029 bool useExplicitLocalCoords,
30 int transformIdx) {
31 const GrCoordTransform& coordTransform =
32 processorStage.getProcessor()->coordTransform(transformIdx);
33 SkMatrix combined;
34
35 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
36 // If we have explicit local coords then we shouldn't need a coord change.
37 const SkMatrix& ccm =
38 useExplicitLocalCoords ? SkMatrix::I() : processorStage.getCoordChangeMatrix();
39 combined.setConcat(coordTransform.getMatrix(), ccm);
kkinnunenec56e452014-08-25 22:21:16 -070040 } else {
joshualitt47bb3822014-10-07 16:43:25 -070041 combined = coordTransform.getMatrix();
kkinnunendddc18a2014-08-03 23:19:46 -070042 }
joshualitt47bb3822014-10-07 16:43:25 -070043 if (coordTransform.reverseY()) {
44 // combined.postScale(1,-1);
45 // combined.postTranslate(0,1);
46 combined.set(SkMatrix::kMSkewY,
47 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
48 combined.set(SkMatrix::kMScaleY,
49 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
50 combined.set(SkMatrix::kMTransY,
51 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000052 }
joshualitt47bb3822014-10-07 16:43:25 -070053 return combined;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000054}
55
joshualitt47bb3822014-10-07 16:43:25 -070056///////////////////////////////////////////////////////////////////////////////////////////////////
57
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000058GrGLProgram::GrGLProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -070059 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -070060 const BuiltinUniformHandles& builtinUniforms,
61 GrGLuint programID,
62 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -070063 GrGLInstalledGeoProc* geometryProcessor,
64 GrGLInstalledFragProcs* fragmentProcessors)
commit-bot@chromium.orga05fa062014-05-30 18:55:03 +000065 : fColor(GrColor_ILLEGAL)
egdaniel37b4d862014-11-03 10:07:07 -080066 , fCoverage(0)
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000067 , fDstCopyTexUnit(-1)
joshualitt47bb3822014-10-07 16:43:25 -070068 , fBuiltinUniformHandles(builtinUniforms)
69 , fProgramID(programID)
joshualitta5305a12014-10-10 17:47:00 -070070 , fGeometryProcessor(geometryProcessor)
71 , fFragmentProcessors(SkRef(fragmentProcessors))
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000072 , fDesc(desc)
73 , fGpu(gpu)
joshualitt47bb3822014-10-07 16:43:25 -070074 , fProgramDataManager(gpu, uniforms) {
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000075 this->initSamplerUniforms();
junov@google.comf93e7172011-03-31 21:26:24 +000076}
77
78GrGLProgram::~GrGLProgram() {
kkinnunendddc18a2014-08-03 23:19:46 -070079 if (fProgramID) {
80 GL_CALL(DeleteProgram(fProgramID));
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000081 }
junov@google.comf93e7172011-03-31 21:26:24 +000082}
83
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000084void GrGLProgram::abandon() {
kkinnunendddc18a2014-08-03 23:19:46 -070085 fProgramID = 0;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000086}
87
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000088void GrGLProgram::initSamplerUniforms() {
kkinnunendddc18a2014-08-03 23:19:46 -070089 GL_CALL(UseProgram(fProgramID));
bsalomon@google.com34cccde2013-01-04 18:34:30 +000090 GrGLint texUnitIdx = 0;
kkinnunendddc18a2014-08-03 23:19:46 -070091 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) {
92 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni, texUnitIdx);
bsalomon@google.com804e9942013-06-06 18:04:38 +000093 fDstCopyTexUnit = texUnitIdx++;
bsalomon@google.com26e18b52013-03-29 19:22:36 +000094 }
bsalomon49f085d2014-09-05 13:34:00 -070095 if (fGeometryProcessor.get()) {
joshualitt47bb3822014-10-07 16:43:25 -070096 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx);
joshualittbd769d02014-09-04 08:56:46 -070097 }
joshualitta5305a12014-10-10 17:47:00 -070098 int numProcs = fFragmentProcessors->fProcs.count();
99 for (int i = 0; i < numProcs; i++) {
100 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx);
joshualitt47bb3822014-10-07 16:43:25 -0700101 }
102}
103
joshualitta5305a12014-10-10 17:47:00 -0700104void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) {
105 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
106 int numSamplers = samplers.count();
107 for (int s = 0; s < numSamplers; ++s) {
108 SkASSERT(samplers[s].fUniform.isValid());
109 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx);
110 samplers[s].fTextureUnit = (*texUnitIdx)++;
111 }
112}
113
114void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) {
115 const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
joshualitt47bb3822014-10-07 16:43:25 -0700116 int numSamplers = samplers.count();
117 SkASSERT(numSamplers == processor.numTextures());
118 for (int s = 0; s < numSamplers; ++s) {
119 SkASSERT(samplers[s].fTextureUnit >= 0);
120 const GrTextureAccess& textureAccess = processor.textureAccess(s);
121 fGpu->bindTexture(samplers[s].fTextureUnit,
122 textureAccess.getParams(),
123 static_cast<GrGLTexture*>(textureAccess.getTexture()));
124 }
125}
126
127
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000128///////////////////////////////////////////////////////////////////////////////
junov@google.comf93e7172011-03-31 21:26:24 +0000129
egdaniel170f90b2014-09-16 12:54:40 -0700130void GrGLProgram::setData(const GrOptDrawState& optState,
131 GrGpu::DrawType drawType,
joshualitt0e602822014-10-28 10:27:44 -0700132 const GrDeviceCoordTexture* dstCopy) {
egdaniel170f90b2014-09-16 12:54:40 -0700133 GrColor color = optState.getColor();
egdaniel37b4d862014-11-03 10:07:07 -0800134 uint8_t coverage = optState.getCoverage();
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000135
joshualitt0e602822014-10-28 10:27:44 -0700136 this->setColor(optState, color);
137 this->setCoverage(optState, coverage);
egdaniel170f90b2014-09-16 12:54:40 -0700138 this->setMatrixAndRenderTargetHeight(drawType, optState);
bsalomon@google.com91207482013-02-12 21:45:24 +0000139
bsalomon49f085d2014-09-05 13:34:00 -0700140 if (dstCopy) {
kkinnunendddc18a2014-08-03 23:19:46 -0700141 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
142 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
kkinnunen7510b222014-07-30 00:04:16 -0700143 static_cast<GrGLfloat>(dstCopy->offset().fX),
144 static_cast<GrGLfloat>(dstCopy->offset().fY));
kkinnunendddc18a2014-08-03 23:19:46 -0700145 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
kkinnunen7510b222014-07-30 00:04:16 -0700146 1.f / dstCopy->texture()->width(),
147 1.f / dstCopy->texture()->height());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000148 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
149 static GrTextureParams kParams; // the default is clamp, nearest filtering.
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000150 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000151 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700152 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
153 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000154 }
155 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700156 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
157 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
158 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000159 }
bsalomon@google.comc7818882013-03-20 19:19:53 +0000160
joshualitt47bb3822014-10-07 16:43:25 -0700161 // we set the textures, and uniforms for installed processors in a generic way, but subclasses
162 // of GLProgram determine how to set coord transforms
bsalomon49f085d2014-09-05 13:34:00 -0700163 if (fGeometryProcessor.get()) {
joshualitta5305a12014-10-10 17:47:00 -0700164 SkASSERT(optState.hasGeometryProcessor());
165 const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
166 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp);
167 this->bindTextures(fGeometryProcessor, gp);
joshualittbd769d02014-09-04 08:56:46 -0700168 }
joshualitta5305a12014-10-10 17:47:00 -0700169 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000170
joshualitt47bb3822014-10-07 16:43:25 -0700171 // Some of GrGLProgram subclasses need to update state here
172 this->didSetData(drawType);
173}
174
joshualitta5305a12014-10-10 17:47:00 -0700175void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
176 int numProcessors = fFragmentProcessors->fProcs.count();
177 for (int e = 0; e < numProcessors; ++e) {
178 const GrFragmentStage& stage = optState.getFragmentStage(e);
179 const GrProcessor& processor = *stage.getProcessor();
180 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
181 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
182 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
183 }
184}
185void GrGLProgram::setTransformData(const GrFragmentStage& processor, GrGLInstalledFragProc* ip) {
186 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700187 int numTransforms = transforms.count();
188 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
189 for (int t = 0; t < numTransforms; ++t) {
190 SkASSERT(transforms[t].fHandle.isValid());
joshualitta5305a12014-10-10 17:47:00 -0700191 const SkMatrix& matrix = get_transform_matrix(processor, ip->fLocalCoordAttrib, t);
joshualitt47bb3822014-10-07 16:43:25 -0700192 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
194 transforms[t].fCurrentValue = matrix;
195 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000196 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000197}
bsalomon@google.com91207482013-02-12 21:45:24 +0000198
joshualitt47bb3822014-10-07 16:43:25 -0700199void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
201}
202
joshualitt0e602822014-10-28 10:27:44 -0700203void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) {
joshualitt79f8fae2014-10-28 17:59:26 -0700204 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700205 switch (header.fColorInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700206 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700207 // Attribute case is handled in GrGpuGL::setupGeometry
208 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700209 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700210 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) {
211 // OpenGL ES doesn't support unsigned byte varieties of glUniform
212 GrGLfloat c[4];
213 GrColorToRGBAFloat(color, c);
214 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c);
215 fColor = color;
216 }
217 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700218 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700219 // Handled by shader creation
220 break;
221 default:
222 SkFAIL("Unexpected color type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000223 }
224}
225
egdaniel37b4d862014-11-03 10:07:07 -0800226void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage) {
joshualitt79f8fae2014-10-28 17:59:26 -0700227 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700228 switch (header.fCoverageInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700229 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700230 // Attribute case is handled in GrGpuGL::setupGeometry
231 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700232 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700233 if (fCoverage != coverage) {
234 // OpenGL ES doesn't support unsigned byte varieties of glUniform
egdaniele27065a2014-11-06 08:00:48 -0800235 GrGLfloat c = GrNormalizeByteToFloat(coverage);
egdaniel37b4d862014-11-03 10:07:07 -0800236 fProgramDataManager.set1f(fBuiltinUniformHandles.fCoverageUni, c);
joshualitt0e602822014-10-28 10:27:44 -0700237 fCoverage = coverage;
238 }
239 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700240 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700241 // Handled by shader creation
242 break;
243 default:
244 SkFAIL("Unexpected coverage type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000245 }
246}
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000247
kkinnunenec56e452014-08-25 22:21:16 -0700248void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
egdaniel170f90b2014-09-16 12:54:40 -0700249 const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700250 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
251 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
252 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
253 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
254 SkIntToScalar(optState.getRenderTarget()->height()));
255 }
256
257 // call subclasses to set the actual view matrix
258 this->onSetMatrixAndRenderTargetHeight(drawType, optState);
259}
260
261void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
262 const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700263 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000264 SkISize size;
265 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700266 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
267 fMatrixState.fRenderTargetSize != size ||
268 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700269 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000270
egdaniel170f90b2014-09-16 12:54:40 -0700271 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000272 fMatrixState.fRenderTargetSize = size;
273 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000274
275 GrGLfloat viewMatrix[3 * 3];
276 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700277 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000278
279 GrGLfloat rtAdjustmentVec[4];
280 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700281 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000282 }
283}
joshualitt47bb3822014-10-07 16:43:25 -0700284
285/////////////////////////////////////////////////////////////////////////////////////////
286
287GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700288 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700289 const BuiltinUniformHandles& builtinUniforms,
290 GrGLuint programID,
291 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700292 GrGLInstalledFragProcs* fragmentProcessors)
293 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700294}
295
296void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
297 const GrOptDrawState& optState) {
298 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
299 const GrRenderTarget* rt = optState.getRenderTarget();
300 SkISize size;
301 size.set(rt->width(), rt->height());
302 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
303}
304
305/////////////////////////////////////////////////////////////////////////////////////////
306
307GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700308 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700309 const BuiltinUniformHandles& builtinUniforms,
310 GrGLuint programID,
311 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700312 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700313 const SeparableVaryingInfoArray& separableVaryings)
joshualitta5305a12014-10-10 17:47:00 -0700314 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700315 int count = separableVaryings.count();
316 fVaryings.push_back_n(count);
317 for (int i = 0; i < count; i++) {
318 Varying& varying = fVaryings[i];
319 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
320 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
321 SkDEBUGCODE(
322 varying.fType = builderVarying.fVariable.getType();
323 );
324 varying.fLocation = builderVarying.fLocation;
325 }
326}
327
328void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
329 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
330}
331
joshualitta5305a12014-10-10 17:47:00 -0700332void GrGLNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstalledFragProc* ip) {
333 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700334 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700335 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700336 for (int t = 0; t < numTransforms; ++t) {
337 SkASSERT(transforms[t].fHandle.isValid());
joshualitta5305a12014-10-10 17:47:00 -0700338 const SkMatrix& transform = get_transform_matrix(proc, false, t);
joshualitt47bb3822014-10-07 16:43:25 -0700339 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
340 continue;
341 }
342 transforms[t].fCurrentValue = transform;
343 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
344 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
345 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
346 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
347 fragmentInput.fLocation,
348 GR_GL_OBJECT_LINEAR,
349 components,
350 transform);
351 }
352}
353
354//////////////////////////////////////////////////////////////////////////////////////
355
356GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700357 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700358 const BuiltinUniformHandles& builtinUniforms,
359 GrGLuint programID,
360 const UniformInfoArray& uniforms,
361 GrGLInstalledFragProcs* fps,
362 int texCoordSetCnt)
363 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700364 , fTexCoordSetCnt(texCoordSetCnt) {
365}
366
367void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
368 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
369 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
370}
371
joshualitta5305a12014-10-10 17:47:00 -0700372void
373GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700374 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700375 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
376 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700377 for (int t = 0; t < numTransforms; ++t) {
joshualitta5305a12014-10-10 17:47:00 -0700378 const SkMatrix& transform = get_transform_matrix(proc, false, t);
joshualitt47bb3822014-10-07 16:43:25 -0700379 GrGLPathRendering::PathTexGenComponents components =
380 GrGLPathRendering::kST_PathTexGenComponents;
joshualitta5305a12014-10-10 17:47:00 -0700381 if (proc.isPerspectiveCoordTransform(t, false)) {
joshualitt47bb3822014-10-07 16:43:25 -0700382 components = GrGLPathRendering::kSTR_PathTexGenComponents;
383 }
384 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
385 }
386}