blob: f8770b3664827623473a37fb0c3a02128c29bfc2 [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()) {
joshualitt16b27892014-12-18 07:47:16 -080035 // If we have explicit local coords or are in device coords then we shouldn't need a coord
36 // change.
joshualitt2dd1ae02014-12-03 06:24:10 -080037 const SkMatrix& ccm = stage.getCoordChangeMatrix();
joshualitt47bb3822014-10-07 16:43:25 -070038 combined.setConcat(coordTransform.getMatrix(), ccm);
kkinnunenec56e452014-08-25 22:21:16 -070039 } else {
joshualitt47bb3822014-10-07 16:43:25 -070040 combined = coordTransform.getMatrix();
kkinnunendddc18a2014-08-03 23:19:46 -070041 }
joshualitt47bb3822014-10-07 16:43:25 -070042 if (coordTransform.reverseY()) {
43 // combined.postScale(1,-1);
44 // combined.postTranslate(0,1);
45 combined.set(SkMatrix::kMSkewY,
46 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
47 combined.set(SkMatrix::kMScaleY,
48 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
49 combined.set(SkMatrix::kMTransY,
50 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000051 }
joshualitt47bb3822014-10-07 16:43:25 -070052 return combined;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000053}
54
joshualitt47bb3822014-10-07 16:43:25 -070055///////////////////////////////////////////////////////////////////////////////////////////////////
56
bsalomon861e1032014-12-16 07:33:49 -080057GrGLProgram::GrGLProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -070058 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -070059 const BuiltinUniformHandles& builtinUniforms,
60 GrGLuint programID,
61 const UniformInfoArray& uniforms,
joshualitta5305a12014-10-10 17:47:00 -070062 GrGLInstalledGeoProc* geometryProcessor,
egdanielc2304142014-12-11 13:15:13 -080063 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -070064 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)
egdanielc2304142014-12-11 13:15:13 -080071 , fXferProcessor(xferProcessor)
joshualitta5305a12014-10-10 17:47:00 -070072 , fFragmentProcessors(SkRef(fragmentProcessors))
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000073 , fDesc(desc)
74 , fGpu(gpu)
joshualitt47bb3822014-10-07 16:43:25 -070075 , fProgramDataManager(gpu, uniforms) {
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +000076 this->initSamplerUniforms();
junov@google.comf93e7172011-03-31 21:26:24 +000077}
78
79GrGLProgram::~GrGLProgram() {
kkinnunendddc18a2014-08-03 23:19:46 -070080 if (fProgramID) {
81 GL_CALL(DeleteProgram(fProgramID));
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000082 }
junov@google.comf93e7172011-03-31 21:26:24 +000083}
84
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000085void GrGLProgram::abandon() {
kkinnunendddc18a2014-08-03 23:19:46 -070086 fProgramID = 0;
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000087}
88
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000089void GrGLProgram::initSamplerUniforms() {
kkinnunendddc18a2014-08-03 23:19:46 -070090 GL_CALL(UseProgram(fProgramID));
bsalomon@google.com34cccde2013-01-04 18:34:30 +000091 GrGLint texUnitIdx = 0;
kkinnunendddc18a2014-08-03 23:19:46 -070092 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) {
93 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni, texUnitIdx);
bsalomon@google.com804e9942013-06-06 18:04:38 +000094 fDstCopyTexUnit = texUnitIdx++;
bsalomon@google.com26e18b52013-03-29 19:22:36 +000095 }
bsalomon49f085d2014-09-05 13:34:00 -070096 if (fGeometryProcessor.get()) {
joshualitt47bb3822014-10-07 16:43:25 -070097 this->initSamplers(fGeometryProcessor.get(), &texUnitIdx);
joshualittbd769d02014-09-04 08:56:46 -070098 }
egdanielc2304142014-12-11 13:15:13 -080099 if (fXferProcessor.get()) {
100 this->initSamplers(fXferProcessor.get(), &texUnitIdx);
101 }
joshualitta5305a12014-10-10 17:47:00 -0700102 int numProcs = fFragmentProcessors->fProcs.count();
103 for (int i = 0; i < numProcs; i++) {
104 this->initSamplers(fFragmentProcessors->fProcs[i], &texUnitIdx);
joshualitt47bb3822014-10-07 16:43:25 -0700105 }
106}
107
joshualitta5305a12014-10-10 17:47:00 -0700108void GrGLProgram::initSamplers(GrGLInstalledProc* ip, int* texUnitIdx) {
109 SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
110 int numSamplers = samplers.count();
111 for (int s = 0; s < numSamplers; ++s) {
112 SkASSERT(samplers[s].fUniform.isValid());
113 fProgramDataManager.setSampler(samplers[s].fUniform, *texUnitIdx);
114 samplers[s].fTextureUnit = (*texUnitIdx)++;
115 }
116}
117
118void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& processor) {
119 const SkTArray<GrGLInstalledProc::Sampler, true>& samplers = ip->fSamplers;
joshualitt47bb3822014-10-07 16:43:25 -0700120 int numSamplers = samplers.count();
121 SkASSERT(numSamplers == processor.numTextures());
122 for (int s = 0; s < numSamplers; ++s) {
123 SkASSERT(samplers[s].fTextureUnit >= 0);
124 const GrTextureAccess& textureAccess = processor.textureAccess(s);
125 fGpu->bindTexture(samplers[s].fTextureUnit,
126 textureAccess.getParams(),
127 static_cast<GrGLTexture*>(textureAccess.getTexture()));
128 }
129}
130
131
bsalomon@google.comeb715c82012-07-11 15:03:31 +0000132///////////////////////////////////////////////////////////////////////////////
junov@google.comf93e7172011-03-31 21:26:24 +0000133
joshualittdafa4d02014-12-04 08:59:10 -0800134void GrGLProgram::setData(const GrOptDrawState& optState) {
joshualittdafa4d02014-12-04 08:59:10 -0800135 this->setMatrixAndRenderTargetHeight(optState);
bsalomon@google.com91207482013-02-12 21:45:24 +0000136
joshualitt9176e2c2014-11-20 07:28:52 -0800137 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
bsalomon49f085d2014-09-05 13:34:00 -0700138 if (dstCopy) {
kkinnunendddc18a2014-08-03 23:19:46 -0700139 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
kkinnunen7510b222014-07-30 00:04:16 -0700141 static_cast<GrGLfloat>(dstCopy->offset().fX),
142 static_cast<GrGLfloat>(dstCopy->offset().fY));
kkinnunendddc18a2014-08-03 23:19:46 -0700143 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
kkinnunen7510b222014-07-30 00:04:16 -0700144 1.f / dstCopy->texture()->width(),
145 1.f / dstCopy->texture()->height());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000146 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture());
147 static GrTextureParams kParams; // the default is clamp, nearest filtering.
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000148 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000149 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700150 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
151 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000152 }
153 } else {
kkinnunendddc18a2014-08-03 23:19:46 -0700154 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
155 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
156 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000157 }
bsalomon@google.comc7818882013-03-20 19:19:53 +0000158
joshualitt47bb3822014-10-07 16:43:25 -0700159 // we set the textures, and uniforms for installed processors in a generic way, but subclasses
160 // of GLProgram determine how to set coord transforms
joshualitt9b989322014-12-15 14:16:27 -0800161 const GrPrimitiveProcessor& primProc = *optState.getPrimitiveProcessor();
162 const GrBatchTracker& bt = optState.getBatchTracker();
163 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, bt);
164 this->bindTextures(fGeometryProcessor, primProc);
165
egdanielc2304142014-12-11 13:15:13 -0800166 if (fXferProcessor.get()) {
167 const GrXferProcessor& xp = *optState.getXferProcessor();
168 fXferProcessor->fGLProc->setData(fProgramDataManager, xp);
169 this->bindTextures(fXferProcessor, xp);
170 }
joshualitta5305a12014-10-10 17:47:00 -0700171 this->setFragmentData(optState);
commit-bot@chromium.org20807222013-11-01 11:54:54 +0000172
joshualitt47bb3822014-10-07 16:43:25 -0700173 // Some of GrGLProgram subclasses need to update state here
joshualittdafa4d02014-12-04 08:59:10 -0800174 this->didSetData(optState.drawType());
joshualitt47bb3822014-10-07 16:43:25 -0700175}
176
joshualitta5305a12014-10-10 17:47:00 -0700177void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
178 int numProcessors = fFragmentProcessors->fProcs.count();
179 for (int e = 0; e < numProcessors; ++e) {
bsalomonae59b772014-11-19 08:23:49 -0800180 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
joshualitta5305a12014-10-10 17:47:00 -0700181 const GrProcessor& processor = *stage.getProcessor();
182 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
183 this->setTransformData(stage, fFragmentProcessors->fProcs[e]);
184 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
185 }
186}
bsalomonae59b772014-11-19 08:23:49 -0800187void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
188 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700189 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700190 int numTransforms = transforms.count();
191 SkASSERT(numTransforms == processor.getProcessor()->numTransforms());
192 for (int t = 0; t < numTransforms; ++t) {
193 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800194 const SkMatrix& matrix = get_transform_matrix(processor, t);
joshualitt47bb3822014-10-07 16:43:25 -0700195 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
196 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
197 transforms[t].fCurrentValue = matrix;
198 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000199 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000200}
bsalomon@google.com91207482013-02-12 21:45:24 +0000201
joshualitt47bb3822014-10-07 16:43:25 -0700202void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
203 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
204}
205
joshualittdafa4d02014-12-04 08:59:10 -0800206void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700207 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
208 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
209 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
210 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
211 SkIntToScalar(optState.getRenderTarget()->height()));
212 }
213
214 // call subclasses to set the actual view matrix
joshualittdafa4d02014-12-04 08:59:10 -0800215 this->onSetMatrixAndRenderTargetHeight(optState);
joshualitt47bb3822014-10-07 16:43:25 -0700216}
217
joshualittdafa4d02014-12-04 08:59:10 -0800218void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700219 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000220 SkISize size;
221 size.set(rt->width(), rt->height());
joshualitt47bb3822014-10-07 16:43:25 -0700222 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
223 fMatrixState.fRenderTargetSize != size ||
224 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700225 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000226
egdaniel170f90b2014-09-16 12:54:40 -0700227 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000228 fMatrixState.fRenderTargetSize = size;
229 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000230
231 GrGLfloat viewMatrix[3 * 3];
232 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700233 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000234
235 GrGLfloat rtAdjustmentVec[4];
236 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700237 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000238 }
239}
joshualitt47bb3822014-10-07 16:43:25 -0700240
241/////////////////////////////////////////////////////////////////////////////////////////
242
bsalomon861e1032014-12-16 07:33:49 -0800243GrGLNvprProgramBase::GrGLNvprProgramBase(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700244 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700245 const BuiltinUniformHandles& builtinUniforms,
246 GrGLuint programID,
247 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800248 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800249 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700250 GrGLInstalledFragProcs* fragmentProcessors)
joshualitt9b989322014-12-15 14:16:27 -0800251 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800252 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700253}
254
joshualittdafa4d02014-12-04 08:59:10 -0800255void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
256 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
joshualitt47bb3822014-10-07 16:43:25 -0700257 const GrRenderTarget* rt = optState.getRenderTarget();
258 SkISize size;
259 size.set(rt->width(), rt->height());
260 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
261}
262
263/////////////////////////////////////////////////////////////////////////////////////////
264
bsalomon861e1032014-12-16 07:33:49 -0800265GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700266 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700267 const BuiltinUniformHandles& builtinUniforms,
268 GrGLuint programID,
269 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800270 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800271 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700272 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700273 const SeparableVaryingInfoArray& separableVaryings)
joshualitt9b989322014-12-15 14:16:27 -0800274 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800275 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700276 int count = separableVaryings.count();
277 fVaryings.push_back_n(count);
278 for (int i = 0; i < count; i++) {
279 Varying& varying = fVaryings[i];
280 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
281 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
282 SkDEBUGCODE(
283 varying.fType = builderVarying.fVariable.getType();
284 );
285 varying.fLocation = builderVarying.fLocation;
286 }
287}
288
289void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
290 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
291}
292
bsalomonae59b772014-11-19 08:23:49 -0800293void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
294 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700295 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700296 int numTransforms = transforms.count();
joshualitta5305a12014-10-10 17:47:00 -0700297 SkASSERT(numTransforms == proc.getProcessor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700298 for (int t = 0; t < numTransforms; ++t) {
299 SkASSERT(transforms[t].fHandle.isValid());
joshualitt2dd1ae02014-12-03 06:24:10 -0800300 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700301 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
302 continue;
303 }
304 transforms[t].fCurrentValue = transform;
305 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
306 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
307 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
308 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
309 fragmentInput.fLocation,
310 GR_GL_OBJECT_LINEAR,
311 components,
312 transform);
313 }
314}
315
316//////////////////////////////////////////////////////////////////////////////////////
317
bsalomon861e1032014-12-16 07:33:49 -0800318GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700319 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700320 const BuiltinUniformHandles& builtinUniforms,
321 GrGLuint programID,
322 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800323 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800324 GrGLInstalledXferProc* xp,
joshualitta5305a12014-10-10 17:47:00 -0700325 GrGLInstalledFragProcs* fps,
326 int texCoordSetCnt)
joshualitt9b989322014-12-15 14:16:27 -0800327 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, xp, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700328 , fTexCoordSetCnt(texCoordSetCnt) {
329}
330
331void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
332 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
333 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
334}
335
joshualitta5305a12014-10-10 17:47:00 -0700336void
bsalomonae59b772014-11-19 08:23:49 -0800337GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
338 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700339 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700340 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
341 int numTransforms = proc.getProcessor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700342 for (int t = 0; t < numTransforms; ++t) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800343 const SkMatrix& transform = get_transform_matrix(proc, t);
joshualitt47bb3822014-10-07 16:43:25 -0700344 GrGLPathRendering::PathTexGenComponents components =
345 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800346 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700347 components = GrGLPathRendering::kSTR_PathTexGenComponents;
348 }
349 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
350 }
351}