blob: edab2cbd248c13cd76b49354bd0e8c381ccf6608 [file] [log] [blame]
joshualitt5bf99f12015-03-13 11:47:42 -07001/*
2 * Copyright 2015 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
Brian Salomon2ee084e2016-12-16 18:59:19 -05008#ifndef GrDrawOpAtlas_DEFINED
9#define GrDrawOpAtlas_DEFINED
joshualitt5bf99f12015-03-13 11:47:42 -070010
joshualitt5bf99f12015-03-13 11:47:42 -070011#include "SkPoint.h"
12#include "SkTDArray.h"
13#include "SkTInternalLList.h"
14
Brian Salomon89527432016-12-16 09:52:16 -050015#include "ops/GrDrawOp.h"
joshualittddd22d82016-02-16 06:47:52 -080016
joshualitt5bf99f12015-03-13 11:47:42 -070017class GrRectanizer;
18
Brian Salomon2ee084e2016-12-16 18:59:19 -050019struct GrDrawOpAtlasConfig {
joshualittda04e0e2015-08-19 08:16:43 -070020 int numPlotsX() const { return fWidth / fPlotWidth; }
21 int numPlotsY() const { return fHeight / fPlotWidth; }
22 int fWidth;
23 int fHeight;
24 int fPlotWidth;
25 int fPlotHeight;
26};
27
Brian Salomon2ee084e2016-12-16 18:59:19 -050028/**
Jim Van Verth106b5c42017-09-26 12:45:29 -040029 * This class manages one or more atlas textures on behalf of GrDrawOps. The draw ops that use the
30 * atlas perform texture uploads when preparing their draws during flush. The class provides
31 * facilities for using GrDrawOpUploadToken to detect data hazards. Op's uploads are performed in
Brian Salomon29b60c92017-10-31 14:42:10 -040032 * "ASAP" mode until it is impossible to add data without overwriting texels read by draws that
Jim Van Verth106b5c42017-09-26 12:45:29 -040033 * have not yet executed on the gpu. At that point, the atlas will attempt to allocate a new
34 * atlas texture (or "page") of the same size, up to a maximum number of textures, and upload
35 * to that texture. If that's not possible, the uploads are performed "inline" between draws. If a
36 * single draw would use enough subimage space to overflow the atlas texture then the atlas will
37 * fail to add a subimage. This gives the op the chance to end the draw and begin a new one.
38 * Additional uploads will then succeed in inline mode.
39 *
40 * When the atlas has multiple pages, new uploads are prioritized to the lower index pages, i.e.,
41 * it will try to upload to page 0 before page 1 or 2. To keep the atlas from continually using
42 * excess space, periodic garbage collection is needed to shift data from the higher index pages to
43 * the lower ones, and then eventually remove any pages that are no longer in use. "In use" is
44 * determined by using the GrDrawUploadToken system: After a flush each subarea of the page
45 * is checked to see whether it was used in that flush; if it is not, a counter is incremented.
46 * Once that counter reaches a threshold that subarea is considered to be no longer in use.
47 *
48 * Garbage collection is initiated by the GrDrawOpAtlas's client via the compact() method. One
49 * solution is to make the client a subclass of GrOnFlushCallbackObject, register it with the
50 * GrContext via addOnFlushCallbackObject(), and the client's postFlush() method calls compact()
51 * and passes in the given GrDrawUploadToken.
Brian Salomon2ee084e2016-12-16 18:59:19 -050052 */
53class GrDrawOpAtlas {
Brian Salomon9f545bc2017-11-06 10:36:57 -050054private:
55 static constexpr auto kMaxMultitexturePages = 4;
56
joshualitt5bf99f12015-03-13 11:47:42 -070057public:
Brian Salomon9f545bc2017-11-06 10:36:57 -050058 /** Is the atlas allowed to use more than one texture? */
59 enum class AllowMultitexturing : bool { kNo, kYes };
60
Brian Salomon2ee084e2016-12-16 18:59:19 -050061 /**
62 * An AtlasID is an opaque handle which callers can use to determine if the atlas contains
63 * a specific piece of data.
64 */
joshualitt8db6fdc2015-07-31 08:25:07 -070065 typedef uint64_t AtlasID;
joshualitt7c3a2f82015-03-31 13:32:05 -070066 static const uint32_t kInvalidAtlasID = 0;
67 static const uint64_t kInvalidAtlasGeneration = 0;
joshualitt5bf99f12015-03-13 11:47:42 -070068
Brian Salomon2ee084e2016-12-16 18:59:19 -050069 /**
70 * A function pointer for use as a callback during eviction. Whenever GrDrawOpAtlas evicts a
71 * specific AtlasID, it will call all of the registered listeners so they can process the
72 * eviction.
73 */
74 typedef void (*EvictionFunc)(GrDrawOpAtlas::AtlasID, void*);
joshualitt5bf99f12015-03-13 11:47:42 -070075
Robert Phillips256c37b2017-03-01 14:32:46 -050076 /**
77 * Returns a GrDrawOpAtlas. This function can be called anywhere, but the returned atlas
78 * should only be used inside of GrMeshDrawOp::onPrepareDraws.
79 * @param GrPixelConfig The pixel config which this atlas will store
80 * @param width width in pixels of the atlas
81 * @param height height in pixels of the atlas
82 * @param numPlotsX The number of plots the atlas should be broken up into in the X
83 * direction
84 * @param numPlotsY The number of plots the atlas should be broken up into in the Y
85 * direction
Brian Salomon9f545bc2017-11-06 10:36:57 -050086 * @param allowMultitexturing Can the atlas use more than one texture.
Robert Phillips256c37b2017-03-01 14:32:46 -050087 * @param func An eviction function which will be called whenever the atlas has to
88 * evict data
Brian Salomon9f545bc2017-11-06 10:36:57 -050089 * @param data User supplied data which will be passed into func whenever an
Robert Phillips256c37b2017-03-01 14:32:46 -050090 * eviction occurs
91 * @return An initialized GrDrawOpAtlas, or nullptr if creation fails
92 */
Brian Salomon9f545bc2017-11-06 10:36:57 -050093 static std::unique_ptr<GrDrawOpAtlas> Make(GrContext*, GrPixelConfig, int width, int height,
Robert Phillips256c37b2017-03-01 14:32:46 -050094 int numPlotsX, int numPlotsY,
Brian Salomon9f545bc2017-11-06 10:36:57 -050095 AllowMultitexturing allowMultitexturing,
Robert Phillips256c37b2017-03-01 14:32:46 -050096 GrDrawOpAtlas::EvictionFunc func, void* data);
joshualitt5bf99f12015-03-13 11:47:42 -070097
Brian Salomon2ee084e2016-12-16 18:59:19 -050098 /**
99 * Adds a width x height subimage to the atlas. Upon success it returns an ID and the subimage's
100 * coordinates in the backing texture. False is returned if the subimage cannot fit in the
101 * atlas without overwriting texels that will be read in the current draw. This indicates that
102 * the op should end its current draw and begin another before adding more data. Upon success,
103 * an upload of the provided image data will have been added to the GrDrawOp::Target, in "asap"
104 * mode if possible, otherwise in "inline" mode. Successive uploads in either mode may be
105 * consolidated.
106 * NOTE: When the GrDrawOp prepares a draw that reads from the atlas, it must immediately call
107 * 'setUseToken' with the currentToken from the GrDrawOp::Target, otherwise the next call to
108 * addToAtlas might cause the previous data to be overwritten before it has been read.
109 */
Brian Salomon29b60c92017-10-31 14:42:10 -0400110 bool addToAtlas(AtlasID*, GrDeferredUploadTarget*, int width, int height, const void* image,
joshualitt5bf99f12015-03-13 11:47:42 -0700111 SkIPoint16* loc);
112
Robert Phillips32f28182017-02-28 16:20:03 -0500113 GrContext* context() const { return fContext; }
Jim Van Vertha950b632017-09-12 11:54:11 -0400114 const sk_sp<GrTextureProxy>* getProxies() const { return fProxies; }
joshualitt5bf99f12015-03-13 11:47:42 -0700115
joshualitt7c3a2f82015-03-31 13:32:05 -0700116 uint64_t atlasGeneration() const { return fAtlasGeneration; }
joshualitt5df175e2015-11-18 13:37:54 -0800117
118 inline bool hasID(AtlasID id) {
Jim Van Vertha950b632017-09-12 11:54:11 -0400119 uint32_t plot = GetPlotIndexFromID(id);
120 SkASSERT(plot < fNumPlots);
121 uint32_t page = GetPageIndexFromID(id);
122 SkASSERT(page < fNumPages);
123 return fPages[page].fPlotArray[plot]->genID() == GetGenerationFromID(id);
joshualitt5df175e2015-11-18 13:37:54 -0800124 }
joshualittb4c507e2015-04-08 08:07:59 -0700125
Brian Salomon2ee084e2016-12-16 18:59:19 -0500126 /** To ensure the atlas does not evict a given entry, the client must set the last use token. */
Brian Salomon943ed792017-10-30 09:37:55 -0400127 inline void setLastUseToken(AtlasID id, GrDeferredUploadToken token) {
joshualitt5df175e2015-11-18 13:37:54 -0800128 SkASSERT(this->hasID(id));
Jim Van Vertha950b632017-09-12 11:54:11 -0400129 uint32_t plotIdx = GetPlotIndexFromID(id);
130 SkASSERT(plotIdx < fNumPlots);
131 uint32_t pageIdx = GetPageIndexFromID(id);
132 SkASSERT(pageIdx < fNumPages);
133 Plot* plot = fPages[pageIdx].fPlotArray[plotIdx].get();
134 this->makeMRU(plot, pageIdx);
135 plot->setLastUseToken(token);
joshualitt5df175e2015-11-18 13:37:54 -0800136 }
137
138 inline void registerEvictionCallback(EvictionFunc func, void* userData) {
joshualitt5bf99f12015-03-13 11:47:42 -0700139 EvictionData* data = fEvictionCallbacks.append();
140 data->fFunc = func;
141 data->fData = userData;
142 }
143
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400144 uint32_t pageCount() { return fNumPages; }
Jim Van Vertha950b632017-09-12 11:54:11 -0400145
Brian Salomon2ee084e2016-12-16 18:59:19 -0500146 /**
147 * A class which can be handed back to GrDrawOpAtlas for updating last use tokens in bulk. The
Jim Van Vertha950b632017-09-12 11:54:11 -0400148 * current max number of plots per page the GrDrawOpAtlas can handle is 32. If in the future
149 * this is insufficient then we can move to a 64 bit int.
joshualittb4c507e2015-04-08 08:07:59 -0700150 */
151 class BulkUseTokenUpdater {
152 public:
Jim Van Vertha950b632017-09-12 11:54:11 -0400153 BulkUseTokenUpdater() {
154 memset(fPlotAlreadyUpdated, 0, sizeof(fPlotAlreadyUpdated));
155 }
joshualitt7e97b0b2015-07-31 15:18:08 -0700156 BulkUseTokenUpdater(const BulkUseTokenUpdater& that)
Jim Van Vertha950b632017-09-12 11:54:11 -0400157 : fPlotsToUpdate(that.fPlotsToUpdate) {
158 memcpy(fPlotAlreadyUpdated, that.fPlotAlreadyUpdated, sizeof(fPlotAlreadyUpdated));
joshualitt7e97b0b2015-07-31 15:18:08 -0700159 }
160
joshualittb4c507e2015-04-08 08:07:59 -0700161 void add(AtlasID id) {
Jim Van Vertha950b632017-09-12 11:54:11 -0400162 int index = GrDrawOpAtlas::GetPlotIndexFromID(id);
163 int pageIdx = GrDrawOpAtlas::GetPageIndexFromID(id);
164 if (!this->find(pageIdx, index)) {
165 this->set(pageIdx, index);
joshualittb4c507e2015-04-08 08:07:59 -0700166 }
167 }
168
169 void reset() {
joshualitt4314e082015-04-23 08:03:35 -0700170 fPlotsToUpdate.reset();
Jim Van Vertha950b632017-09-12 11:54:11 -0400171 memset(fPlotAlreadyUpdated, 0, sizeof(fPlotAlreadyUpdated));
joshualittb4c507e2015-04-08 08:07:59 -0700172 }
173
Jim Van Vertha950b632017-09-12 11:54:11 -0400174 struct PlotData {
175 PlotData(int pageIdx, int plotIdx) : fPageIndex(pageIdx), fPlotIndex(plotIdx) {}
176 uint32_t fPageIndex;
177 uint32_t fPlotIndex;
178 };
179
joshualittb4c507e2015-04-08 08:07:59 -0700180 private:
Jim Van Vertha950b632017-09-12 11:54:11 -0400181 bool find(int pageIdx, int index) const {
joshualittb4c507e2015-04-08 08:07:59 -0700182 SkASSERT(index < kMaxPlots);
Jim Van Vertha950b632017-09-12 11:54:11 -0400183 return (fPlotAlreadyUpdated[pageIdx] >> index) & 1;
joshualittb4c507e2015-04-08 08:07:59 -0700184 }
185
Jim Van Vertha950b632017-09-12 11:54:11 -0400186 void set(int pageIdx, int index) {
187 SkASSERT(!this->find(pageIdx, index));
188 fPlotAlreadyUpdated[pageIdx] |= (1 << index);
189 fPlotsToUpdate.push_back(PlotData(pageIdx, index));
joshualittb4c507e2015-04-08 08:07:59 -0700190 }
191
Jim Van Vertha950b632017-09-12 11:54:11 -0400192 static constexpr int kMinItems = 4;
193 static constexpr int kMaxPlots = 32;
194 SkSTArray<kMinItems, PlotData, true> fPlotsToUpdate;
Brian Salomon9f545bc2017-11-06 10:36:57 -0500195 uint32_t fPlotAlreadyUpdated[kMaxMultitexturePages];
joshualittb4c507e2015-04-08 08:07:59 -0700196
Brian Salomon2ee084e2016-12-16 18:59:19 -0500197 friend class GrDrawOpAtlas;
joshualittb4c507e2015-04-08 08:07:59 -0700198 };
199
Brian Salomon943ed792017-10-30 09:37:55 -0400200 void setLastUseTokenBulk(const BulkUseTokenUpdater& updater, GrDeferredUploadToken token) {
joshualitt5df175e2015-11-18 13:37:54 -0800201 int count = updater.fPlotsToUpdate.count();
202 for (int i = 0; i < count; i++) {
Jim Van Vertha950b632017-09-12 11:54:11 -0400203 const BulkUseTokenUpdater::PlotData& pd = updater.fPlotsToUpdate[i];
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400204 // it's possible we've added a plot to the updater and subsequently the plot's page
205 // was deleted -- so we check to prevent a crash
Jim Van Verth6ca9c6f2017-09-27 18:04:34 -0400206 if (pd.fPageIndex < fNumPages) {
207 Plot* plot = fPages[pd.fPageIndex].fPlotArray[pd.fPlotIndex].get();
208 this->makeMRU(plot, pd.fPageIndex);
209 plot->setLastUseToken(token);
210 }
joshualitt5df175e2015-11-18 13:37:54 -0800211 }
212 }
joshualittb4c507e2015-04-08 08:07:59 -0700213
Brian Salomon943ed792017-10-30 09:37:55 -0400214 void compact(GrDeferredUploadToken startTokenForNextFlush);
Jim Van Verth106b5c42017-09-26 12:45:29 -0400215
Jim Van Vertha950b632017-09-12 11:54:11 -0400216 static constexpr auto kGlyphMaxDim = 256;
joshualitt010db532015-04-21 10:07:26 -0700217 static bool GlyphTooLargeForAtlas(int width, int height) {
218 return width > kGlyphMaxDim || height > kGlyphMaxDim;
219 }
220
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400221 static uint32_t GetPageIndexFromID(AtlasID id) {
222 return id & 0xff;
223 }
224
joshualitt5bf99f12015-03-13 11:47:42 -0700225private:
Brian Salomon9f545bc2017-11-06 10:36:57 -0500226 uint32_t maxPages() const {
227 return AllowMultitexturing::kYes == fAllowMultitexturing ? kMaxMultitexturePages : 1;
228 }
229
230 GrDrawOpAtlas(GrContext*, GrPixelConfig config, int width, int height, int numPlotsX,
231 int numPlotsY, AllowMultitexturing allowMultitexturing);
Robert Phillips256c37b2017-03-01 14:32:46 -0500232
Brian Salomon2ee084e2016-12-16 18:59:19 -0500233 /**
234 * The backing GrTexture for a GrDrawOpAtlas is broken into a spatial grid of Plots. The Plots
235 * keep track of subimage placement via their GrRectanizer. A Plot manages the lifetime of its
236 * data using two tokens, a last use token and a last upload token. Once a Plot is "full" (i.e.
237 * there is no room for the new subimage according to the GrRectanizer), it can no longer be
238 * used unless the last use of the Plot has already been flushed through to the gpu.
239 */
240 class Plot : public SkRefCnt {
241 SK_DECLARE_INTERNAL_LLIST_INTERFACE(Plot);
joshualitt5df175e2015-11-18 13:37:54 -0800242
243 public:
Jim Van Vertha950b632017-09-12 11:54:11 -0400244 /** index() is a unique id for the plot relative to the owning GrAtlas and page. */
245 uint32_t index() const { return fPlotIndex; }
Brian Salomon2ee084e2016-12-16 18:59:19 -0500246 /**
247 * genID() is incremented when the plot is evicted due to a atlas spill. It is used to know
248 * if a particular subimage is still present in the atlas.
249 */
joshualitt5df175e2015-11-18 13:37:54 -0800250 uint64_t genID() const { return fGenID; }
Brian Salomon2ee084e2016-12-16 18:59:19 -0500251 GrDrawOpAtlas::AtlasID id() const {
252 SkASSERT(GrDrawOpAtlas::kInvalidAtlasID != fID);
joshualitt5df175e2015-11-18 13:37:54 -0800253 return fID;
254 }
255 SkDEBUGCODE(size_t bpp() const { return fBytesPerPixel; })
256
257 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc);
258
Brian Salomon2ee084e2016-12-16 18:59:19 -0500259 /**
260 * To manage the lifetime of a plot, we use two tokens. We use the last upload token to
261 * know when we can 'piggy back' uploads, i.e. if the last upload hasn't been flushed to
262 * the gpu, we don't need to issue a new upload even if we update the cpu backing store. We
263 * use lastUse to determine when we can evict a plot from the cache, i.e. if the last use
264 * has already flushed through the gpu then we can reuse the plot.
265 */
Brian Salomon943ed792017-10-30 09:37:55 -0400266 GrDeferredUploadToken lastUploadToken() const { return fLastUpload; }
267 GrDeferredUploadToken lastUseToken() const { return fLastUse; }
268 void setLastUploadToken(GrDeferredUploadToken token) { fLastUpload = token; }
269 void setLastUseToken(GrDeferredUploadToken token) { fLastUse = token; }
joshualitt5df175e2015-11-18 13:37:54 -0800270
Brian Salomon943ed792017-10-30 09:37:55 -0400271 void uploadToTexture(GrDeferredTextureUploadWritePixelsFn&, GrTextureProxy*);
joshualitt5df175e2015-11-18 13:37:54 -0800272 void resetRects();
273
Jim Van Verth106b5c42017-09-26 12:45:29 -0400274 int flushesSinceLastUsed() { return fFlushesSinceLastUse; }
275 void resetFlushesSinceLastUsed() { fFlushesSinceLastUse = 0; }
276 void incFlushesSinceLastUsed() { fFlushesSinceLastUse++; }
277
joshualitt5df175e2015-11-18 13:37:54 -0800278 private:
Jim Van Vertha950b632017-09-12 11:54:11 -0400279 Plot(int pageIndex, int plotIndex, uint64_t genID, int offX, int offY, int width, int height,
Brian Salomon2ee084e2016-12-16 18:59:19 -0500280 GrPixelConfig config);
joshualitt5df175e2015-11-18 13:37:54 -0800281
Brian Salomon2ee084e2016-12-16 18:59:19 -0500282 ~Plot() override;
joshualitt5df175e2015-11-18 13:37:54 -0800283
Brian Salomon2ee084e2016-12-16 18:59:19 -0500284 /**
285 * Create a clone of this plot. The cloned plot will take the place of the current plot in
286 * the atlas
287 */
288 Plot* clone() const {
Jim Van Vertha950b632017-09-12 11:54:11 -0400289 return new Plot(fPageIndex, fPlotIndex, fGenID + 1, fX, fY, fWidth, fHeight, fConfig);
joshualitt5df175e2015-11-18 13:37:54 -0800290 }
291
Jim Van Vertha950b632017-09-12 11:54:11 -0400292 static GrDrawOpAtlas::AtlasID CreateId(uint32_t pageIdx, uint32_t plotIdx,
293 uint64_t generation) {
294 SkASSERT(pageIdx < (1 << 8));
Brian Salomon9f545bc2017-11-06 10:36:57 -0500295 SkASSERT(pageIdx < kMaxMultitexturePages);
Jim Van Vertha950b632017-09-12 11:54:11 -0400296 SkASSERT(plotIdx < (1 << 8));
joshualitt5df175e2015-11-18 13:37:54 -0800297 SkASSERT(generation < ((uint64_t)1 << 48));
Jim Van Vertha950b632017-09-12 11:54:11 -0400298 return generation << 16 | plotIdx << 8 | pageIdx;
joshualitt5df175e2015-11-18 13:37:54 -0800299 }
300
Brian Salomon943ed792017-10-30 09:37:55 -0400301 GrDeferredUploadToken fLastUpload;
302 GrDeferredUploadToken fLastUse;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400303 // the number of flushes since this plot has been last used
304 int fFlushesSinceLastUse;
joshualitt5df175e2015-11-18 13:37:54 -0800305
Jim Van Vertha950b632017-09-12 11:54:11 -0400306 struct {
307 const uint32_t fPageIndex : 16;
308 const uint32_t fPlotIndex : 16;
309 };
Brian Salomon2ee084e2016-12-16 18:59:19 -0500310 uint64_t fGenID;
311 GrDrawOpAtlas::AtlasID fID;
312 unsigned char* fData;
313 const int fWidth;
314 const int fHeight;
315 const int fX;
316 const int fY;
317 GrRectanizer* fRects;
318 const SkIPoint16 fOffset; // the offset of the plot in the backing texture
319 const GrPixelConfig fConfig;
320 const size_t fBytesPerPixel;
321 SkIRect fDirtyRect;
322 SkDEBUGCODE(bool fDirty);
joshualitt5df175e2015-11-18 13:37:54 -0800323
Brian Salomon2ee084e2016-12-16 18:59:19 -0500324 friend class GrDrawOpAtlas;
joshualitt5df175e2015-11-18 13:37:54 -0800325
326 typedef SkRefCnt INHERITED;
327 };
328
Brian Salomon2ee084e2016-12-16 18:59:19 -0500329 typedef SkTInternalLList<Plot> PlotList;
robertphillips2b0536f2015-11-06 14:10:42 -0800330
Jim Van Vertha950b632017-09-12 11:54:11 -0400331 static uint32_t GetPlotIndexFromID(AtlasID id) {
332 return (id >> 8) & 0xff;
joshualitt5bf99f12015-03-13 11:47:42 -0700333 }
334
joshualitt8db6fdc2015-07-31 08:25:07 -0700335 // top 48 bits are reserved for the generation ID
336 static uint64_t GetGenerationFromID(AtlasID id) {
337 return (id >> 16) & 0xffffffffffff;
joshualitt5bf99f12015-03-13 11:47:42 -0700338 }
339
Brian Salomon29b60c92017-10-31 14:42:10 -0400340 inline bool updatePlot(GrDeferredUploadTarget*, AtlasID*, Plot*);
joshualitt5bf99f12015-03-13 11:47:42 -0700341
Jim Van Vertha950b632017-09-12 11:54:11 -0400342 inline void makeMRU(Plot* plot, int pageIdx) {
343 if (fPages[pageIdx].fPlotList.head() == plot) {
joshualitt5df175e2015-11-18 13:37:54 -0800344 return;
345 }
346
Jim Van Vertha950b632017-09-12 11:54:11 -0400347 fPages[pageIdx].fPlotList.remove(plot);
348 fPages[pageIdx].fPlotList.addToHead(plot);
349
Jim Van Verth106b5c42017-09-26 12:45:29 -0400350 // No MRU update for pages -- since we will always try to add from
351 // the front and remove from the back there is no need for MRU.
joshualitt5df175e2015-11-18 13:37:54 -0800352 }
joshualitt5bf99f12015-03-13 11:47:42 -0700353
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400354 bool createNewPage();
Jim Van Verth106b5c42017-09-26 12:45:29 -0400355 void deleteLastPage();
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400356
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400357 void processEviction(AtlasID);
358 inline void processEvictionAndResetRects(Plot* plot) {
359 this->processEviction(plot->id());
360 plot->resetRects();
361 }
joshualitt5bf99f12015-03-13 11:47:42 -0700362
Robert Phillips32f28182017-02-28 16:20:03 -0500363 GrContext* fContext;
Jim Van Verthd74f3f22017-08-31 16:44:08 -0400364 GrPixelConfig fPixelConfig;
365 int fTextureWidth;
366 int fTextureHeight;
Robert Phillips32f28182017-02-28 16:20:03 -0500367 int fPlotWidth;
368 int fPlotHeight;
369 SkDEBUGCODE(uint32_t fNumPlots;)
robertphillips2b0536f2015-11-06 14:10:42 -0800370
Robert Phillips32f28182017-02-28 16:20:03 -0500371 uint64_t fAtlasGeneration;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400372 // nextTokenToFlush() value at the end of the previous flush
Brian Salomon943ed792017-10-30 09:37:55 -0400373 GrDeferredUploadToken fPrevFlushToken;
joshualitt5bf99f12015-03-13 11:47:42 -0700374
375 struct EvictionData {
376 EvictionFunc fFunc;
377 void* fData;
378 };
379
380 SkTDArray<EvictionData> fEvictionCallbacks;
Jim Van Vertha950b632017-09-12 11:54:11 -0400381
382 struct Page {
383 // allocated array of Plots
384 std::unique_ptr<sk_sp<Plot>[]> fPlotArray;
385 // LRU list of Plots (MRU at head - LRU at tail)
386 PlotList fPlotList;
387 };
388 // proxies kept separate to make it easier to pass them up to client
Brian Salomon9f545bc2017-11-06 10:36:57 -0500389 sk_sp<GrTextureProxy> fProxies[kMaxMultitexturePages];
390 Page fPages[kMaxMultitexturePages];
391 AllowMultitexturing fAllowMultitexturing;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400392 uint32_t fNumPages;
joshualitt5bf99f12015-03-13 11:47:42 -0700393};
394
395#endif