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 "GrOp.h"
12 #include "GrOpFlushState.h"
13 
14 class GrCopySurfaceOp final : public GrOp {
15 public:
16     DEFINE_OP_CLASS_ID
17 
18     static std::unique_ptr<GrOp> Make(GrContext*,
19                                       GrSurfaceProxy* dst,
20                                       GrSurfaceProxy* src,
21                                       const SkIRect& srcRect,
22                                       const SkIPoint& dstPoint);
23 
name()24     const char* name() const override { return "CopySurface"; }
25 
visitProxies(const VisitProxyFunc & func,VisitorType)26     void visitProxies(const VisitProxyFunc& func, VisitorType) const override { func(fSrc.get()); }
27 
28 #ifdef SK_DEBUG
dumpInfo()29     SkString dumpInfo() const override {
30         SkString string;
31         string.append(INHERITED::dumpInfo());
32         string.printf("srcProxyID: %d,\n"
33                       "srcRect: [ L: %d, T: %d, R: %d, B: %d ], dstPt: [ X: %d, Y: %d ]\n",
34                       fSrc.get()->uniqueID().asUInt(),
35                       fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom,
36                       fDstPoint.fX, fDstPoint.fY);
37         return string;
38     }
39 #endif
40 
41 private:
42     friend class GrOpMemoryPool; // for ctor
43 
GrCopySurfaceOp(GrSurfaceProxy * dst,GrSurfaceProxy * src,const SkIRect & srcRect,const SkIPoint & dstPoint)44     GrCopySurfaceOp(GrSurfaceProxy* dst, GrSurfaceProxy* src,
45                     const SkIRect& srcRect, const SkIPoint& dstPoint)
46             : INHERITED(ClassID())
47             , fSrc(src)
48             , fSrcRect(srcRect)
49             , 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 
onPrepare(GrOpFlushState *)56     void onPrepare(GrOpFlushState*) override {}
57 
58     void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
59 
60     GrPendingIOResource<GrSurfaceProxy, kRead_GrIOType>  fSrc;
61     SkIRect                                              fSrcRect;
62     SkIPoint                                             fDstPoint;
63 
64     typedef GrOp INHERITED;
65 };
66 
67 #endif
68