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 | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 19 | const GrCaps* caps) { |
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 | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 23 | // Make sure our caller's values are inside the backing surfaces' bounds. |
| 24 | SkASSERT(SkIRect::MakeSize(src->backingStoreDimensions()).contains(srcRect)); |
| 25 | SkASSERT(SkIRect::MakeSize(dst->backingStoreDimensions()).contains( |
| 26 | SkIRect::MakePtSize(dstPoint, srcRect.size()))); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 27 | |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 28 | sk_sp<GrCopyRenderTask> task(new GrCopyRenderTask(drawingMgr, |
| 29 | std::move(src), |
| 30 | srcRect, |
| 31 | std::move(dst), |
| 32 | dstPoint)); |
Mike Klein | a9609ea | 2020-02-18 13:33:23 -0600 | [diff] [blame] | 33 | return std::move(task); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 36 | GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr, |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 37 | sk_sp<GrSurfaceProxy> src, |
| 38 | SkIRect srcRect, |
| 39 | sk_sp<GrSurfaceProxy> dst, |
| 40 | SkIPoint dstPoint) |
| 41 | : GrRenderTask(), fSrc(std::move(src)), fSrcRect(srcRect), fDstPoint(dstPoint) { |
| 42 | this->addTarget(drawingMgr, std::move(dst)); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 46 | // 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] | 47 | // 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] | 48 | // we read fSrcView and copy to target view. |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 49 | alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(), |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 50 | GrResourceAllocator::ActualUse::kYes); |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 51 | alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(), |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 52 | GrResourceAllocator::ActualUse::kYes); |
| 53 | alloc->incOps(); |
| 54 | } |
| 55 | |
| 56 | bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 57 | GrSurfaceProxy* dstProxy = this->target(0); |
| 58 | if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 59 | return false; |
| 60 | } |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 61 | GrSurface* srcSurface = fSrc->peekSurface(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 62 | GrSurface* dstSurface = dstProxy->peekSurface(); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 63 | return flushState->gpu()->copySurface(dstSurface, srcSurface, fSrcRect, fDstPoint); |
| 64 | } |
| 65 | |