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

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

Issue 709133003: Snap optdrawstate in inorder draw buffer and pass into gpu (Closed) Base URL: https://skia.googlesource.com/skia.git@remove_friends
Patch Set: Created 6 years, 1 month 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/GrGpuGL.cpp ('k') | no next file » | 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 "GrGpuGL.h" 8 #include "GrGpuGL.h"
9 9
10 #include "builders/GrGLProgramBuilder.h" 10 #include "builders/GrGLProgramBuilder.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 194 }
195 } 195 }
196 ++fCurrLRUStamp; 196 ++fCurrLRUStamp;
197 return entry->fProgram; 197 return entry->fProgram;
198 } 198 }
199 199
200 //////////////////////////////////////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////////////////
201 201
202 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) 202 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
203 203
204 bool GrGpuGL::flushGraphicsState(DrawType type, 204 bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState,
205 DrawType type,
205 const GrClipMaskManager::ScissorState& scissorS tate, 206 const GrClipMaskManager::ScissorState& scissorS tate,
206 const GrDeviceCoordTexture* dstCopy) { 207 const GrDeviceCoordTexture* dstCopy) {
207 SkAutoTUnref<GrOptDrawState> optState(GrOptDrawState::Create(this->getDrawSt ate(),
208 this,
209 dstCopy,
210 type));
211
212 if (!optState) {
213 return false;
214 }
215
216 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. 208 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
217 SkASSERT(optState->getRenderTarget()); 209 SkASSERT(optState.getRenderTarget());
218 210
219 if (kStencilPath_DrawType == type) { 211 if (kStencilPath_DrawType == type) {
220 const GrRenderTarget* rt = optState->getRenderTarget(); 212 const GrRenderTarget* rt = optState.getRenderTarget();
221 SkISize size; 213 SkISize size;
222 size.set(rt->width(), rt->height()); 214 size.set(rt->width(), rt->height());
223 this->glPathRendering()->setProjectionMatrix(optState->getViewMatrix(), size, rt->origin()); 215 this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s ize, rt->origin());
224 } else { 216 } else {
225 this->flushMiscFixedFunctionState(*optState.get()); 217 this->flushMiscFixedFunctionState(optState);
226 218
227 GrBlendCoeff srcCoeff = optState->getSrcBlendCoeff(); 219 GrBlendCoeff srcCoeff = optState.getSrcBlendCoeff();
228 GrBlendCoeff dstCoeff = optState->getDstBlendCoeff(); 220 GrBlendCoeff dstCoeff = optState.getDstBlendCoeff();
229 221
230 // In these blend coeff's we end up drawing nothing so we can skip draw all together 222 // In these blend coeff's we end up drawing nothing so we can skip draw all together
231 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && 223 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
232 !optState->getStencil().doesWrite()) { 224 !optState.getStencil().doesWrite()) {
233 return false; 225 return false;
234 } 226 }
235 227
236 fCurrentProgram.reset(fProgramCache->getProgram(*optState.get(), type)); 228 fCurrentProgram.reset(fProgramCache->getProgram(optState, type));
237 if (NULL == fCurrentProgram.get()) { 229 if (NULL == fCurrentProgram.get()) {
238 SkDEBUGFAIL("Failed to create program!"); 230 SkDEBUGFAIL("Failed to create program!");
239 return false; 231 return false;
240 } 232 }
241 233
242 fCurrentProgram.get()->ref(); 234 fCurrentProgram.get()->ref();
243 235
244 GrGLuint programID = fCurrentProgram->programID(); 236 GrGLuint programID = fCurrentProgram->programID();
245 if (fHWProgramID != programID) { 237 if (fHWProgramID != programID) {
246 GL_CALL(UseProgram(programID)); 238 GL_CALL(UseProgram(programID));
247 fHWProgramID = programID; 239 fHWProgramID = programID;
248 } 240 }
249 241
250 this->flushBlend(*optState.get(), kDrawLines_DrawType == type, srcCoeff, dstCoeff); 242 this->flushBlend(optState, kDrawLines_DrawType == type, srcCoeff, dstCoe ff);
251 243
252 fCurrentProgram->setData(*optState.get(), type, dstCopy); 244 fCurrentProgram->setData(optState, type, dstCopy);
253 } 245 }
254 246
255 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState->getRenderT arget()); 247 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTa rget());
256 this->flushStencil(optState->getStencil(), type); 248 this->flushStencil(optState.getStencil(), type);
257 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); 249 this->flushScissor(scissorState, glRT->getViewport(), glRT->origin());
258 this->flushAAState(*optState.get(), type); 250 this->flushAAState(optState, type);
259 251
260 // This must come after textures are flushed because a texture may need 252 // This must come after textures are flushed because a texture may need
261 // to be msaa-resolved (which will modify bound FBO state). 253 // to be msaa-resolved (which will modify bound FBO state).
262 this->flushRenderTarget(glRT, NULL); 254 this->flushRenderTarget(glRT, NULL);
263 255
264 return true; 256 return true;
265 } 257 }
266 258
267 void GrGpuGL::setupGeometry(const GrDrawTarget::DrawInfo& info, size_t* indexOff setInBytes) { 259 void GrGpuGL::setupGeometry(const GrOptDrawState& optState,
268 SkAutoTUnref<GrOptDrawState> optState( 260 const GrDrawTarget::DrawInfo& info,
269 GrOptDrawState::Create(this->getDrawState(), this, info.getDstCopy(), 261 size_t* indexOffsetInBytes) {
270 PrimTypeToDrawType(info.primitiveType()))); 262 GrGLsizei stride = static_cast<GrGLsizei>(optState.getVertexStride());
271
272 // If the optState would is NULL it should have been caught in flushGraphics State before getting
273 // here.
274 SkASSERT(optState);
275
276 GrGLsizei stride = static_cast<GrGLsizei>(optState->getVertexStride());
277 263
278 size_t vertexOffsetInBytes = stride * info.startVertex(); 264 size_t vertexOffsetInBytes = stride * info.startVertex();
279 265
280 GrGLVertexBuffer* vbuf; 266 GrGLVertexBuffer* vbuf;
281 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer; 267 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
282 268
283 SkASSERT(vbuf); 269 SkASSERT(vbuf);
284 SkASSERT(!vbuf->isMapped()); 270 SkASSERT(!vbuf->isMapped());
285 vertexOffsetInBytes += vbuf->baseOffset(); 271 vertexOffsetInBytes += vbuf->baseOffset();
286 272
287 GrGLIndexBuffer* ibuf = NULL; 273 GrGLIndexBuffer* ibuf = NULL;
288 if (info.isIndexed()) { 274 if (info.isIndexed()) {
289 SkASSERT(indexOffsetInBytes); 275 SkASSERT(indexOffsetInBytes);
290 276
291 *indexOffsetInBytes = 0; 277 *indexOffsetInBytes = 0;
292 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer; 278 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
293 279
294 SkASSERT(ibuf); 280 SkASSERT(ibuf);
295 SkASSERT(!ibuf->isMapped()); 281 SkASSERT(!ibuf->isMapped());
296 *indexOffsetInBytes += ibuf->baseOffset(); 282 *indexOffsetInBytes += ibuf->baseOffset();
297 } 283 }
298 GrGLAttribArrayState* attribState = 284 GrGLAttribArrayState* attribState =
299 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); 285 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
300 286
301 if (fCurrentProgram->hasVertexShader()) { 287 if (fCurrentProgram->hasVertexShader()) {
302 int vertexAttribCount = optState->getVertexAttribCount(); 288 int vertexAttribCount = optState.getVertexAttribCount();
303 uint32_t usedAttribArraysMask = 0; 289 uint32_t usedAttribArraysMask = 0;
304 const GrVertexAttrib* vertexAttrib = optState->getVertexAttribs(); 290 const GrVertexAttrib* vertexAttrib = optState.getVertexAttribs();
305 291
306 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount; 292 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
307 ++vertexAttribIndex, ++vertexAttrib) { 293 ++vertexAttribIndex, ++vertexAttrib) {
308 usedAttribArraysMask |= (1 << vertexAttribIndex); 294 usedAttribArraysMask |= (1 << vertexAttribIndex);
309 GrVertexAttribType attribType = vertexAttrib->fType; 295 GrVertexAttribType attribType = vertexAttrib->fType;
310 attribState->set(this, 296 attribState->set(this,
311 vertexAttribIndex, 297 vertexAttribIndex,
312 vbuf, 298 vbuf,
313 GrGLAttribTypeToLayout(attribType).fCount, 299 GrGLAttribTypeToLayout(attribType).fCount,
314 GrGLAttribTypeToLayout(attribType).fType, 300 GrGLAttribTypeToLayout(attribType).fType,
315 GrGLAttribTypeToLayout(attribType).fNormalized, 301 GrGLAttribTypeToLayout(attribType).fNormalized,
316 stride, 302 stride,
317 reinterpret_cast<GrGLvoid*>( 303 reinterpret_cast<GrGLvoid*>(
318 vertexOffsetInBytes + vertexAttrib->fOffset)); 304 vertexOffsetInBytes + vertexAttrib->fOffset));
319 } 305 }
320 attribState->disableUnusedArrays(this, usedAttribArraysMask); 306 attribState->disableUnusedArrays(this, usedAttribArraysMask);
321 } 307 }
322 } 308 }
323 309
324 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState, 310 void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState,
325 const GrProgramDesc::DescInfo& descInfo, 311 const GrProgramDesc::DescInfo& descInfo,
326 GrGpu::DrawType drawType, 312 GrGpu::DrawType drawType,
327 const GrDeviceCoordTexture* dstCopy, 313 const GrDeviceCoordTexture* dstCopy,
328 GrProgramDesc* desc) { 314 GrProgramDesc* desc) {
329 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, dstCo py, desc)) { 315 if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, dstCo py, desc)) {
330 SkDEBUGFAIL("Failed to generate GL program descriptor"); 316 SkDEBUGFAIL("Failed to generate GL program descriptor");
331 } 317 }
332 } 318 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGpuGL.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698