blob: f2887e3a9c40730294b365f4dd01ba00a9008e57 [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 Salomon982127b2021-01-21 10:43:35 -050032 sk_sp<GrCopyRenderTask> task(new GrCopyRenderTask(drawingMgr,
33 std::move(src),
34 srcRect,
35 std::move(dst),
Brian Salomon0f9f8002021-01-22 16:30:50 -050036 dstPoint,
37 origin));
Mike Kleina9609ea2020-02-18 13:33:23 -060038 return std::move(task);
Greg Daniele227fe42019-08-21 13:52:24 -040039}
40
Adlai Hollerd71b7b02020-06-08 15:55:00 -040041GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr,
Brian Salomon982127b2021-01-21 10:43:35 -050042 sk_sp<GrSurfaceProxy> src,
43 SkIRect srcRect,
44 sk_sp<GrSurfaceProxy> dst,
Brian Salomon0f9f8002021-01-22 16:30:50 -050045 SkIPoint dstPoint,
46 GrSurfaceOrigin origin)
47 : fSrc(std::move(src)), fSrcRect(srcRect), fDstPoint(dstPoint), fOrigin(origin) {
Brian Salomon982127b2021-01-21 10:43:35 -050048 this->addTarget(drawingMgr, std::move(dst));
Greg Daniele227fe42019-08-21 13:52:24 -040049}
50
51void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
52 // 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 -040053 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Adlai Holler33d569e2020-06-16 14:30:08 -040054 // we read fSrcView and copy to target view.
Adlai Holler7f7a5df2021-02-09 17:41:10 +000055 alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(),
56 GrResourceAllocator::ActualUse::kYes);
57 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
58 GrResourceAllocator::ActualUse::kYes);
Greg Daniele227fe42019-08-21 13:52:24 -040059 alloc->incOps();
60}
61
Brian Salomon0f9f8002021-01-22 16:30:50 -050062GrRenderTask::ExpectedOutcome GrCopyRenderTask::onMakeClosed(const GrCaps&,
63 SkIRect* targetUpdateBounds) {
64 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
65 fOrigin,
66 this->target(0)->height(),
67 SkIRect::MakePtSize(fDstPoint, fSrcRect.size()));
68 return ExpectedOutcome::kTargetDirty;
69}
70
Greg Daniele227fe42019-08-21 13:52:24 -040071bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -050072 GrSurfaceProxy* dstProxy = this->target(0);
73 if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) {
Greg Daniele227fe42019-08-21 13:52:24 -040074 return false;
75 }
Brian Salomon982127b2021-01-21 10:43:35 -050076 GrSurface* srcSurface = fSrc->peekSurface();
Greg Daniel16f5c652019-10-29 11:26:01 -040077 GrSurface* dstSurface = dstProxy->peekSurface();
Brian Salomon0f9f8002021-01-22 16:30:50 -050078 SkIRect srcRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, srcSurface->height(), fSrcRect);
79 SkIPoint dstPoint = fDstPoint;
80 if (fOrigin == kBottomLeft_GrSurfaceOrigin) {
81 dstPoint.fY = dstSurface->height() - dstPoint.fY - srcRect.height();
82 }
83 return flushState->gpu()->copySurface(dstSurface, srcSurface, srcRect, dstPoint);
Greg Daniele227fe42019-08-21 13:52:24 -040084}
85