blob: ab36c7df4da1864990a9c879f744ac7daa9b631f [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/**
21 * This class manages the small path renderer's atlas.
22 */
23class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject,
24 public GrDrawOpAtlas::EvictionCallback,
25 public GrDrawOpAtlas::GenerationCounter{
26public:
27 GrSmallPathAtlasMgr();
28 ~GrSmallPathAtlasMgr() override;
29
30 bool initAtlas(GrProxyProvider*, const GrCaps*);
31
32 GrDrawOpAtlas* atlas() { return fAtlas.get(); }
33
Robert Phillips109ff202020-08-10 16:39:31 -040034 GrSmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
35 GrSmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
36
Robert Phillips46a324a2020-08-10 13:08:12 -040037 const GrSurfaceProxyView* getViews(int* numActiveProxies) {
38 *numActiveProxies = fAtlas->numActivePages();
39 return fAtlas->getViews();
40 }
41
42 void setUseToken(GrSmallPathShapeData*, GrDeferredUploadToken);
43
44 // GrOnFlushCallbackObject overrides
45 //
46 // Note: because this class is associated with a path renderer we want it to be removed from
Robert Phillips109ff202020-08-10 16:39:31 -040047 // the list of active OnFlushCallbackObjects in an freeGpuResources call (i.e., we accept the
Robert Phillips46a324a2020-08-10 13:08:12 -040048 // default retainOnFreeGpuResources implementation).
49 void preFlush(GrOnFlushResourceProvider* onFlushRP,
Robert Phillips109ff202020-08-10 16:39:31 -040050 const uint32_t* /* opsTaskIDs */,
51 int /* numOpsTaskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040052 if (fAtlas) {
53 fAtlas->instantiate(onFlushRP);
54 }
55 }
56
57 void postFlush(GrDeferredUploadToken startTokenForNextFlush,
Robert Phillips109ff202020-08-10 16:39:31 -040058 const uint32_t* /* opsTaskIDs */,
59 int /* numOpsTaskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040060 if (fAtlas) {
61 fAtlas->compact(startTokenForNextFlush);
62 }
63 }
64
Robert Phillips46a324a2020-08-10 13:08:12 -040065 void deleteCacheEntry(GrSmallPathShapeData*);
66
67private:
Robert Phillips109ff202020-08-10 16:39:31 -040068 GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey&);
69
70 void evict(GrDrawOpAtlas::PlotLocator) override;
71
Robert Phillips46a324a2020-08-10 13:08:12 -040072 using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
73 typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
74
Robert Phillips46a324a2020-08-10 13:08:12 -040075 std::unique_ptr<GrDrawOpAtlas> fAtlas;
76 ShapeCache fShapeCache;
77 ShapeDataList fShapeList;
78};
79
80#endif // GrSmallPathAtlasMgr_DEFINED