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, |
| 15 | GrSurfaceProxyView srcView, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 16 | const SkIRect& srcRect, |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 17 | GrSurfaceProxyView dstView, |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 18 | const SkIPoint& dstPoint, |
| 19 | const GrCaps* caps) { |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 20 | SkASSERT(dstView.proxy()); |
| 21 | SkASSERT(srcView.proxy()); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 22 | SkIRect clippedSrcRect; |
| 23 | SkIPoint clippedDstPoint; |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 24 | GrSurfaceProxy* srcProxy = srcView.proxy(); |
| 25 | GrSurfaceProxy* dstProxy = dstView.proxy(); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 26 | // 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] | 27 | if (!GrClipSrcRectAndDstPoint(dstProxy->dimensions(), srcProxy->dimensions(), srcRect, dstPoint, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 28 | &clippedSrcRect, &clippedDstPoint)) { |
| 29 | return nullptr; |
| 30 | } |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 31 | |
| 32 | if (caps->isFormatCompressed(dstProxy->backendFormat())) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 33 | return nullptr; |
| 34 | } |
| 35 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 36 | SkASSERT(dstView.origin() == srcView.origin()); |
| 37 | if (srcView.origin() == kBottomLeft_GrSurfaceOrigin) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 38 | int rectHeight = clippedSrcRect.height(); |
| 39 | clippedSrcRect.fTop = srcProxy->height() - clippedSrcRect.fBottom; |
| 40 | clippedSrcRect.fBottom = clippedSrcRect.fTop + rectHeight; |
| 41 | clippedDstPoint.fY = dstProxy->height() - clippedDstPoint.fY - rectHeight; |
| 42 | } |
| 43 | |
| 44 | sk_sp<GrCopyRenderTask> task(new GrCopyRenderTask( |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 45 | drawingMgr, std::move(srcView), clippedSrcRect, std::move(dstView), clippedDstPoint)); |
Mike Klein | a9609ea | 2020-02-18 13:33:23 -0600 | [diff] [blame] | 46 | return std::move(task); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 49 | GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr, |
| 50 | GrSurfaceProxyView srcView, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 51 | const SkIRect& srcRect, |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 52 | GrSurfaceProxyView dstView, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 53 | const SkIPoint& dstPoint) |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame^] | 54 | : GrRenderTask() |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 55 | , fSrcView(std::move(srcView)) |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 56 | , fSrcRect(srcRect) |
| 57 | , fDstPoint(dstPoint) { |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame^] | 58 | this->addTarget(drawingMgr, dstView); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 62 | // 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] | 63 | // 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^] | 64 | // we read fSrcView and copy to target view. |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 65 | alloc->addInterval(fSrcView.proxy(), alloc->curOp(), alloc->curOp(), |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 66 | GrResourceAllocator::ActualUse::kYes); |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame^] | 67 | alloc->addInterval(this->target(0).proxy(), alloc->curOp(), alloc->curOp(), |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 68 | GrResourceAllocator::ActualUse::kYes); |
| 69 | alloc->incOps(); |
| 70 | } |
| 71 | |
| 72 | bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) { |
Adlai Holler | 33d569e | 2020-06-16 14:30:08 -0400 | [diff] [blame^] | 73 | GrSurfaceProxy* dstProxy = this->target(0).proxy(); |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 74 | GrSurfaceProxy* srcProxy = fSrcView.proxy(); |
| 75 | if (!srcProxy->isInstantiated() || !dstProxy->isInstantiated()) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 76 | return false; |
| 77 | } |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 78 | GrSurface* srcSurface = srcProxy->peekSurface(); |
| 79 | GrSurface* dstSurface = dstProxy->peekSurface(); |
| 80 | if (fSrcView.origin() == kBottomLeft_GrSurfaceOrigin) { |
| 81 | if (srcProxy->height() != srcSurface->height()) { |
| 82 | fSrcRect.offset(0, srcSurface->height() - srcProxy->height()); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 83 | } |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 84 | if (dstProxy->height() != dstSurface->height()) { |
| 85 | fDstPoint.fY = fDstPoint.fY + (dstSurface->height() - dstProxy->height()); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | return flushState->gpu()->copySurface(dstSurface, srcSurface, fSrcRect, fDstPoint); |
| 89 | } |
| 90 | |