Chromium Code Reviews| 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 #include "GrDrawTarget.h" | |
| 9 | 10 |
| 10 | 11 #include "GrBatch.h" |
| 11 #include "GrDrawTarget.h" | |
| 12 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
| 14 #include "GrPath.h" | 14 #include "GrPath.h" |
| 15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
| 16 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
| 17 #include "GrTemplates.h" | 17 #include "GrTemplates.h" |
| 18 #include "GrTexture.h" | 18 #include "GrTexture.h" |
| 19 #include "GrVertexBuffer.h" | 19 #include "GrVertexBuffer.h" |
| 20 | 20 |
| 21 #include "SkStrokeRec.h" | 21 #include "SkStrokeRec.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 SkIPoint dstPoint = {0, 0}; | 426 SkIPoint dstPoint = {0, 0}; |
| 427 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | 427 if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 428 dstCopy->setTexture(copy); | 428 dstCopy->setTexture(copy); |
| 429 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); | 429 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
| 430 return true; | 430 return true; |
| 431 } else { | 431 } else { |
| 432 return false; | 432 return false; |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 // TODO disgusting hack | |
| 437 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, | |
| 438 const GrBatch* batch, | |
| 439 GrDeviceCoordTexture* dstCopy, | |
| 440 const SkRect* drawBounds) { | |
| 441 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor(ba tch)) { | |
| 442 return true; | |
| 443 } | |
| 444 SkIRect copyRect; | |
| 445 const GrClipData* clip = this->getClip(); | |
| 446 GrRenderTarget* rt = ds->getRenderTarget(); | |
| 447 clip->getConservativeBounds(rt, ©Rect); | |
| 448 | |
| 449 if (drawBounds) { | |
| 450 SkIRect drawIBounds; | |
| 451 drawBounds->roundOut(&drawIBounds); | |
| 452 if (!copyRect.intersect(drawIBounds)) { | |
| 453 #ifdef SK_DEBUG | |
| 454 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadI fNecessary.\n"); | |
| 455 #endif | |
| 456 return false; | |
| 457 } | |
| 458 } else { | |
| 459 #ifdef SK_DEBUG | |
| 460 //SkDebugf("No dev bounds when dst copy is made.\n"); | |
| 461 #endif | |
| 462 } | |
| 463 | |
| 464 // MSAA consideration: When there is support for reading MSAA samples in the shader we could | |
| 465 // have per-sample dst values by making the copy multisampled. | |
| 466 GrSurfaceDesc desc; | |
| 467 this->initCopySurfaceDstDesc(rt, &desc); | |
| 468 desc.fWidth = copyRect.width(); | |
| 469 desc.fHeight = copyRect.height(); | |
| 470 | |
| 471 SkAutoTUnref<GrTexture> copy( | |
| 472 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); | |
| 473 | |
| 474 if (!copy) { | |
| 475 SkDebugf("Failed to create temporary copy of destination texture.\n"); | |
| 476 return false; | |
| 477 } | |
| 478 SkIPoint dstPoint = {0, 0}; | |
| 479 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | |
| 480 dstCopy->setTexture(copy); | |
| 481 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); | |
| 482 return true; | |
| 483 } else { | |
| 484 return false; | |
| 485 } | |
| 486 } | |
| 487 | |
| 436 void GrDrawTarget::drawIndexed(GrDrawState* ds, | 488 void GrDrawTarget::drawIndexed(GrDrawState* ds, |
| 437 const GrGeometryProcessor* gp, | 489 const GrGeometryProcessor* gp, |
| 438 GrPrimitiveType type, | 490 GrPrimitiveType type, |
| 439 int startVertex, | 491 int startVertex, |
| 440 int startIndex, | 492 int startIndex, |
| 441 int vertexCount, | 493 int vertexCount, |
| 442 int indexCount, | 494 int indexCount, |
| 443 const SkRect* devBounds) { | 495 const SkRect* devBounds) { |
| 444 SkASSERT(ds); | 496 SkASSERT(ds); |
| 445 if (indexCount > 0 && | 497 if (indexCount > 0 && |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 if (!this->setupDstReadIfNecessary(ds, gp, &dstCopy, devBounds)) { | 568 if (!this->setupDstReadIfNecessary(ds, gp, &dstCopy, devBounds)) { |
| 517 return; | 569 return; |
| 518 } | 570 } |
| 519 | 571 |
| 520 this->setDrawBuffers(&info, gp->getVertexStride()); | 572 this->setDrawBuffers(&info, gp->getVertexStride()); |
| 521 | 573 |
| 522 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL); | 574 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL); |
| 523 } | 575 } |
| 524 } | 576 } |
| 525 | 577 |
| 578 | |
| 579 void GrDrawTarget::batchDraw(GrDrawState* ds, | |
| 580 GrBatch* batch, | |
| 581 GrPrimitiveType type, | |
| 582 const SkRect* devBounds) { | |
| 583 SkASSERT(ds); | |
| 584 // TODO some kind of checkdraw, but not at this level | |
| 585 | |
| 586 // Setup clip | |
| 587 GrScissorState scissorState; | |
| 588 GrDrawState::AutoRestoreEffects are; | |
| 589 GrDrawState::AutoRestoreStencil ars; | |
| 590 if (!this->setupClip(ds, &are, &ars, &scissorState, devBounds)) { | |
| 591 return; | |
| 592 } | |
| 593 | |
| 594 // TODO: We should continue with incorrect blending. | |
|
bsalomon
2015/01/20 16:14:02
let's just remove the todo... we will probably nev
| |
| 595 GrDeviceCoordTexture dstCopy; | |
| 596 if (!this->setupDstReadIfNecessary(ds, batch, &dstCopy, devBounds)) { | |
| 597 return; | |
| 598 } | |
| 599 | |
| 600 this->onBatchDraw(batch, *ds, type, scissorState, dstCopy.texture() ? &dstCo py : NULL); | |
| 601 } | |
| 602 | |
| 526 static const GrStencilSettings& winding_path_stencil_settings() { | 603 static const GrStencilSettings& winding_path_stencil_settings() { |
| 527 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 604 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 528 kIncClamp_StencilOp, | 605 kIncClamp_StencilOp, |
| 529 kIncClamp_StencilOp, | 606 kIncClamp_StencilOp, |
| 530 kAlwaysIfInClip_StencilFunc, | 607 kAlwaysIfInClip_StencilFunc, |
| 531 0xFFFF, 0xFFFF, 0xFFFF); | 608 0xFFFF, 0xFFFF, 0xFFFF); |
| 532 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 609 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 533 } | 610 } |
| 534 | 611 |
| 535 static const GrStencilSettings& even_odd_path_stencil_settings() { | 612 static const GrStencilSettings& even_odd_path_stencil_settings() { |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1216 GrDrawState::AutoRestoreStencil* ars, | 1293 GrDrawState::AutoRestoreStencil* ars, |
| 1217 GrScissorState* scissorState, | 1294 GrScissorState* scissorState, |
| 1218 const SkRect* devBounds) { | 1295 const SkRect* devBounds) { |
| 1219 return fClipMaskManager.setupClipping(ds, | 1296 return fClipMaskManager.setupClipping(ds, |
| 1220 are, | 1297 are, |
| 1221 ars, | 1298 ars, |
| 1222 scissorState, | 1299 scissorState, |
| 1223 this->getClip(), | 1300 this->getClip(), |
| 1224 devBounds); | 1301 devBounds); |
| 1225 } | 1302 } |
| OLD | NEW |