blob: 9400e54b12c8a40a5082e0cb1616f8d717896a8f [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"
jvanverth39edf762014-12-22 11:44:19 -080016#include "GrGLGpu.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 */
joshualitt290c09b2014-12-19 13:45:20 -080030static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage,
31 int transformIdx,
32 const SkMatrix& localMatrix) {
joshualitt40d4bd82014-12-29 09:04:40 -080033 const GrCoordTransform& coordTransform = stage.processor()->coordTransform(transformIdx);
joshualitt47bb3822014-10-07 16:43:25 -070034 SkMatrix combined;
35
joshualitt40d4bd82014-12-29 09:04:40 -080036 // We only apply the localmatrix to localcoords
joshualitt47bb3822014-10-07 16:43:25 -070037 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) {
joshualitt40d4bd82014-12-29 09:04:40 -080038 combined.setConcat(coordTransform.getMatrix(), localMatrix);
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) {
joshualittee2af952014-12-30 09:04:15 -0800135 this->setRenderTargetState(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);
joshualitt40d4bd82014-12-29 09:04:40 -0800181 const GrProcessor& processor = *stage.processor();
joshualitta5305a12014-10-10 17:47:00 -0700182 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, processor);
joshualitt290c09b2014-12-19 13:45:20 -0800183 const SkMatrix& localMatrix = optState.getPrimitiveProcessor()->localMatrix();
184 this->setTransformData(stage, localMatrix, fFragmentProcessors->fProcs[e]);
joshualitta5305a12014-10-10 17:47:00 -0700185 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
186 }
187}
bsalomonae59b772014-11-19 08:23:49 -0800188void GrGLProgram::setTransformData(const GrPendingFragmentStage& processor,
joshualitt290c09b2014-12-19 13:45:20 -0800189 const SkMatrix& localMatrix,
bsalomonae59b772014-11-19 08:23:49 -0800190 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700191 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700192 int numTransforms = transforms.count();
joshualitt40d4bd82014-12-29 09:04:40 -0800193 SkASSERT(numTransforms == processor.processor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700194 for (int t = 0; t < numTransforms; ++t) {
195 SkASSERT(transforms[t].fHandle.isValid());
joshualitt290c09b2014-12-19 13:45:20 -0800196 const SkMatrix& matrix = get_transform_matrix(processor, t, localMatrix);
joshualitt47bb3822014-10-07 16:43:25 -0700197 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
198 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUniformHandle(), matrix);
199 transforms[t].fCurrentValue = matrix;
200 }
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000201 }
skia.committer@gmail.com8ae714b2013-01-05 02:02:05 +0000202}
bsalomon@google.com91207482013-02-12 21:45:24 +0000203
joshualitt47bb3822014-10-07 16:43:25 -0700204void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
205 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
206}
207
joshualittee2af952014-12-30 09:04:15 -0800208void GrGLProgram::setRenderTargetState(const GrOptDrawState& optState) {
joshualitt47bb3822014-10-07 16:43:25 -0700209 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
210 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
joshualittee2af952014-12-30 09:04:15 -0800211 fRenderTargetState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
joshualitt47bb3822014-10-07 16:43:25 -0700212 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
213 SkIntToScalar(optState.getRenderTarget()->height()));
214 }
215
216 // call subclasses to set the actual view matrix
joshualittee2af952014-12-30 09:04:15 -0800217 this->onSetRenderTargetState(optState);
joshualitt47bb3822014-10-07 16:43:25 -0700218}
219
joshualittee2af952014-12-30 09:04:15 -0800220void GrGLProgram::onSetRenderTargetState(const GrOptDrawState& optState) {
egdaniel170f90b2014-09-16 12:54:40 -0700221 const GrRenderTarget* rt = optState.getRenderTarget();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000222 SkISize size;
223 size.set(rt->width(), rt->height());
joshualittee2af952014-12-30 09:04:15 -0800224 if (fRenderTargetState.fRenderTargetOrigin != rt->origin() ||
225 fRenderTargetState.fRenderTargetSize != size) {
226 fRenderTargetState.fRenderTargetSize = size;
227 fRenderTargetState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000228
229 GrGLfloat rtAdjustmentVec[4];
joshualittee2af952014-12-30 09:04:15 -0800230 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700231 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000232 }
233}
joshualitt47bb3822014-10-07 16:43:25 -0700234
235/////////////////////////////////////////////////////////////////////////////////////////
236
bsalomon861e1032014-12-16 07:33:49 -0800237GrGLNvprProgramBase::GrGLNvprProgramBase(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700238 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700239 const BuiltinUniformHandles& builtinUniforms,
240 GrGLuint programID,
241 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800242 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800243 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700244 GrGLInstalledFragProcs* fragmentProcessors)
joshualitt9b989322014-12-15 14:16:27 -0800245 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800246 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700247}
248
joshualittee2af952014-12-30 09:04:15 -0800249void GrGLNvprProgramBase::onSetRenderTargetState(const GrOptDrawState& optState) {
joshualittdafa4d02014-12-04 08:59:10 -0800250 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
joshualitt47bb3822014-10-07 16:43:25 -0700251 const GrRenderTarget* rt = optState.getRenderTarget();
252 SkISize size;
253 size.set(rt->width(), rt->height());
joshualittee2af952014-12-30 09:04:15 -0800254 fGpu->glPathRendering()->setProjectionMatrix(optState.getPrimitiveProcessor()->viewMatrix(),
255 size, rt->origin());
joshualitt47bb3822014-10-07 16:43:25 -0700256}
257
258/////////////////////////////////////////////////////////////////////////////////////////
259
bsalomon861e1032014-12-16 07:33:49 -0800260GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700261 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700262 const BuiltinUniformHandles& builtinUniforms,
263 GrGLuint programID,
264 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800265 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800266 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700267 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700268 const SeparableVaryingInfoArray& separableVaryings)
joshualitt9b989322014-12-15 14:16:27 -0800269 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800270 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700271 int count = separableVaryings.count();
272 fVaryings.push_back_n(count);
273 for (int i = 0; i < count; i++) {
274 Varying& varying = fVaryings[i];
275 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
276 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
277 SkDEBUGCODE(
278 varying.fType = builderVarying.fVariable.getType();
279 );
280 varying.fLocation = builderVarying.fLocation;
281 }
282}
283
284void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
285 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
286}
287
bsalomonae59b772014-11-19 08:23:49 -0800288void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
joshualitt290c09b2014-12-19 13:45:20 -0800289 const SkMatrix& localMatrix,
bsalomonae59b772014-11-19 08:23:49 -0800290 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700291 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700292 int numTransforms = transforms.count();
joshualitt40d4bd82014-12-29 09:04:40 -0800293 SkASSERT(numTransforms == proc.processor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700294 for (int t = 0; t < numTransforms; ++t) {
295 SkASSERT(transforms[t].fHandle.isValid());
joshualitt290c09b2014-12-19 13:45:20 -0800296 const SkMatrix& transform = get_transform_matrix(proc, t, localMatrix);
joshualitt47bb3822014-10-07 16:43:25 -0700297 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
298 continue;
299 }
300 transforms[t].fCurrentValue = transform;
301 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
302 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
303 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
304 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
305 fragmentInput.fLocation,
306 GR_GL_OBJECT_LINEAR,
307 components,
308 transform);
309 }
310}
311
312//////////////////////////////////////////////////////////////////////////////////////
313
bsalomon861e1032014-12-16 07:33:49 -0800314GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700315 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700316 const BuiltinUniformHandles& builtinUniforms,
317 GrGLuint programID,
318 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800319 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800320 GrGLInstalledXferProc* xp,
joshualitta5305a12014-10-10 17:47:00 -0700321 GrGLInstalledFragProcs* fps,
322 int texCoordSetCnt)
joshualitt9b989322014-12-15 14:16:27 -0800323 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, xp, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700324 , fTexCoordSetCnt(texCoordSetCnt) {
325}
326
327void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
328 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
329 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
330}
331
joshualitta5305a12014-10-10 17:47:00 -0700332void
bsalomonae59b772014-11-19 08:23:49 -0800333GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
joshualitt290c09b2014-12-19 13:45:20 -0800334 const SkMatrix& localMatrix,
bsalomonae59b772014-11-19 08:23:49 -0800335 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700336 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700337 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
joshualitt40d4bd82014-12-29 09:04:40 -0800338 int numTransforms = proc.processor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700339 for (int t = 0; t < numTransforms; ++t) {
joshualitt290c09b2014-12-19 13:45:20 -0800340 const SkMatrix& transform = get_transform_matrix(proc, t, localMatrix);
joshualitt47bb3822014-10-07 16:43:25 -0700341 GrGLPathRendering::PathTexGenComponents components =
342 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800343 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700344 components = GrGLPathRendering::kSTR_PathTexGenComponents;
345 }
346 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
347 }
348}