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; |
| 18 | |
| 19 | /** |
| 20 | * This class manages the small path renderer's atlas. |
| 21 | */ |
| 22 | class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject, |
| 23 | public GrDrawOpAtlas::EvictionCallback, |
| 24 | public GrDrawOpAtlas::GenerationCounter{ |
| 25 | public: |
| 26 | GrSmallPathAtlasMgr(); |
| 27 | ~GrSmallPathAtlasMgr() override; |
| 28 | |
| 29 | bool initAtlas(GrProxyProvider*, const GrCaps*); |
| 30 | |
| 31 | GrDrawOpAtlas* atlas() { return fAtlas.get(); } |
| 32 | |
| 33 | const GrSurfaceProxyView* getViews(int* numActiveProxies) { |
| 34 | *numActiveProxies = fAtlas->numActivePages(); |
| 35 | return fAtlas->getViews(); |
| 36 | } |
| 37 | |
| 38 | void setUseToken(GrSmallPathShapeData*, GrDeferredUploadToken); |
| 39 | |
| 40 | // GrOnFlushCallbackObject overrides |
| 41 | // |
| 42 | // Note: because this class is associated with a path renderer we want it to be removed from |
| 43 | // the list of active OnFlushBackkbackObjects in an freeGpuResources call (i.e., we accept the |
| 44 | // default retainOnFreeGpuResources implementation). |
| 45 | void preFlush(GrOnFlushResourceProvider* onFlushRP, |
| 46 | const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override { |
| 47 | if (fAtlas) { |
| 48 | fAtlas->instantiate(onFlushRP); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | void postFlush(GrDeferredUploadToken startTokenForNextFlush, |
| 53 | const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override { |
| 54 | if (fAtlas) { |
| 55 | fAtlas->compact(startTokenForNextFlush); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey& key); |
| 60 | |
| 61 | void deleteCacheEntry(GrSmallPathShapeData*); |
| 62 | |
| 63 | private: |
| 64 | using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>; |
| 65 | typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList; |
| 66 | |
| 67 | void evict(GrDrawOpAtlas::PlotLocator plotLocator) override; |
| 68 | |
| 69 | std::unique_ptr<GrDrawOpAtlas> fAtlas; |
| 70 | ShapeCache fShapeCache; |
| 71 | ShapeDataList fShapeList; |
| 72 | }; |
| 73 | |
| 74 | #endif // GrSmallPathAtlasMgr_DEFINED |