blob: eb65dd54ba70156ba5b3a89841877d58c4122946 [file] [log] [blame]
Greg Daniele227fe42019-08-21 13:52:24 -04001/*
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 Hollerd71b7b02020-06-08 15:55:00 -040014sk_sp<GrRenderTask> GrCopyRenderTask::Make(GrDrawingManager* drawingMgr,
Brian Salomon982127b2021-01-21 10:43:35 -050015 sk_sp<GrSurfaceProxy> src,
16 SkIRect srcRect,
17 sk_sp<GrSurfaceProxy> dst,
18 SkIPoint dstPoint,
Brian Salomon0f9f8002021-01-22 16:30:50 -050019 GrSurfaceOrigin origin) {
Brian Salomon982127b2021-01-21 10:43:35 -050020 SkASSERT(src);
21 SkASSERT(dst);
Brian Salomone4bce012019-09-20 15:34:23 -040022
Brian Salomon0f9f8002021-01-22 16:30:50 -050023 if (!GrClipSrcRectAndDstPoint(dst->dimensions(),
24 src->dimensions(),
25 srcRect,
26 dstPoint,
27 &srcRect,
28 &dstPoint)) {
29 return nullptr;
30 }
Greg Daniele227fe42019-08-21 13:52:24 -040031
Brian Salomond63638b2021-03-05 14:00:07 -050032 return sk_sp<GrRenderTask>(new GrCopyRenderTask(drawingMgr,
33 std::move(src),
34 srcRect,
35 std::move(dst),
36 dstPoint,
37 origin));
Greg Daniele227fe42019-08-21 13:52:24 -040038}
39
Adlai Hollerd71b7b02020-06-08 15:55:00 -040040GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr,
Brian Salomon982127b2021-01-21 10:43:35 -050041 sk_sp<GrSurfaceProxy> src,
42 SkIRect srcRect,
43 sk_sp<GrSurfaceProxy> dst,
Brian Salomon0f9f8002021-01-22 16:30:50 -050044 SkIPoint dstPoint,
45 GrSurfaceOrigin origin)
46 : fSrc(std::move(src)), fSrcRect(srcRect), fDstPoint(dstPoint), fOrigin(origin) {
Brian Salomon982127b2021-01-21 10:43:35 -050047 this->addTarget(drawingMgr, std::move(dst));
Greg Daniele227fe42019-08-21 13:52:24 -040048}
49
50void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Brian Salomond63638b2021-03-05 14:00:07 -050051 if (!fSrc) {
52 alloc->incOps();
53 return;
54 }
Greg Daniele227fe42019-08-21 13:52:24 -040055 // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so
Greg Danielf41b2bd2019-08-22 16:19:24 -040056 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Adlai Holler33d569e2020-06-16 14:30:08 -040057 // we read fSrcView and copy to target view.
Adlai Holler7f7a5df2021-02-09 17:41:10 +000058 alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(),
59 GrResourceAllocator::ActualUse::kYes);
60 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
61 GrResourceAllocator::ActualUse::kYes);
Greg Daniele227fe42019-08-21 13:52:24 -040062 alloc->incOps();
63}
64
Brian Salomon0f9f8002021-01-22 16:30:50 -050065GrRenderTask::ExpectedOutcome GrCopyRenderTask::onMakeClosed(const GrCaps&,
66 SkIRect* targetUpdateBounds) {
Brian Salomond63638b2021-03-05 14:00:07 -050067 // We don't expect to be marked skippable before being closed.
68 SkASSERT(fSrc);
Brian Salomon0f9f8002021-01-22 16:30:50 -050069 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
70 fOrigin,
71 this->target(0)->height(),
72 SkIRect::MakePtSize(fDstPoint, fSrcRect.size()));
73 return ExpectedOutcome::kTargetDirty;
74}
75
Greg Daniele227fe42019-08-21 13:52:24 -040076bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) {
Brian Salomond63638b2021-03-05 14:00:07 -050077 if (!fSrc) {
78 // Did nothing, just like we're supposed to.
79 return true;
80 }
Brian Salomon982127b2021-01-21 10:43:35 -050081 GrSurfaceProxy* dstProxy = this->target(0);
82 if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) {
Greg Daniele227fe42019-08-21 13:52:24 -040083 return false;
84 }
Brian Salomon982127b2021-01-21 10:43:35 -050085 GrSurface* srcSurface = fSrc->peekSurface();
Greg Daniel16f5c652019-10-29 11:26:01 -040086 GrSurface* dstSurface = dstProxy->peekSurface();
Brian Salomon0f9f8002021-01-22 16:30:50 -050087 SkIRect srcRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, srcSurface->height(), fSrcRect);
88 SkIPoint dstPoint = fDstPoint;
89 if (fOrigin == kBottomLeft_GrSurfaceOrigin) {
90 dstPoint.fY = dstSurface->height() - dstPoint.fY - srcRect.height();
91 }
92 return flushState->gpu()->copySurface(dstSurface, srcSurface, srcRect, dstPoint);
Greg Daniele227fe42019-08-21 13:52:24 -040093}
94