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 |
11 #include "GrCaps.h" | 11 #include "GrCaps.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "GrPath.h" | 13 #include "GrPath.h" |
14 #include "GrPipeline.h" | 14 #include "GrPipeline.h" |
15 #include "GrMemoryPool.h" | 15 #include "GrMemoryPool.h" |
16 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
18 #include "GrRenderTargetPriv.h" | 18 #include "GrRenderTargetPriv.h" |
19 #include "GrSurfacePriv.h" | 19 #include "GrSurfacePriv.h" |
20 #include "GrTexture.h" | 20 #include "GrTexture.h" |
21 #include "GrVertexBuffer.h" | 21 #include "GrVertexBuffer.h" |
22 | 22 |
23 #include "batches/GrClearBatch.h" | 23 #include "batches/GrClearBatch.h" |
| 24 #include "batches/GrCopySurfaceBatch.h" |
24 #include "batches/GrDiscardBatch.h" | 25 #include "batches/GrDiscardBatch.h" |
25 #include "batches/GrDrawBatch.h" | 26 #include "batches/GrDrawBatch.h" |
26 #include "batches/GrRectBatchFactory.h" | 27 #include "batches/GrRectBatchFactory.h" |
27 | 28 |
28 #include "SkStrokeRec.h" | 29 #include "SkStrokeRec.h" |
29 | 30 |
30 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
31 | 32 |
32 GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) | 33 GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) |
33 : fGpu(SkRef(gpu)) | 34 : fGpu(SkRef(gpu)) |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 392 void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
392 if (this->caps()->gpuTracingSupport()) { | 393 if (this->caps()->gpuTracingSupport()) { |
393 SkASSERT(fGpuTraceMarkerCount >= 1); | 394 SkASSERT(fGpuTraceMarkerCount >= 1); |
394 this->fActiveTraceMarkers.remove(*marker); | 395 this->fActiveTraceMarkers.remove(*marker); |
395 --fGpuTraceMarkerCount; | 396 --fGpuTraceMarkerCount; |
396 } | 397 } |
397 } | 398 } |
398 | 399 |
399 //////////////////////////////////////////////////////////////////////////////// | 400 //////////////////////////////////////////////////////////////////////////////// |
400 | 401 |
401 namespace { | |
402 // returns true if the read/written rect intersects the src/dst and false if not
. | |
403 bool clip_srcrect_and_dstpoint(const GrSurface* dst, | |
404 const GrSurface* src, | |
405 const SkIRect& srcRect, | |
406 const SkIPoint& dstPoint, | |
407 SkIRect* clippedSrcRect, | |
408 SkIPoint* clippedDstPoint) { | |
409 *clippedSrcRect = srcRect; | |
410 *clippedDstPoint = dstPoint; | |
411 | |
412 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary | |
413 if (clippedSrcRect->fLeft < 0) { | |
414 clippedDstPoint->fX -= clippedSrcRect->fLeft; | |
415 clippedSrcRect->fLeft = 0; | |
416 } | |
417 if (clippedDstPoint->fX < 0) { | |
418 clippedSrcRect->fLeft -= clippedDstPoint->fX; | |
419 clippedDstPoint->fX = 0; | |
420 } | |
421 | |
422 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary | |
423 if (clippedSrcRect->fTop < 0) { | |
424 clippedDstPoint->fY -= clippedSrcRect->fTop; | |
425 clippedSrcRect->fTop = 0; | |
426 } | |
427 if (clippedDstPoint->fY < 0) { | |
428 clippedSrcRect->fTop -= clippedDstPoint->fY; | |
429 clippedDstPoint->fY = 0; | |
430 } | |
431 | |
432 // clip the right edge to the src and dst bounds. | |
433 if (clippedSrcRect->fRight > src->width()) { | |
434 clippedSrcRect->fRight = src->width(); | |
435 } | |
436 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { | |
437 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedD
stPoint->fX; | |
438 } | |
439 | |
440 // clip the bottom edge to the src and dst bounds. | |
441 if (clippedSrcRect->fBottom > src->height()) { | |
442 clippedSrcRect->fBottom = src->height(); | |
443 } | |
444 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { | |
445 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clipped
DstPoint->fY; | |
446 } | |
447 | |
448 // The above clipping steps may have inverted the rect if it didn't intersec
t either the src or | |
449 // dst bounds. | |
450 return !clippedSrcRect->isEmpty(); | |
451 } | |
452 } | |
453 | |
454 void GrDrawTarget::copySurface(GrSurface* dst, | 402 void GrDrawTarget::copySurface(GrSurface* dst, |
455 GrSurface* src, | 403 GrSurface* src, |
456 const SkIRect& srcRect, | 404 const SkIRect& srcRect, |
457 const SkIPoint& dstPoint) { | 405 const SkIPoint& dstPoint) { |
458 SkASSERT(dst); | 406 GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
459 SkASSERT(src); | 407 if (batch) { |
460 | 408 this->onDrawBatch(batch); |
461 SkIRect clippedSrcRect; | 409 batch->unref(); |
462 SkIPoint clippedDstPoint; | |
463 // If the rect is outside the src or dst then we've already succeeded. | |
464 if (!clip_srcrect_and_dstpoint(dst, | |
465 src, | |
466 srcRect, | |
467 dstPoint, | |
468 &clippedSrcRect, | |
469 &clippedDstPoint)) { | |
470 return; | |
471 } | 410 } |
472 | |
473 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); | |
474 } | 411 } |
475 | 412 |
476 /////////////////////////////////////////////////////////////////////////////// | 413 /////////////////////////////////////////////////////////////////////////////// |
477 | 414 |
478 GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilde
r, | 415 GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilde
r, |
479 const GrScissorState* scissor, | 416 const GrScissorState* scissor, |
480 const GrPrimitiveProcessor* primProc, | 417 const GrPrimitiveProcessor* primProc, |
481 const SkRect* devBounds, | 418 const SkRect* devBounds, |
482 GrDrawTarget* target) { | 419 GrDrawTarget* target) { |
483 fArgs.fPipelineBuilder = pipelineBuilder; | 420 fArgs.fPipelineBuilder = pipelineBuilder; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 // The clip mask manager can rebuild all its clip masks so just | 468 // The clip mask manager can rebuild all its clip masks so just |
532 // get rid of them all. | 469 // get rid of them all. |
533 fClipMaskManager->purgeResources(); | 470 fClipMaskManager->purgeResources(); |
534 }; | 471 }; |
535 | 472 |
536 void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 473 void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
537 GrBatch* batch = SkNEW_ARGS(GrClearStencilClipBatch, (rect, insideClip, rt))
; | 474 GrBatch* batch = SkNEW_ARGS(GrClearStencilClipBatch, (rect, insideClip, rt))
; |
538 this->onDrawBatch(batch); | 475 this->onDrawBatch(batch); |
539 batch->unref(); | 476 batch->unref(); |
540 } | 477 } |
OLD | NEW |