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

Side by Side Diff: src/gpu/GrInOrderDrawBuffer.cpp

Issue 216503004: SK_SUPPORT_LEGACY_GRTYPES to hide duplicate types from SkTypes.h (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 "GrInOrderDrawBuffer.h" 8 #include "GrInOrderDrawBuffer.h"
9 9
10 #include "GrBufferAllocPool.h" 10 #include "GrBufferAllocPool.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 fDstGpu->unref(); 55 fDstGpu->unref();
56 } 56 }
57 57
58 //////////////////////////////////////////////////////////////////////////////// 58 ////////////////////////////////////////////////////////////////////////////////
59 59
60 namespace { 60 namespace {
61 void get_vertex_bounds(const void* vertices, 61 void get_vertex_bounds(const void* vertices,
62 size_t vertexSize, 62 size_t vertexSize,
63 int vertexCount, 63 int vertexCount,
64 SkRect* bounds) { 64 SkRect* bounds) {
65 SkASSERT(vertexSize >= sizeof(GrPoint)); 65 SkASSERT(vertexSize >= sizeof(SkPoint));
66 SkASSERT(vertexCount > 0); 66 SkASSERT(vertexCount > 0);
67 const GrPoint* point = static_cast<const GrPoint*>(vertices); 67 const SkPoint* point = static_cast<const SkPoint*>(vertices);
68 bounds->fLeft = bounds->fRight = point->fX; 68 bounds->fLeft = bounds->fRight = point->fX;
69 bounds->fTop = bounds->fBottom = point->fY; 69 bounds->fTop = bounds->fBottom = point->fY;
70 for (int i = 1; i < vertexCount; ++i) { 70 for (int i = 1; i < vertexCount; ++i) {
71 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + v ertexSize); 71 point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + v ertexSize);
72 bounds->growToInclude(point->fX, point->fY); 72 bounds->growToInclude(point->fX, point->fY);
73 } 73 }
74 } 74 }
75 } 75 }
76 76
77 77
78 namespace { 78 namespace {
79 79
80 extern const GrVertexAttrib kRectPosColorUVAttribs[] = { 80 extern const GrVertexAttrib kRectPosColorUVAttribs[] = {
81 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin g}, 81 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin g},
82 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding}, 82 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding},
83 {kVec2f_GrVertexAttribType, sizeof(GrPoint)+sizeof(GrColor), 83 {kVec2f_GrVertexAttribType, sizeof(SkPoint)+sizeof(GrColor),
84 kLocalCoord_GrVertexAttribBind ing}, 84 kLocalCoord_GrVertexAttribBind ing},
85 }; 85 };
86 86
87 extern const GrVertexAttrib kRectPosUVAttribs[] = { 87 extern const GrVertexAttrib kRectPosUVAttribs[] = {
88 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, 88 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
89 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBindi ng}, 89 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBindi ng},
90 }; 90 };
91 91
92 static void set_vertex_attributes(GrDrawState* drawState, 92 static void set_vertex_attributes(GrDrawState* drawState,
93 bool hasColor, bool hasUVs, 93 bool hasColor, bool hasUVs,
94 int* colorOffset, int* localOffset) { 94 int* colorOffset, int* localOffset) {
95 *colorOffset = -1; 95 *colorOffset = -1;
96 *localOffset = -1; 96 *localOffset = -1;
97 97
98 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing 98 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
99 // only in color is a common occurrence in tables). However, having per-vert ex colors disables 99 // only in color is a common occurrence in tables). However, having per-vert ex colors disables
100 // blending optimizations because we don't know if the color will be solid o r not. These 100 // blending optimizations because we don't know if the color will be solid o r not. These
101 // optimizations help determine whether coverage and color can be blended co rrectly when 101 // optimizations help determine whether coverage and color can be blended co rrectly when
102 // dual-source blending isn't available. This comes into play when there is coverage. If colors 102 // dual-source blending isn't available. This comes into play when there is coverage. If colors
103 // were a stage it could take a hint that every vertex's color will be opaqu e. 103 // were a stage it could take a hint that every vertex's color will be opaqu e.
104 if (hasColor && hasUVs) { 104 if (hasColor && hasUVs) {
105 *colorOffset = sizeof(GrPoint); 105 *colorOffset = sizeof(SkPoint);
106 *localOffset = sizeof(GrPoint) + sizeof(GrColor); 106 *localOffset = sizeof(SkPoint) + sizeof(GrColor);
107 drawState->setVertexAttribs<kRectPosColorUVAttribs>(3); 107 drawState->setVertexAttribs<kRectPosColorUVAttribs>(3);
108 } else if (hasColor) { 108 } else if (hasColor) {
109 *colorOffset = sizeof(GrPoint); 109 *colorOffset = sizeof(SkPoint);
110 drawState->setVertexAttribs<kRectPosColorUVAttribs>(2); 110 drawState->setVertexAttribs<kRectPosColorUVAttribs>(2);
111 } else if (hasUVs) { 111 } else if (hasUVs) {
112 *localOffset = sizeof(GrPoint); 112 *localOffset = sizeof(SkPoint);
113 drawState->setVertexAttribs<kRectPosUVAttribs>(2); 113 drawState->setVertexAttribs<kRectPosUVAttribs>(2);
114 } else { 114 } else {
115 drawState->setVertexAttribs<kRectPosUVAttribs>(1); 115 drawState->setVertexAttribs<kRectPosUVAttribs>(1);
116 } 116 }
117 } 117 }
118 118
119 }; 119 };
120 120
121 enum { 121 enum {
122 kTraceCmdBit = 0x80, 122 kTraceCmdBit = 0x80,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vsize); 186 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vsize);
187 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4); 187 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
188 188
189 SkRect devBounds; 189 SkRect devBounds;
190 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid 190 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid
191 // unnecessary clipping in our onDraw(). 191 // unnecessary clipping in our onDraw().
192 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); 192 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
193 193
194 if (localOffset >= 0) { 194 if (localOffset >= 0) {
195 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset); 195 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
196 coords->setRectFan(localRect->fLeft, localRect->fTop, 196 coords->setRectFan(localRect->fLeft, localRect->fTop,
197 localRect->fRight, localRect->fBottom, 197 localRect->fRight, localRect->fBottom,
198 vsize); 198 vsize);
199 if (NULL != localMatrix) { 199 if (NULL != localMatrix) {
200 localMatrix->mapPointsWithStride(coords, vsize, 4); 200 localMatrix->mapPointsWithStride(coords, vsize, 4);
201 } 201 }
202 } 202 }
203 203
204 if (colorOffset >= 0) { 204 if (colorOffset >= 0) {
205 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset); 205 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex(); 293 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
294 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) { 294 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
295 return 0; 295 return 0;
296 } 296 }
297 297
298 SkASSERT(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCou nt()); 298 SkASSERT(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCou nt());
299 299
300 // how many instances can be concat'ed onto draw given the size of the index buffer 300 // how many instances can be concat'ed onto draw given the size of the index buffer
301 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance(); 301 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance();
302 instancesToConcat -= draw->instanceCount(); 302 instancesToConcat -= draw->instanceCount();
303 instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); 303 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount());
304 304
305 // update the amount of reserved vertex data actually referenced in draws 305 // update the amount of reserved vertex data actually referenced in draws
306 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * 306 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
307 drawState.getVertexSize(); 307 drawState.getVertexSize();
308 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, verte xBytes); 308 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vert exBytes);
309 309
310 draw->adjustInstanceCount(instancesToConcat); 310 draw->adjustInstanceCount(instancesToConcat);
311 311
312 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added 312 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added
313 if (this->getActiveTraceMarkers().count() > 0) { 313 if (this->getActiveTraceMarkers().count() > 0) {
314 if (cmd_has_trace_marker(fCmds.back())) { 314 if (cmd_has_trace_marker(fCmds.back())) {
315 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); 315 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers());
316 } else { 316 } else {
317 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); 317 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers());
318 fCmds.back() = add_trace_bit(fCmds.back()); 318 fCmds.back() = add_trace_bit(fCmds.back());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 373 }
374 374
375 switch (this->getGeomSrc().fVertexSrc) { 375 switch (this->getGeomSrc().fVertexSrc) {
376 case kBuffer_GeometrySrcType: 376 case kBuffer_GeometrySrcType:
377 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; 377 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
378 break; 378 break;
379 case kReserved_GeometrySrcType: // fallthrough 379 case kReserved_GeometrySrcType: // fallthrough
380 case kArray_GeometrySrcType: { 380 case kArray_GeometrySrcType: {
381 size_t vertexBytes = (info.vertexCount() + info.startVertex()) * 381 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
382 drawState.getVertexSize(); 382 drawState.getVertexSize();
383 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexByte s, vertexBytes); 383 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexByt es, vertexBytes);
384 draw->fVertexBuffer = poolState.fPoolVertexBuffer; 384 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
385 draw->adjustStartVertex(poolState.fPoolStartVertex); 385 draw->adjustStartVertex(poolState.fPoolStartVertex);
386 break; 386 break;
387 } 387 }
388 default: 388 default:
389 GrCrash("unknown geom src type"); 389 GrCrash("unknown geom src type");
390 } 390 }
391 draw->fVertexBuffer->ref(); 391 draw->fVertexBuffer->ref();
392 392
393 if (info.isIndexed()) { 393 if (info.isIndexed()) {
394 switch (this->getGeomSrc().fIndexSrc) { 394 switch (this->getGeomSrc().fIndexSrc) {
395 case kBuffer_GeometrySrcType: 395 case kBuffer_GeometrySrcType:
396 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer; 396 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
397 break; 397 break;
398 case kReserved_GeometrySrcType: // fallthrough 398 case kReserved_GeometrySrcType: // fallthrough
399 case kArray_GeometrySrcType: { 399 case kArray_GeometrySrcType: {
400 size_t indexBytes = (info.indexCount() + info.startIndex()) * si zeof(uint16_t); 400 size_t indexBytes = (info.indexCount() + info.startIndex()) * si zeof(uint16_t);
401 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBy tes, indexBytes); 401 poolState.fUsedPoolIndexBytes = SkTMax(poolState.fUsedPoolIndexB ytes, indexBytes);
402 draw->fIndexBuffer = poolState.fPoolIndexBuffer; 402 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
403 draw->adjustStartIndex(poolState.fPoolStartIndex); 403 draw->adjustStartIndex(poolState.fPoolStartIndex);
404 break; 404 break;
405 } 405 }
406 default: 406 default:
407 GrCrash("unknown geom src type"); 407 GrCrash("unknown geom src type");
408 } 408 }
409 draw->fIndexBuffer->ref(); 409 draw->fIndexBuffer->ref();
410 } else { 410 } else {
411 draw->fIndexBuffer = NULL; 411 draw->fIndexBuffer = NULL;
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 this->addToCmdBuffer(kCopySurface_Cmd); 963 this->addToCmdBuffer(kCopySurface_Cmd);
964 return &fCopySurfaces.push_back(); 964 return &fCopySurfaces.push_back();
965 } 965 }
966 966
967 967
968 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { 968 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
969 INHERITED::clipWillBeSet(newClipData); 969 INHERITED::clipWillBeSet(newClipData);
970 fClipSet = true; 970 fClipSet = true;
971 fClipProxyState = kUnknown_ClipProxyState; 971 fClipProxyState = kUnknown_ClipProxyState;
972 } 972 }
OLDNEW
« include/gpu/GrPoint.h ('K') | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrMemoryPool.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698