| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 fPrimitiveType = di.fPrimitiveType; | 25 fPrimitiveType = di.fPrimitiveType; |
| 26 fStartVertex = di.fStartVertex; | 26 fStartVertex = di.fStartVertex; |
| 27 fStartIndex = di.fStartIndex; | 27 fStartIndex = di.fStartIndex; |
| 28 fVertexCount = di.fVertexCount; | 28 fVertexCount = di.fVertexCount; |
| 29 fIndexCount = di.fIndexCount; | 29 fIndexCount = di.fIndexCount; |
| 30 | 30 |
| 31 fInstanceCount = di.fInstanceCount; | 31 fInstanceCount = di.fInstanceCount; |
| 32 fVerticesPerInstance = di.fVerticesPerInstance; | 32 fVerticesPerInstance = di.fVerticesPerInstance; |
| 33 fIndicesPerInstance = di.fIndicesPerInstance; | 33 fIndicesPerInstance = di.fIndicesPerInstance; |
| 34 | 34 |
| 35 if (NULL != di.fDevBounds) { | 35 if (di.fDevBounds) { |
| 36 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage); | 36 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage); |
| 37 fDevBoundsStorage = di.fDevBoundsStorage; | 37 fDevBoundsStorage = di.fDevBoundsStorage; |
| 38 fDevBounds = &fDevBoundsStorage; | 38 fDevBounds = &fDevBoundsStorage; |
| 39 } else { | 39 } else { |
| 40 fDevBounds = NULL; | 40 fDevBounds = NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 fDstCopy = di.fDstCopy; | 43 fDstCopy = di.fDstCopy; |
| 44 | 44 |
| 45 return *this; | 45 return *this; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
| 86 | 86 |
| 87 #define DEBUG_INVAL_BUFFER 0xdeadcafe | 87 #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 88 #define DEBUG_INVAL_START_IDX -1 | 88 #define DEBUG_INVAL_START_IDX -1 |
| 89 | 89 |
| 90 GrDrawTarget::GrDrawTarget(GrContext* context) | 90 GrDrawTarget::GrDrawTarget(GrContext* context) |
| 91 : fClip(NULL) | 91 : fClip(NULL) |
| 92 , fContext(context) | 92 , fContext(context) |
| 93 , fGpuTraceMarkerCount(0) { | 93 , fGpuTraceMarkerCount(0) { |
| 94 SkASSERT(NULL != context); | 94 SkASSERT(context); |
| 95 | 95 |
| 96 fDrawState = &fDefaultDrawState; | 96 fDrawState = &fDefaultDrawState; |
| 97 // We assume that fDrawState always owns a ref to the object it points at. | 97 // We assume that fDrawState always owns a ref to the object it points at. |
| 98 fDefaultDrawState.ref(); | 98 fDefaultDrawState.ref(); |
| 99 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); | 99 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
| 100 #ifdef SK_DEBUG | 100 #ifdef SK_DEBUG |
| 101 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; | 101 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 102 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; | 102 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 103 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; | 103 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| 104 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; | 104 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 void GrDrawTarget::setClip(const GrClipData* clip) { | 128 void GrDrawTarget::setClip(const GrClipData* clip) { |
| 129 clipWillBeSet(clip); | 129 clipWillBeSet(clip); |
| 130 fClip = clip; | 130 fClip = clip; |
| 131 } | 131 } |
| 132 | 132 |
| 133 const GrClipData* GrDrawTarget::getClip() const { | 133 const GrClipData* GrDrawTarget::getClip() const { |
| 134 return fClip; | 134 return fClip; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void GrDrawTarget::setDrawState(GrDrawState* drawState) { | 137 void GrDrawTarget::setDrawState(GrDrawState* drawState) { |
| 138 SkASSERT(NULL != fDrawState); | 138 SkASSERT(fDrawState); |
| 139 if (NULL == drawState) { | 139 if (NULL == drawState) { |
| 140 drawState = &fDefaultDrawState; | 140 drawState = &fDefaultDrawState; |
| 141 } | 141 } |
| 142 if (fDrawState != drawState) { | 142 if (fDrawState != drawState) { |
| 143 fDrawState->unref(); | 143 fDrawState->unref(); |
| 144 drawState->ref(); | 144 drawState->ref(); |
| 145 fDrawState = drawState; | 145 fDrawState = drawState; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, | 149 bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, |
| 150 int vertexCount, | 150 int vertexCount, |
| 151 void** vertices) { | 151 void** vertices) { |
| 152 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 152 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 153 bool acquired = false; | 153 bool acquired = false; |
| 154 if (vertexCount > 0) { | 154 if (vertexCount > 0) { |
| 155 SkASSERT(NULL != vertices); | 155 SkASSERT(vertices); |
| 156 this->releasePreviousVertexSource(); | 156 this->releasePreviousVertexSource(); |
| 157 geoSrc.fVertexSrc = kNone_GeometrySrcType; | 157 geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 158 | 158 |
| 159 acquired = this->onReserveVertexSpace(vertexSize, | 159 acquired = this->onReserveVertexSpace(vertexSize, |
| 160 vertexCount, | 160 vertexCount, |
| 161 vertices); | 161 vertices); |
| 162 } | 162 } |
| 163 if (acquired) { | 163 if (acquired) { |
| 164 geoSrc.fVertexSrc = kReserved_GeometrySrcType; | 164 geoSrc.fVertexSrc = kReserved_GeometrySrcType; |
| 165 geoSrc.fVertexCount = vertexCount; | 165 geoSrc.fVertexCount = vertexCount; |
| 166 geoSrc.fVertexSize = vertexSize; | 166 geoSrc.fVertexSize = vertexSize; |
| 167 } else if (NULL != vertices) { | 167 } else if (vertices) { |
| 168 *vertices = NULL; | 168 *vertices = NULL; |
| 169 } | 169 } |
| 170 return acquired; | 170 return acquired; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool GrDrawTarget::reserveIndexSpace(int indexCount, | 173 bool GrDrawTarget::reserveIndexSpace(int indexCount, |
| 174 void** indices) { | 174 void** indices) { |
| 175 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 175 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 176 bool acquired = false; | 176 bool acquired = false; |
| 177 if (indexCount > 0) { | 177 if (indexCount > 0) { |
| 178 SkASSERT(NULL != indices); | 178 SkASSERT(indices); |
| 179 this->releasePreviousIndexSource(); | 179 this->releasePreviousIndexSource(); |
| 180 geoSrc.fIndexSrc = kNone_GeometrySrcType; | 180 geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 181 | 181 |
| 182 acquired = this->onReserveIndexSpace(indexCount, indices); | 182 acquired = this->onReserveIndexSpace(indexCount, indices); |
| 183 } | 183 } |
| 184 if (acquired) { | 184 if (acquired) { |
| 185 geoSrc.fIndexSrc = kReserved_GeometrySrcType; | 185 geoSrc.fIndexSrc = kReserved_GeometrySrcType; |
| 186 geoSrc.fIndexCount = indexCount; | 186 geoSrc.fIndexCount = indexCount; |
| 187 } else if (NULL != indices) { | 187 } else if (indices) { |
| 188 *indices = NULL; | 188 *indices = NULL; |
| 189 } | 189 } |
| 190 return acquired; | 190 return acquired; |
| 191 | 191 |
| 192 } | 192 } |
| 193 | 193 |
| 194 bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, | 194 bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, |
| 195 int indexCount, | 195 int indexCount, |
| 196 void** vertices, | 196 void** vertices, |
| 197 void** indices) { | 197 void** indices) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 211 this->resetVertexSource(); | 211 this->resetVertexSource(); |
| 212 } | 212 } |
| 213 return false; | 213 return false; |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 return true; | 216 return true; |
| 217 } | 217 } |
| 218 | 218 |
| 219 bool GrDrawTarget::geometryHints(int32_t* vertexCount, | 219 bool GrDrawTarget::geometryHints(int32_t* vertexCount, |
| 220 int32_t* indexCount) const { | 220 int32_t* indexCount) const { |
| 221 if (NULL != vertexCount) { | 221 if (vertexCount) { |
| 222 *vertexCount = -1; | 222 *vertexCount = -1; |
| 223 } | 223 } |
| 224 if (NULL != indexCount) { | 224 if (indexCount) { |
| 225 *indexCount = -1; | 225 *indexCount = -1; |
| 226 } | 226 } |
| 227 return false; | 227 return false; |
| 228 } | 228 } |
| 229 | 229 |
| 230 void GrDrawTarget::releasePreviousVertexSource() { | 230 void GrDrawTarget::releasePreviousVertexSource() { |
| 231 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 231 GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 232 switch (geoSrc.fVertexSrc) { | 232 switch (geoSrc.fVertexSrc) { |
| 233 case kNone_GeometrySrcType: | 233 case kNone_GeometrySrcType: |
| 234 break; | 234 break; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 break; | 380 break; |
| 381 case kBuffer_GeometrySrcType: | 381 case kBuffer_GeometrySrcType: |
| 382 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); | 382 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); |
| 383 break; | 383 break; |
| 384 } | 384 } |
| 385 if (maxIndex > maxValidIndex) { | 385 if (maxIndex > maxValidIndex) { |
| 386 SkFAIL("Index reads outside valid index range."); | 386 SkFAIL("Index reads outside valid index range."); |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 SkASSERT(NULL != drawState.getRenderTarget()); | 390 SkASSERT(drawState.getRenderTarget()); |
| 391 | 391 |
| 392 if (drawState.hasGeometryProcessor()) { | 392 if (drawState.hasGeometryProcessor()) { |
| 393 const GrEffect* effect = drawState.getGeometryProcessor()->getEffect(); | 393 const GrEffect* effect = drawState.getGeometryProcessor()->getEffect(); |
| 394 int numTextures = effect->numTextures(); | 394 int numTextures = effect->numTextures(); |
| 395 for (int t = 0; t < numTextures; ++t) { | 395 for (int t = 0; t < numTextures; ++t) { |
| 396 GrTexture* texture = effect->texture(t); | 396 GrTexture* texture = effect->texture(t); |
| 397 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); | 397 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 425 | 425 |
| 426 bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const
SkRect* drawBounds) { | 426 bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const
SkRect* drawBounds) { |
| 427 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffe
ctReadDstColor()) { | 427 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffe
ctReadDstColor()) { |
| 428 return true; | 428 return true; |
| 429 } | 429 } |
| 430 GrRenderTarget* rt = this->drawState()->getRenderTarget(); | 430 GrRenderTarget* rt = this->drawState()->getRenderTarget(); |
| 431 SkIRect copyRect; | 431 SkIRect copyRect; |
| 432 const GrClipData* clip = this->getClip(); | 432 const GrClipData* clip = this->getClip(); |
| 433 clip->getConservativeBounds(rt, ©Rect); | 433 clip->getConservativeBounds(rt, ©Rect); |
| 434 | 434 |
| 435 if (NULL != drawBounds) { | 435 if (drawBounds) { |
| 436 SkIRect drawIBounds; | 436 SkIRect drawIBounds; |
| 437 drawBounds->roundOut(&drawIBounds); | 437 drawBounds->roundOut(&drawIBounds); |
| 438 if (!copyRect.intersect(drawIBounds)) { | 438 if (!copyRect.intersect(drawIBounds)) { |
| 439 #ifdef SK_DEBUG | 439 #ifdef SK_DEBUG |
| 440 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); | 440 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); |
| 441 #endif | 441 #endif |
| 442 return false; | 442 return false; |
| 443 } | 443 } |
| 444 } else { | 444 } else { |
| 445 #ifdef SK_DEBUG | 445 #ifdef SK_DEBUG |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 info.fPrimitiveType = type; | 481 info.fPrimitiveType = type; |
| 482 info.fStartVertex = startVertex; | 482 info.fStartVertex = startVertex; |
| 483 info.fStartIndex = startIndex; | 483 info.fStartIndex = startIndex; |
| 484 info.fVertexCount = vertexCount; | 484 info.fVertexCount = vertexCount; |
| 485 info.fIndexCount = indexCount; | 485 info.fIndexCount = indexCount; |
| 486 | 486 |
| 487 info.fInstanceCount = 0; | 487 info.fInstanceCount = 0; |
| 488 info.fVerticesPerInstance = 0; | 488 info.fVerticesPerInstance = 0; |
| 489 info.fIndicesPerInstance = 0; | 489 info.fIndicesPerInstance = 0; |
| 490 | 490 |
| 491 if (NULL != devBounds) { | 491 if (devBounds) { |
| 492 info.setDevBounds(*devBounds); | 492 info.setDevBounds(*devBounds); |
| 493 } | 493 } |
| 494 // TODO: We should continue with incorrect blending. | 494 // TODO: We should continue with incorrect blending. |
| 495 if (!this->setupDstReadIfNecessary(&info)) { | 495 if (!this->setupDstReadIfNecessary(&info)) { |
| 496 return; | 496 return; |
| 497 } | 497 } |
| 498 this->onDraw(info); | 498 this->onDraw(info); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, | 502 void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, |
| 503 int startVertex, | 503 int startVertex, |
| 504 int vertexCount, | 504 int vertexCount, |
| 505 const SkRect* devBounds) { | 505 const SkRect* devBounds) { |
| 506 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -
1)) { | 506 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -
1)) { |
| 507 DrawInfo info; | 507 DrawInfo info; |
| 508 info.fPrimitiveType = type; | 508 info.fPrimitiveType = type; |
| 509 info.fStartVertex = startVertex; | 509 info.fStartVertex = startVertex; |
| 510 info.fStartIndex = 0; | 510 info.fStartIndex = 0; |
| 511 info.fVertexCount = vertexCount; | 511 info.fVertexCount = vertexCount; |
| 512 info.fIndexCount = 0; | 512 info.fIndexCount = 0; |
| 513 | 513 |
| 514 info.fInstanceCount = 0; | 514 info.fInstanceCount = 0; |
| 515 info.fVerticesPerInstance = 0; | 515 info.fVerticesPerInstance = 0; |
| 516 info.fIndicesPerInstance = 0; | 516 info.fIndicesPerInstance = 0; |
| 517 | 517 |
| 518 if (NULL != devBounds) { | 518 if (devBounds) { |
| 519 info.setDevBounds(*devBounds); | 519 info.setDevBounds(*devBounds); |
| 520 } | 520 } |
| 521 // TODO: We should continue with incorrect blending. | 521 // TODO: We should continue with incorrect blending. |
| 522 if (!this->setupDstReadIfNecessary(&info)) { | 522 if (!this->setupDstReadIfNecessary(&info)) { |
| 523 return; | 523 return; |
| 524 } | 524 } |
| 525 this->onDraw(info); | 525 this->onDraw(info); |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 void GrDrawTarget::stencilPath(const GrPath* path, SkPath::FillType fill) { | 529 void GrDrawTarget::stencilPath(const GrPath* path, SkPath::FillType fill) { |
| 530 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 530 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 531 SkASSERT(NULL != path); | 531 SkASSERT(path); |
| 532 SkASSERT(this->caps()->pathRenderingSupport()); | 532 SkASSERT(this->caps()->pathRenderingSupport()); |
| 533 SkASSERT(!SkPath::IsInverseFillType(fill)); | 533 SkASSERT(!SkPath::IsInverseFillType(fill)); |
| 534 this->onStencilPath(path, fill); | 534 this->onStencilPath(path, fill); |
| 535 } | 535 } |
| 536 | 536 |
| 537 void GrDrawTarget::drawPath(const GrPath* path, SkPath::FillType fill) { | 537 void GrDrawTarget::drawPath(const GrPath* path, SkPath::FillType fill) { |
| 538 // TODO: extract portions of checkDraw that are relevant to path rendering. | 538 // TODO: extract portions of checkDraw that are relevant to path rendering. |
| 539 SkASSERT(NULL != path); | 539 SkASSERT(path); |
| 540 SkASSERT(this->caps()->pathRenderingSupport()); | 540 SkASSERT(this->caps()->pathRenderingSupport()); |
| 541 const GrDrawState* drawState = &getDrawState(); | 541 const GrDrawState* drawState = &getDrawState(); |
| 542 | 542 |
| 543 SkRect devBounds; | 543 SkRect devBounds; |
| 544 if (SkPath::IsInverseFillType(fill)) { | 544 if (SkPath::IsInverseFillType(fill)) { |
| 545 devBounds = SkRect::MakeWH(SkIntToScalar(drawState->getRenderTarget()->w
idth()), | 545 devBounds = SkRect::MakeWH(SkIntToScalar(drawState->getRenderTarget()->w
idth()), |
| 546 SkIntToScalar(drawState->getRenderTarget()->h
eight())); | 546 SkIntToScalar(drawState->getRenderTarget()->h
eight())); |
| 547 } else { | 547 } else { |
| 548 devBounds = path->getBounds(); | 548 devBounds = path->getBounds(); |
| 549 } | 549 } |
| 550 SkMatrix viewM = drawState->getViewMatrix(); | 550 SkMatrix viewM = drawState->getViewMatrix(); |
| 551 viewM.mapRect(&devBounds); | 551 viewM.mapRect(&devBounds); |
| 552 | 552 |
| 553 GrDeviceCoordTexture dstCopy; | 553 GrDeviceCoordTexture dstCopy; |
| 554 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { | 554 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { |
| 555 return; | 555 return; |
| 556 } | 556 } |
| 557 | 557 |
| 558 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); | 558 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void GrDrawTarget::drawPaths(const GrPathRange* pathRange, | 561 void GrDrawTarget::drawPaths(const GrPathRange* pathRange, |
| 562 const uint32_t indices[], int count, | 562 const uint32_t indices[], int count, |
| 563 const float transforms[], PathTransformType transfo
rmsType, | 563 const float transforms[], PathTransformType transfo
rmsType, |
| 564 SkPath::FillType fill) { | 564 SkPath::FillType fill) { |
| 565 SkASSERT(this->caps()->pathRenderingSupport()); | 565 SkASSERT(this->caps()->pathRenderingSupport()); |
| 566 SkASSERT(NULL != pathRange); | 566 SkASSERT(pathRange); |
| 567 SkASSERT(NULL != indices); | 567 SkASSERT(indices); |
| 568 SkASSERT(NULL != transforms); | 568 SkASSERT(transforms); |
| 569 | 569 |
| 570 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt | 570 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
| 571 // instead for it to just copy the entire dst. Realistically this is a moot | 571 // instead for it to just copy the entire dst. Realistically this is a moot |
| 572 // point, because any context that supports NV_path_rendering will also | 572 // point, because any context that supports NV_path_rendering will also |
| 573 // support NV_blend_equation_advanced. | 573 // support NV_blend_equation_advanced. |
| 574 GrDeviceCoordTexture dstCopy; | 574 GrDeviceCoordTexture dstCopy; |
| 575 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { | 575 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { |
| 576 return; | 576 return; |
| 577 } | 577 } |
| 578 | 578 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 638 } |
| 639 | 639 |
| 640 DrawInfo info; | 640 DrawInfo info; |
| 641 info.fPrimitiveType = type; | 641 info.fPrimitiveType = type; |
| 642 info.fStartIndex = 0; | 642 info.fStartIndex = 0; |
| 643 info.fStartVertex = 0; | 643 info.fStartVertex = 0; |
| 644 info.fIndicesPerInstance = indicesPerInstance; | 644 info.fIndicesPerInstance = indicesPerInstance; |
| 645 info.fVerticesPerInstance = verticesPerInstance; | 645 info.fVerticesPerInstance = verticesPerInstance; |
| 646 | 646 |
| 647 // Set the same bounds for all the draws. | 647 // Set the same bounds for all the draws. |
| 648 if (NULL != devBounds) { | 648 if (devBounds) { |
| 649 info.setDevBounds(*devBounds); | 649 info.setDevBounds(*devBounds); |
| 650 } | 650 } |
| 651 // TODO: We should continue with incorrect blending. | 651 // TODO: We should continue with incorrect blending. |
| 652 if (!this->setupDstReadIfNecessary(&info)) { | 652 if (!this->setupDstReadIfNecessary(&info)) { |
| 653 return; | 653 return; |
| 654 } | 654 } |
| 655 | 655 |
| 656 while (instanceCount) { | 656 while (instanceCount) { |
| 657 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 657 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
| 658 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 658 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 687 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint)); | 687 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint)); |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 | 690 |
| 691 }; | 691 }; |
| 692 | 692 |
| 693 void GrDrawTarget::onDrawRect(const SkRect& rect, | 693 void GrDrawTarget::onDrawRect(const SkRect& rect, |
| 694 const SkRect* localRect, | 694 const SkRect* localRect, |
| 695 const SkMatrix* localMatrix) { | 695 const SkMatrix* localMatrix) { |
| 696 | 696 |
| 697 set_vertex_attributes(this->drawState(), NULL != localRect); | 697 set_vertex_attributes(this->drawState(), SkToBool(localRect)); |
| 698 | 698 |
| 699 AutoReleaseGeometry geo(this, 4, 0); | 699 AutoReleaseGeometry geo(this, 4, 0); |
| 700 if (!geo.succeeded()) { | 700 if (!geo.succeeded()) { |
| 701 GrPrintf("Failed to get space for vertices!\n"); | 701 GrPrintf("Failed to get space for vertices!\n"); |
| 702 return; | 702 return; |
| 703 } | 703 } |
| 704 | 704 |
| 705 size_t vstride = this->drawState()->getVertexStride(); | 705 size_t vstride = this->drawState()->getVertexStride(); |
| 706 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vstride); | 706 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom
, vstride); |
| 707 if (NULL != localRect) { | 707 if (localRect) { |
| 708 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + | 708 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + |
| 709 sizeof(SkPoint)); | 709 sizeof(SkPoint)); |
| 710 coords->setRectFan(localRect->fLeft, localRect->fTop, | 710 coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 711 localRect->fRight, localRect->fBottom, | 711 localRect->fRight, localRect->fBottom, |
| 712 vstride); | 712 vstride); |
| 713 if (NULL != localMatrix) { | 713 if (localMatrix) { |
| 714 localMatrix->mapPointsWithStride(coords, vstride, 4); | 714 localMatrix->mapPointsWithStride(coords, vstride, 4); |
| 715 } | 715 } |
| 716 } | 716 } |
| 717 SkRect bounds; | 717 SkRect bounds; |
| 718 this->getDrawState().getViewMatrix().mapRect(&bounds, rect); | 718 this->getDrawState().getViewMatrix().mapRect(&bounds, rect); |
| 719 | 719 |
| 720 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds); | 720 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds); |
| 721 } | 721 } |
| 722 | 722 |
| 723 void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { | 723 void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { |
| 724 } | 724 } |
| 725 | 725 |
| 726 //////////////////////////////////////////////////////////////////////////////// | 726 //////////////////////////////////////////////////////////////////////////////// |
| 727 | 727 |
| 728 GrDrawTarget::AutoStateRestore::AutoStateRestore() { | 728 GrDrawTarget::AutoStateRestore::AutoStateRestore() { |
| 729 fDrawTarget = NULL; | 729 fDrawTarget = NULL; |
| 730 } | 730 } |
| 731 | 731 |
| 732 GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target, | 732 GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target, |
| 733 ASRInit init, | 733 ASRInit init, |
| 734 const SkMatrix* vm) { | 734 const SkMatrix* vm) { |
| 735 fDrawTarget = NULL; | 735 fDrawTarget = NULL; |
| 736 this->set(target, init, vm); | 736 this->set(target, init, vm); |
| 737 } | 737 } |
| 738 | 738 |
| 739 GrDrawTarget::AutoStateRestore::~AutoStateRestore() { | 739 GrDrawTarget::AutoStateRestore::~AutoStateRestore() { |
| 740 if (NULL != fDrawTarget) { | 740 if (fDrawTarget) { |
| 741 fDrawTarget->setDrawState(fSavedState); | 741 fDrawTarget->setDrawState(fSavedState); |
| 742 fSavedState->unref(); | 742 fSavedState->unref(); |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 | 745 |
| 746 void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, con
st SkMatrix* vm) { | 746 void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, con
st SkMatrix* vm) { |
| 747 SkASSERT(NULL == fDrawTarget); | 747 SkASSERT(NULL == fDrawTarget); |
| 748 fDrawTarget = target; | 748 fDrawTarget = target; |
| 749 fSavedState = target->drawState(); | 749 fSavedState = target->drawState(); |
| 750 SkASSERT(fSavedState); | 750 SkASSERT(fSavedState); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { | 810 GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { |
| 811 this->reset(); | 811 this->reset(); |
| 812 } | 812 } |
| 813 | 813 |
| 814 bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, | 814 bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, |
| 815 int vertexCount, | 815 int vertexCount, |
| 816 int indexCount) { | 816 int indexCount) { |
| 817 this->reset(); | 817 this->reset(); |
| 818 fTarget = target; | 818 fTarget = target; |
| 819 bool success = true; | 819 bool success = true; |
| 820 if (NULL != fTarget) { | 820 if (fTarget) { |
| 821 fTarget = target; | 821 fTarget = target; |
| 822 success = target->reserveVertexAndIndexSpace(vertexCount, | 822 success = target->reserveVertexAndIndexSpace(vertexCount, |
| 823 indexCount, | 823 indexCount, |
| 824 &fVertices, | 824 &fVertices, |
| 825 &fIndices); | 825 &fIndices); |
| 826 if (!success) { | 826 if (!success) { |
| 827 fTarget = NULL; | 827 fTarget = NULL; |
| 828 this->reset(); | 828 this->reset(); |
| 829 } | 829 } |
| 830 } | 830 } |
| 831 SkASSERT(success == (NULL != fTarget)); | 831 SkASSERT(success == SkToBool(fTarget)); |
| 832 return success; | 832 return success; |
| 833 } | 833 } |
| 834 | 834 |
| 835 void GrDrawTarget::AutoReleaseGeometry::reset() { | 835 void GrDrawTarget::AutoReleaseGeometry::reset() { |
| 836 if (NULL != fTarget) { | 836 if (fTarget) { |
| 837 if (NULL != fVertices) { | 837 if (fVertices) { |
| 838 fTarget->resetVertexSource(); | 838 fTarget->resetVertexSource(); |
| 839 } | 839 } |
| 840 if (NULL != fIndices) { | 840 if (fIndices) { |
| 841 fTarget->resetIndexSource(); | 841 fTarget->resetIndexSource(); |
| 842 } | 842 } |
| 843 fTarget = NULL; | 843 fTarget = NULL; |
| 844 } | 844 } |
| 845 fVertices = NULL; | 845 fVertices = NULL; |
| 846 fIndices = NULL; | 846 fIndices = NULL; |
| 847 } | 847 } |
| 848 | 848 |
| 849 GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRe
ct& newClip) { | 849 GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRe
ct& newClip) { |
| 850 fTarget = target; | 850 fTarget = target; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or | 905 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or |
| 906 // dst bounds. | 906 // dst bounds. |
| 907 return !clippedSrcRect->isEmpty(); | 907 return !clippedSrcRect->isEmpty(); |
| 908 } | 908 } |
| 909 } | 909 } |
| 910 | 910 |
| 911 bool GrDrawTarget::copySurface(GrSurface* dst, | 911 bool GrDrawTarget::copySurface(GrSurface* dst, |
| 912 GrSurface* src, | 912 GrSurface* src, |
| 913 const SkIRect& srcRect, | 913 const SkIRect& srcRect, |
| 914 const SkIPoint& dstPoint) { | 914 const SkIPoint& dstPoint) { |
| 915 SkASSERT(NULL != dst); | 915 SkASSERT(dst); |
| 916 SkASSERT(NULL != src); | 916 SkASSERT(src); |
| 917 | 917 |
| 918 SkIRect clippedSrcRect; | 918 SkIRect clippedSrcRect; |
| 919 SkIPoint clippedDstPoint; | 919 SkIPoint clippedDstPoint; |
| 920 // If the rect is outside the src or dst then we've already succeeded. | 920 // If the rect is outside the src or dst then we've already succeeded. |
| 921 if (!clip_srcrect_and_dstpoint(dst, | 921 if (!clip_srcrect_and_dstpoint(dst, |
| 922 src, | 922 src, |
| 923 srcRect, | 923 srcRect, |
| 924 dstPoint, | 924 dstPoint, |
| 925 &clippedSrcRect, | 925 &clippedSrcRect, |
| 926 &clippedDstPoint)) { | 926 &clippedDstPoint)) { |
| 927 SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint)); | 927 SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint)); |
| 928 return true; | 928 return true; |
| 929 } | 929 } |
| 930 | 930 |
| 931 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)
; | 931 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)
; |
| 932 SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDst
Point)); | 932 SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDst
Point)); |
| 933 return result; | 933 return result; |
| 934 } | 934 } |
| 935 | 935 |
| 936 bool GrDrawTarget::canCopySurface(GrSurface* dst, | 936 bool GrDrawTarget::canCopySurface(GrSurface* dst, |
| 937 GrSurface* src, | 937 GrSurface* src, |
| 938 const SkIRect& srcRect, | 938 const SkIRect& srcRect, |
| 939 const SkIPoint& dstPoint) { | 939 const SkIPoint& dstPoint) { |
| 940 SkASSERT(NULL != dst); | 940 SkASSERT(dst); |
| 941 SkASSERT(NULL != src); | 941 SkASSERT(src); |
| 942 | 942 |
| 943 SkIRect clippedSrcRect; | 943 SkIRect clippedSrcRect; |
| 944 SkIPoint clippedDstPoint; | 944 SkIPoint clippedDstPoint; |
| 945 // If the rect is outside the src or dst then we're guaranteed success | 945 // If the rect is outside the src or dst then we're guaranteed success |
| 946 if (!clip_srcrect_and_dstpoint(dst, | 946 if (!clip_srcrect_and_dstpoint(dst, |
| 947 src, | 947 src, |
| 948 srcRect, | 948 srcRect, |
| 949 dstPoint, | 949 dstPoint, |
| 950 &clippedSrcRect, | 950 &clippedSrcRect, |
| 951 &clippedDstPoint)) { | 951 &clippedDstPoint)) { |
| 952 return true; | 952 return true; |
| 953 } | 953 } |
| 954 return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); | 954 return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
| 955 } | 955 } |
| 956 | 956 |
| 957 bool GrDrawTarget::onCanCopySurface(GrSurface* dst, | 957 bool GrDrawTarget::onCanCopySurface(GrSurface* dst, |
| 958 GrSurface* src, | 958 GrSurface* src, |
| 959 const SkIRect& srcRect, | 959 const SkIRect& srcRect, |
| 960 const SkIPoint& dstPoint) { | 960 const SkIPoint& dstPoint) { |
| 961 // Check that the read/write rects are contained within the src/dst bounds. | 961 // Check that the read/write rects are contained within the src/dst bounds. |
| 962 SkASSERT(!srcRect.isEmpty()); | 962 SkASSERT(!srcRect.isEmpty()); |
| 963 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect)); | 963 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect)); |
| 964 SkASSERT(dstPoint.fX >= 0 && dstPoint.fY >= 0); | 964 SkASSERT(dstPoint.fX >= 0 && dstPoint.fY >= 0); |
| 965 SkASSERT(dstPoint.fX + srcRect.width() <= dst->width() && | 965 SkASSERT(dstPoint.fX + srcRect.width() <= dst->width() && |
| 966 dstPoint.fY + srcRect.height() <= dst->height()); | 966 dstPoint.fY + srcRect.height() <= dst->height()); |
| 967 | 967 |
| 968 return !dst->isSameAs(src) && NULL != dst->asRenderTarget() && NULL != src->
asTexture(); | 968 return !dst->isSameAs(src) && dst->asRenderTarget() && src->asTexture(); |
| 969 } | 969 } |
| 970 | 970 |
| 971 bool GrDrawTarget::onCopySurface(GrSurface* dst, | 971 bool GrDrawTarget::onCopySurface(GrSurface* dst, |
| 972 GrSurface* src, | 972 GrSurface* src, |
| 973 const SkIRect& srcRect, | 973 const SkIRect& srcRect, |
| 974 const SkIPoint& dstPoint) { | 974 const SkIPoint& dstPoint) { |
| 975 if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) { | 975 if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) { |
| 976 return false; | 976 return false; |
| 977 } | 977 } |
| 978 | 978 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); | 1141 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
| 1142 | 1142 |
| 1143 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { | 1143 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 1144 r.appendf("%s is uploadable to a texture: %s\n", | 1144 r.appendf("%s is uploadable to a texture: %s\n", |
| 1145 kConfigNames[i], | 1145 kConfigNames[i], |
| 1146 gNY[fConfigTextureSupport[i]]); | 1146 gNY[fConfigTextureSupport[i]]); |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 return r; | 1149 return r; |
| 1150 } | 1150 } |
| OLD | NEW |