bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 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 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 8 | #ifndef GrCopySurfaceOp_DEFINED |
| 9 | #define GrCopySurfaceOp_DEFINED |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrOpFlushState.h" |
| 12 | #include "src/gpu/ops/GrOp.h" |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 13 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 14 | class GrRecordingContext; |
| 15 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 16 | class GrCopySurfaceOp final : public GrOp { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 17 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 18 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 19 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 20 | static std::unique_ptr<GrOp> Make(GrRecordingContext*, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 21 | GrSurfaceProxy* dst, |
| 22 | GrSurfaceProxy* src, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 23 | const SkIRect& srcRect, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 24 | const SkIPoint& dstPoint); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 25 | |
| 26 | const char* name() const override { return "CopySurface"; } |
| 27 | |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 28 | void visitProxies(const VisitProxyFunc& func) const override { |
| 29 | func(fSrc.get(), GrMipMapped::kNo); |
Greg Daniel | a47ab49 | 2019-06-11 16:44:23 -0400 | [diff] [blame^] | 30 | func(fDst.get(), GrMipMapped::kNo); |
Chris Dalton | 7eb5c0f | 2019-05-23 15:15:47 -0600 | [diff] [blame] | 31 | } |
Robert Phillips | 9d6c64f | 2017-09-14 10:56:45 -0400 | [diff] [blame] | 32 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 33 | #ifdef SK_DEBUG |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 34 | SkString dumpInfo() const override { |
| 35 | SkString string; |
Brian Salomon | ab32f65 | 2019-05-10 14:24:50 -0400 | [diff] [blame] | 36 | 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); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 42 | return string; |
| 43 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 44 | #endif |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 45 | |
| 46 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 47 | friend class GrOpMemoryPool; // for ctor |
| 48 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 49 | GrCopySurfaceOp(GrSurfaceProxy* src, GrSurfaceProxy* dst, const SkIRect& srcRect, |
| 50 | const SkIPoint& dstPoint) |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 51 | : INHERITED(ClassID()) |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 52 | , fSrc(src) |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 53 | , fDst(dst) |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 54 | , fSrcRect(srcRect) |
| 55 | , fDstPoint(dstPoint) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 56 | 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 Daniel | a47ab49 | 2019-06-11 16:44:23 -0400 | [diff] [blame^] | 60 | |
| 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 | |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 71 | void onPrepare(GrOpFlushState*) override {} |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 72 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 73 | void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 74 | |
Robert Phillips | 3d4cac5 | 2019-06-11 08:08:08 -0400 | [diff] [blame] | 75 | GrProxyPendingIO fSrc; |
| 76 | GrProxyPendingIO fDst; |
| 77 | SkIRect fSrcRect; |
| 78 | SkIPoint fDstPoint; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 79 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 80 | typedef GrOp INHERITED; |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif |