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/ganesh/GrCopyRenderTask.h"
9
10 #include "src/gpu/ganesh/GrGpu.h"
11 #include "src/gpu/ganesh/GrNativeRect.h"
12 #include "src/gpu/ganesh/GrOpFlushState.h"
13 #include "src/gpu/ganesh/GrResourceAllocator.h"
14
Make(GrDrawingManager * drawingMgr,sk_sp<GrSurfaceProxy> dst,SkIRect dstRect,sk_sp<GrSurfaceProxy> src,SkIRect srcRect,GrSamplerState::Filter filter,GrSurfaceOrigin origin)15 sk_sp<GrRenderTask> GrCopyRenderTask::Make(GrDrawingManager* drawingMgr,
16 sk_sp<GrSurfaceProxy> dst,
17 SkIRect dstRect,
18 sk_sp<GrSurfaceProxy> src,
19 SkIRect srcRect,
20 GrSamplerState::Filter filter,
21 GrSurfaceOrigin origin) {
22 SkASSERT(src);
23 SkASSERT(dst);
24
25 // canCopySurface() should have returned true, guaranteeing this property.
26 SkASSERT(SkIRect::MakeSize(dst->dimensions()).contains(dstRect));
27 SkASSERT(SkIRect::MakeSize(src->dimensions()).contains(srcRect));
28
29 return sk_sp<GrRenderTask>(new GrCopyRenderTask(drawingMgr,
30 std::move(dst),
31 dstRect,
32 std::move(src),
33 srcRect,
34 filter,
35 origin));
36 }
37
GrCopyRenderTask(GrDrawingManager * drawingMgr,sk_sp<GrSurfaceProxy> dst,SkIRect dstRect,sk_sp<GrSurfaceProxy> src,SkIRect srcRect,GrSamplerState::Filter filter,GrSurfaceOrigin origin)38 GrCopyRenderTask::GrCopyRenderTask(GrDrawingManager* drawingMgr,
39 sk_sp<GrSurfaceProxy> dst,
40 SkIRect dstRect,
41 sk_sp<GrSurfaceProxy> src,
42 SkIRect srcRect,
43 GrSamplerState::Filter filter,
44 GrSurfaceOrigin origin)
45 : fSrc(std::move(src))
46 , fSrcRect(srcRect)
47 , fDstRect(dstRect)
48 , fFilter(filter)
49 , fOrigin(origin) {
50 this->addTarget(drawingMgr, std::move(dst));
51 }
52
gatherProxyIntervals(GrResourceAllocator * alloc) const53 void GrCopyRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
54 if (!fSrc) {
55 alloc->incOps();
56 return;
57 }
58 // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so
59 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
60 // we read fSrcView and copy to target view.
61 alloc->addInterval(fSrc.get(), alloc->curOp(), alloc->curOp(),
62 GrResourceAllocator::ActualUse::kYes,
63 GrResourceAllocator::AllowRecycling::kYes);
64 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
65 GrResourceAllocator::ActualUse::kYes,
66 GrResourceAllocator::AllowRecycling::kYes);
67 alloc->incOps();
68 }
69
onMakeClosed(GrRecordingContext *,SkIRect * targetUpdateBounds)70 GrRenderTask::ExpectedOutcome GrCopyRenderTask::onMakeClosed(GrRecordingContext*,
71 SkIRect* targetUpdateBounds) {
72 // We don't expect to be marked skippable before being closed.
73 SkASSERT(fSrc);
74 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
75 fOrigin,
76 this->target(0)->height(),
77 fDstRect);
78 return ExpectedOutcome::kTargetDirty;
79 }
80
onExecute(GrOpFlushState * flushState)81 bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) {
82 if (!fSrc) {
83 // Did nothing, just like we're supposed to.
84 return true;
85 }
86 GrSurfaceProxy* dstProxy = this->target(0);
87 if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) {
88 return false;
89 }
90 GrSurface* srcSurface = fSrc->peekSurface();
91 GrSurface* dstSurface = dstProxy->peekSurface();
92 SkIRect srcRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, srcSurface->height(), fSrcRect);
93 SkIRect dstRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, dstSurface->height(), fDstRect);
94 return flushState->gpu()->copySurface(dstSurface, dstRect, srcSurface, srcRect, fFilter);
95 }
96