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