bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrCopySurfaceBatch_DEFINED |
| 9 | #define GrCopySurfaceBatch_DEFINED |
| 10 | |
| 11 | #include "GrBatch.h" |
| 12 | #include "GrBatchFlushState.h" |
| 13 | #include "GrGpu.h" |
| 14 | #include "GrRenderTarget.h" |
| 15 | |
| 16 | class GrCopySurfaceBatch final : public GrBatch { |
| 17 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 18 | DEFINE_BATCH_CLASS_ID |
| 19 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 20 | /** This should not really be exposed as Create() will apply this clipping, but there is |
| 21 | * currently a workaround in GrContext::copySurface() for non-render target dsts that relies |
| 22 | * on it. */ |
| 23 | static bool ClipSrcRectAndDstPoint(const GrSurface* dst, |
| 24 | const GrSurface* src, |
| 25 | const SkIRect& srcRect, |
| 26 | const SkIPoint& dstPoint, |
| 27 | SkIRect* clippedSrcRect, |
| 28 | SkIPoint* clippedDstPoint); |
| 29 | |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 30 | static GrBatch* Create(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 31 | const SkIPoint& dstPoint); |
| 32 | |
| 33 | const char* name() const override { return "CopySurface"; } |
| 34 | |
| 35 | uint32_t renderTargetUniqueID() const override { |
| 36 | GrRenderTarget* rt = fDst.get()->asRenderTarget(); |
| 37 | return rt ? rt->getUniqueID() : 0; |
| 38 | } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 39 | GrRenderTarget* renderTarget() const override { return fDst.get()->asRenderTarget(); } |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 40 | |
| 41 | SkString dumpInfo() const override { |
| 42 | SkString string; |
| 43 | string.printf("SRC: 0x%p, DST: 0x%p, SRECT: [L: %d, T: %d, R: %d, B: %d], " |
| 44 | "DPT:[X: %d, Y: %d]", |
| 45 | fDst.get(), fSrc.get(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, |
| 46 | fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY); |
| 47 | return string; |
| 48 | } |
| 49 | |
| 50 | private: |
| 51 | GrCopySurfaceBatch(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 52 | const SkIPoint& dstPoint) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 53 | : INHERITED(ClassID()) |
| 54 | , fDst(dst) |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 55 | , fSrc(src) |
| 56 | , fSrcRect(srcRect) |
| 57 | , fDstPoint(dstPoint) { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 58 | fBounds = SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY), |
| 59 | SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height())); |
| 60 | } |
| 61 | |
| 62 | bool onCombineIfPossible(GrBatch* that, const GrCaps& caps) override { return false; } |
| 63 | |
| 64 | void onPrepare(GrBatchFlushState*) override {} |
| 65 | |
| 66 | void onDraw(GrBatchFlushState* state) override { |
| 67 | state->gpu()->copySurface(fDst.get(), fSrc.get(), fSrcRect, fDstPoint); |
| 68 | } |
| 69 | |
| 70 | GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
| 71 | GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
| 72 | SkIRect fSrcRect; |
| 73 | SkIPoint fDstPoint; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 74 | |
| 75 | typedef GrBatch INHERITED; |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | #endif |