• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 SmallPathAtlasMgr_DEFINED
9 #define SmallPathAtlasMgr_DEFINED
10 
11 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
12 
13 #include "src/base/SkTInternalLList.h"
14 #include "src/core/SkTDynamicHash.h"
15 #include "src/gpu/ganesh/GrDrawOpAtlas.h"
16 #include "src/gpu/ganesh/GrOnFlushResourceProvider.h"
17 
18 class GrStyledShape;
19 
20 namespace skgpu::v1 {
21 
22 class SmallPathShapeData;
23 class SmallPathShapeDataKey;
24 
25 /**
26  * This class manages the small path renderer's atlas. It solely operates at flush time. Thus
27  * the small path renderer will generate ops at record time but the location of the ops' source
28  * data and even the number of proxies to be used will not be determined until the recorded
29  * DAGs/DDLs are (re)played.
30  *
31  * TODO: investigate fusing this class and the GrAtlasManager.
32  */
33 class SmallPathAtlasMgr final : public GrOnFlushCallbackObject,
34                                 public skgpu::PlotEvictionCallback,
35                                 public skgpu::AtlasGenerationCounter {
36 public:
37     SmallPathAtlasMgr();
38     ~SmallPathAtlasMgr() override;
39 
40     void reset();
41 
42     bool initAtlas(GrProxyProvider*, const GrCaps*);
43 
44     SmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
45     SmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
46 
47     GrDrawOpAtlas::ErrorCode addToAtlas(GrResourceProvider*,
48                                         GrDeferredUploadTarget*,
49                                         int width, int height, const void* image,
50                                         skgpu::AtlasLocator*);
51 
52     void setUseToken(SmallPathShapeData*, skgpu::AtlasToken);
53 
54     // GrOnFlushCallbackObject overrides
preFlush(GrOnFlushResourceProvider * onFlushRP)55     bool preFlush(GrOnFlushResourceProvider* onFlushRP) override {
56 #if GR_TEST_UTILS
57         if (onFlushRP->failFlushTimeCallbacks()) {
58             return false;
59         }
60 #endif
61 
62         if (fAtlas) {
63             fAtlas->instantiate(onFlushRP);
64         }
65         return true;
66     }
67 
postFlush(skgpu::AtlasToken startTokenForNextFlush)68     void postFlush(skgpu::AtlasToken startTokenForNextFlush) override {
69         if (fAtlas) {
70             fAtlas->compact(startTokenForNextFlush);
71         }
72     }
73 
74     // This object has the same lifetime as the GrContext so we want it to survive freeGpuResources
75     // calls
retainOnFreeGpuResources()76     bool retainOnFreeGpuResources() override { return true; }
77 
getViews(int * numActiveProxies)78     const GrSurfaceProxyView* getViews(int* numActiveProxies) {
79         *numActiveProxies = fAtlas->numActivePages();
80         return fAtlas->getViews();
81     }
82 
83     void deleteCacheEntry(SmallPathShapeData*);
84 
85 private:
86     SmallPathShapeData* findOrCreate(const SmallPathShapeDataKey&);
87 
88     void evict(skgpu::PlotLocator) override;
89 
90     using ShapeCache = SkTDynamicHash<SmallPathShapeData, SmallPathShapeDataKey>;
91     typedef SkTInternalLList<SmallPathShapeData> ShapeDataList;
92 
93     std::unique_ptr<GrDrawOpAtlas> fAtlas;
94     ShapeCache                     fShapeCache;
95     ShapeDataList                  fShapeList;
96 };
97 
98 } // namespace skgpu::v1
99 
100 #endif // SK_ENABLE_OPTIMIZE_SIZE
101 
102 #endif // SmallPathAtlasMgr_DEFINED
103