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 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
64 GrResourceAllocator::ActualUse::kYes);
65 alloc->incOps();
66 }
67
onMakeClosed(GrRecordingContext *,SkIRect * targetUpdateBounds)68 GrRenderTask::ExpectedOutcome GrCopyRenderTask::onMakeClosed(GrRecordingContext*,
69 SkIRect* targetUpdateBounds) {
70 // We don't expect to be marked skippable before being closed.
71 SkASSERT(fSrc);
72 *targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo(
73 fOrigin,
74 this->target(0)->height(),
75 fDstRect);
76 return ExpectedOutcome::kTargetDirty;
77 }
78
onExecute(GrOpFlushState * flushState)79 bool GrCopyRenderTask::onExecute(GrOpFlushState* flushState) {
80 if (!fSrc) {
81 // Did nothing, just like we're supposed to.
82 return true;
83 }
84 GrSurfaceProxy* dstProxy = this->target(0);
85 if (!fSrc->isInstantiated() || !dstProxy->isInstantiated()) {
86 return false;
87 }
88 GrSurface* srcSurface = fSrc->peekSurface();
89 GrSurface* dstSurface = dstProxy->peekSurface();
90 SkIRect srcRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, srcSurface->height(), fSrcRect);
91 SkIRect dstRect = GrNativeRect::MakeIRectRelativeTo(fOrigin, dstSurface->height(), fDstRect);
92 return flushState->gpu()->copySurface(dstSurface, dstRect, srcSurface, srcRect, fFilter);
93 }
94