blob: 0f4b70de2b235d8a8e4ca50eb6c73829fbeae208 [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"
egdanielc2304142014-12-11 13:15:13 -080015#include "GrGLXferProcessor.h"
bsalomon@google.com34cccde2013-01-04 18:34:30 +000016#include "GrGpuGL.h"
kkinnunenec56e452014-08-25 22:21:16 -070017#include "GrGLPathRendering.h"
bsalomon@google.com4fa66942011-09-20 19:06:12 +000018#include "GrGLShaderVar.h"
bsalomon@google.com018f1792013-04-18 19:36:09 +000019#include "GrGLSL.h"
egdaniel170f90b2014-09-16 12:54:40 -070020#include "GrOptDrawState.h"
egdanielc2304142014-12-11 13:15:13 -080021#include "GrXferProcessor.h"
Scroggo97c88c22011-05-11 14:05:25 +000022#include "SkXfermode.h"
23
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000024#define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
25#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000026
joshualitt47bb3822014-10-07 16:43:25 -070027/**
28 * Retrieves the final matrix that a transform needs to apply to its source coords.
29 */
joshualitt2dd1ae02014-12-03 06:24:10 -080030static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int transformIdx) {
bsalomonae59b772014-11-19 08:23:49 -080031 const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransform(transformIdx);
joshualitt47bb3822014-10-07 16:43:25 -070032 SkMatrix combined;
33
34 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
35 // If we have explicit local coords then we shouldn't need a coord change.
joshualitt2dd1ae02014-12-03 06:24:10 -080036 const SkMatrix& ccm = stage.getCoordChangeMatrix();
joshualitt47bb3822014-10-07 16:43:25 -070037 combined.setConcat(coordTransform.getMatrix(), ccm);
kkinnunenec56e452014-08-25 22:21:16 -070038 } else {
joshualitt47bb3822014-10-07 16:43:25 -070039 combined = coordTransform.getMatrix();
kkinnunendddc18a2014-08-03 23:19:46 -070040 }
joshualitt47bb3822014-10-07 16:43:25 -070041 if (coordTransform.reverseY()) {
42 // combined.postScale(1,-1);
43 // combined.postTranslate(0,1);
44 combined.set(SkMatrix::kMSkewY,
45 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
46 combined.set(SkMatrix::kMScaleY,
47 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
48 combined.set(SkMatrix::kMTransY,
49 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000050 }
joshualitt47bb3822014-10-07 16:43:25 -070051 return combined;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000052}
53
joshualitt47bb3822014-10-07 16:43:25 -070054///////////////////////////////////////////////////////////////////////////////////////////////////
55
bsalomon861e1032014-12-16 07:33:49 -080056GrGLProgram::GrGLProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -070057 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -070058 const BuiltinUniformHandles& builtinUniforms,
59 GrGLuint programID,
60 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -070061 GrGLInstalledGeoProc* geometryProcessor,
egdanielc2304142014-12-11 13:15:13 -080062 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -070063 GrGLInstalledFragProcs* fragmentProcessors)
commit-bot@chromium.orga05fa062014-05-30 18:55:03 +000064 : fColor(GrColor_ILLEGAL)
egdaniel37b4d862014-11-03 10:07:07 -080065 , fCoverage(0)
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000066 , fDstCopyTexUnit(-1)
joshualitt47bb3822014-10-07 16:43:25 -070067 , fBuiltinUniformHandles(builtinUniforms)
68 , fProgramID(programID)
joshualitta5305a12014-10-10 17:47:00 -070069 , fGeometryProcessor(geometryProcessor)
egdanielc2304142014-12-11 13:15:13 -080070 , fXferProcessor(xferProcessor)
joshualitta5305a12014-10-10 17:47:00 -070071 , 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 }
egdanielc2304142014-12-11 13:15:13 -080098 if (fXferProcessor.get()) {
99 this->initSamplers(fXferProcessor.get(), &texUnitIdx);
100 }
joshualitta5305a12014-10-10 17:47:00 -0700101 int numProcs = fFragmentProcessors->fProcs.count();
102 for (int i = 0; i < numProcs; i++) {
103 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx);
joshualitt47bb3822014-10-07 16:43:25 -0700104 }
105}
106
joshualitta5305a12014-10-10 17:47:00 -0700107void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) {
108 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
109 int numSamplers = samplers.count();
110 for (int s = 0; s < numSamplers; ++s) {
111 SkASSERT(samplers[s].fUniform.isValid());
112 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx);
113 samplers[s].fTextureUnit = (*texUnitIdx)++;
114 }
115}
116
117void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) {
118 const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
joshualitt47bb3822014-10-07 16:43:25 -0700119 int numSamplers = samplers.count();
120 SkASSERT(numSamplers == processor.numTextures());
121 for (int s = 0; s < numSamplers; ++s) {
122 SkASSERT(samplers[s].fTextureUnit >= 0);
123 const GrTextureAccess& textureAccess = processor.textureAccess(s);
124 fGpu->bindTexture(samplers[s].fTextureUnit,
125 textureAccess.getParams(),
126 static_cast<GrGLTexture*>(textureAccess.getTexture()));
127 }
128}
129
130
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000131///////////////////////////////////////////////////////////////////////////////
junov@google.comf93e7172011-03-31 21:26:24 +0000132
joshualittdafa4d02014-12-04 08:59:10 -0800133void GrGLProgram::setData(const GrOptDrawState& optState) {
joshualittdafa4d02014-12-04 08:59:10 -0800134 this->setMatrixAndRenderTargetHeight(optState);
bsalomon@google.com91207482013-02-12 21:45:24 +0000135
joshualitt9176e2c2014-11-20 07:28:52 -0800136 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
bsalomon49f085d2014-09-05 13:34:00 -0700137 if (dstCopy) {
kkinnunendddc18a2014-08-03 23:19:46 -0700138 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
139 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
kkinnunen7510b222014-07-30 00:04:16 -0700140 static_cast<GrGLfloat>(dstCopy->offset().fX),
141 static_cast<GrGLfloat>(dstCopy->offset().fY));
kkinnunendddc18a2014-08-03 23:19:46 -0700142 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
kkinnunen7510b222014-07-30 00:04:16 -0700143 1.f / dstCopy->texture()->width(),
144 1.f / dstCopy->texture()->height());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000145 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
146 static GrTextureParams kParams; // the default is clamp, nearest filtering.
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000147 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000148 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700149 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
150 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000151 }
152 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700153 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
154 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
155 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000156 }
bsalomon@google.comc7818882013-03-20 19:19:53 +0000157
joshualitt47bb3822014-10-07 16:43:25 -0700158 // we set the textures, and uniforms for installed processors in a generic way, but subclasses
159 // of GLProgram determine how to set coord transforms
joshualitt9b989322014-12-15 14:16:27 -0800160 const GrPrimitiveProcessor& primProc = *optState.getPrimitiveProcessor();
161 const GrBatchTracker& bt = optState.getBatchTracker();
162 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, bt);
163 this->bindTextures(fGeometryProcessor, primProc);
164
egdanielc2304142014-12-11 13:15:13 -0800165 if (fXferProcessor.get()) {
166 const GrXferProcessor& xp = *optState.getXferProcessor();
167 fXferProcessor->fGLProc->setData(fProgramDataManager, xp);
168 this->bindTextures(fXferProcessor, xp);
169 }
joshualitta5305a12014-10-10 17:47:00 -0700170 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000171
joshualitt47bb3822014-10-07 16:43:25 -0700172 // Some of GrGLProgram subclasses need to update state here
joshualittdafa4d02014-12-04 08:59:10 -0800173 this->didSetData(optState.drawType());
joshualitt47bb3822014-10-07 16:43:25 -0700174}
175
joshualitta5305a12014-10-10 17:47:00 -0700176void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
177 int numProcessors = fFragmentProcessors->fProcs.count();
178 for (int e = 0; e < numProcessors; ++e) {
bsalomonae59b772014-11-19 08:23:49 -0800179 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
joshualitta5305a12014-10-10 17:47:00 -0700180 const GrProcessor& processor = *stage.getProcessor();
181 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
182 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
183 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
184 }
185}
bsalomonae59b772014-11-19 08:23:49 -0800186void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
187 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700188 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700189 int numTransforms = transforms.count();
190 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
191 for (int t = 0; t < numTransforms; ++t) {
192 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800193 const SkMatrix& matrix = get_transform_matrix(processor, t);
joshualitt47bb3822014-10-07 16:43:25 -0700194 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
195 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
196 transforms[t].fCurrentValue = matrix;
197 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000198 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000199}
bsalomon@google.com91207482013-02-12 21:45:24 +0000200
joshualitt47bb3822014-10-07 16:43:25 -0700201void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
202 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
203}
204
joshualittdafa4d02014-12-04 08:59:10 -0800205void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700206 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
207 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
208 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
209 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
210 SkIntToScalar(optState.getRenderTarget()->height()));
211 }
212
213 // call subclasses to set the actual view matrix
joshualittdafa4d02014-12-04 08:59:10 -0800214 this->onSetMatrixAndRenderTargetHeight(optState);
joshualitt47bb3822014-10-07 16:43:25 -0700215}
216
joshualittdafa4d02014-12-04 08:59:10 -0800217void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700218 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000219 SkISize size;
220 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700221 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
222 fMatrixState.fRenderTargetSize != size ||
223 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700224 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000225
egdaniel170f90b2014-09-16 12:54:40 -0700226 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000227 fMatrixState.fRenderTargetSize = size;
228 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000229
230 GrGLfloat viewMatrix[3 * 3];
231 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700232 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000233
234 GrGLfloat rtAdjustmentVec[4];
235 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700236 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000237 }
238}
joshualitt47bb3822014-10-07 16:43:25 -0700239
240/////////////////////////////////////////////////////////////////////////////////////////
241
bsalomon861e1032014-12-16 07:33:49 -0800242GrGLNvprProgramBase::GrGLNvprProgramBase(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700243 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700244 const BuiltinUniformHandles& builtinUniforms,
245 GrGLuint programID,
246 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800247 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800248 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700249 GrGLInstalledFragProcs* fragmentProcessors)
joshualitt9b989322014-12-15 14:16:27 -0800250 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800251 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700252}
253
joshualittdafa4d02014-12-04 08:59:10 -0800254void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
255 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
joshualitt47bb3822014-10-07 16:43:25 -0700256 const GrRenderTarget* rt = optState.getRenderTarget();
257 SkISize size;
258 size.set(rt->width(), rt->height());
259 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
260}
261
262/////////////////////////////////////////////////////////////////////////////////////////
263
bsalomon861e1032014-12-16 07:33:49 -0800264GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700265 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700266 const BuiltinUniformHandles& builtinUniforms,
267 GrGLuint programID,
268 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800269 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800270 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700271 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700272 const SeparableVaryingInfoArray& separableVaryings)
joshualitt9b989322014-12-15 14:16:27 -0800273 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800274 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700275 int count = separableVaryings.count();
276 fVaryings.push_back_n(count);
277 for (int i = 0; i < count; i++) {
278 Varying& varying = fVaryings[i];
279 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
280 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
281 SkDEBUGCODE(
282 varying.fType = builderVarying.fVariable.getType();
283 );
284 varying.fLocation = builderVarying.fLocation;
285 }
286}
287
288void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
289 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
290}
291
bsalomonae59b772014-11-19 08:23:49 -0800292void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
293 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700294 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700295 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700296 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700297 for (int t = 0; t < numTransforms; ++t) {
298 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800299 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700300 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
301 continue;
302 }
303 transforms[t].fCurrentValue = transform;
304 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
305 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
306 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
307 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
308 fragmentInput.fLocation,
309 GR_GL_OBJECT_LINEAR,
310 components,
311 transform);
312 }
313}
314
315//////////////////////////////////////////////////////////////////////////////////////
316
bsalomon861e1032014-12-16 07:33:49 -0800317GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700318 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700319 const BuiltinUniformHandles& builtinUniforms,
320 GrGLuint programID,
321 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800322 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800323 GrGLInstalledXferProc* xp,
joshualitta5305a12014-10-10 17:47:00 -0700324 GrGLInstalledFragProcs* fps,
325 int texCoordSetCnt)
joshualitt9b989322014-12-15 14:16:27 -0800326 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, xp, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700327 , fTexCoordSetCnt(texCoordSetCnt) {
328}
329
330void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
331 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
332 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
333}
334
joshualitta5305a12014-10-10 17:47:00 -0700335void
bsalomonae59b772014-11-19 08:23:49 -0800336GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
337 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700338 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700339 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
340 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700341 for (int t = 0; t < numTransforms; ++t) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800342 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700343 GrGLPathRendering::PathTexGenComponents components =
344 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800345 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700346 components = GrGLPathRendering::kSTR_PathTexGenComponents;
347 }
348 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
349 }
350}