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 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 8 | #ifndef SmallPathAtlasMgr_DEFINED |
| 9 | #define SmallPathAtlasMgr_DEFINED |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 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 | |
Robert Phillips | 109ff20 | 2020-08-10 16:39:31 -0400 | [diff] [blame] | 16 | class GrStyledShape; |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 17 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 18 | namespace skgpu::v1 { |
| 19 | |
| 20 | class SmallPathShapeData; |
| 21 | class SmallPathShapeDataKey; |
| 22 | |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 23 | /** |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 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. |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 30 | */ |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 31 | class SmallPathAtlasMgr final : public GrOnFlushCallbackObject, |
| 32 | public GrDrawOpAtlas::EvictionCallback, |
| 33 | public GrDrawOpAtlas::GenerationCounter { |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 34 | public: |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 35 | SmallPathAtlasMgr(); |
| 36 | ~SmallPathAtlasMgr() override; |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 37 | |
Robert Phillips | a4bb064 | 2020-08-11 09:55:17 -0400 | [diff] [blame] | 38 | void reset(); |
| 39 | |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 40 | bool initAtlas(GrProxyProvider*, const GrCaps*); |
| 41 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 42 | SmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension); |
| 43 | SmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm); |
Robert Phillips | 109ff20 | 2020-08-10 16:39:31 -0400 | [diff] [blame] | 44 | |
Robert Phillips | 6704bc8 | 2020-08-14 12:45:07 -0400 | [diff] [blame] | 45 | GrDrawOpAtlas::ErrorCode addToAtlas(GrResourceProvider*, |
| 46 | GrDeferredUploadTarget*, |
| 47 | int width, int height, const void* image, |
| 48 | GrDrawOpAtlas::AtlasLocator*); |
| 49 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 50 | void setUseToken(SmallPathShapeData*, GrDeferredUploadToken); |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 51 | |
| 52 | // GrOnFlushCallbackObject overrides |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 53 | void preFlush(GrOnFlushResourceProvider* onFlushRP, |
Adlai Holler | 9902cff | 2020-11-11 08:51:25 -0500 | [diff] [blame] | 54 | SkSpan<const uint32_t> /* taskIDs */) override { |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 55 | if (fAtlas) { |
| 56 | fAtlas->instantiate(onFlushRP); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
Adlai Holler | 9902cff | 2020-11-11 08:51:25 -0500 | [diff] [blame] | 61 | SkSpan<const uint32_t> /* taskIDs */) override { |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 62 | if (fAtlas) { |
| 63 | fAtlas->compact(startTokenForNextFlush); |
| 64 | } |
| 65 | } |
| 66 | |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 67 | // This object has the same lifetime as the GrContext so we want it to survive freeGpuResources |
| 68 | // calls |
| 69 | bool retainOnFreeGpuResources() override { return true; } |
| 70 | |
Robert Phillips | a4bb064 | 2020-08-11 09:55:17 -0400 | [diff] [blame] | 71 | const GrSurfaceProxyView* getViews(int* numActiveProxies) { |
| 72 | *numActiveProxies = fAtlas->numActivePages(); |
| 73 | return fAtlas->getViews(); |
| 74 | } |
| 75 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 76 | void deleteCacheEntry(SmallPathShapeData*); |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 77 | |
| 78 | private: |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 79 | SmallPathShapeData* findOrCreate(const SmallPathShapeDataKey&); |
Robert Phillips | 109ff20 | 2020-08-10 16:39:31 -0400 | [diff] [blame] | 80 | |
| 81 | void evict(GrDrawOpAtlas::PlotLocator) override; |
| 82 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 83 | using ShapeCache = SkTDynamicHash<SmallPathShapeData, SmallPathShapeDataKey>; |
| 84 | typedef SkTInternalLList<SmallPathShapeData> ShapeDataList; |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 85 | |
Robert Phillips | 46a324a | 2020-08-10 13:08:12 -0400 | [diff] [blame] | 86 | std::unique_ptr<GrDrawOpAtlas> fAtlas; |
| 87 | ShapeCache fShapeCache; |
| 88 | ShapeDataList fShapeList; |
| 89 | }; |
| 90 | |
Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 91 | } // namespace skgpu::v1 |
| 92 | |
| 93 | #endif // SmallPathAtlasMgr_DEFINED |