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 GrCopySurfaceOp_DEFINED
9 #define GrCopySurfaceOp_DEFINED
10 
11 #include "GrGpu.h"
12 #include "GrOp.h"
13 #include "GrOpFlushState.h"
14 #include "GrRenderTarget.h"
15 
16 class GrCopySurfaceOp final : public GrOp {
17 public:
18     DEFINE_OP_CLASS_ID
19 
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 
30     static std::unique_ptr<GrOp> Make(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
31                                       const SkIPoint& dstPoint);
32 
name()33     const char* name() const override { return "CopySurface"; }
34 
dumpInfo()35     SkString dumpInfo() const override {
36         SkString string;
37         string.printf(
38                 "SRC: 0x%p, DST: 0x%p, SRECT: [L: %d, T: %d, R: %d, B: %d], "
39                 "DPT:[X: %d, Y: %d]",
40                 fDst.get(), fSrc.get(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight,
41                 fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY);
42         string.append(INHERITED::dumpInfo());
43         return string;
44     }
45 
46 private:
GrCopySurfaceOp(GrSurface * dst,GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)47     GrCopySurfaceOp(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
48                     const SkIPoint& dstPoint)
49             : INHERITED(ClassID()), fDst(dst), fSrc(src), fSrcRect(srcRect), fDstPoint(dstPoint) {
50         SkRect bounds =
51                 SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY),
52                                  SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
53         this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
54     }
55 
onCombineIfPossible(GrOp * that,const GrCaps & caps)56     bool onCombineIfPossible(GrOp* that, const GrCaps& caps) override { return false; }
57 
onPrepare(GrOpFlushState *)58     void onPrepare(GrOpFlushState*) override {}
59 
onExecute(GrOpFlushState * state)60     void onExecute(GrOpFlushState* state) override {
61         if (!state->commandBuffer()) {
62             state->gpu()->copySurface(fDst.get(), fSrc.get(), fSrcRect, fDstPoint);
63         } else {
64             // Currently we are not sending copies through the GrGpuCommandBuffer. See comment in
65             // renderTargetUniqueID().
66             SkASSERT(false);
67         }
68     }
69 
70     GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
71     GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
72     SkIRect fSrcRect;
73     SkIPoint fDstPoint;
74 
75     typedef GrOp INHERITED;
76 };
77 
78 #endif
79