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 | |
14 | sk_sp<GrRenderTask> GrCopyRenderTask::Make(GrDrawingManager* drawingMgr, |
15 | GrSurfaceProxyView srcView, |
16 | const SkIRect& srcRect, |
17 | GrSurfaceProxyView dstView, |
18 | const SkIPoint& dstPoint, |
19 | const GrCaps* caps) { |
20 | SkASSERT(dstView.proxy()); |
21 | SkASSERT(srcView.proxy()); |
22 | SkIRect clippedSrcRect; |
23 | SkIPoint clippedDstPoint; |
24 | GrSurfaceProxy* srcProxy = srcView.proxy(); |
25 | GrSurfaceProxy* dstProxy = dstView.proxy(); |
26 | // If the rect is outside the srcProxy or dstProxy then we've already succeeded. |
27 | if (!GrClipSrcRectAndDstPoint(dstProxy->dimensions(), srcProxy->dimensions(), srcRect, dstPoint, |
28 | &clippedSrcRect, &clippedDstPoint)) { |
29 | return nullptr; |
30 | } |
31 | |
32 | if (caps->isFormatCompressed(dstProxy->backendFormat())) { |
33 | return nullptr; |
34 | } |
35 | |
36 | SkASSERT(dstView.origin() == srcView.origin()); |
37 | if (srcView.origin() == kBottomLeft_GrSurfaceOrigin) { |
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( |
45 | drawingMgr, std::move(srcView), clippedSrcRect, std::move(dstView), clippedDstPoint)); |
46 | return std::move(task); |
47 | } |
48 | |
49 | GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr, |
50 | GrSurfaceProxyView srcView, |
51 | const SkIRect& srcRect, |
52 | GrSurfaceProxyView dstView, |
53 | const SkIPoint& dstPoint) |
54 | : GrRenderTask() |
55 | , fSrcView(std::move(srcView)) |
56 | , fSrcRect(srcRect) |
57 | , fDstPoint(dstPoint) { |
58 | this->addTarget(drawingMgr, dstView); |
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 |
63 | // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that |
64 | // we read fSrcView and copy to target view. |
65 | alloc->addInterval(fSrcView.proxy(), alloc->curOp(), alloc->curOp(), |
66 | GrResourceAllocator::ActualUse::kYes); |
67 | alloc->addInterval(this->target(0).proxy(), alloc->curOp(), alloc->curOp(), |
68 | GrResourceAllocator::ActualUse::kYes); |
69 | alloc->incOps(); |
70 | } |
71 | |
72 | bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) { |
73 | GrSurfaceProxy* dstProxy = this->target(0).proxy(); |
74 | GrSurfaceProxy* srcProxy = fSrcView.proxy(); |
75 | if (!srcProxy->isInstantiated() || !dstProxy->isInstantiated()) { |
76 | return false; |
77 | } |
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()); |
83 | } |
84 | if (dstProxy->height() != dstSurface->height()) { |
85 | fDstPoint.fY = fDstPoint.fY + (dstSurface->height() - dstProxy->height()); |
86 | } |
87 | } |
88 | return flushState->gpu()->copySurface(dstSurface, srcSurface, fSrcRect, fDstPoint); |
89 | } |
90 | |
91 | |