1 /*
2  * Copyright 2017 Google Inc.
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 SkDeferredDisplayList_DEFINED
9 #define SkDeferredDisplayList_DEFINED
10 
11 #include "SkSurfaceCharacterization.h"
12 
13 #if SK_SUPPORT_GPU
14 #include "GrCCPerOpListPaths.h"
15 #include "GrOpList.h"
16 
17 #include <map>
18 #endif
19 
20 class SkDeferredDisplayListPriv;
21 class SkSurface;
22 /*
23  * This class contains pre-processed gpu operations that can be replayed into
24  * an SkSurface via draw(SkDeferredDisplayList*).
25  *
26  * TODO: we probably need to expose this class so users can query it for memory usage.
27  */
28 class SK_API SkDeferredDisplayList {
29 public:
30 
31 #if SK_SUPPORT_GPU
32     // This object is the source from which the lazy proxy backing the DDL will pull its backing
33     // texture when the DDL is replayed. It has to be separately ref counted bc the lazy proxy
34     // can outlive the DDL.
35     class LazyProxyData : public SkRefCnt {
36     public:
37         // Upon being replayed - this field will be filled in (by the DrawingManager) with the proxy
38         // backing the destination SkSurface. Note that, since there is no good place to clear it
39         // it can become a dangling pointer.
40         GrRenderTargetProxy*     fReplayDest = nullptr;
41     };
42 #else
43     class LazyProxyData : public SkRefCnt {};
44 #endif
45 
46     SkDeferredDisplayList(const SkSurfaceCharacterization& characterization,
47                           sk_sp<LazyProxyData>);
48     ~SkDeferredDisplayList();
49 
characterization()50     const SkSurfaceCharacterization& characterization() const {
51         return fCharacterization;
52     }
53 
54     // Provides access to functions that aren't part of the public API.
55     SkDeferredDisplayListPriv priv();
56     const SkDeferredDisplayListPriv priv() const;
57 
58 private:
59     friend class GrDrawingManager; // for access to 'fOpLists' and 'fLazyProxyData'
60     friend class SkDeferredDisplayListRecorder; // for access to 'fLazyProxyData'
61     friend class SkDeferredDisplayListPriv;
62 
63     const SkSurfaceCharacterization fCharacterization;
64 
65 #if SK_SUPPORT_GPU
66     // This needs to match the same type in GrCoverageCountingPathRenderer.h
67     using PendingPathsMap = std::map<uint32_t, sk_sp<GrCCPerOpListPaths>>;
68 
69     SkTArray<sk_sp<GrOpList>>    fOpLists;
70     PendingPathsMap              fPendingPaths;  // This is the path data from CCPR.
71 #endif
72     sk_sp<LazyProxyData>         fLazyProxyData;
73 };
74 
75 #endif
76