| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 SkASSERT(fGeoSrcStateStack.count() > 1); | 299 SkASSERT(fGeoSrcStateStack.count() > 1); |
| 300 | 300 |
| 301 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); | 301 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
| 302 this->releasePreviousVertexSource(); | 302 this->releasePreviousVertexSource(); |
| 303 this->releasePreviousIndexSource(); | 303 this->releasePreviousIndexSource(); |
| 304 fGeoSrcStateStack.pop_back(); | 304 fGeoSrcStateStack.pop_back(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 //////////////////////////////////////////////////////////////////////////////// | 307 //////////////////////////////////////////////////////////////////////////////// |
| 308 | 308 |
| 309 bool GrDrawTarget::checkDraw(const GrDrawState& drawState, | 309 bool GrDrawTarget::checkDraw(const GrPipelineBuilder& pipelineBuilder, |
| 310 const GrGeometryProcessor* gp, | 310 const GrGeometryProcessor* gp, |
| 311 GrPrimitiveType type, | 311 GrPrimitiveType type, |
| 312 int startVertex, | 312 int startVertex, |
| 313 int startIndex, | 313 int startIndex, |
| 314 int vertexCount, | 314 int vertexCount, |
| 315 int indexCount) const { | 315 int indexCount) const { |
| 316 #ifdef SK_DEBUG | 316 #ifdef SK_DEBUG |
| 317 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 317 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 318 int maxVertex = startVertex + vertexCount; | 318 int maxVertex = startVertex + vertexCount; |
| 319 int maxValidVertex; | 319 int maxValidVertex; |
| 320 switch (geoSrc.fVertexSrc) { | 320 switch (geoSrc.fVertexSrc) { |
| 321 case kNone_GeometrySrcType: | 321 case kNone_GeometrySrcType: |
| 322 SkFAIL("Attempting to draw without vertex src."); | 322 SkFAIL("Attempting to draw without vertex src."); |
| 323 case kReserved_GeometrySrcType: // fallthrough | 323 case kReserved_GeometrySrcType: // fallthrough |
| 324 maxValidVertex = geoSrc.fVertexCount; | 324 maxValidVertex = geoSrc.fVertexCount; |
| 325 break; | 325 break; |
| 326 case kBuffer_GeometrySrcType: | 326 case kBuffer_GeometrySrcType: |
| 327 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySiz
e() / geoSrc.fVertexSize); | 327 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySiz
e() / |
| 328 geoSrc.fVertexSize); |
| 328 break; | 329 break; |
| 329 } | 330 } |
| 330 if (maxVertex > maxValidVertex) { | 331 if (maxVertex > maxValidVertex) { |
| 331 SkFAIL("Drawing outside valid vertex range."); | 332 SkFAIL("Drawing outside valid vertex range."); |
| 332 } | 333 } |
| 333 if (indexCount > 0) { | 334 if (indexCount > 0) { |
| 334 int maxIndex = startIndex + indexCount; | 335 int maxIndex = startIndex + indexCount; |
| 335 int maxValidIndex; | 336 int maxValidIndex; |
| 336 switch (geoSrc.fIndexSrc) { | 337 switch (geoSrc.fIndexSrc) { |
| 337 case kNone_GeometrySrcType: | 338 case kNone_GeometrySrcType: |
| 338 SkFAIL("Attempting to draw indexed geom without index src."); | 339 SkFAIL("Attempting to draw indexed geom without index src."); |
| 339 case kReserved_GeometrySrcType: // fallthrough | 340 case kReserved_GeometrySrcType: // fallthrough |
| 340 maxValidIndex = geoSrc.fIndexCount; | 341 maxValidIndex = geoSrc.fIndexCount; |
| 341 break; | 342 break; |
| 342 case kBuffer_GeometrySrcType: | 343 case kBuffer_GeometrySrcType: |
| 343 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); | 344 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / |
| 345 sizeof(uint16_t)); |
| 344 break; | 346 break; |
| 345 } | 347 } |
| 346 if (maxIndex > maxValidIndex) { | 348 if (maxIndex > maxValidIndex) { |
| 347 SkFAIL("Index reads outside valid index range."); | 349 SkFAIL("Index reads outside valid index range."); |
| 348 } | 350 } |
| 349 } | 351 } |
| 350 | 352 |
| 351 SkASSERT(drawState.getRenderTarget()); | 353 SkASSERT(pipelineBuilder.getRenderTarget()); |
| 352 | 354 |
| 353 if (gp) { | 355 if (gp) { |
| 354 int numTextures = gp->numTextures(); | 356 int numTextures = gp->numTextures(); |
| 355 for (int t = 0; t < numTextures; ++t) { | 357 for (int t = 0; t < numTextures; ++t) { |
| 356 GrTexture* texture = gp->texture(t); | 358 GrTexture* texture = gp->texture(t); |
| 357 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); | 359 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarge
t()); |
| 358 } | 360 } |
| 359 } | 361 } |
| 360 | 362 |
| 361 for (int s = 0; s < drawState.numColorStages(); ++s) { | 363 for (int s = 0; s < pipelineBuilder.numColorStages(); ++s) { |
| 362 const GrProcessor* effect = drawState.getColorStage(s).processor(); | 364 const GrProcessor* effect = pipelineBuilder.getColorStage(s).processor()
; |
| 363 int numTextures = effect->numTextures(); | 365 int numTextures = effect->numTextures(); |
| 364 for (int t = 0; t < numTextures; ++t) { | 366 for (int t = 0; t < numTextures; ++t) { |
| 365 GrTexture* texture = effect->texture(t); | 367 GrTexture* texture = effect->texture(t); |
| 366 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); | 368 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarge
t()); |
| 367 } | 369 } |
| 368 } | 370 } |
| 369 for (int s = 0; s < drawState.numCoverageStages(); ++s) { | 371 for (int s = 0; s < pipelineBuilder.numCoverageStages(); ++s) { |
| 370 const GrProcessor* effect = drawState.getCoverageStage(s).processor(); | 372 const GrProcessor* effect = pipelineBuilder.getCoverageStage(s).processo
r(); |
| 371 int numTextures = effect->numTextures(); | 373 int numTextures = effect->numTextures(); |
| 372 for (int t = 0; t < numTextures; ++t) { | 374 for (int t = 0; t < numTextures; ++t) { |
| 373 GrTexture* texture = effect->texture(t); | 375 GrTexture* texture = effect->texture(t); |
| 374 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); | 376 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarge
t()); |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 | 379 |
| 378 #endif | 380 #endif |
| 379 if (NULL == drawState.getRenderTarget()) { | 381 if (NULL == pipelineBuilder.getRenderTarget()) { |
| 380 return false; | 382 return false; |
| 381 } | 383 } |
| 382 return true; | 384 return true; |
| 383 } | 385 } |
| 384 | 386 |
| 385 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, | 387 bool GrDrawTarget::setupDstReadIfNecessary(GrPipelineBuilder* pipelineBuilder, |
| 386 GrDeviceCoordTexture* dstCopy, | 388 GrDeviceCoordTexture* dstCopy, |
| 387 const SkRect* drawBounds) { | 389 const SkRect* drawBounds) { |
| 388 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor())
{ | 390 if (this->caps()->dstReadInShaderSupport() || !pipelineBuilder->willEffectRe
adDstColor()) { |
| 389 return true; | 391 return true; |
| 390 } | 392 } |
| 391 SkIRect copyRect; | 393 SkIRect copyRect; |
| 392 const GrClipData* clip = this->getClip(); | 394 const GrClipData* clip = this->getClip(); |
| 393 GrRenderTarget* rt = ds->getRenderTarget(); | 395 GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
| 394 clip->getConservativeBounds(rt, ©Rect); | 396 clip->getConservativeBounds(rt, ©Rect); |
| 395 | 397 |
| 396 if (drawBounds) { | 398 if (drawBounds) { |
| 397 SkIRect drawIBounds; | 399 SkIRect drawIBounds; |
| 398 drawBounds->roundOut(&drawIBounds); | 400 drawBounds->roundOut(&drawIBounds); |
| 399 if (!copyRect.intersect(drawIBounds)) { | 401 if (!copyRect.intersect(drawIBounds)) { |
| 400 #ifdef SK_DEBUG | 402 #ifdef SK_DEBUG |
| 401 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); | 403 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI
fNecessary.\n"); |
| 402 #endif | 404 #endif |
| 403 return false; | 405 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 425 SkIPoint dstPoint = {0, 0}; | 427 SkIPoint dstPoint = {0, 0}; |
| 426 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | 428 if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 427 dstCopy->setTexture(copy); | 429 dstCopy->setTexture(copy); |
| 428 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); | 430 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
| 429 return true; | 431 return true; |
| 430 } else { | 432 } else { |
| 431 return false; | 433 return false; |
| 432 } | 434 } |
| 433 } | 435 } |
| 434 | 436 |
| 435 void GrDrawTarget::drawIndexed(GrDrawState* ds, | 437 void GrDrawTarget::drawIndexed(GrPipelineBuilder* pipelineBuilder, |
| 436 const GrGeometryProcessor* gp, | 438 const GrGeometryProcessor* gp, |
| 437 GrPrimitiveType type, | 439 GrPrimitiveType type, |
| 438 int startVertex, | 440 int startVertex, |
| 439 int startIndex, | 441 int startIndex, |
| 440 int vertexCount, | 442 int vertexCount, |
| 441 int indexCount, | 443 int indexCount, |
| 442 const SkRect* devBounds) { | 444 const SkRect* devBounds) { |
| 443 SkASSERT(ds); | 445 SkASSERT(pipelineBuilder); |
| 444 if (indexCount > 0 && | 446 if (indexCount > 0 && |
| 445 this->checkDraw(*ds, gp, type, startVertex, startIndex, vertexCount, ind
exCount)) { | 447 this->checkDraw(*pipelineBuilder, gp, type, startVertex, startIndex, ver
texCount, |
| 448 indexCount)) { |
| 446 | 449 |
| 447 // Setup clip | 450 // Setup clip |
| 448 GrScissorState scissorState; | 451 GrScissorState scissorState; |
| 449 GrDrawState::AutoRestoreEffects are; | 452 GrPipelineBuilder::AutoRestoreEffects are; |
| 450 GrDrawState::AutoRestoreStencil ars; | 453 GrPipelineBuilder::AutoRestoreStencil ars; |
| 451 if (!this->setupClip(ds, &are, &ars, &scissorState, devBounds)) { | 454 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBoun
ds)) { |
| 452 return; | 455 return; |
| 453 } | 456 } |
| 454 | 457 |
| 455 DrawInfo info; | 458 DrawInfo info; |
| 456 info.fPrimitiveType = type; | 459 info.fPrimitiveType = type; |
| 457 info.fStartVertex = startVertex; | 460 info.fStartVertex = startVertex; |
| 458 info.fStartIndex = startIndex; | 461 info.fStartIndex = startIndex; |
| 459 info.fVertexCount = vertexCount; | 462 info.fVertexCount = vertexCount; |
| 460 info.fIndexCount = indexCount; | 463 info.fIndexCount = indexCount; |
| 461 | 464 |
| 462 info.fInstanceCount = 0; | 465 info.fInstanceCount = 0; |
| 463 info.fVerticesPerInstance = 0; | 466 info.fVerticesPerInstance = 0; |
| 464 info.fIndicesPerInstance = 0; | 467 info.fIndicesPerInstance = 0; |
| 465 | 468 |
| 466 if (devBounds) { | 469 if (devBounds) { |
| 467 info.setDevBounds(*devBounds); | 470 info.setDevBounds(*devBounds); |
| 468 } | 471 } |
| 469 | 472 |
| 470 // TODO: We should continue with incorrect blending. | 473 // TODO: We should continue with incorrect blending. |
| 471 GrDeviceCoordTexture dstCopy; | 474 GrDeviceCoordTexture dstCopy; |
| 472 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) { | 475 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)
) { |
| 473 return; | 476 return; |
| 474 } | 477 } |
| 475 this->setDrawBuffers(&info, gp->getVertexStride()); | 478 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 476 | 479 |
| 477 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); | 480 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture()
? &dstCopy : NULL); |
| 478 } | 481 } |
| 479 } | 482 } |
| 480 | 483 |
| 481 void GrDrawTarget::drawNonIndexed(GrDrawState* ds, | 484 void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder, |
| 482 const GrGeometryProcessor* gp, | 485 const GrGeometryProcessor* gp, |
| 483 GrPrimitiveType type, | 486 GrPrimitiveType type, |
| 484 int startVertex, | 487 int startVertex, |
| 485 int vertexCount, | 488 int vertexCount, |
| 486 const SkRect* devBounds) { | 489 const SkRect* devBounds) { |
| 487 SkASSERT(ds); | 490 SkASSERT(pipelineBuilder); |
| 488 if (vertexCount > 0 && this->checkDraw(*ds, gp, type, startVertex, -1, verte
xCount, -1)) { | 491 if (vertexCount > 0 && this->checkDraw(*pipelineBuilder, gp, type, startVert
ex, -1, vertexCount, |
| 492 -1)) { |
| 489 | 493 |
| 490 // Setup clip | 494 // Setup clip |
| 491 GrScissorState scissorState; | 495 GrScissorState scissorState; |
| 492 GrDrawState::AutoRestoreEffects are; | 496 GrPipelineBuilder::AutoRestoreEffects are; |
| 493 GrDrawState::AutoRestoreStencil ars; | 497 GrPipelineBuilder::AutoRestoreStencil ars; |
| 494 if (!this->setupClip(ds, &are, &ars, &scissorState, devBounds)) { | 498 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBoun
ds)) { |
| 495 return; | 499 return; |
| 496 } | 500 } |
| 497 | 501 |
| 498 DrawInfo info; | 502 DrawInfo info; |
| 499 info.fPrimitiveType = type; | 503 info.fPrimitiveType = type; |
| 500 info.fStartVertex = startVertex; | 504 info.fStartVertex = startVertex; |
| 501 info.fStartIndex = 0; | 505 info.fStartIndex = 0; |
| 502 info.fVertexCount = vertexCount; | 506 info.fVertexCount = vertexCount; |
| 503 info.fIndexCount = 0; | 507 info.fIndexCount = 0; |
| 504 | 508 |
| 505 info.fInstanceCount = 0; | 509 info.fInstanceCount = 0; |
| 506 info.fVerticesPerInstance = 0; | 510 info.fVerticesPerInstance = 0; |
| 507 info.fIndicesPerInstance = 0; | 511 info.fIndicesPerInstance = 0; |
| 508 | 512 |
| 509 if (devBounds) { | 513 if (devBounds) { |
| 510 info.setDevBounds(*devBounds); | 514 info.setDevBounds(*devBounds); |
| 511 } | 515 } |
| 512 | 516 |
| 513 // TODO: We should continue with incorrect blending. | 517 // TODO: We should continue with incorrect blending. |
| 514 GrDeviceCoordTexture dstCopy; | 518 GrDeviceCoordTexture dstCopy; |
| 515 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) { | 519 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)
) { |
| 516 return; | 520 return; |
| 517 } | 521 } |
| 518 | 522 |
| 519 this->setDrawBuffers(&info, gp->getVertexStride()); | 523 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 520 | 524 |
| 521 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); | 525 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture()
? &dstCopy : NULL); |
| 522 } | 526 } |
| 523 } | 527 } |
| 524 | 528 |
| 525 static const GrStencilSettings& winding_path_stencil_settings() { | 529 static const GrStencilSettings& winding_path_stencil_settings() { |
| 526 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 530 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 527 kIncClamp_StencilOp, | 531 kIncClamp_StencilOp, |
| 528 kIncClamp_StencilOp, | 532 kIncClamp_StencilOp, |
| 529 kAlwaysIfInClip_StencilFunc, | 533 kAlwaysIfInClip_StencilFunc, |
| 530 0xFFFF, 0xFFFF, 0xFFFF); | 534 0xFFFF, 0xFFFF, 0xFFFF); |
| 531 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 535 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 550 case GrPathRendering::kWinding_FillType: | 554 case GrPathRendering::kWinding_FillType: |
| 551 *outStencilSettings = winding_path_stencil_settings(); | 555 *outStencilSettings = winding_path_stencil_settings(); |
| 552 break; | 556 break; |
| 553 case GrPathRendering::kEvenOdd_FillType: | 557 case GrPathRendering::kEvenOdd_FillType: |
| 554 *outStencilSettings = even_odd_path_stencil_settings(); | 558 *outStencilSettings = even_odd_path_stencil_settings(); |
| 555 break; | 559 break; |
| 556 } | 560 } |
| 557 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); | 561 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
| 558 } | 562 } |
| 559 | 563 |
| 560 void GrDrawTarget::stencilPath(GrDrawState* ds, | 564 void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder, |
| 561 const GrPathProcessor* pathProc, | 565 const GrPathProcessor* pathProc, |
| 562 const GrPath* path, | 566 const GrPath* path, |
| 563 GrPathRendering::FillType fill) { | 567 GrPathRendering::FillType fill) { |
| 564 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 568 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 565 SkASSERT(path); | 569 SkASSERT(path); |
| 566 SkASSERT(this->caps()->pathRenderingSupport()); | 570 SkASSERT(this->caps()->pathRenderingSupport()); |
| 567 SkASSERT(ds); | 571 SkASSERT(pipelineBuilder); |
| 568 | 572 |
| 569 // Setup clip | 573 // Setup clip |
| 570 GrScissorState scissorState; | 574 GrScissorState scissorState; |
| 571 GrDrawState::AutoRestoreEffects are; | 575 GrPipelineBuilder::AutoRestoreEffects are; |
| 572 GrDrawState::AutoRestoreStencil ars; | 576 GrPipelineBuilder::AutoRestoreStencil ars; |
| 573 if (!this->setupClip(ds, &are, &ars, &scissorState, NULL)) { | 577 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { |
| 574 return; | 578 return; |
| 575 } | 579 } |
| 576 | 580 |
| 577 // set stencil settings for path | 581 // set stencil settings for path |
| 578 GrStencilSettings stencilSettings; | 582 GrStencilSettings stencilSettings; |
| 579 this->getPathStencilSettingsForFilltype(fill, | 583 this->getPathStencilSettingsForFilltype(fill, |
| 580 ds->getRenderTarget()->getStencilBuf
fer(), | 584 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), |
| 581 &stencilSettings); | 585 &stencilSettings); |
| 582 | 586 |
| 583 this->onStencilPath(*ds, pathProc, path, scissorState, stencilSettings); | 587 this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilS
ettings); |
| 584 } | 588 } |
| 585 | 589 |
| 586 void GrDrawTarget::drawPath(GrDrawState* ds, | 590 void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder, |
| 587 const GrPathProcessor* pathProc, | 591 const GrPathProcessor* pathProc, |
| 588 const GrPath* path, | 592 const GrPath* path, |
| 589 GrPathRendering::FillType fill) { | 593 GrPathRendering::FillType fill) { |
| 590 // TODO: extract portions of checkDraw that are relevant to path rendering. | 594 // TODO: extract portions of checkDraw that are relevant to path rendering. |
| 591 SkASSERT(path); | 595 SkASSERT(path); |
| 592 SkASSERT(this->caps()->pathRenderingSupport()); | 596 SkASSERT(this->caps()->pathRenderingSupport()); |
| 593 SkASSERT(ds); | 597 SkASSERT(pipelineBuilder); |
| 594 | 598 |
| 595 SkRect devBounds = path->getBounds(); | 599 SkRect devBounds = path->getBounds(); |
| 596 pathProc->viewMatrix().mapRect(&devBounds); | 600 pathProc->viewMatrix().mapRect(&devBounds); |
| 597 | 601 |
| 598 // Setup clip | 602 // Setup clip |
| 599 GrScissorState scissorState; | 603 GrScissorState scissorState; |
| 600 GrDrawState::AutoRestoreEffects are; | 604 GrPipelineBuilder::AutoRestoreEffects are; |
| 601 GrDrawState::AutoRestoreStencil ars; | 605 GrPipelineBuilder::AutoRestoreStencil ars; |
| 602 if (!this->setupClip(ds, &are, &ars, &scissorState, &devBounds)) { | 606 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds)
) { |
| 603 return; | 607 return; |
| 604 } | 608 } |
| 605 | 609 |
| 606 // set stencil settings for path | 610 // set stencil settings for path |
| 607 GrStencilSettings stencilSettings; | 611 GrStencilSettings stencilSettings; |
| 608 this->getPathStencilSettingsForFilltype(fill, | 612 this->getPathStencilSettingsForFilltype(fill, |
| 609 ds->getRenderTarget()->getStencilBuf
fer(), | 613 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), |
| 610 &stencilSettings); | 614 &stencilSettings); |
| 611 | 615 |
| 612 GrDeviceCoordTexture dstCopy; | 616 GrDeviceCoordTexture dstCopy; |
| 613 if (!this->setupDstReadIfNecessary(ds, &dstCopy, &devBounds)) { | 617 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, &devBounds)) { |
| 614 return; | 618 return; |
| 615 } | 619 } |
| 616 | 620 |
| 617 this->onDrawPath(*ds, pathProc, path, scissorState, stencilSettings, dstCopy
.texture() ? &dstCopy : | 621 this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSett
ings, |
| 618
NULL); | 622 dstCopy.texture() ? &dstCopy : NULL); |
| 619 } | 623 } |
| 620 | 624 |
| 621 void GrDrawTarget::drawPaths(GrDrawState* ds, | 625 void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
| 622 const GrPathProcessor* pathProc, | 626 const GrPathProcessor* pathProc, |
| 623 const GrPathRange* pathRange, | 627 const GrPathRange* pathRange, |
| 624 const void* indices, | 628 const void* indices, |
| 625 PathIndexType indexType, | 629 PathIndexType indexType, |
| 626 const float transformValues[], | 630 const float transformValues[], |
| 627 PathTransformType transformType, | 631 PathTransformType transformType, |
| 628 int count, | 632 int count, |
| 629 GrPathRendering::FillType fill) { | 633 GrPathRendering::FillType fill) { |
| 630 SkASSERT(this->caps()->pathRenderingSupport()); | 634 SkASSERT(this->caps()->pathRenderingSupport()); |
| 631 SkASSERT(pathRange); | 635 SkASSERT(pathRange); |
| 632 SkASSERT(indices); | 636 SkASSERT(indices); |
| 633 SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeIn
Bytes(indexType)); | 637 SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeIn
Bytes(indexType)); |
| 634 SkASSERT(transformValues); | 638 SkASSERT(transformValues); |
| 635 SkASSERT(ds); | 639 SkASSERT(pipelineBuilder); |
| 636 | 640 |
| 637 // Setup clip | 641 // Setup clip |
| 638 GrScissorState scissorState; | 642 GrScissorState scissorState; |
| 639 GrDrawState::AutoRestoreEffects are; | 643 GrPipelineBuilder::AutoRestoreEffects are; |
| 640 GrDrawState::AutoRestoreStencil ars; | 644 GrPipelineBuilder::AutoRestoreStencil ars; |
| 641 | 645 |
| 642 if (!this->setupClip(ds, &are, &ars, &scissorState, NULL)) { | 646 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { |
| 643 return; | 647 return; |
| 644 } | 648 } |
| 645 | 649 |
| 646 // set stencil settings for path | 650 // set stencil settings for path |
| 647 GrStencilSettings stencilSettings; | 651 GrStencilSettings stencilSettings; |
| 648 this->getPathStencilSettingsForFilltype(fill, | 652 this->getPathStencilSettingsForFilltype(fill, |
| 649 ds->getRenderTarget()->getStencilBuf
fer(), | 653 pipelineBuilder->getRenderTarget()->
getStencilBuffer(), |
| 650 &stencilSettings); | 654 &stencilSettings); |
| 651 | 655 |
| 652 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt | 656 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
| 653 // instead for it to just copy the entire dst. Realistically this is a moot | 657 // instead for it to just copy the entire dst. Realistically this is a moot |
| 654 // point, because any context that supports NV_path_rendering will also | 658 // point, because any context that supports NV_path_rendering will also |
| 655 // support NV_blend_equation_advanced. | 659 // support NV_blend_equation_advanced. |
| 656 GrDeviceCoordTexture dstCopy; | 660 GrDeviceCoordTexture dstCopy; |
| 657 if (!this->setupDstReadIfNecessary(ds, &dstCopy, NULL)) { | 661 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, NULL)) { |
| 658 return; | 662 return; |
| 659 } | 663 } |
| 660 | 664 |
| 661 this->onDrawPaths(*ds, pathProc, pathRange, indices, indexType, transformVal
ues, transformType, | 665 this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType,
transformValues, |
| 662 count, scissorState, stencilSettings, dstCopy.texture() ?
&dstCopy : NULL); | 666 transformType, count, scissorState, stencilSettings, |
| 667 dstCopy.texture() ? &dstCopy : NULL); |
| 663 } | 668 } |
| 664 | 669 |
| 665 void GrDrawTarget::clear(const SkIRect* rect, | 670 void GrDrawTarget::clear(const SkIRect* rect, |
| 666 GrColor color, | 671 GrColor color, |
| 667 bool canIgnoreRect, | 672 bool canIgnoreRect, |
| 668 GrRenderTarget* renderTarget) { | 673 GrRenderTarget* renderTarget) { |
| 669 if (fCaps->useDrawInsteadOfClear()) { | 674 if (fCaps->useDrawInsteadOfClear()) { |
| 670 // This works around a driver bug with clear by drawing a rect instead. | 675 // This works around a driver bug with clear by drawing a rect instead. |
| 671 // The driver will ignore a clear if it is the only thing rendered to a | 676 // The driver will ignore a clear if it is the only thing rendered to a |
| 672 // target before the target is read. | 677 // target before the target is read. |
| 673 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he
ight()); | 678 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->he
ight()); |
| 674 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { | 679 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { |
| 675 rect = &rtRect; | 680 rect = &rtRect; |
| 676 // We first issue a discard() since that may help tilers. | 681 // We first issue a discard() since that may help tilers. |
| 677 this->discard(renderTarget); | 682 this->discard(renderTarget); |
| 678 } | 683 } |
| 679 | 684 |
| 680 GrDrawState drawState; | 685 GrPipelineBuilder pipelineBuilder; |
| 681 drawState.setRenderTarget(renderTarget); | 686 pipelineBuilder.setRenderTarget(renderTarget); |
| 682 | 687 |
| 683 this->drawSimpleRect(&drawState, color, SkMatrix::I(), *rect); | 688 this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect); |
| 684 } else { | 689 } else { |
| 685 this->onClear(rect, color, canIgnoreRect, renderTarget); | 690 this->onClear(rect, color, canIgnoreRect, renderTarget); |
| 686 } | 691 } |
| 687 } | 692 } |
| 688 | 693 |
| 689 typedef GrTraceMarkerSet::Iter TMIter; | 694 typedef GrTraceMarkerSet::Iter TMIter; |
| 690 void GrDrawTarget::saveActiveTraceMarkers() { | 695 void GrDrawTarget::saveActiveTraceMarkers() { |
| 691 if (this->caps()->gpuTracingSupport()) { | 696 if (this->caps()->gpuTracingSupport()) { |
| 692 SkASSERT(0 == fStoredTraceMarkers.count()); | 697 SkASSERT(0 == fStoredTraceMarkers.count()); |
| 693 fStoredTraceMarkers.addSet(fActiveTraceMarkers); | 698 fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 720 void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 725 void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 721 if (this->caps()->gpuTracingSupport()) { | 726 if (this->caps()->gpuTracingSupport()) { |
| 722 SkASSERT(fGpuTraceMarkerCount >= 1); | 727 SkASSERT(fGpuTraceMarkerCount >= 1); |
| 723 this->fActiveTraceMarkers.remove(*marker); | 728 this->fActiveTraceMarkers.remove(*marker); |
| 724 --fGpuTraceMarkerCount; | 729 --fGpuTraceMarkerCount; |
| 725 } | 730 } |
| 726 } | 731 } |
| 727 | 732 |
| 728 //////////////////////////////////////////////////////////////////////////////// | 733 //////////////////////////////////////////////////////////////////////////////// |
| 729 | 734 |
| 730 void GrDrawTarget::drawIndexedInstances(GrDrawState* ds, | 735 void GrDrawTarget::drawIndexedInstances(GrPipelineBuilder* pipelineBuilder, |
| 731 const GrGeometryProcessor* gp, | 736 const GrGeometryProcessor* gp, |
| 732 GrPrimitiveType type, | 737 GrPrimitiveType type, |
| 733 int instanceCount, | 738 int instanceCount, |
| 734 int verticesPerInstance, | 739 int verticesPerInstance, |
| 735 int indicesPerInstance, | 740 int indicesPerInstance, |
| 736 const SkRect* devBounds) { | 741 const SkRect* devBounds) { |
| 737 SkASSERT(ds); | 742 SkASSERT(pipelineBuilder); |
| 738 | 743 |
| 739 if (!verticesPerInstance || !indicesPerInstance) { | 744 if (!verticesPerInstance || !indicesPerInstance) { |
| 740 return; | 745 return; |
| 741 } | 746 } |
| 742 | 747 |
| 743 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst
ance; | 748 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInst
ance; |
| 744 if (!maxInstancesPerDraw) { | 749 if (!maxInstancesPerDraw) { |
| 745 return; | 750 return; |
| 746 } | 751 } |
| 747 | 752 |
| 748 // Setup clip | 753 // Setup clip |
| 749 GrScissorState scissorState; | 754 GrScissorState scissorState; |
| 750 GrDrawState::AutoRestoreEffects are; | 755 GrPipelineBuilder::AutoRestoreEffects are; |
| 751 GrDrawState::AutoRestoreStencil ars; | 756 GrPipelineBuilder::AutoRestoreStencil ars; |
| 752 if (!this->setupClip(ds, &are, &ars, &scissorState, devBounds)) { | 757 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds))
{ |
| 753 return; | 758 return; |
| 754 } | 759 } |
| 755 | 760 |
| 756 DrawInfo info; | 761 DrawInfo info; |
| 757 info.fPrimitiveType = type; | 762 info.fPrimitiveType = type; |
| 758 info.fStartIndex = 0; | 763 info.fStartIndex = 0; |
| 759 info.fStartVertex = 0; | 764 info.fStartVertex = 0; |
| 760 info.fIndicesPerInstance = indicesPerInstance; | 765 info.fIndicesPerInstance = indicesPerInstance; |
| 761 info.fVerticesPerInstance = verticesPerInstance; | 766 info.fVerticesPerInstance = verticesPerInstance; |
| 762 | 767 |
| 763 // Set the same bounds for all the draws. | 768 // Set the same bounds for all the draws. |
| 764 if (devBounds) { | 769 if (devBounds) { |
| 765 info.setDevBounds(*devBounds); | 770 info.setDevBounds(*devBounds); |
| 766 } | 771 } |
| 767 | 772 |
| 768 // TODO: We should continue with incorrect blending. | 773 // TODO: We should continue with incorrect blending. |
| 769 GrDeviceCoordTexture dstCopy; | 774 GrDeviceCoordTexture dstCopy; |
| 770 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) { | 775 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
| 771 return; | 776 return; |
| 772 } | 777 } |
| 773 | 778 |
| 774 while (instanceCount) { | 779 while (instanceCount) { |
| 775 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 780 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
| 776 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 781 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 777 info.fIndexCount = info.fInstanceCount * indicesPerInstance; | 782 info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 778 | 783 |
| 779 if (this->checkDraw(*ds, | 784 if (this->checkDraw(*pipelineBuilder, |
| 780 gp, | 785 gp, |
| 781 type, | 786 type, |
| 782 info.fStartVertex, | 787 info.fStartVertex, |
| 783 info.fStartIndex, | 788 info.fStartIndex, |
| 784 info.fVertexCount, | 789 info.fVertexCount, |
| 785 info.fIndexCount)) { | 790 info.fIndexCount)) { |
| 786 this->setDrawBuffers(&info, gp->getVertexStride()); | 791 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 787 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCo
py : NULL); | 792 this->onDraw(*pipelineBuilder, gp, info, scissorState, |
| 793 dstCopy.texture() ? &dstCopy : NULL); |
| 788 } | 794 } |
| 789 info.fStartVertex += info.fVertexCount; | 795 info.fStartVertex += info.fVertexCount; |
| 790 instanceCount -= info.fInstanceCount; | 796 instanceCount -= info.fInstanceCount; |
| 791 } | 797 } |
| 792 } | 798 } |
| 793 | 799 |
| 794 //////////////////////////////////////////////////////////////////////////////// | 800 //////////////////////////////////////////////////////////////////////////////// |
| 795 | 801 |
| 796 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( | 802 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 797 GrDrawTarget* target, | 803 GrDrawTarget* target, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 return true; | 937 return true; |
| 932 } | 938 } |
| 933 | 939 |
| 934 GrRenderTarget* rt = dst->asRenderTarget(); | 940 GrRenderTarget* rt = dst->asRenderTarget(); |
| 935 GrTexture* tex = src->asTexture(); | 941 GrTexture* tex = src->asTexture(); |
| 936 | 942 |
| 937 if ((dst == src) || !rt || !tex) { | 943 if ((dst == src) || !rt || !tex) { |
| 938 return false; | 944 return false; |
| 939 } | 945 } |
| 940 | 946 |
| 941 GrDrawState drawState; | 947 GrPipelineBuilder pipelineBuilder; |
| 942 drawState.setRenderTarget(rt); | 948 pipelineBuilder.setRenderTarget(rt); |
| 943 SkMatrix matrix; | 949 SkMatrix matrix; |
| 944 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX)
, | 950 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX)
, |
| 945 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY))
; | 951 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY))
; |
| 946 matrix.postIDiv(tex->width(), tex->height()); | 952 matrix.postIDiv(tex->width(), tex->height()); |
| 947 drawState.addColorTextureProcessor(tex, matrix); | 953 pipelineBuilder.addColorTextureProcessor(tex, matrix); |
| 948 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, | 954 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 949 clippedDstPoint.fY, | 955 clippedDstPoint.fY, |
| 950 clippedSrcRect.width(), | 956 clippedSrcRect.width(), |
| 951 clippedSrcRect.height()); | 957 clippedSrcRect.height()); |
| 952 this->drawSimpleRect(&drawState, GrColor_WHITE, SkMatrix::I(), dstRect); | 958 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect
); |
| 953 return true; | 959 return true; |
| 954 } | 960 } |
| 955 | 961 |
| 956 bool GrDrawTarget::canCopySurface(const GrSurface* dst, | 962 bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 957 const GrSurface* src, | 963 const GrSurface* src, |
| 958 const SkIRect& srcRect, | 964 const SkIRect& srcRect, |
| 959 const SkIPoint& dstPoint) { | 965 const SkIPoint& dstPoint) { |
| 960 SkASSERT(dst); | 966 SkASSERT(dst); |
| 961 SkASSERT(src); | 967 SkASSERT(src); |
| 962 | 968 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 static int32_t gUniqueID = SK_InvalidUniqueID; | 1209 static int32_t gUniqueID = SK_InvalidUniqueID; |
| 1204 uint32_t id; | 1210 uint32_t id; |
| 1205 do { | 1211 do { |
| 1206 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); | 1212 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 1207 } while (id == SK_InvalidUniqueID); | 1213 } while (id == SK_InvalidUniqueID); |
| 1208 return id; | 1214 return id; |
| 1209 } | 1215 } |
| 1210 | 1216 |
| 1211 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1217 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 1212 | 1218 |
| 1213 bool GrClipTarget::setupClip(GrDrawState* ds, | 1219 bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder, |
| 1214 GrDrawState::AutoRestoreEffects* are, | 1220 GrPipelineBuilder::AutoRestoreEffects* are, |
| 1215 GrDrawState::AutoRestoreStencil* ars, | 1221 GrPipelineBuilder::AutoRestoreStencil* ars, |
| 1216 GrScissorState* scissorState, | 1222 GrScissorState* scissorState, |
| 1217 const SkRect* devBounds) { | 1223 const SkRect* devBounds) { |
| 1218 return fClipMaskManager.setupClipping(ds, | 1224 return fClipMaskManager.setupClipping(pipelineBuilder, |
| 1219 are, | 1225 are, |
| 1220 ars, | 1226 ars, |
| 1221 scissorState, | 1227 scissorState, |
| 1222 this->getClip(), | 1228 this->getClip(), |
| 1223 devBounds); | 1229 devBounds); |
| 1224 } | 1230 } |
| OLD | NEW |