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 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 14 | sk_sp<GrRenderTask> GrCopyRenderTask::Make(GrSurfaceProxyView srcView, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 15 | const SkIRect& srcRect, |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 16 | GrSurfaceProxyView dstView, |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 17 | const SkIPoint& dstPoint, |
| 18 | const GrCaps* caps) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 19 | SkASSERT(dstView.proxy()); |
| 20 | SkASSERT(srcView.proxy()); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 21 | SkIRect clippedSrcRect; |
| 22 | SkIPoint clippedDstPoint; |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 23 | GrSurfaceProxy* srcProxy = srcView.proxy(); |
| 24 | GrSurfaceProxy* dstProxy = dstView.proxy(); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 25 | // If the rect is outside the srcProxy or dstProxy then we've already succeeded. |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 26 | if (!GrClipSrcRectAndDstPoint(dstProxy->dimensions(), srcProxy->dimensions(), srcRect, dstPoint, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 27 | &clippedSrcRect, &clippedDstPoint)) { |
| 28 | return nullptr; |
| 29 | } |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 30 | |
| 31 | if (caps->isFormatCompressed(dstProxy->backendFormat())) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 32 | return nullptr; |
| 33 | } |
| 34 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 35 | SkASSERT(dstView.origin() == srcView.origin()); |
| 36 | if (srcView.origin() == kBottomLeft_GrSurfaceOrigin) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 37 | int rectHeight = clippedSrcRect.height(); |
| 38 | clippedSrcRect.fTop = srcProxy->height() - clippedSrcRect.fBottom; |
| 39 | clippedSrcRect.fBottom = clippedSrcRect.fTop + rectHeight; |
| 40 | clippedDstPoint.fY = dstProxy->height() - clippedDstPoint.fY - rectHeight; |
| 41 | } |
| 42 | |
| 43 | sk_sp<GrCopyRenderTask> task(new GrCopyRenderTask( |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 44 | std::move(srcView), clippedSrcRect, std::move(dstView), clippedDstPoint)); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 45 | return task; |
| 46 | } |
| 47 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 48 | GrCopyRenderTask::GrCopyRenderTask(GrSurfaceProxyView srcView, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 49 | const SkIRect& srcRect, |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 50 | GrSurfaceProxyView dstView, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 51 | const SkIPoint& dstPoint) |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 52 | : GrRenderTask(std::move(dstView)) |
| 53 | , fSrcView(std::move(srcView)) |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 54 | , fSrcRect(srcRect) |
| 55 | , fDstPoint(dstPoint) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 56 | fTargetView.proxy()->setLastRenderTask(this); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 60 | // 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] | 61 | // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 62 | // we read fSrcView and copy to fTargetView. |
| 63 | alloc->addInterval(fSrcView.proxy(), alloc->curOp(), alloc->curOp(), |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 64 | GrResourceAllocator::ActualUse::kYes); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 65 | alloc->addInterval(fTargetView.proxy(), alloc->curOp(), alloc->curOp(), |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 66 | GrResourceAllocator::ActualUse::kYes); |
| 67 | alloc->incOps(); |
| 68 | } |
| 69 | |
| 70 | bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 71 | GrSurfaceProxy* dstProxy = fTargetView.proxy(); |
| 72 | GrSurfaceProxy* srcProxy = fSrcView.proxy(); |
| 73 | if (!srcProxy->isInstantiated() || !dstProxy->isInstantiated()) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 74 | return false; |
| 75 | } |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 76 | GrSurface* srcSurface = srcProxy->peekSurface(); |
| 77 | GrSurface* dstSurface = dstProxy->peekSurface(); |
| 78 | if (fSrcView.origin() == kBottomLeft_GrSurfaceOrigin) { |
| 79 | if (srcProxy->height() != srcSurface->height()) { |
| 80 | fSrcRect.offset(0, srcSurface->height() - srcProxy->height()); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 81 | } |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame^] | 82 | if (dstProxy->height() != dstSurface->height()) { |
| 83 | fDstPoint.fY = fDstPoint.fY + (dstSurface->height() - dstProxy->height()); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | return flushState->gpu()->copySurface(dstSurface, srcSurface, fSrcRect, fDstPoint); |
| 87 | } |
| 88 | |