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

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

Issue 511593004: Make setVertexAttribs in GrDrawState take a stride parameter. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Release Fix Created 6 years, 3 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/GrDrawTarget.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('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 "GrInOrderDrawBuffer.h" 8 #include "GrInOrderDrawBuffer.h"
9 9
10 #include "GrBufferAllocPool.h" 10 #include "GrBufferAllocPool.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we 90 and just duplicate the positions when the caller hasn't provided a local coo rd rect, but we
91 haven't seen a use case which frequently switches between local rect and no local rect draws. 91 haven't seen a use case which frequently switches between local rect and no local rect draws.
92 92
93 The color param is used to determine whether the opaque hint can be set on t he draw state. 93 The color param is used to determine whether the opaque hint can be set on t he draw state.
94 The caller must populate the vertex colors itself. 94 The caller must populate the vertex colors itself.
95 95
96 The vertex attrib order is always pos, color, [local coords]. 96 The vertex attrib order is always pos, color, [local coords].
97 */ 97 */
98 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G rColor color) { 98 static void set_vertex_attributes(GrDrawState* drawState, bool hasLocalCoords, G rColor color) {
99 if (hasLocalCoords) { 99 if (hasLocalCoords) {
100 drawState->setVertexAttribs<kRectAttribs>(3); 100 drawState->setVertexAttribs<kRectAttribs>(3, 2 * sizeof(SkPoint) + sizeo f(SkColor));
101 } else { 101 } else {
102 drawState->setVertexAttribs<kRectAttribs>(2); 102 drawState->setVertexAttribs<kRectAttribs>(2, sizeof(SkPoint) + sizeof(Sk Color));
103 } 103 }
104 if (0xFF == GrColorUnpackA(color)) { 104 if (0xFF == GrColorUnpackA(color)) {
105 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); 105 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
106 } 106 }
107 } 107 }
108 108
109 enum { 109 enum {
110 kTraceCmdBit = 0x80, 110 kTraceCmdBit = 0x80,
111 kCmdMask = 0x7f, 111 kCmdMask = 0x7f,
112 }; 112 };
(...skipping 23 matching lines...) Expand all
136 SkMatrix matrix = drawState->getViewMatrix(); 136 SkMatrix matrix = drawState->getViewMatrix();
137 137
138 // When the caller has provided an explicit source rect for a stage then we don't want to 138 // When the caller has provided an explicit source rect for a stage then we don't want to
139 // modify that stage's matrix. Otherwise if the effect is generating its sou rce rect from 139 // modify that stage's matrix. Otherwise if the effect is generating its sou rce rect from
140 // the vertex positions then we have to account for the view matrix change. 140 // the vertex positions then we have to account for the view matrix change.
141 GrDrawState::AutoViewMatrixRestore avmr; 141 GrDrawState::AutoViewMatrixRestore avmr;
142 if (!avmr.setIdentity(drawState)) { 142 if (!avmr.setIdentity(drawState)) {
143 return; 143 return;
144 } 144 }
145 145
146 size_t vsize = drawState->getVertexSize(); 146 size_t vstride = drawState->getVertexStride();
147 147
148 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vsize); 148 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom , vstride);
149 matrix.mapPointsWithStride(geo.positions(), vsize, 4); 149 matrix.mapPointsWithStride(geo.positions(), vstride, 4);
150 150
151 SkRect devBounds; 151 SkRect devBounds;
152 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid 152 // since we already computed the dev verts, set the bounds hint. This will h elp us avoid
153 // unnecessary clipping in our onDraw(). 153 // unnecessary clipping in our onDraw().
154 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); 154 get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds);
155 155
156 if (NULL != localRect) { 156 if (NULL != localRect) {
157 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); 157 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
158 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + kLocalOffset); 158 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + kLocalOffset);
159 coords->setRectFan(localRect->fLeft, localRect->fTop, 159 coords->setRectFan(localRect->fLeft, localRect->fTop,
160 localRect->fRight, localRect->fBottom, 160 localRect->fRight, localRect->fBottom,
161 vsize); 161 vstride);
162 if (NULL != localMatrix) { 162 if (NULL != localMatrix) {
163 localMatrix->mapPointsWithStride(coords, vsize, 4); 163 localMatrix->mapPointsWithStride(coords, vstride, 4);
164 } 164 }
165 } 165 }
166 166
167 static const int kColorOffset = sizeof(SkPoint); 167 static const int kColorOffset = sizeof(SkPoint);
168 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + k ColorOffset); 168 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + k ColorOffset);
169 for (int i = 0; i < 4; ++i) { 169 for (int i = 0; i < 4; ++i) {
170 *vertColor = color; 170 *vertColor = color;
171 vertColor = (GrColor*) ((intptr_t) vertColor + vsize); 171 vertColor = (GrColor*) ((intptr_t) vertColor + vstride);
172 } 172 }
173 173
174 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); 174 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
175 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds); 175 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
176 176
177 // to ensure that stashing the drawState ptr is valid 177 // to ensure that stashing the drawState ptr is valid
178 SkASSERT(this->drawState() == drawState); 178 SkASSERT(this->drawState() == drawState);
179 } 179 }
180 180
181 bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) { 181 bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 SkASSERT(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCou nt()); 260 SkASSERT(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCou nt());
261 261
262 // how many instances can be concat'ed onto draw given the size of the index buffer 262 // how many instances can be concat'ed onto draw given the size of the index buffer
263 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance(); 263 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerI nstance();
264 instancesToConcat -= draw->instanceCount(); 264 instancesToConcat -= draw->instanceCount();
265 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); 265 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount());
266 266
267 // update the amount of reserved vertex data actually referenced in draws 267 // update the amount of reserved vertex data actually referenced in draws
268 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * 268 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
269 drawState.getVertexSize(); 269 drawState.getVertexStride();
270 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vert exBytes); 270 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vert exBytes);
271 271
272 draw->adjustInstanceCount(instancesToConcat); 272 draw->adjustInstanceCount(instancesToConcat);
273 273
274 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added 274 // update last fGpuCmdMarkers to include any additional trace markers that h ave been added
275 if (this->getActiveTraceMarkers().count() > 0) { 275 if (this->getActiveTraceMarkers().count() > 0) {
276 if (cmd_has_trace_marker(fCmds.back())) { 276 if (cmd_has_trace_marker(fCmds.back())) {
277 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); 277 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers());
278 } else { 278 } else {
279 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); 279 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 draw = this->recordDraw(info); 332 draw = this->recordDraw(info);
333 } 333 }
334 334
335 switch (this->getGeomSrc().fVertexSrc) { 335 switch (this->getGeomSrc().fVertexSrc) {
336 case kBuffer_GeometrySrcType: 336 case kBuffer_GeometrySrcType:
337 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; 337 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
338 break; 338 break;
339 case kReserved_GeometrySrcType: // fallthrough 339 case kReserved_GeometrySrcType: // fallthrough
340 case kArray_GeometrySrcType: { 340 case kArray_GeometrySrcType: {
341 size_t vertexBytes = (info.vertexCount() + info.startVertex()) * 341 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
342 drawState.getVertexSize(); 342 drawState.getVertexStride();
343 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexByt es, vertexBytes); 343 poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexByt es, vertexBytes);
344 draw->fVertexBuffer = poolState.fPoolVertexBuffer; 344 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
345 draw->adjustStartVertex(poolState.fPoolStartVertex); 345 draw->adjustStartVertex(poolState.fPoolStartVertex);
346 break; 346 break;
347 } 347 }
348 default: 348 default:
349 SkFAIL("unknown geom src type"); 349 SkFAIL("unknown geom src type");
350 } 350 }
351 draw->fVertexBuffer->ref(); 351 draw->fVertexBuffer->ref();
352 352
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 int32_t currIndices = fIndexPool.currentBufferIndices(); 719 int32_t currIndices = fIndexPool.currentBufferIndices();
720 if (*indexCount > currIndices && 720 if (*indexCount > currIndices &&
721 (!fIndexPool.preallocatedBuffersRemaining() && 721 (!fIndexPool.preallocatedBuffersRemaining() &&
722 *indexCount <= fIndexPool.preallocatedBufferIndices())) { 722 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
723 723
724 flush = true; 724 flush = true;
725 } 725 }
726 *indexCount = currIndices; 726 *indexCount = currIndices;
727 } 727 }
728 if (NULL != vertexCount) { 728 if (NULL != vertexCount) {
729 size_t vertexSize = this->getDrawState().getVertexSize(); 729 size_t vertexStride = this->getDrawState().getVertexStride();
730 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize); 730 int32_t currVertices = fVertexPool.currentBufferVertices(vertexStride);
731 if (*vertexCount > currVertices && 731 if (*vertexCount > currVertices &&
732 (!fVertexPool.preallocatedBuffersRemaining() && 732 (!fVertexPool.preallocatedBuffersRemaining() &&
733 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize)) ) { 733 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexStride ))) {
734 734
735 flush = true; 735 flush = true;
736 } 736 }
737 *vertexCount = currVertices; 737 *vertexCount = currVertices;
738 } 738 }
739 return flush; 739 return flush;
740 } 740 }
741 741
742 bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize, 742 bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
743 int vertexCount, 743 int vertexCount,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { 958 GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() {
959 this->addToCmdBuffer(kCopySurface_Cmd); 959 this->addToCmdBuffer(kCopySurface_Cmd);
960 return &fCopySurfaces.push_back(); 960 return &fCopySurfaces.push_back();
961 } 961 }
962 962
963 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { 963 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
964 INHERITED::clipWillBeSet(newClipData); 964 INHERITED::clipWillBeSet(newClipData);
965 fClipSet = true; 965 fClipSet = true;
966 fClipProxyState = kUnknown_ClipProxyState; 966 fClipProxyState = kUnknown_ClipProxyState;
967 } 967 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698