blob: 1481ce88b61e906f4d8ad89229367bf9539859cf [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 Salomone4bce012019-09-20 15:34:23 -040019 const GrCaps* caps) {
Brian Salomon982127b2021-01-21 10:43:35 -050020 SkASSERT(src);
21 SkASSERT(dst);
Brian Salomone4bce012019-09-20 15:34:23 -040022
Brian Salomon982127b2021-01-21 10:43:35 -050023 // Make sure our caller's values are inside the backing surfaces' bounds.
24 SkASSERT(SkIRect::MakeSize(src->backingStoreDimensions()).contains(srcRect));
25 SkASSERT(SkIRect::MakeSize(dst->backingStoreDimensions()).contains(
26 SkIRect::MakePtSize(dstPoint, srcRect.size())));
Greg Daniele227fe42019-08-21 13:52:24 -040027
Brian Salomon982127b2021-01-21 10:43:35 -050028 sk_sp<GrCopyRenderTask> task(new GrCopyRenderTask(drawingMgr,
29 std::move(src),
30 srcRect,
31 std::move(dst),
32 dstPoint));
Mike Kleina9609ea2020-02-18 13:33:23 -060033 return std::move(task);
Greg Daniele227fe42019-08-21 13:52:24 -040034}
35
Adlai Hollerd71b7b02020-06-08 15:55:00 -040036GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr,
Brian Salomon982127b2021-01-21 10:43:35 -050037 sk_sp<GrSurfaceProxy> src,
38 SkIRect srcRect,
39 sk_sp<GrSurfaceProxy> dst,
40 SkIPoint dstPoint)
41 : GrRenderTask(), fSrc(std::move(src)), fSrcRect(srcRect), fDstPoint(dstPoint) {
42 this->addTarget(drawingMgr, std::move(dst));
Greg Daniele227fe42019-08-21 13:52:24 -040043}
44
45void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
46 // 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 -040047 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Adlai Holler33d569e2020-06-16 14:30:08 -040048 // we read fSrcView and copy to target view.
Brian Salomon982127b2021-01-21 10:43:35 -050049 alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(),
Greg Daniele227fe42019-08-21 13:52:24 -040050 GrResourceAllocator::ActualUse::kYes);
Brian Salomon982127b2021-01-21 10:43:35 -050051 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
Greg Daniele227fe42019-08-21 13:52:24 -040052 GrResourceAllocator::ActualUse::kYes);
53 alloc->incOps();
54}
55
56bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) {
Brian Salomon982127b2021-01-21 10:43:35 -050057 GrSurfaceProxy* dstProxy = this->target(0);
58 if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) {
Greg Daniele227fe42019-08-21 13:52:24 -040059 return false;
60 }
Brian Salomon982127b2021-01-21 10:43:35 -050061 GrSurface* srcSurface = fSrc->peekSurface();
Greg Daniel16f5c652019-10-29 11:26:01 -040062 GrSurface* dstSurface = dstProxy->peekSurface();
Greg Daniele227fe42019-08-21 13:52:24 -040063 return flushState->gpu()->copySurface(dstSurface, srcSurface, fSrcRect, fDstPoint);
64}
65