blob: 17ab571ce202cc19137d8104ac2a47f78972d030 [file] [log] [blame]
Robert Phillips46a324a2020-08-10 13:08:12 -04001/*
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
16class GrSmallPathShapeData;
17class GrSmallPathShapeDataKey;
Robert Phillips109ff202020-08-10 16:39:31 -040018class GrStyledShape;
Robert Phillips46a324a2020-08-10 13:08:12 -040019
20/**
Robert Phillips079455c2020-08-11 15:18:46 -040021 * 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 Phillips46a324a2020-08-10 13:08:12 -040027 */
28class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject,
29 public GrDrawOpAtlas::EvictionCallback,
Robert Phillipsa4bb0642020-08-11 09:55:17 -040030 public GrDrawOpAtlas::GenerationCounter {
Robert Phillips46a324a2020-08-10 13:08:12 -040031public:
32 GrSmallPathAtlasMgr();
33 ~GrSmallPathAtlasMgr() override;
34
Robert Phillipsa4bb0642020-08-11 09:55:17 -040035 void reset();
36
Robert Phillips46a324a2020-08-10 13:08:12 -040037 bool initAtlas(GrProxyProvider*, const GrCaps*);
38
39 GrDrawOpAtlas* atlas() { return fAtlas.get(); }
40
Robert Phillips109ff202020-08-10 16:39:31 -040041 GrSmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
42 GrSmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
43
Robert Phillips46a324a2020-08-10 13:08:12 -040044 void setUseToken(GrSmallPathShapeData*, GrDeferredUploadToken);
45
46 // GrOnFlushCallbackObject overrides
Robert Phillips46a324a2020-08-10 13:08:12 -040047 void preFlush(GrOnFlushResourceProvider* onFlushRP,
Robert Phillips109ff202020-08-10 16:39:31 -040048 const uint32_t* /* opsTaskIDs */,
49 int /* numOpsTaskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040050 if (fAtlas) {
51 fAtlas->instantiate(onFlushRP);
52 }
53 }
54
55 void postFlush(GrDeferredUploadToken startTokenForNextFlush,
Robert Phillips109ff202020-08-10 16:39:31 -040056 const uint32_t* /* opsTaskIDs */,
57 int /* numOpsTaskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040058 if (fAtlas) {
59 fAtlas->compact(startTokenForNextFlush);
60 }
61 }
62
Robert Phillips079455c2020-08-11 15:18:46 -040063 // This object has the same lifetime as the GrContext so we want it to survive freeGpuResources
64 // calls
65 bool retainOnFreeGpuResources() override { return true; }
66
Robert Phillipsa4bb0642020-08-11 09:55:17 -040067 const GrSurfaceProxyView* getViews(int* numActiveProxies) {
68 *numActiveProxies = fAtlas->numActivePages();
69 return fAtlas->getViews();
70 }
71
Robert Phillips46a324a2020-08-10 13:08:12 -040072 void deleteCacheEntry(GrSmallPathShapeData*);
73
74private:
Robert Phillips109ff202020-08-10 16:39:31 -040075 GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey&);
76
77 void evict(GrDrawOpAtlas::PlotLocator) override;
78
Robert Phillips46a324a2020-08-10 13:08:12 -040079 using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
80 typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
81
Robert Phillips46a324a2020-08-10 13:08:12 -040082 std::unique_ptr<GrDrawOpAtlas> fAtlas;
83 ShapeCache fShapeCache;
84 ShapeDataList fShapeList;
85};
86
87#endif // GrSmallPathAtlasMgr_DEFINED