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 | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 20 | static GrBatch* Create(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 21 | const SkIPoint& dstPoint); |
| 22 | |
| 23 | const char* name() const override { return "CopySurface"; } |
| 24 | |
| 25 | uint32_t renderTargetUniqueID() const override { |
| 26 | GrRenderTarget* rt = fDst.get()->asRenderTarget(); |
| 27 | return rt ? rt->getUniqueID() : 0; |
| 28 | } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame^] | 29 | GrRenderTarget* renderTarget() const override { return fDst.get()->asRenderTarget(); } |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 30 | |
| 31 | SkString dumpInfo() const override { |
| 32 | SkString string; |
| 33 | string.printf("SRC: 0x%p, DST: 0x%p, SRECT: [L: %d, T: %d, R: %d, B: %d], " |
| 34 | "DPT:[X: %d, Y: %d]", |
| 35 | fDst.get(), fSrc.get(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, |
| 36 | fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY); |
| 37 | return string; |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | GrCopySurfaceBatch(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 42 | const SkIPoint& dstPoint) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 43 | : INHERITED(ClassID()) |
| 44 | , fDst(dst) |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 45 | , fSrc(src) |
| 46 | , fSrcRect(srcRect) |
| 47 | , fDstPoint(dstPoint) { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 48 | fBounds = SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY), |
| 49 | SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height())); |
| 50 | } |
| 51 | |
| 52 | bool onCombineIfPossible(GrBatch* that, const GrCaps& caps) override { return false; } |
| 53 | |
| 54 | void onPrepare(GrBatchFlushState*) override {} |
| 55 | |
| 56 | void onDraw(GrBatchFlushState* state) override { |
| 57 | state->gpu()->copySurface(fDst.get(), fSrc.get(), fSrcRect, fDstPoint); |
| 58 | } |
| 59 | |
| 60 | GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
| 61 | GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
| 62 | SkIRect fSrcRect; |
| 63 | SkIPoint fDstPoint; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 64 | |
| 65 | typedef GrBatch INHERITED; |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #endif |