| OLD | NEW |
| 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 Loading... |
| 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 fVAStride = that.fVAStride; | 78 fVertexSize = that.fVertexSize; |
| 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 Loading... |
| 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 void validate_vertex_attribs(const GrVertexAttrib* attribs, int count, si
ze_t stride) { | 181 static size_t vertex_size(const GrVertexAttrib* attribs, int count) { |
| 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 |
| 185 SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt); | 186 SkASSERT(count <= GrRODrawState::kMaxVertexAttribCnt); |
| 187 size_t size = 0; |
| 186 for (int index = 0; index < count; ++index) { | 188 for (int index = 0; index < count; ++index) { |
| 187 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); | 189 size_t attribSize = GrVertexAttribTypeSize(attribs[index].fType); |
| 188 size_t attribOffset = attribs[index].fOffset; | 190 size += attribSize; |
| 189 SkASSERT(attribOffset + attribSize <= stride); | 191 #ifdef SK_DEBUG |
| 190 size_t dwordCount = attribSize >> 2; | 192 size_t dwordCount = attribSize >> 2; |
| 191 uint32_t mask = (1 << dwordCount)-1; | 193 uint32_t mask = (1 << dwordCount)-1; |
| 192 size_t offsetShift = attribOffset >> 2; | 194 size_t offsetShift = attribs[index].fOffset >> 2; |
| 193 SkASSERT(!(overlapCheck & (mask << offsetShift))); | 195 SkASSERT(!(overlapCheck & (mask << offsetShift))); |
| 194 overlapCheck |= (mask << offsetShift); | 196 overlapCheck |= (mask << offsetShift); |
| 197 #endif |
| 195 } | 198 } |
| 196 #endif | 199 return size; |
| 197 } | 200 } |
| 198 | 201 |
| 199 //////////////////////////////////////////////////////////////////////////////// | 202 //////////////////////////////////////////////////////////////////////////////// |
| 200 | 203 |
| 201 void GrDrawState::internalSetVertexAttribs(const GrVertexAttrib* attribs, int co
unt, | 204 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { |
| 202 size_t stride) { | |
| 203 SkASSERT(count <= kMaxVertexAttribCnt); | 205 SkASSERT(count <= kMaxVertexAttribCnt); |
| 204 | 206 |
| 205 fVAPtr = attribs; | 207 fVAPtr = attribs; |
| 206 fVACount = count; | 208 fVACount = count; |
| 207 fVAStride = stride; | 209 fVertexSize = vertex_size(fVAPtr, fVACount); |
| 208 validate_vertex_attribs(fVAPtr, fVACount, fVAStride); | |
| 209 | 210 |
| 210 // Set all the indices to -1 | 211 // Set all the indices to -1 |
| 211 memset(fFixedFunctionVertexAttribIndices, | 212 memset(fFixedFunctionVertexAttribIndices, |
| 212 0xff, | 213 0xff, |
| 213 sizeof(fFixedFunctionVertexAttribIndices)); | 214 sizeof(fFixedFunctionVertexAttribIndices)); |
| 214 #ifdef SK_DEBUG | 215 #ifdef SK_DEBUG |
| 215 uint32_t overlapCheck = 0; | 216 uint32_t overlapCheck = 0; |
| 216 #endif | 217 #endif |
| 217 for (int i = 0; i < count; ++i) { | 218 for (int i = 0; i < count; ++i) { |
| 218 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | 219 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 236 } | 237 } |
| 237 | 238 |
| 238 //////////////////////////////////////////////////////////////////////////////// | 239 //////////////////////////////////////////////////////////////////////////////// |
| 239 | 240 |
| 240 void GrDrawState::setDefaultVertexAttribs() { | 241 void GrDrawState::setDefaultVertexAttribs() { |
| 241 static const GrVertexAttrib kPositionAttrib = | 242 static const GrVertexAttrib kPositionAttrib = |
| 242 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; | 243 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
| 243 | 244 |
| 244 fVAPtr = &kPositionAttrib; | 245 fVAPtr = &kPositionAttrib; |
| 245 fVACount = 1; | 246 fVACount = 1; |
| 246 fVAStride = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); | 247 fVertexSize = GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); |
| 247 | 248 |
| 248 // set all the fixed function indices to -1 except position. | 249 // set all the fixed function indices to -1 except position. |
| 249 memset(fFixedFunctionVertexAttribIndices, | 250 memset(fFixedFunctionVertexAttribIndices, |
| 250 0xff, | 251 0xff, |
| 251 sizeof(fFixedFunctionVertexAttribIndices)); | 252 sizeof(fFixedFunctionVertexAttribIndices)); |
| 252 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; | 253 fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0; |
| 253 this->invalidateBlendOptFlags(); | 254 this->invalidateBlendOptFlags(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 //////////////////////////////////////////////////////////////////////////////// | 257 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 14 matching lines...) Expand all Loading... |
| 271 } | 272 } |
| 272 | 273 |
| 273 ////////////////////////////////////////////////////////////////////////////// | 274 ////////////////////////////////////////////////////////////////////////////// |
| 274 | 275 |
| 275 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore( | 276 GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore( |
| 276 GrDrawState* drawState) { | 277 GrDrawState* drawState) { |
| 277 SkASSERT(NULL != drawState); | 278 SkASSERT(NULL != drawState); |
| 278 fDrawState = drawState; | 279 fDrawState = drawState; |
| 279 fVAPtr = drawState->fVAPtr; | 280 fVAPtr = drawState->fVAPtr; |
| 280 fVACount = drawState->fVACount; | 281 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 Loading... |
| 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 |
| OLD | NEW |