GrCopySurfaceOp.h revision f5442bb4c152e7c8138c83d27140e55d846f7ea5
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
14class GrCopySurfaceOp final : public GrOp {
15public:
16    DEFINE_OP_CLASS_ID
17
18    // MDB TODO: remove the resourceProvider parameter
19    static std::unique_ptr<GrOp> Make(GrResourceProvider*,
20                                      GrSurfaceProxy* dst, GrSurfaceProxy* src,
21                                      const SkIRect& srcRect,
22                                      const SkIPoint& dstPoint);
23
24    const char* name() const override { return "CopySurface"; }
25
26    SkString dumpInfo() const override {
27        SkString string;
28        string.append(INHERITED::dumpInfo());
29        string.printf("src: (proxyID: %d, rtID: %d), dst: (proxyID: %d, rtID: %d),\n"
30                      "srcRect: [L: %d, T: %d, R: %d, B: %d], dstPt: [X: %d, Y: %d]\n",
31                      fSrcProxyID.asUInt(), fSrc.get()->uniqueID().asUInt(),
32                      fDstProxyID.asUInt(), fDst.get()->uniqueID().asUInt(),
33                      fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom,
34                      fDstPoint.fX, fDstPoint.fY);
35        return string;
36    }
37
38    bool needsCommandBufferIsolation() const override { return true; }
39
40private:
41    GrCopySurfaceOp(GrSurface* dst, GrSurface* src,
42                    GrSurfaceProxy::UniqueID dstID, GrSurfaceProxy::UniqueID srcID,
43                    const SkIRect& srcRect, const SkIPoint& dstPoint)
44            : INHERITED(ClassID())
45            , fDstProxyID(dstID)
46            , fSrcProxyID(srcID)
47            , fDst(dst)
48            , fSrc(src)
49            , fSrcRect(srcRect)
50            , fDstPoint(dstPoint) {
51        SkRect bounds =
52                SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY),
53                                 SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
54        this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
55    }
56
57    bool onCombineIfPossible(GrOp* that, const GrCaps& caps) override { return false; }
58
59    void onPrepare(GrOpFlushState*) override {}
60
61    void onExecute(GrOpFlushState* state) override {
62        SkASSERT(!state->commandBuffer());
63        state->gpu()->copySurface(fDst.get(), fSrc.get(), fSrcRect, fDstPoint);
64    }
65
66    // MDB TODO: remove the proxy IDs once the GrSurfaceProxy carries the ref since they will
67    // be redundant
68    GrSurfaceProxy::UniqueID                        fDstProxyID;
69    GrSurfaceProxy::UniqueID                        fSrcProxyID;
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