blob: ec229aea22922c3826ac22399e8b18d3f3c37e43 [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
Robert Phillipsde60d7a2021-09-13 17:17:45 -04008#ifndef SmallPathAtlasMgr_DEFINED
9#define SmallPathAtlasMgr_DEFINED
Robert Phillips46a324a2020-08-10 13:08:12 -040010
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 Phillips109ff202020-08-10 16:39:31 -040016class GrStyledShape;
Robert Phillips46a324a2020-08-10 13:08:12 -040017
Robert Phillipsde60d7a2021-09-13 17:17:45 -040018namespace skgpu::v1 {
19
20class SmallPathShapeData;
21class SmallPathShapeDataKey;
22
Robert Phillips46a324a2020-08-10 13:08:12 -040023/**
Robert Phillips079455c2020-08-11 15:18:46 -040024 * 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 Phillips46a324a2020-08-10 13:08:12 -040030 */
Robert Phillipsde60d7a2021-09-13 17:17:45 -040031class SmallPathAtlasMgr final : public GrOnFlushCallbackObject,
32 public GrDrawOpAtlas::EvictionCallback,
33 public GrDrawOpAtlas::GenerationCounter {
Robert Phillips46a324a2020-08-10 13:08:12 -040034public:
Robert Phillipsde60d7a2021-09-13 17:17:45 -040035 SmallPathAtlasMgr();
36 ~SmallPathAtlasMgr() override;
Robert Phillips46a324a2020-08-10 13:08:12 -040037
Robert Phillipsa4bb0642020-08-11 09:55:17 -040038 void reset();
39
Robert Phillips46a324a2020-08-10 13:08:12 -040040 bool initAtlas(GrProxyProvider*, const GrCaps*);
41
Robert Phillipsde60d7a2021-09-13 17:17:45 -040042 SmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
43 SmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
Robert Phillips109ff202020-08-10 16:39:31 -040044
Robert Phillips6704bc82020-08-14 12:45:07 -040045 GrDrawOpAtlas::ErrorCode addToAtlas(GrResourceProvider*,
46 GrDeferredUploadTarget*,
47 int width, int height, const void* image,
48 GrDrawOpAtlas::AtlasLocator*);
49
Robert Phillipsde60d7a2021-09-13 17:17:45 -040050 void setUseToken(SmallPathShapeData*, GrDeferredUploadToken);
Robert Phillips46a324a2020-08-10 13:08:12 -040051
52 // GrOnFlushCallbackObject overrides
Robert Phillips46a324a2020-08-10 13:08:12 -040053 void preFlush(GrOnFlushResourceProvider* onFlushRP,
Adlai Holler9902cff2020-11-11 08:51:25 -050054 SkSpan<const uint32_t> /* taskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040055 if (fAtlas) {
56 fAtlas->instantiate(onFlushRP);
57 }
58 }
59
60 void postFlush(GrDeferredUploadToken startTokenForNextFlush,
Adlai Holler9902cff2020-11-11 08:51:25 -050061 SkSpan<const uint32_t> /* taskIDs */) override {
Robert Phillips46a324a2020-08-10 13:08:12 -040062 if (fAtlas) {
63 fAtlas->compact(startTokenForNextFlush);
64 }
65 }
66
Robert Phillips079455c2020-08-11 15:18:46 -040067 // 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 Phillipsa4bb0642020-08-11 09:55:17 -040071 const GrSurfaceProxyView* getViews(int* numActiveProxies) {
72 *numActiveProxies = fAtlas->numActivePages();
73 return fAtlas->getViews();
74 }
75
Robert Phillipsde60d7a2021-09-13 17:17:45 -040076 void deleteCacheEntry(SmallPathShapeData*);
Robert Phillips46a324a2020-08-10 13:08:12 -040077
78private:
Robert Phillipsde60d7a2021-09-13 17:17:45 -040079 SmallPathShapeData* findOrCreate(const SmallPathShapeDataKey&);
Robert Phillips109ff202020-08-10 16:39:31 -040080
81 void evict(GrDrawOpAtlas::PlotLocator) override;
82
Robert Phillipsde60d7a2021-09-13 17:17:45 -040083 using ShapeCache = SkTDynamicHash<SmallPathShapeData, SmallPathShapeDataKey>;
84 typedef SkTInternalLList<SmallPathShapeData> ShapeDataList;
Robert Phillips46a324a2020-08-10 13:08:12 -040085
Robert Phillips46a324a2020-08-10 13:08:12 -040086 std::unique_ptr<GrDrawOpAtlas> fAtlas;
87 ShapeCache fShapeCache;
88 ShapeDataList fShapeList;
89};
90
Robert Phillipsde60d7a2021-09-13 17:17:45 -040091} // namespace skgpu::v1
92
93#endif // SmallPathAtlasMgr_DEFINED