blob: a578451b1a7df9f4ab59acb29b06978923fd9808 [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,
15 GrSurfaceProxyView srcView,
Greg Daniele227fe42019-08-21 13:52:24 -040016 const SkIRect& srcRect,
Greg Daniel16f5c652019-10-29 11:26:01 -040017 GrSurfaceProxyView dstView,
Brian Salomone4bce012019-09-20 15:34:23 -040018 const SkIPoint& dstPoint,
19 const GrCaps* caps) {
Greg Daniel16f5c652019-10-29 11:26:01 -040020 SkASSERT(dstView.proxy());
21 SkASSERT(srcView.proxy());
Greg Daniele227fe42019-08-21 13:52:24 -040022 SkIRect clippedSrcRect;
23 SkIPoint clippedDstPoint;
Greg Daniel16f5c652019-10-29 11:26:01 -040024 GrSurfaceProxy* srcProxy = srcView.proxy();
25 GrSurfaceProxy* dstProxy = dstView.proxy();
Greg Daniele227fe42019-08-21 13:52:24 -040026 // If the rect is outside the srcProxy or dstProxy then we've already succeeded.
Brian Salomon9f2b86c2019-10-22 10:37:46 -040027 if (!GrClipSrcRectAndDstPoint(dstProxy->dimensions(), srcProxy->dimensions(), srcRect, dstPoint,
Greg Daniele227fe42019-08-21 13:52:24 -040028 &clippedSrcRect, &clippedDstPoint)) {
29 return nullptr;
30 }
Brian Salomone4bce012019-09-20 15:34:23 -040031
32 if (caps->isFormatCompressed(dstProxy->backendFormat())) {
Greg Daniele227fe42019-08-21 13:52:24 -040033 return nullptr;
34 }
35
Greg Daniel16f5c652019-10-29 11:26:01 -040036 SkASSERT(dstView.origin() == srcView.origin());
37 if (srcView.origin() == kBottomLeft_GrSurfaceOrigin) {
Greg Daniele227fe42019-08-21 13:52:24 -040038 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 Hollerd71b7b02020-06-08 15:55:00 -040045 drawingMgr, std::move(srcView), clippedSrcRect, std::move(dstView), clippedDstPoint));
Mike Kleina9609ea2020-02-18 13:33:23 -060046 return std::move(task);
Greg Daniele227fe42019-08-21 13:52:24 -040047}
48
Adlai Hollerd71b7b02020-06-08 15:55:00 -040049GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr,
50 GrSurfaceProxyView srcView,
Greg Daniele227fe42019-08-21 13:52:24 -040051 const SkIRect& srcRect,
Greg Daniel16f5c652019-10-29 11:26:01 -040052 GrSurfaceProxyView dstView,
Greg Daniele227fe42019-08-21 13:52:24 -040053 const SkIPoint& dstPoint)
Adlai Holler33d569e2020-06-16 14:30:08 -040054 : GrRenderTask()
Greg Daniel16f5c652019-10-29 11:26:01 -040055 , fSrcView(std::move(srcView))
Greg Daniele227fe42019-08-21 13:52:24 -040056 , fSrcRect(srcRect)
57 , fDstPoint(dstPoint) {
Adlai Holler33d569e2020-06-16 14:30:08 -040058 this->addTarget(drawingMgr, dstView);
Greg Daniele227fe42019-08-21 13:52:24 -040059}
60
61void 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 Danielf41b2bd2019-08-22 16:19:24 -040063 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Adlai Holler33d569e2020-06-16 14:30:08 -040064 // we read fSrcView and copy to target view.
Greg Daniel16f5c652019-10-29 11:26:01 -040065 alloc->addInterval(fSrcView.proxy(), alloc->curOp(), alloc->curOp(),
Greg Daniele227fe42019-08-21 13:52:24 -040066 GrResourceAllocator::ActualUse::kYes);
Adlai Holler33d569e2020-06-16 14:30:08 -040067 alloc->addInterval(this->target(0).proxy(), alloc->curOp(), alloc->curOp(),
Greg Daniele227fe42019-08-21 13:52:24 -040068 GrResourceAllocator::ActualUse::kYes);
69 alloc->incOps();
70}
71
72bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) {
Adlai Holler33d569e2020-06-16 14:30:08 -040073 GrSurfaceProxy* dstProxy = this->target(0).proxy();
Greg Daniel16f5c652019-10-29 11:26:01 -040074 GrSurfaceProxy* srcProxy = fSrcView.proxy();
75 if (!srcProxy->isInstantiated() || !dstProxy->isInstantiated()) {
Greg Daniele227fe42019-08-21 13:52:24 -040076 return false;
77 }
Greg Daniel16f5c652019-10-29 11:26:01 -040078 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 Daniele227fe42019-08-21 13:52:24 -040083 }
Greg Daniel16f5c652019-10-29 11:26:01 -040084 if (dstProxy->height() != dstSurface->height()) {
85 fDstPoint.fY = fDstPoint.fY + (dstSurface->height() - dstProxy->height());
Greg Daniele227fe42019-08-21 13:52:24 -040086 }
87 }
88 return flushState->gpu()->copySurface(dstSurface, srcSurface, fSrcRect, fDstPoint);
89}
90