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

Side by Side Diff: src/gpu/GrDrawState.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/GrDrawState.h ('k') | src/gpu/GrDrawTarget.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 2012 Google Inc. 2 * Copyright 2012 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 "GrDrawState.h" 8 #include "GrDrawState.h"
9 #include "GrPaint.h" 9 #include "GrPaint.h"
10 #include "GrDrawTargetCaps.h" 10 #include "GrDrawTargetCaps.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); 68 SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
69 this->setRenderTarget(that.fRenderTarget.get()); 69 this->setRenderTarget(that.fRenderTarget.get());
70 fColor = that.fColor; 70 fColor = that.fColor;
71 fViewMatrix = that.fViewMatrix; 71 fViewMatrix = that.fViewMatrix;
72 fSrcBlend = that.fSrcBlend; 72 fSrcBlend = that.fSrcBlend;
73 fDstBlend = that.fDstBlend; 73 fDstBlend = that.fDstBlend;
74 fBlendConstant = that.fBlendConstant; 74 fBlendConstant = that.fBlendConstant;
75 fFlagBits = that.fFlagBits; 75 fFlagBits = that.fFlagBits;
76 fVACount = that.fVACount; 76 fVACount = that.fVACount;
77 fVAPtr = that.fVAPtr; 77 fVAPtr = that.fVAPtr;
78 fVertexSize = that.fVertexSize; 78 fVAStride = that.fVAStride;
79 fStencilSettings = that.fStencilSettings; 79 fStencilSettings = that.fStencilSettings;
80 fCoverage = that.fCoverage; 80 fCoverage = that.fCoverage;
81 fDrawFace = that.fDrawFace; 81 fDrawFace = that.fDrawFace;
82 fColorStages = that.fColorStages; 82 fColorStages = that.fColorStages;
83 fCoverageStages = that.fCoverageStages; 83 fCoverageStages = that.fCoverageStages;
84 fOptSrcBlend = that.fOptSrcBlend; 84 fOptSrcBlend = that.fOptSrcBlend;
85 fOptDstBlend = that.fOptDstBlend; 85 fOptDstBlend = that.fOptDstBlend;
86 fBlendOptFlags = that.fBlendOptFlags; 86 fBlendOptFlags = that.fBlendOptFlags;
87 87
88 fHints = that.fHints; 88 fHints = that.fHints;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 this->setState(GrDrawState::kDither_StateBit, paint.isDither()); 171 this->setState(GrDrawState::kDither_StateBit, paint.isDither());
172 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias()); 172 this->setState(GrDrawState::kHWAntialias_StateBit, paint.isAntiAlias());
173 173
174 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff()); 174 this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
175 this->setCoverage(paint.getCoverage()); 175 this->setCoverage(paint.getCoverage());
176 this->invalidateBlendOptFlags(); 176 this->invalidateBlendOptFlags();
177 } 177 }
178 178
179 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
180 180
181 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { 181 static void validate_vertex_attribs(const GrVertexAttrib* attribs, int count, si ze_t stride) {
182 // this works as long as we're 4 byte-aligned 182 // this works as long as we're 4 byte-aligned
183 #ifdef SK_DEBUG 183 #ifdef SK_DEBUG
184 uint32_t overlapCheck = 0; 184 uint32_t overlapCheck = 0;
185 #endif
186 SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt); 185 SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt);
187 size_t size = 0;
188 for (int index = 0; index < count; ++index) { 186 for (int index = 0; index < count; ++index) {
189 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); 187 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType);
190 size += attribSize; 188 size_t attribOffset = attribs[index].fOffset;
191 #ifdef SK_DEBUG 189 SkASSERT(attribOffset + attribSize <= stride);
192 size_t dwordCount = attribSize >> 2; 190 size_t dwordCount = attribSize >> 2;
193 uint32_t mask = (1 << dwordCount)-1; 191 uint32_t mask = (1 << dwordCount)-1;
194 size_t offsetShift = attribs[index].fOffset >> 2; 192 size_t offsetShift = attribOffset >> 2;
195 SkASSERT(!(overlapCheck & (mask << offsetShift))); 193 SkASSERT(!(overlapCheck & (mask << offsetShift)));
196 overlapCheck |= (mask << offsetShift); 194 overlapCheck |= (mask << offsetShift);
195 }
197 #endif 196 #endif
198 }
199 return size;
200 } 197 }
201 198
202 //////////////////////////////////////////////////////////////////////////////// 199 ////////////////////////////////////////////////////////////////////////////////
203 200
204 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { 201 void GrDrawState::internalSetVertexAttribs(const GrVertexAttrib* attribs, int co unt,
202 size_t stride) {
205 SkASSERT(count <= kMaxVertexAttribCnt); 203 SkASSERT(count <= kMaxVertexAttribCnt);
206 204
207 fVAPtr = attribs; 205 fVAPtr = attribs;
208 fVACount = count; 206 fVACount = count;
209 fVertexSize = vertex_size(fVAPtr, fVACount); 207 fVAStride = stride;
208 validate_vertex_attribs(fVAPtr, fVACount, fVAStride);
210 209
211 // Set all the indices to -1 210 // Set all the indices to -1
212 memset(fFixedFunctionVertexAttribIndices, 211 memset(fFixedFunctionVertexAttribIndices,
213 0xff, 212 0xff,
214 sizeof(fFixedFunctionVertexAttribIndices)); 213 sizeof(fFixedFunctionVertexAttribIndices));
215 #ifdef SK_DEBUG 214 #ifdef SK_DEBUG
216 uint32_t overlapCheck = 0; 215 uint32_t overlapCheck = 0;
217 #endif 216 #endif
218 for (int i = 0; i < count; ++i) { 217 for (int i = 0; i < count; ++i) {
219 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { 218 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) {
(...skipping 17 matching lines...) Expand all
237 } 236 }
238 237
239 //////////////////////////////////////////////////////////////////////////////// 238 ////////////////////////////////////////////////////////////////////////////////
240 239
241 void GrDrawState::setDefaultVertexAttribs() { 240 void GrDrawState::setDefaultVertexAttribs() {
242 static const GrVertexAttrib kPositionAttrib = 241 static const GrVertexAttrib kPositionAttrib =
243 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; 242 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding};
244 243
245 fVAPtr = &kPositionAttrib; 244 fVAPtr = &kPositionAttrib;
246 fVACount = 1; 245 fVACount = 1;
247 fVertexSize = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); 246 fVAStride = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType);
248 247
249 // set all the fixed function indices to -1 except position. 248 // set all the fixed function indices to -1 except position.
250 memset(fFixedFunctionVertexAttribIndices, 249 memset(fFixedFunctionVertexAttribIndices,
251 0xff, 250 0xff,
252 sizeof(fFixedFunctionVertexAttribIndices)); 251 sizeof(fFixedFunctionVertexAttribIndices));
253 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; 252 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0;
254 this->invalidateBlendOptFlags(); 253 this->invalidateBlendOptFlags();
255 } 254 }
256 255
257 //////////////////////////////////////////////////////////////////////////////// 256 ////////////////////////////////////////////////////////////////////////////////
(...skipping 14 matching lines...) Expand all
272 } 271 }
273 272
274 ////////////////////////////////////////////////////////////////////////////// 273 //////////////////////////////////////////////////////////////////////////////
275 274
276 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore( 275 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(
277 GrDrawState* drawState) { 276 GrDrawState* drawState) {
278 SkASSERT(NULL != drawState); 277 SkASSERT(NULL != drawState);
279 fDrawState = drawState; 278 fDrawState = drawState;
280 fVAPtr = drawState->fVAPtr; 279 fVAPtr = drawState->fVAPtr;
281 fVACount = drawState->fVACount; 280 fVACount = drawState->fVACount;
281 fVAStride = drawState->fVAStride;
282 fDrawState->setDefaultVertexAttribs(); 282 fDrawState->setDefaultVertexAttribs();
283 } 283 }
284 284
285 //////////////////////////////////////////////////////////////////////////////s 285 //////////////////////////////////////////////////////////////////////////////s
286 286
287 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) { 287 void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
288 if (NULL != fDrawState) { 288 if (NULL != fDrawState) {
289 int m = fDrawState->numColorStages() - fColorEffectCnt; 289 int m = fDrawState->numColorStages() - fColorEffectCnt;
290 SkASSERT(m >= 0); 290 SkASSERT(m >= 0);
291 fDrawState->fColorStages.pop_back_n(m); 291 fDrawState->fColorStages.pop_back_n(m);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 //////////////////////////////////////////////////////////////////////////////// 561 ////////////////////////////////////////////////////////////////////////////////
562 562
563 bool GrDrawState::canIgnoreColorAttribute() const { 563 bool GrDrawState::canIgnoreColorAttribute() const {
564 if (fBlendOptFlags & kInvalid_BlendOptFlag) { 564 if (fBlendOptFlags & kInvalid_BlendOptFlag) {
565 this->getBlendOpts(); 565 this->getBlendOpts();
566 } 566 }
567 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla g | 567 return SkToBool(fBlendOptFlags & (GrRODrawState::kEmitTransBlack_BlendOptFla g |
568 GrRODrawState::kEmitCoverage_BlendOptFlag) ); 568 GrRODrawState::kEmitCoverage_BlendOptFlag) );
569 } 569 }
570 570
OLDNEW
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698