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" |
Robert Phillips | 550de7f | 2021-07-06 16:28:52 -0400 | [diff] [blame] | 13 | #include "src/gpu/geometry/GrRect.h" |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 14 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 15 | sk_sp<GrRenderTask> GrCopyRenderTask::Make(GrDrawingManager* drawingMgr, |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 16 | sk_sp<GrSurfaceProxy> src, |
| 17 | SkIRect srcRect, |
| 18 | sk_sp<GrSurfaceProxy> dst, |
| 19 | SkIPoint dstPoint, |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 20 | GrSurfaceOrigin origin) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 21 | SkASSERT(src); |
| 22 | SkASSERT(dst); |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 23 | |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 24 | if (!GrClipSrcRectAndDstPoint(dst->dimensions(), |
| 25 | src->dimensions(), |
| 26 | srcRect, |
| 27 | dstPoint, |
| 28 | &srcRect, |
| 29 | &dstPoint)) { |
| 30 | return nullptr; |
| 31 | } |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 32 | |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 33 | return sk_sp<GrRenderTask>(new GrCopyRenderTask(drawingMgr, |
| 34 | std::move(src), |
| 35 | srcRect, |
| 36 | std::move(dst), |
| 37 | dstPoint, |
| 38 | origin)); |
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 { |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 52 | if (!fSrc) { |
| 53 | alloc->incOps(); |
| 54 | return; |
| 55 | } |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 56 | // 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] | 57 | // 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] | 58 | // we read fSrcView and copy to target view. |
Adlai Holler | 7f7a5df | 2021-02-09 17:41:10 +0000 | [diff] [blame] | 59 | alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(), |
| 60 | GrResourceAllocator::ActualUse::kYes); |
| 61 | alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(), |
| 62 | GrResourceAllocator::ActualUse::kYes); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 63 | alloc->incOps(); |
| 64 | } |
| 65 | |
Chris Dalton | aa938ce | 2021-06-23 18:13:59 -0600 | [diff] [blame] | 66 | GrRenderTask::ExpectedOutcome GrCopyRenderTask::onMakeClosed(GrRecordingContext*, |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 67 | SkIRect* targetUpdateBounds) { |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 68 | // We don't expect to be marked skippable before being closed. |
| 69 | SkASSERT(fSrc); |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 70 | *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo( |
| 71 | fOrigin, |
| 72 | this->target(0)->height(), |
| 73 | SkIRect::MakePtSize(fDstPoint, fSrcRect.size())); |
| 74 | return ExpectedOutcome::kTargetDirty; |
| 75 | } |
| 76 | |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 77 | bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) { |
Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 78 | if (!fSrc) { |
| 79 | // Did nothing, just like we're supposed to. |
| 80 | return true; |
| 81 | } |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 82 | GrSurfaceProxy* dstProxy = this->target(0); |
| 83 | if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 84 | return false; |
| 85 | } |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame] | 86 | GrSurface* srcSurface = fSrc->peekSurface(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 87 | GrSurface* dstSurface = dstProxy->peekSurface(); |
Brian Salomon | 0f9f800 | 2021-01-22 16:30:50 -0500 | [diff] [blame] | 88 | SkIRect srcRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, srcSurface->height(), fSrcRect); |
| 89 | SkIPoint dstPoint = fDstPoint; |
| 90 | if (fOrigin == kBottomLeft_GrSurfaceOrigin) { |
| 91 | dstPoint.fY = dstSurface->height() - dstPoint.fY - srcRect.height(); |
| 92 | } |
| 93 | return flushState->gpu()->copySurface(dstSurface, srcSurface, srcRect, dstPoint); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 94 | } |
| 95 | |