blob: 29c44ac56ccb9e92181b4b254c999857f325dadb [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
joshualitt829e1b82014-12-03 13:57:36 -0800126void GrGLProgram::setData(const GrOptDrawState& optState) {
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);
joshualitt829e1b82014-12-03 13:57:36 -0800132 this->setMatrixAndRenderTargetHeight(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();
joshualittc3a6eb22014-12-03 15:34:20 -0800161 const GrBatchTracker& bt = optState.getBatchTracker();
162 fGeometryProcessor->fGLProc->setData(fProgramDataManager, gp, bt);
joshualitta5305a12014-10-10 17:47:00 -0700163 this->bindTextures(fGeometryProcessor, gp);
joshualittbd769d02014-09-04 08:56:46 -0700164 }
joshualitta5305a12014-10-10 17:47:00 -0700165 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000166
joshualitt47bb3822014-10-07 16:43:25 -0700167 // Some of GrGLProgram subclasses need to update state here
joshualitt829e1b82014-12-03 13:57:36 -0800168 this->didSetData(optState.drawType());
joshualitt47bb3822014-10-07 16:43:25 -0700169}
170
joshualitta5305a12014-10-10 17:47:00 -0700171void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
172 int numProcessors = fFragmentProcessors->fProcs.count();
173 for (int e = 0; e < numProcessors; ++e) {
bsalomonae59b772014-11-19 08:23:49 -0800174 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
joshualitta5305a12014-10-10 17:47:00 -0700175 const GrProcessor& processor = *stage.getProcessor();
176 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
177 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
178 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
179 }
180}
bsalomonae59b772014-11-19 08:23:49 -0800181void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
182 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700183 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700184 int numTransforms = transforms.count();
185 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
186 for (int t = 0; t < numTransforms; ++t) {
187 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800188 const SkMatrix& matrix = get_transform_matrix(processor, t);
joshualitt47bb3822014-10-07 16:43:25 -0700189 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
190 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
191 transforms[t].fCurrentValue = matrix;
192 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000193 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000194}
bsalomon@google.com91207482013-02-12 21:45:24 +0000195
joshualitt47bb3822014-10-07 16:43:25 -0700196void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
197 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
198}
199
joshualitt0e602822014-10-28 10:27:44 -0700200void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) {
joshualitt79f8fae2014-10-28 17:59:26 -0700201 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700202 switch (header.fColorInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700203 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700204 // Attribute case is handled in GrGpuGL::setupGeometry
205 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700206 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700207 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) {
208 // OpenGL ES doesn't support unsigned byte varieties of glUniform
209 GrGLfloat c[4];
210 GrColorToRGBAFloat(color, c);
211 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c);
212 fColor = color;
213 }
214 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700215 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700216 // Handled by shader creation
217 break;
218 default:
219 SkFAIL("Unexpected color type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000220 }
221}
222
egdaniel37b4d862014-11-03 10:07:07 -0800223void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage) {
joshualitt79f8fae2014-10-28 17:59:26 -0700224 const GrProgramDesc::KeyHeader& header = fDesc.header();
joshualitt0e602822014-10-28 10:27:44 -0700225 switch (header.fCoverageInput) {
joshualitt79f8fae2014-10-28 17:59:26 -0700226 case GrProgramDesc::kAttribute_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700227 // Attribute case is handled in GrGpuGL::setupGeometry
228 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700229 case GrProgramDesc::kUniform_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700230 if (fCoverage != coverage) {
231 // OpenGL ES doesn't support unsigned byte varieties of glUniform
egdaniele27065a2014-11-06 08:00:48 -0800232 GrGLfloat c = GrNormalizeByteToFloat(coverage);
egdaniel37b4d862014-11-03 10:07:07 -0800233 fProgramDataManager.set1f(fBuiltinUniformHandles.fCoverageUni, c);
joshualitt0e602822014-10-28 10:27:44 -0700234 fCoverage = coverage;
235 }
236 break;
joshualitt79f8fae2014-10-28 17:59:26 -0700237 case GrProgramDesc::kAllOnes_ColorInput:
joshualitt0e602822014-10-28 10:27:44 -0700238 // Handled by shader creation
239 break;
240 default:
241 SkFAIL("Unexpected coverage type.");
bsalomon@google.com91207482013-02-12 21:45:24 +0000242 }
243}
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000244
joshualitt829e1b82014-12-03 13:57:36 -0800245void GrGLProgram::setMatrixAndRenderTargetHeight(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
joshualitt829e1b82014-12-03 13:57:36 -0800254 this->onSetMatrixAndRenderTargetHeight(optState);
joshualitt47bb3822014-10-07 16:43:25 -0700255}
256
joshualitt829e1b82014-12-03 13:57:36 -0800257void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700258 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000259 SkISize size;
260 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700261 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
262 fMatrixState.fRenderTargetSize != size ||
263 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700264 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000265
egdaniel170f90b2014-09-16 12:54:40 -0700266 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000267 fMatrixState.fRenderTargetSize = size;
268 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000269
270 GrGLfloat viewMatrix[3 * 3];
271 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700272 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000273
274 GrGLfloat rtAdjustmentVec[4];
275 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700276 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000277 }
278}
joshualitt47bb3822014-10-07 16:43:25 -0700279
280/////////////////////////////////////////////////////////////////////////////////////////
281
282GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700283 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700284 const BuiltinUniformHandles& builtinUniforms,
285 GrGLuint programID,
286 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700287 GrGLInstalledFragProcs* fragmentProcessors)
288 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700289}
290
joshualitt829e1b82014-12-03 13:57:36 -0800291void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
292 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
joshualitt47bb3822014-10-07 16:43:25 -0700293 const GrRenderTarget* rt = optState.getRenderTarget();
294 SkISize size;
295 size.set(rt->width(), rt->height());
296 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
297}
298
299/////////////////////////////////////////////////////////////////////////////////////////
300
301GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700302 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700303 const BuiltinUniformHandles& builtinUniforms,
304 GrGLuint programID,
305 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -0700306 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700307 const SeparableVaryingInfoArray& separableVaryings)
joshualitta5305a12014-10-10 17:47:00 -0700308 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700309 int count = separableVaryings.count();
310 fVaryings.push_back_n(count);
311 for (int i = 0; i < count; i++) {
312 Varying& varying = fVaryings[i];
313 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
314 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
315 SkDEBUGCODE(
316 varying.fType = builderVarying.fVariable.getType();
317 );
318 varying.fLocation = builderVarying.fLocation;
319 }
320}
321
322void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
323 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
324}
325
bsalomonae59b772014-11-19 08:23:49 -0800326void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
327 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700328 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700329 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700330 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700331 for (int t = 0; t < numTransforms; ++t) {
332 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800333 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700334 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
335 continue;
336 }
337 transforms[t].fCurrentValue = transform;
338 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
339 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
340 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
341 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
342 fragmentInput.fLocation,
343 GR_GL_OBJECT_LINEAR,
344 components,
345 transform);
346 }
347}
348
349//////////////////////////////////////////////////////////////////////////////////////
350
351GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700352 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700353 const BuiltinUniformHandles& builtinUniforms,
354 GrGLuint programID,
355 const UniformInfoArray& uniforms,
356 GrGLInstalledFragProcs* fps,
357 int texCoordSetCnt)
358 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700359 , fTexCoordSetCnt(texCoordSetCnt) {
360}
361
362void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
363 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
364 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
365}
366
joshualitta5305a12014-10-10 17:47:00 -0700367void
bsalomonae59b772014-11-19 08:23:49 -0800368GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
369 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700370 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700371 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
372 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700373 for (int t = 0; t < numTransforms; ++t) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800374 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700375 GrGLPathRendering::PathTexGenComponents components =
376 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800377 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700378 components = GrGLPathRendering::kSTR_PathTexGenComponents;
379 }
380 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
381 }
382}