1 /*
2  * Copyright 2020 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 #ifndef GrDDLTask_DEFINED
9 #define GrDDLTask_DEFINED
10 
11 #include "include/core/SkPoint.h"
12 #include "src/gpu/GrRenderTask.h"
13 
14 class GrRenderTargetProxy;
15 
16 /**
17  * This render task isolates the DDL's tasks from the rest of the DAG. This means that
18  * the DDL's tasks cannot be reordered by the topological sort and are always executed
19  * as a single block.
20  * It almost entirely just forwards calls down to the DDL's render tasks.
21  */
22 class GrDDLTask final : public GrRenderTask {
23 public:
24     GrDDLTask(GrDrawingManager*,
25               sk_sp<GrRenderTargetProxy> ddlTarget,
26               sk_sp<const SkDeferredDisplayList>,
27               SkIPoint offset);
28 
29     ~GrDDLTask() override;
30 
31     // The render tasks w/in the DDL don't appear in the DAG so need explicit notification
32     // when they can free their contents.
requiresExplicitCleanup()33     bool requiresExplicitCleanup() const override { return true; }
34 
35     void endFlush(GrDrawingManager*) override;
36 
37     void disown(GrDrawingManager*) override;
38 
39 private:
40     bool onIsUsed(GrSurfaceProxy*) const override;
41 
42     void gatherProxyIntervals(GrResourceAllocator*) const override;
43 
44     ExpectedOutcome onMakeClosed(const GrCaps&, SkIRect* targetUpdateBounds) override;
45 
46     void gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const override;
47 
onPrePrepare(GrRecordingContext *)48     void onPrePrepare(GrRecordingContext*) override {
49         // This entry point is only called when a DDL is snapped off of a recorder.
50         // Since DDL tasks should never recursively appear within a DDL this should never
51         // be called.
52         SkASSERT(0);
53     }
54 
55     void onPrepare(GrOpFlushState*) override;
56 
57     bool onExecute(GrOpFlushState*) override;
58 
59 #if GR_TEST_UTILS
60     void dump(const SkString& label,
61               SkString indent,
62               bool printDependencies,
63               bool close) const final;
name()64     const char* name() const final { return "DDL"; }
65 #endif
66 #ifdef SK_DEBUG
visitProxies_debugOnly(const GrOp::VisitProxyFunc & fn)67     void visitProxies_debugOnly(const GrOp::VisitProxyFunc& fn) const override {}
68 #endif
69 
70     sk_sp<const SkDeferredDisplayList> fDDL;
71     sk_sp<GrRenderTargetProxy>         fDDLTarget;
72     SkIPoint                           fOffset;
73 
74     typedef GrRenderTask INHERITED;
75 };
76 
77 #endif
78