Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/gpu/gl/GrGLProgram.cpp

Issue 815643005: Move program descriptor and primitive processor off of optstate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: bug fix Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const GrTextureAccess& textureAccess = processor.textureAccess(s); 96 const GrTextureAccess& textureAccess = processor.textureAccess(s);
97 fGpu->bindTexture(samplers[s].fTextureUnit, 97 fGpu->bindTexture(samplers[s].fTextureUnit,
98 textureAccess.getParams(), 98 textureAccess.getParams(),
99 static_cast<GrGLTexture*>(textureAccess.getTexture())) ; 99 static_cast<GrGLTexture*>(textureAccess.getTexture())) ;
100 } 100 }
101 } 101 }
102 102
103 103
104 /////////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////////
105 105
106 void GrGLProgram::setData(const GrOptDrawState& optState) { 106 void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrOptDrawS tate& optState,
107 this->setRenderTargetState(optState); 107 const GrBatchTracker& batchTracker) {
108 this->setRenderTargetState(primProc, optState);
108 109
109 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); 110 const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
110 if (dstCopy) { 111 if (dstCopy) {
111 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { 112 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
112 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, 113 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
113 static_cast<GrGLfloat>(dstCopy->offset(). fX), 114 static_cast<GrGLfloat>(dstCopy->offset(). fX),
114 static_cast<GrGLfloat>(dstCopy->offset(). fY)); 115 static_cast<GrGLfloat>(dstCopy->offset(). fY));
115 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, 116 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
116 1.f / dstCopy->texture()->width(), 117 1.f / dstCopy->texture()->width(),
117 1.f / dstCopy->texture()->height()); 118 1.f / dstCopy->texture()->height());
118 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; 119 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ;
119 static GrTextureParams kParams; // the default is clamp, nearest fil tering. 120 static GrTextureParams kParams; // the default is clamp, nearest fil tering.
120 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); 121 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
121 } else { 122 } else {
122 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); 123 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
123 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); 124 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
124 } 125 }
125 } else { 126 } else {
126 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); 127 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
127 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); 128 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
128 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); 129 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
129 } 130 }
130 131
131 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses 132 // we set the textures, and uniforms for installed processors in a generic w ay, but subclasses
132 // of GLProgram determine how to set coord transforms 133 // of GLProgram determine how to set coord transforms
133 const GrPrimitiveProcessor& primProc = *optState.getPrimitiveProcessor(); 134 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, batchTra cker);
134 const GrBatchTracker& bt = optState.getBatchTracker();
135 fGeometryProcessor->fGLProc->setData(fProgramDataManager, primProc, bt);
136 this->bindTextures(fGeometryProcessor.get(), primProc); 135 this->bindTextures(fGeometryProcessor.get(), primProc);
137 136
138 if (fXferProcessor.get()) { 137 if (fXferProcessor.get()) {
139 const GrXferProcessor& xp = *optState.getXferProcessor(); 138 const GrXferProcessor& xp = *optState.getXferProcessor();
140 fXferProcessor->fGLProc->setData(fProgramDataManager, xp); 139 fXferProcessor->fGLProc->setData(fProgramDataManager, xp);
141 this->bindTextures(fXferProcessor.get(), xp); 140 this->bindTextures(fXferProcessor.get(), xp);
142 } 141 }
143 this->setFragmentData(optState); 142 this->setFragmentData(primProc, optState);
144 143
145 // Some of GrGLProgram subclasses need to update state here 144 // Some of GrGLProgram subclasses need to update state here
146 this->didSetData(optState.drawType()); 145 this->didSetData(optState.drawType());
147 } 146 }
148 147
149 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { 148 void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc,
149 const GrOptDrawState& optState) {
150 int numProcessors = fFragmentProcessors->fProcs.count(); 150 int numProcessors = fFragmentProcessors->fProcs.count();
151 for (int e = 0; e < numProcessors; ++e) { 151 for (int e = 0; e < numProcessors; ++e) {
152 const GrPendingFragmentStage& stage = optState.getFragmentStage(e); 152 const GrPendingFragmentStage& stage = optState.getFragmentStage(e);
153 const GrProcessor& processor = *stage.processor(); 153 const GrProcessor& processor = *stage.processor();
154 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr ocessor); 154 fFragmentProcessors->fProcs[e]->fGLProc->setData(fProgramDataManager, pr ocessor);
155 this->setTransformData(optState.getPrimitiveProcessor(), 155 this->setTransformData(primProc,
156 stage, 156 stage,
157 e, 157 e,
158 fFragmentProcessors->fProcs[e]); 158 fFragmentProcessors->fProcs[e]);
159 this->bindTextures(fFragmentProcessors->fProcs[e], processor); 159 this->bindTextures(fFragmentProcessors->fProcs[e], processor);
160 } 160 }
161 } 161 }
162 void GrGLProgram::setTransformData(const GrPrimitiveProcessor* primProc, 162 void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc,
163 const GrPendingFragmentStage& processor, 163 const GrPendingFragmentStage& processor,
164 int index, 164 int index,
165 GrGLInstalledFragProc* ip) { 165 GrGLInstalledFragProc* ip) {
166 GrGLGeometryProcessor* gp = 166 GrGLGeometryProcessor* gp =
167 static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLPro c.get()); 167 static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLPro c.get());
168 gp->setTransformData(primProc, fProgramDataManager, index, 168 gp->setTransformData(primProc, fProgramDataManager, index,
169 processor.processor()->coordTransforms()); 169 processor.processor()->coordTransforms());
170 } 170 }
171 171
172 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { 172 void GrGLProgram::didSetData(GrGpu::DrawType drawType) {
173 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); 173 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType));
174 } 174 }
175 175
176 void GrGLProgram::setRenderTargetState(const GrOptDrawState& optState) { 176 void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc,
177 const GrOptDrawState& optState) {
177 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 178 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
178 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && 179 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
179 fRenderTargetState.fRenderTargetSize.fHeight != optState.getRenderTarget ()->height()) { 180 fRenderTargetState.fRenderTargetSize.fHeight != optState.getRenderTarget ()->height()) {
180 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, 181 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
181 SkIntToScalar(optState.getRenderTarget()->hei ght())); 182 SkIntToScalar(optState.getRenderTarget()->hei ght()));
182 } 183 }
183 184
184 // call subclasses to set the actual view matrix 185 // call subclasses to set the actual view matrix
185 this->onSetRenderTargetState(optState); 186 this->onSetRenderTargetState(primProc, optState);
186 } 187 }
187 188
188 void GrGLProgram::onSetRenderTargetState(const GrOptDrawState& optState) { 189 void GrGLProgram::onSetRenderTargetState(const GrPrimitiveProcessor&,
190 const GrOptDrawState& optState) {
189 const GrRenderTarget* rt = optState.getRenderTarget(); 191 const GrRenderTarget* rt = optState.getRenderTarget();
190 SkISize size; 192 SkISize size;
191 size.set(rt->width(), rt->height()); 193 size.set(rt->width(), rt->height());
192 if (fRenderTargetState.fRenderTargetOrigin != rt->origin() || 194 if (fRenderTargetState.fRenderTargetOrigin != rt->origin() ||
193 fRenderTargetState.fRenderTargetSize != size) { 195 fRenderTargetState.fRenderTargetSize != size) {
194 fRenderTargetState.fRenderTargetSize = size; 196 fRenderTargetState.fRenderTargetSize = size;
195 fRenderTargetState.fRenderTargetOrigin = rt->origin(); 197 fRenderTargetState.fRenderTargetOrigin = rt->origin();
196 198
197 GrGLfloat rtAdjustmentVec[4]; 199 GrGLfloat rtAdjustmentVec[4];
198 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); 200 fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec);
(...skipping 14 matching lines...) Expand all
213 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, 215 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc,
214 xferProcessor, fragmentProcessors) { 216 xferProcessor, fragmentProcessors) {
215 } 217 }
216 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) { 218 void GrGLNvprProgram::didSetData(GrGpu::DrawType drawType) {
217 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); 219 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
218 GrGLPathProcessor* pathProc = 220 GrGLPathProcessor* pathProc =
219 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t()); 221 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t());
220 pathProc->didSetData(fGpu->glPathRendering()); 222 pathProc->didSetData(fGpu->glPathRendering());
221 } 223 }
222 224
223 void GrGLNvprProgram::setTransformData(const GrPrimitiveProcessor* primProc, 225 void GrGLNvprProgram::setTransformData(const GrPrimitiveProcessor& primProc,
224 const GrPendingFragmentStage& proc, 226 const GrPendingFragmentStage& proc,
225 int index, 227 int index,
226 GrGLInstalledFragProc* ip) { 228 GrGLInstalledFragProc* ip) {
227 GrGLPathProcessor* pathProc = 229 GrGLPathProcessor* pathProc =
228 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t()); 230 static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.ge t());
229 pathProc->setTransformData(primProc, index, proc.processor()->coordTransform s(), 231 pathProc->setTransformData(primProc, index, proc.processor()->coordTransform s(),
230 fGpu->glPathRendering(), fProgramID); 232 fGpu->glPathRendering(), fProgramID);
231 } 233 }
232 234
233 void GrGLNvprProgram::onSetRenderTargetState(const GrOptDrawState& optState) { 235 void GrGLNvprProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primPro c,
236 const GrOptDrawState& optState) {
234 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()) && 237 SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()) &&
235 !optState.getPrimitiveProcessor()->willUseGeoShader() && 238 !primProc.willUseGeoShader() && primProc.numAttribs() == 0);
236 optState.getPrimitiveProcessor()->numAttribs() == 0);
237 const GrRenderTarget* rt = optState.getRenderTarget(); 239 const GrRenderTarget* rt = optState.getRenderTarget();
238 SkISize size; 240 SkISize size;
239 size.set(rt->width(), rt->height()); 241 size.set(rt->width(), rt->height());
240 fGpu->glPathRendering()->setProjectionMatrix(optState.getPrimitiveProcessor( )->viewMatrix(), 242 fGpu->glPathRendering()->setProjectionMatrix(primProc.viewMatrix(),
241 size, rt->origin()); 243 size, rt->origin());
242 } 244 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698