blob: 69652bd3600f6d23deccbd2514006ec1d30ce76d [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
Brian Salomon7dae46a2016-12-14 16:21:37 -05008#ifndef GrCopySurfaceOp_DEFINED
9#define GrCopySurfaceOp_DEFINED
bsalomon872062c2015-08-18 12:12:35 -070010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrOpFlushState.h"
12#include "src/gpu/ops/GrOp.h"
bsalomon872062c2015-08-18 12:12:35 -070013
Robert Phillipsb97da532019-02-12 15:24:12 -050014class GrRecordingContext;
15
Brian Salomon7dae46a2016-12-14 16:21:37 -050016class GrCopySurfaceOp final : public GrOp {
bsalomon872062c2015-08-18 12:12:35 -070017public:
Brian Salomon25a88092016-12-01 09:36:50 -050018 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070019
Robert Phillipsb97da532019-02-12 15:24:12 -050020 static std::unique_ptr<GrOp> Make(GrRecordingContext*,
Robert Phillips7c525e62018-06-12 10:11:12 -040021 GrSurfaceProxy* dst,
22 GrSurfaceProxy* src,
Robert Phillipsbf25d432017-04-07 10:08:53 -040023 const SkIRect& srcRect,
Brian Salomonf8334782017-01-03 09:42:58 -050024 const SkIPoint& dstPoint);
bsalomon872062c2015-08-18 12:12:35 -070025
26 const char* name() const override { return "CopySurface"; }
27
Chris Dalton7eb5c0f2019-05-23 15:15:47 -060028 void visitProxies(const VisitProxyFunc& func) const override {
29 func(fSrc.get(), GrMipMapped::kNo);
Greg Daniela47ab492019-06-11 16:44:23 -040030 func(fDst.get(), GrMipMapped::kNo);
Chris Dalton7eb5c0f2019-05-23 15:15:47 -060031 }
Robert Phillips9d6c64f2017-09-14 10:56:45 -040032
Brian Osman9a390ac2018-11-12 09:47:48 -050033#ifdef SK_DEBUG
bsalomon872062c2015-08-18 12:12:35 -070034 SkString dumpInfo() const override {
35 SkString string;
Brian Salomonab32f652019-05-10 14:24:50 -040036 string = INHERITED::dumpInfo();
37 string.appendf(
38 "srcProxyID: %d,\n"
39 "srcRect: [ L: %d, T: %d, R: %d, B: %d ], dstPt: [ X: %d, Y: %d ]\n",
40 fSrc.get()->uniqueID().asUInt(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight,
41 fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY);
bsalomon872062c2015-08-18 12:12:35 -070042 return string;
43 }
Brian Osman9a390ac2018-11-12 09:47:48 -050044#endif
bsalomon872062c2015-08-18 12:12:35 -070045
46private:
Robert Phillips7c525e62018-06-12 10:11:12 -040047 friend class GrOpMemoryPool; // for ctor
48
Greg Daniel46cfbc62019-06-07 11:43:30 -040049 GrCopySurfaceOp(GrSurfaceProxy* src, GrSurfaceProxy* dst, const SkIRect& srcRect,
50 const SkIPoint& dstPoint)
Robert Phillipsbf25d432017-04-07 10:08:53 -040051 : INHERITED(ClassID())
Robert Phillipsbf25d432017-04-07 10:08:53 -040052 , fSrc(src)
Greg Daniel46cfbc62019-06-07 11:43:30 -040053 , fDst(dst)
Robert Phillipsbf25d432017-04-07 10:08:53 -040054 , fSrcRect(srcRect)
55 , fDstPoint(dstPoint) {
bsalomon88cf17d2016-07-08 06:40:56 -070056 SkRect bounds =
57 SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY),
58 SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height()));
59 this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
Greg Daniela47ab492019-06-11 16:44:23 -040060
61 SkASSERT(dst->origin() == src->origin());
62 if (kBottomLeft_GrSurfaceOrigin == src->origin()) {
63 int rectHeight = fSrcRect.height();
64 fSrcRect.fTop = src->height() - fSrcRect.fBottom;
65 fSrcRect.fBottom = fSrcRect.fTop + rectHeight;
66 fDstPoint.fY = dst->height() - fDstPoint.fY - rectHeight;
67 }
68
bsalomon872062c2015-08-18 12:12:35 -070069 }
70
Brian Salomon742e31d2016-12-07 17:06:19 -050071 void onPrepare(GrOpFlushState*) override {}
bsalomon872062c2015-08-18 12:12:35 -070072
Brian Salomon588cec72018-11-14 13:56:37 -050073 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
bsalomon872062c2015-08-18 12:12:35 -070074
Robert Phillips3d4cac52019-06-11 08:08:08 -040075 GrProxyPendingIO fSrc;
76 GrProxyPendingIO fDst;
77 SkIRect fSrcRect;
78 SkIPoint fDstPoint;
reed1b55a962015-09-17 20:16:13 -070079
Brian Salomon25a88092016-12-01 09:36:50 -050080 typedef GrOp INHERITED;
bsalomon872062c2015-08-18 12:12:35 -070081};
82
83#endif