blob: 7c5be41e64af235f442efc6d076e60095453db9b [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,
Robert Phillipsa4bb0642020-08-11 09:55:17 -040025 public GrDrawOpAtlas::GenerationCounter {
Robert Phillips46a324a2020-08-10 13:08:12 -040026public:
27 GrSmallPathAtlasMgr();
28 ~GrSmallPathAtlasMgr() override;
29
Robert Phillipsa4bb0642020-08-11 09:55:17 -040030 void reset();
31
Robert Phillips46a324a2020-08-10 13:08:12 -040032 bool initAtlas(GrProxyProvider*, const GrCaps*);
33
34 GrDrawOpAtlas* atlas() { return fAtlas.get(); }
35
Robert Phillips109ff202020-08-10 16:39:31 -040036 GrSmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
37 GrSmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
38
Robert Phillips46a324a2020-08-10 13:08:12 -040039 void setUseToken(GrSmallPathShapeData*, GrDeferredUploadToken);
40
41 // GrOnFlushCallbackObject overrides
Robert Phillips46a324a2020-08-10 13:08:12 -040042 void preFlush(GrOnFlushResourceProvider* onFlushRP,
Robert Phillips109ff202020-08-10 16:39:31 -040043 const uint32_t* /* opsTaskIDs */,
44 int /* numOpsTaskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040045 if (fAtlas) {
46 fAtlas->instantiate(onFlushRP);
47 }
48 }
49
50 void postFlush(GrDeferredUploadToken startTokenForNextFlush,
Robert Phillips109ff202020-08-10 16:39:31 -040051 const uint32_t* /* opsTaskIDs */,
52 int /* numOpsTaskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040053 if (fAtlas) {
54 fAtlas->compact(startTokenForNextFlush);
55 }
56 }
57
Robert Phillipsa4bb0642020-08-11 09:55:17 -040058 const GrSurfaceProxyView* getViews(int* numActiveProxies) {
59 *numActiveProxies = fAtlas->numActivePages();
60 return fAtlas->getViews();
61 }
62
Robert Phillips46a324a2020-08-10 13:08:12 -040063 void deleteCacheEntry(GrSmallPathShapeData*);
64
65private:
Robert Phillips109ff202020-08-10 16:39:31 -040066 GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey&);
67
68 void evict(GrDrawOpAtlas::PlotLocator) override;
69
Robert Phillips46a324a2020-08-10 13:08:12 -040070 using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
71 typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
72
Robert Phillips46a324a2020-08-10 13:08:12 -040073 std::unique_ptr<GrDrawOpAtlas> fAtlas;
74 ShapeCache fShapeCache;
75 ShapeDataList fShapeList;
76};
77
78#endif // GrSmallPathAtlasMgr_DEFINED