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 #include "GrDrawTarget.h" |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 desc.fHeight = copyRect.height(); | 93 desc.fHeight = copyRect.height(); |
94 | 94 |
95 SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(
desc, | 95 SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(
desc, |
96 GrTextureProvider::kApprox_ScratchTexMatch)); | 96 GrTextureProvider::kApprox_ScratchTexMatch)); |
97 | 97 |
98 if (!copy) { | 98 if (!copy) { |
99 SkDebugf("Failed to create temporary copy of destination texture.\n"); | 99 SkDebugf("Failed to create temporary copy of destination texture.\n"); |
100 return false; | 100 return false; |
101 } | 101 } |
102 SkIPoint dstPoint = {0, 0}; | 102 SkIPoint dstPoint = {0, 0}; |
103 this->copySurface(copy, rt, copyRect, dstPoint); | 103 if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
104 dstCopy->setTexture(copy); | 104 dstCopy->setTexture(copy); |
105 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); | 105 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
106 return true; | 106 return true; |
| 107 } else { |
| 108 return false; |
| 109 } |
107 } | 110 } |
108 | 111 |
109 void GrDrawTarget::flush() { | 112 void GrDrawTarget::flush() { |
110 if (fFlushing) { | 113 if (fFlushing) { |
111 return; | 114 return; |
112 } | 115 } |
113 fFlushing = true; | 116 fFlushing = true; |
114 | 117 |
115 this->getGpu()->saveActiveTraceMarkers(); | 118 this->getGpu()->saveActiveTraceMarkers(); |
116 | 119 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { | 414 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
412 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clipped
DstPoint->fY; | 415 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clipped
DstPoint->fY; |
413 } | 416 } |
414 | 417 |
415 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or | 418 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or |
416 // dst bounds. | 419 // dst bounds. |
417 return !clippedSrcRect->isEmpty(); | 420 return !clippedSrcRect->isEmpty(); |
418 } | 421 } |
419 } | 422 } |
420 | 423 |
421 void GrDrawTarget::copySurface(GrSurface* dst, | 424 bool GrDrawTarget::copySurface(GrSurface* dst, |
422 GrSurface* src, | 425 GrSurface* src, |
423 const SkIRect& srcRect, | 426 const SkIRect& srcRect, |
424 const SkIPoint& dstPoint) { | 427 const SkIPoint& dstPoint) { |
425 SkASSERT(dst); | 428 SkASSERT(dst); |
426 SkASSERT(src); | 429 SkASSERT(src); |
427 | 430 |
428 SkIRect clippedSrcRect; | 431 SkIRect clippedSrcRect; |
429 SkIPoint clippedDstPoint; | 432 SkIPoint clippedDstPoint; |
430 // If the rect is outside the src or dst then we've already succeeded. | 433 // If the rect is outside the src or dst then we've already succeeded. |
431 if (!clip_srcrect_and_dstpoint(dst, | 434 if (!clip_srcrect_and_dstpoint(dst, |
432 src, | 435 src, |
433 srcRect, | 436 srcRect, |
434 dstPoint, | 437 dstPoint, |
435 &clippedSrcRect, | 438 &clippedSrcRect, |
436 &clippedDstPoint)) { | 439 &clippedDstPoint)) { |
437 return; | 440 return true; |
438 } | 441 } |
439 | 442 |
440 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); | 443 if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint
)) { |
| 444 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
| 445 return true; |
| 446 } |
| 447 |
| 448 GrRenderTarget* rt = dst->asRenderTarget(); |
| 449 GrTexture* tex = src->asTexture(); |
| 450 |
| 451 if ((dst == src) || !rt || !tex) { |
| 452 return false; |
| 453 } |
| 454 |
| 455 GrPipelineBuilder pipelineBuilder; |
| 456 pipelineBuilder.setRenderTarget(rt); |
| 457 SkMatrix matrix; |
| 458 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX)
, |
| 459 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY))
; |
| 460 matrix.postIDiv(tex->width(), tex->height()); |
| 461 pipelineBuilder.addColorTextureProcessor(tex, matrix); |
| 462 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 463 clippedDstPoint.fY, |
| 464 clippedSrcRect.width(), |
| 465 clippedSrcRect.height()); |
| 466 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect
); |
| 467 return true; |
| 468 } |
| 469 |
| 470 bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 471 const GrSurface* src, |
| 472 const SkIRect& srcRect, |
| 473 const SkIPoint& dstPoint) { |
| 474 SkASSERT(dst); |
| 475 SkASSERT(src); |
| 476 |
| 477 SkIRect clippedSrcRect; |
| 478 SkIPoint clippedDstPoint; |
| 479 // If the rect is outside the src or dst then we're guaranteed success |
| 480 if (!clip_srcrect_and_dstpoint(dst, |
| 481 src, |
| 482 srcRect, |
| 483 dstPoint, |
| 484 &clippedSrcRect, |
| 485 &clippedDstPoint)) { |
| 486 return true; |
| 487 } |
| 488 return ((dst != src) && dst->asRenderTarget() && src->asTexture()) || |
| 489 this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPo
int); |
441 } | 490 } |
442 | 491 |
443 void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo, | 492 void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo, |
444 GrPipeline* pipeline) { | 493 GrPipeline* pipeline) { |
445 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder, | 494 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder, |
446 pipelineInfo.fColorPOI, | 495 pipelineInfo.fColorPOI, |
447 pipelineInfo.fCoveragePOI, | 496 pipelineInfo.fCoveragePOI, |
448 *this->caps(), | 497 *this->caps(), |
449 *pipelineInfo.fScissor, | 498 *pipelineInfo.fScissor, |
450 &pipelineInfo.fDstCopy)); | 499 &pipelineInfo.fDstCopy)); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 GrPipelineBuilder::AutoRestoreFragmentProcessors* a
rfp, | 778 GrPipelineBuilder::AutoRestoreFragmentProcessors* a
rfp, |
730 GrPipelineBuilder::AutoRestoreStencil* ars, | 779 GrPipelineBuilder::AutoRestoreStencil* ars, |
731 GrScissorState* scissorState, | 780 GrScissorState* scissorState, |
732 const SkRect* devBounds) { | 781 const SkRect* devBounds) { |
733 return fClipMaskManager.setupClipping(pipelineBuilder, | 782 return fClipMaskManager.setupClipping(pipelineBuilder, |
734 arfp, | 783 arfp, |
735 ars, | 784 ars, |
736 scissorState, | 785 scissorState, |
737 devBounds); | 786 devBounds); |
738 } | 787 } |
OLD | NEW |