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