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