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