blob: 60d97a296976985ff5149a2d01dffbca2df7a85e [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) {
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);
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
joshualittdafa4d02014-12-04 08:59:10 -0800208void GrGLProgram::setMatrixAndRenderTargetHeight(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() &&
211 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
212 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
213 SkIntToScalar(optState.getRenderTarget()->height()));
214 }
215
216 // call subclasses to set the actual view matrix
joshualittdafa4d02014-12-04 08:59:10 -0800217 this->onSetMatrixAndRenderTargetHeight(optState);
joshualitt47bb3822014-10-07 16:43:25 -0700218}
219
joshualittdafa4d02014-12-04 08:59:10 -0800220void GrGLProgram::onSetMatrixAndRenderTargetHeight(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());
joshualitt47bb3822014-10-07 16:43:25 -0700224 if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
225 fMatrixState.fRenderTargetSize != size ||
226 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) {
kkinnunendddc18a2014-08-03 23:19:46 -0700227 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000228
egdaniel170f90b2014-09-16 12:54:40 -0700229 fMatrixState.fViewMatrix = optState.getViewMatrix();
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000230 fMatrixState.fRenderTargetSize = size;
231 fMatrixState.fRenderTargetOrigin = rt->origin();
commit-bot@chromium.org215a6822013-09-05 18:28:42 +0000232
233 GrGLfloat viewMatrix[3 * 3];
234 fMatrixState.getGLMatrix<3>(viewMatrix);
kkinnunendddc18a2014-08-03 23:19:46 -0700235 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, viewMatrix);
commit-bot@chromium.org47c66dd2014-05-29 01:12:10 +0000236
237 GrGLfloat rtAdjustmentVec[4];
238 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
kkinnunendddc18a2014-08-03 23:19:46 -0700239 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000240 }
241}
joshualitt47bb3822014-10-07 16:43:25 -0700242
243/////////////////////////////////////////////////////////////////////////////////////////
244
bsalomon861e1032014-12-16 07:33:49 -0800245GrGLNvprProgramBase::GrGLNvprProgramBase(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700246 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700247 const BuiltinUniformHandles& builtinUniforms,
248 GrGLuint programID,
249 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800250 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800251 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700252 GrGLInstalledFragProcs* fragmentProcessors)
joshualitt9b989322014-12-15 14:16:27 -0800253 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800254 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700255}
256
joshualittdafa4d02014-12-04 08:59:10 -0800257void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
258 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
joshualitt47bb3822014-10-07 16:43:25 -0700259 const GrRenderTarget* rt = optState.getRenderTarget();
260 SkISize size;
261 size.set(rt->width(), rt->height());
262 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
263}
264
265/////////////////////////////////////////////////////////////////////////////////////////
266
bsalomon861e1032014-12-16 07:33:49 -0800267GrGLNvprProgram::GrGLNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700268 const GrProgramDesc& desc,
joshualitt47bb3822014-10-07 16:43:25 -0700269 const BuiltinUniformHandles& builtinUniforms,
270 GrGLuint programID,
271 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800272 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800273 GrGLInstalledXferProc* xferProcessor,
joshualitta5305a12014-10-10 17:47:00 -0700274 GrGLInstalledFragProcs* fragmentProcessors,
joshualitt47bb3822014-10-07 16:43:25 -0700275 const SeparableVaryingInfoArray& separableVaryings)
joshualitt9b989322014-12-15 14:16:27 -0800276 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
egdanielc2304142014-12-11 13:15:13 -0800277 xferProcessor, fragmentProcessors) {
joshualitt47bb3822014-10-07 16:43:25 -0700278 int count = separableVaryings.count();
279 fVaryings.push_back_n(count);
280 for (int i = 0; i < count; i++) {
281 Varying& varying = fVaryings[i];
282 const SeparableVaryingInfo& builderVarying = separableVaryings[i];
283 SkASSERT(GrGLShaderVar::kNonArray == builderVarying.fVariable.getArrayCount());
284 SkDEBUGCODE(
285 varying.fType = builderVarying.fVariable.getType();
286 );
287 varying.fLocation = builderVarying.fLocation;
288 }
289}
290
291void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
292 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
293}
294
bsalomonae59b772014-11-19 08:23:49 -0800295void GrGLNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
joshualitt290c09b2014-12-19 13:45:20 -0800296 const SkMatrix& localMatrix,
bsalomonae59b772014-11-19 08:23:49 -0800297 GrGLInstalledFragProc* ip) {
joshualitta5305a12014-10-10 17:47:00 -0700298 SkTArray<GrGLInstalledFragProc::Transform, true>& transforms = ip->fTransforms;
joshualitt47bb3822014-10-07 16:43:25 -0700299 int numTransforms = transforms.count();
joshualitt40d4bd82014-12-29 09:04:40 -0800300 SkASSERT(numTransforms == proc.processor()->numTransforms());
joshualitt47bb3822014-10-07 16:43:25 -0700301 for (int t = 0; t < numTransforms; ++t) {
302 SkASSERT(transforms[t].fHandle.isValid());
joshualitt290c09b2014-12-19 13:45:20 -0800303 const SkMatrix& transform = get_transform_matrix(proc, t, localMatrix);
joshualitt47bb3822014-10-07 16:43:25 -0700304 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) {
305 continue;
306 }
307 transforms[t].fCurrentValue = transform;
308 const Varying& fragmentInput = fVaryings[transforms[t].fHandle.handle()];
309 SkASSERT(transforms[t].fType == kVec2f_GrSLType || transforms[t].fType == kVec3f_GrSLType);
310 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3;
311 fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID,
312 fragmentInput.fLocation,
313 GR_GL_OBJECT_LINEAR,
314 components,
315 transform);
316 }
317}
318
319//////////////////////////////////////////////////////////////////////////////////////
320
bsalomon861e1032014-12-16 07:33:49 -0800321GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGLGpu* gpu,
joshualitt79f8fae2014-10-28 17:59:26 -0700322 const GrProgramDesc& desc,
joshualitta5305a12014-10-10 17:47:00 -0700323 const BuiltinUniformHandles& builtinUniforms,
324 GrGLuint programID,
325 const UniformInfoArray& uniforms,
joshualitt9b989322014-12-15 14:16:27 -0800326 GrGLInstalledGeoProc* primProc,
egdanielc2304142014-12-11 13:15:13 -0800327 GrGLInstalledXferProc* xp,
joshualitta5305a12014-10-10 17:47:00 -0700328 GrGLInstalledFragProcs* fps,
329 int texCoordSetCnt)
joshualitt9b989322014-12-15 14:16:27 -0800330 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, xp, fps)
joshualitt47bb3822014-10-07 16:43:25 -0700331 , fTexCoordSetCnt(texCoordSetCnt) {
332}
333
334void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) {
335 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
336 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
337}
338
joshualitta5305a12014-10-10 17:47:00 -0700339void
bsalomonae59b772014-11-19 08:23:49 -0800340GrGLLegacyNvprProgram::setTransformData(const GrPendingFragmentStage& proc,
joshualitt290c09b2014-12-19 13:45:20 -0800341 const SkMatrix& localMatrix,
bsalomonae59b772014-11-19 08:23:49 -0800342 GrGLInstalledFragProc* ip) {
joshualitt47bb3822014-10-07 16:43:25 -0700343 // We've hidden the texcoord index in the first entry of the transforms array for each effect
joshualitta5305a12014-10-10 17:47:00 -0700344 int texCoordIndex = ip->fTransforms[0].fHandle.handle();
joshualitt40d4bd82014-12-29 09:04:40 -0800345 int numTransforms = proc.processor()->numTransforms();
joshualitt47bb3822014-10-07 16:43:25 -0700346 for (int t = 0; t < numTransforms; ++t) {
joshualitt290c09b2014-12-19 13:45:20 -0800347 const SkMatrix& transform = get_transform_matrix(proc, t, localMatrix);
joshualitt47bb3822014-10-07 16:43:25 -0700348 GrGLPathRendering::PathTexGenComponents components =
349 GrGLPathRendering::kST_PathTexGenComponents;
bsalomonae59b772014-11-19 08:23:49 -0800350 if (proc.isPerspectiveCoordTransform(t)) {
joshualitt47bb3822014-10-07 16:43:25 -0700351 components = GrGLPathRendering::kSTR_PathTexGenComponents;
352 }
353 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, transform);
354 }
355}