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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 desc.fHeight = copyRect.height(); | 97 desc.fHeight = copyRect.height(); |
98 | 98 |
99 SkAutoTUnref<GrTexture> copy( | 99 SkAutoTUnref<GrTexture> copy( |
100 fResourceProvider->refScratchTexture(desc, GrTextureProvider::kApprox_Sc
ratchTexMatch)); | 100 fResourceProvider->refScratchTexture(desc, GrTextureProvider::kApprox_Sc
ratchTexMatch)); |
101 | 101 |
102 if (!copy) { | 102 if (!copy) { |
103 SkDebugf("Failed to create temporary copy of destination texture.\n"); | 103 SkDebugf("Failed to create temporary copy of destination texture.\n"); |
104 return false; | 104 return false; |
105 } | 105 } |
106 SkIPoint dstPoint = {0, 0}; | 106 SkIPoint dstPoint = {0, 0}; |
107 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | 107 this->copySurface(copy, rt, copyRect, dstPoint); |
108 dstTexture->setTexture(copy); | 108 dstTexture->setTexture(copy); |
109 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); | 109 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
110 return true; | 110 return true; |
111 } else { | |
112 return false; | |
113 } | |
114 } | 111 } |
115 | 112 |
116 void GrDrawTarget::flush() { | 113 void GrDrawTarget::flush() { |
117 if (fFlushing) { | 114 if (fFlushing) { |
118 return; | 115 return; |
119 } | 116 } |
120 fFlushing = true; | 117 fFlushing = true; |
121 | 118 |
122 this->getGpu()->saveActiveTraceMarkers(); | 119 this->getGpu()->saveActiveTraceMarkers(); |
123 | 120 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { | 423 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
427 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clipped
DstPoint->fY; | 424 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clipped
DstPoint->fY; |
428 } | 425 } |
429 | 426 |
430 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or | 427 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or |
431 // dst bounds. | 428 // dst bounds. |
432 return !clippedSrcRect->isEmpty(); | 429 return !clippedSrcRect->isEmpty(); |
433 } | 430 } |
434 } | 431 } |
435 | 432 |
436 bool GrDrawTarget::copySurface(GrSurface* dst, | 433 void GrDrawTarget::copySurface(GrSurface* dst, |
437 GrSurface* src, | 434 GrSurface* src, |
438 const SkIRect& srcRect, | 435 const SkIRect& srcRect, |
439 const SkIPoint& dstPoint) { | 436 const SkIPoint& dstPoint) { |
440 SkASSERT(dst); | 437 SkASSERT(dst); |
441 SkASSERT(src); | 438 SkASSERT(src); |
442 | 439 |
443 SkIRect clippedSrcRect; | 440 SkIRect clippedSrcRect; |
444 SkIPoint clippedDstPoint; | 441 SkIPoint clippedDstPoint; |
445 // If the rect is outside the src or dst then we've already succeeded. | 442 // If the rect is outside the src or dst then we've already succeeded. |
446 if (!clip_srcrect_and_dstpoint(dst, | 443 if (!clip_srcrect_and_dstpoint(dst, |
447 src, | 444 src, |
448 srcRect, | 445 srcRect, |
449 dstPoint, | 446 dstPoint, |
450 &clippedSrcRect, | 447 &clippedSrcRect, |
451 &clippedDstPoint)) { | 448 &clippedDstPoint)) { |
452 return true; | 449 return; |
453 } | 450 } |
454 | 451 |
455 if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint
)) { | 452 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
456 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); | |
457 return true; | |
458 } | |
459 | |
460 GrRenderTarget* rt = dst->asRenderTarget(); | |
461 GrTexture* tex = src->asTexture(); | |
462 | |
463 if ((dst == src) || !rt || !tex) { | |
464 return false; | |
465 } | |
466 | |
467 GrPipelineBuilder pipelineBuilder; | |
468 pipelineBuilder.setRenderTarget(rt); | |
469 SkMatrix matrix; | |
470 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX)
, | |
471 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY))
; | |
472 matrix.postIDiv(tex->width(), tex->height()); | |
473 pipelineBuilder.addColorTextureProcessor(tex, matrix); | |
474 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, | |
475 clippedDstPoint.fY, | |
476 clippedSrcRect.width(), | |
477 clippedSrcRect.height()); | |
478 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect
); | |
479 return true; | |
480 } | |
481 | |
482 bool GrDrawTarget::canCopySurface(const GrSurface* dst, | |
483 const GrSurface* src, | |
484 const SkIRect& srcRect, | |
485 const SkIPoint& dstPoint) { | |
486 SkASSERT(dst); | |
487 SkASSERT(src); | |
488 | |
489 SkIRect clippedSrcRect; | |
490 SkIPoint clippedDstPoint; | |
491 // If the rect is outside the src or dst then we're guaranteed success | |
492 if (!clip_srcrect_and_dstpoint(dst, | |
493 src, | |
494 srcRect, | |
495 dstPoint, | |
496 &clippedSrcRect, | |
497 &clippedDstPoint)) { | |
498 return true; | |
499 } | |
500 return ((dst != src) && dst->asRenderTarget() && src->asTexture()) || | |
501 this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPo
int); | |
502 } | 453 } |
503 | 454 |
504 void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo, | 455 void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo, |
505 GrPipeline* pipeline) { | 456 GrPipeline* pipeline) { |
506 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder, | 457 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder, |
507 pipelineInfo.fColorPOI, | 458 pipelineInfo.fColorPOI, |
508 pipelineInfo.fCoveragePOI, | 459 pipelineInfo.fCoveragePOI, |
509 *this->caps(), | 460 *this->caps(), |
510 *pipelineInfo.fScissor, | 461 *pipelineInfo.fScissor, |
511 &pipelineInfo.fDstTexture)); | 462 &pipelineInfo.fDstTexture)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 ars, | 511 ars, |
561 scissorState, | 512 scissorState, |
562 devBounds); | 513 devBounds); |
563 } | 514 } |
564 | 515 |
565 void GrClipTarget::purgeResources() { | 516 void GrClipTarget::purgeResources() { |
566 // The clip mask manager can rebuild all its clip masks so just | 517 // The clip mask manager can rebuild all its clip masks so just |
567 // get rid of them all. | 518 // get rid of them all. |
568 fClipMaskManager->purgeResources(); | 519 fClipMaskManager->purgeResources(); |
569 }; | 520 }; |
OLD | NEW |