blob: ed5e77f5b061d9bce393c3a30f4f2f3eeffe410a [file] [log] [blame]
bsalomon872062c2015-08-18 12:12:35 -07001/*
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
16class GrCopySurfaceBatch final : public GrBatch {
17public:
reed1b55a962015-09-17 20:16:13 -070018 DEFINE_BATCH_CLASS_ID
19
bsalomon872062c2015-08-18 12:12:35 -070020 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 }
29
30 SkString dumpInfo() const override {
31 SkString string;
32 string.printf("SRC: 0x%p, DST: 0x%p, SRECT: [L: %d, T: %d, R: %d, B: %d], "
33 "DPT:[X: %d, Y: %d]",
34 fDst.get(), fSrc.get(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight,
35 fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY);
36 return string;
37 }
38
39private:
40 GrCopySurfaceBatch(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
41 const SkIPoint& dstPoint)
reed1b55a962015-09-17 20:16:13 -070042 : INHERITED(ClassID())
43 , fDst(dst)
bsalomon872062c2015-08-18 12:12:35 -070044 , fSrc(src)
45 , fSrcRect(srcRect)
46 , fDstPoint(dstPoint) {
bsalomon872062c2015-08-18 12:12:35 -070047 fBounds = SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY),
48 SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
49 }
50
51 bool onCombineIfPossible(GrBatch* that, const GrCaps& caps) override { return false; }
52
53 void onPrepare(GrBatchFlushState*) override {}
54
55 void onDraw(GrBatchFlushState* state) override {
56 state->gpu()->copySurface(fDst.get(), fSrc.get(), fSrcRect, fDstPoint);
57 }
58
59 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
60 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
61 SkIRect fSrcRect;
62 SkIPoint fDstPoint;
reed1b55a962015-09-17 20:16:13 -070063
64 typedef GrBatch INHERITED;
bsalomon872062c2015-08-18 12:12:35 -070065};
66
67#endif