Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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 | #include "src/gpu/GrCopyRenderTask.h" |
| 9 | |
| 10 | #include "src/gpu/GrGpu.h" |
| 11 | #include "src/gpu/GrOpFlushState.h" |
| 12 | #include "src/gpu/GrResourceAllocator.h" |
| 13 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 14 | sk_sp<GrRenderTask> GrCopyRenderTask::Make(GrDrawingManager* drawingMgr, |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 15 | sk_sp<GrSurfaceProxy> src, |
| 16 | SkIRect srcRect, |
| 17 | sk_sp<GrSurfaceProxy> dst, |
| 18 | SkIPoint dstPoint, |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 19 | GrSurfaceOrigin origin) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 20 | SkASSERT(src); |
| 21 | SkASSERT(dst); |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 22 | |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 23 | if (!GrClipSrcRectAndDstPoint(dst->dimensions(), |
| 24 | src->dimensions(), |
| 25 | srcRect, |
| 26 | dstPoint, |
| 27 | &srcRect, |
| 28 | &dstPoint)) { |
| 29 | return nullptr; |
| 30 | } |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 31 | |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 32 | sk_sp<GrCopyRenderTask> task(new GrCopyRenderTask(drawingMgr, |
| 33 | std::move(src), |
| 34 | srcRect, |
| 35 | std::move(dst), |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 36 | dstPoint, |
| 37 | origin)); |
Mike Klein | a9609ea | 2020-02-18 13:33:23 -0600 | [diff] [blame] | 38 | return std::move(task); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 41 | GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr, |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 42 | sk_sp<GrSurfaceProxy> src, |
| 43 | SkIRect srcRect, |
| 44 | sk_sp<GrSurfaceProxy> dst, |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 45 | SkIPoint dstPoint, |
| 46 | GrSurfaceOrigin origin) |
| 47 | : fSrc(std::move(src)), fSrcRect(srcRect), fDstPoint(dstPoint), fOrigin(origin) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 48 | this->addTarget(drawingMgr, std::move(dst)); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 52 | // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 53 | // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame] | 54 | // we read fSrcView and copy to target view. |
Adlai Holler | 7f7a5df | 2021-02-09 17:41:10 +0000 | [diff] [blame] | 55 | alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(), |
| 56 | GrResourceAllocator::ActualUse::kYes); |
| 57 | alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(), |
| 58 | GrResourceAllocator::ActualUse::kYes); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 59 | alloc->incOps(); |
| 60 | } |
| 61 | |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 62 | GrRenderTask::ExpectedOutcome GrCopyRenderTask::onMakeClosed(const GrCaps&, |
| 63 | SkIRect* targetUpdateBounds) { |
| 64 | *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo( |
| 65 | fOrigin, |
| 66 | this->target(0)->height(), |
| 67 | SkIRect::MakePtSize(fDstPoint, fSrcRect.size())); |
| 68 | return ExpectedOutcome::kTargetDirty; |
| 69 | } |
| 70 | |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 71 | bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 72 | GrSurfaceProxy* dstProxy = this->target(0); |
| 73 | if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 74 | return false; |
| 75 | } |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 76 | GrSurface* srcSurface = fSrc->peekSurface(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 77 | GrSurface* dstSurface = dstProxy->peekSurface(); |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 78 | SkIRect srcRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, srcSurface->height(), fSrcRect); |
| 79 | SkIPoint dstPoint = fDstPoint; |
| 80 | if (fOrigin == kBottomLeft_GrSurfaceOrigin) { |
| 81 | dstPoint.fY = dstSurface->height() - dstPoint.fY - srcRect.height(); |
| 82 | } |
| 83 | return flushState->gpu()->copySurface(dstSurface, srcSurface, srcRect, dstPoint); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 84 | } |
| 85 | |