blob: bc1b78937830c5b0c42eb086509abd294f6be5bb [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrDrawOpAtlas.h"
Robert Phillips32f28182017-02-28 16:20:03 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/gpu/GrContext.h"
11#include "include/gpu/GrTexture.h"
Robert Phillips03e4c952019-11-26 16:20:22 -050012#include "src/core/SkOpts.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrContextPriv.h"
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040014#include "src/gpu/GrGpu.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrOnFlushResourceProvider.h"
16#include "src/gpu/GrOpFlushState.h"
17#include "src/gpu/GrProxyProvider.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrResourceProvider.h"
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040019#include "src/gpu/GrResourceProviderPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrSurfaceProxyPriv.h"
21#include "src/gpu/GrTracing.h"
joshualitt5bf99f12015-03-13 11:47:42 -070022
Robert Phillipscd5099c2018-02-09 09:56:56 -050023// When proxy allocation is deferred until flush time the proxies acting as atlases require
24// special handling. This is because the usage that can be determined from the ops themselves
25// isn't sufficient. Independent of the ops there will be ASAP and inline uploads to the
26// atlases. Extending the usage interval of any op that uses an atlas to the start of the
27// flush (as is done for proxies that are used for sw-generated masks) also won't work because
28// the atlas persists even beyond the last use in an op - for a given flush. Given this, atlases
29// must explicitly manage the lifetime of their backing proxies via the onFlushCallback system
30// (which calls this method).
31void GrDrawOpAtlas::instantiate(GrOnFlushResourceProvider* onFlushResourceProvider) {
Robert Phillips4bc70112018-03-01 10:24:02 -050032 for (uint32_t i = 0; i < fNumActivePages; ++i) {
33 // All the atlas pages are now instantiated at flush time in the activeNewPage method.
Greg Daniel9715b6c2019-12-10 15:03:10 -050034 SkASSERT(fViews[i].proxy() && fViews[i].proxy()->isInstantiated());
Robert Phillipscd5099c2018-02-09 09:56:56 -050035 }
36}
37
Robert Phillips4bc70112018-03-01 10:24:02 -050038std::unique_ptr<GrDrawOpAtlas> GrDrawOpAtlas::Make(GrProxyProvider* proxyProvider,
Greg Daniel4065d452018-11-16 15:43:41 -050039 const GrBackendFormat& format,
Robert Phillips42dda082019-05-14 13:29:45 -040040 GrColorType colorType, int width,
Jim Van Verthf6206f92018-12-14 08:22:24 -050041 int height, int plotWidth, int plotHeight,
Brian Salomon9f545bc2017-11-06 10:36:57 -050042 AllowMultitexturing allowMultitexturing,
Herb Derby1a496c52020-01-22 17:26:56 -050043 EvictionCallback* evictor) {
Robert Phillips0a15cc62019-07-30 12:49:10 -040044 if (!format.isValid()) {
45 return nullptr;
46 }
47
Robert Phillips42dda082019-05-14 13:29:45 -040048 std::unique_ptr<GrDrawOpAtlas> atlas(new GrDrawOpAtlas(proxyProvider, format, colorType, width,
Jim Van Verthf6206f92018-12-14 08:22:24 -050049 height, plotWidth, plotHeight,
Robert Phillips4bc70112018-03-01 10:24:02 -050050 allowMultitexturing));
Greg Daniel9715b6c2019-12-10 15:03:10 -050051 if (!atlas->getViews()[0].proxy()) {
Jim Van Verthd74f3f22017-08-31 16:44:08 -040052 return nullptr;
53 }
54
Herb Derby1a496c52020-01-22 17:26:56 -050055 atlas->fEvictionCallbacks.emplace_back(evictor);
Robert Phillips256c37b2017-03-01 14:32:46 -050056 return atlas;
57}
58
Jim Van Verth28a9b122020-01-27 16:00:19 +000059#ifdef DUMP_ATLAS_DATA
60static bool gDumpAtlasData = false;
61#endif
Robert Phillips256c37b2017-03-01 14:32:46 -050062
joshualitt5df175e2015-11-18 13:37:54 -080063////////////////////////////////////////////////////////////////////////////////
Jim Van Vertha950b632017-09-12 11:54:11 -040064GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX, int offY,
Robert Phillips42dda082019-05-14 13:29:45 -040065 int width, int height, GrColorType colorType)
Brian Salomon943ed792017-10-30 09:37:55 -040066 : fLastUpload(GrDeferredUploadToken::AlreadyFlushedToken())
67 , fLastUse(GrDeferredUploadToken::AlreadyFlushedToken())
Jim Van Verth106b5c42017-09-26 12:45:29 -040068 , fFlushesSinceLastUse(0)
Jim Van Vertha950b632017-09-12 11:54:11 -040069 , fPageIndex(pageIndex)
70 , fPlotIndex(plotIndex)
Brian Salomon2ee084e2016-12-16 18:59:19 -050071 , fGenID(genID)
Herb Derby4d721712020-01-24 14:31:16 -050072 , fPlotLocator(CreatePlotLocator(fPageIndex, fPlotIndex, fGenID))
Brian Salomon2ee084e2016-12-16 18:59:19 -050073 , fData(nullptr)
74 , fWidth(width)
75 , fHeight(height)
76 , fX(offX)
77 , fY(offY)
Herb Derby73c75872020-01-22 18:09:16 -050078 , fRectanizer(width, height)
Brian Salomon2ee084e2016-12-16 18:59:19 -050079 , fOffset(SkIPoint16::Make(fX * fWidth, fY * fHeight))
Robert Phillips42dda082019-05-14 13:29:45 -040080 , fColorType(colorType)
81 , fBytesPerPixel(GrColorTypeBytesPerPixel(colorType))
joshualitt5df175e2015-11-18 13:37:54 -080082#ifdef SK_DEBUG
Brian Salomon2ee084e2016-12-16 18:59:19 -050083 , fDirty(false)
joshualitt5df175e2015-11-18 13:37:54 -080084#endif
85{
Jim Van Vertha8c55fa2018-02-20 15:38:08 -050086 // We expect the allocated dimensions to be a multiple of 4 bytes
87 SkASSERT(((width*fBytesPerPixel) & 0x3) == 0);
88 // The padding for faster uploads only works for 1, 2 and 4 byte texels
89 SkASSERT(fBytesPerPixel != 3 && fBytesPerPixel <= 4);
joshualitt5df175e2015-11-18 13:37:54 -080090 fDirtyRect.setEmpty();
91}
joshualitt5bf99f12015-03-13 11:47:42 -070092
Brian Salomon2ee084e2016-12-16 18:59:19 -050093GrDrawOpAtlas::Plot::~Plot() {
jvanverthc3d706f2016-04-20 10:33:27 -070094 sk_free(fData);
joshualitt5df175e2015-11-18 13:37:54 -080095}
joshualitt5bf99f12015-03-13 11:47:42 -070096
Brian Salomon2ee084e2016-12-16 18:59:19 -050097bool GrDrawOpAtlas::Plot::addSubImage(int width, int height, const void* image, SkIPoint16* loc) {
joshualitt5df175e2015-11-18 13:37:54 -080098 SkASSERT(width <= fWidth && height <= fHeight);
joshualitt5bf99f12015-03-13 11:47:42 -070099
Herb Derby73c75872020-01-22 18:09:16 -0500100 if (!fRectanizer.addRect(width, height, loc)) {
joshualitt5df175e2015-11-18 13:37:54 -0800101 return false;
joshualittb4c507e2015-04-08 08:07:59 -0700102 }
joshualitt5bf99f12015-03-13 11:47:42 -0700103
jvanverthc3d706f2016-04-20 10:33:27 -0700104 if (!fData) {
105 fData = reinterpret_cast<unsigned char*>(sk_calloc_throw(fBytesPerPixel * fWidth *
106 fHeight));
joshualitt5df175e2015-11-18 13:37:54 -0800107 }
108 size_t rowBytes = width * fBytesPerPixel;
109 const unsigned char* imagePtr = (const unsigned char*)image;
110 // point ourselves at the right starting spot
jvanverthc3d706f2016-04-20 10:33:27 -0700111 unsigned char* dataPtr = fData;
joshualitt5df175e2015-11-18 13:37:54 -0800112 dataPtr += fBytesPerPixel * fWidth * loc->fY;
113 dataPtr += fBytesPerPixel * loc->fX;
Brian Osmancce3e582016-10-14 11:42:20 -0400114 // copy into the data buffer, swizzling as we go if this is ARGB data
Greg Danielb58a3c72020-01-23 10:05:14 -0500115 if (4 == fBytesPerPixel && kN32_SkColorType == kBGRA_8888_SkColorType) {
Brian Osmancce3e582016-10-14 11:42:20 -0400116 for (int i = 0; i < height; ++i) {
Mike Klein6e78ae52018-09-19 13:37:16 -0400117 SkOpts::RGBA_to_BGRA((uint32_t*)dataPtr, (const uint32_t*)imagePtr, width);
Brian Osmancce3e582016-10-14 11:42:20 -0400118 dataPtr += fBytesPerPixel * fWidth;
119 imagePtr += rowBytes;
120 }
121 } else {
122 for (int i = 0; i < height; ++i) {
123 memcpy(dataPtr, imagePtr, rowBytes);
124 dataPtr += fBytesPerPixel * fWidth;
125 imagePtr += rowBytes;
126 }
joshualitt5bf99f12015-03-13 11:47:42 -0700127 }
128
Mike Reed92b33352019-08-24 19:39:13 -0400129 fDirtyRect.join({loc->fX, loc->fY, loc->fX + width, loc->fY + height});
robertphillips2b0536f2015-11-06 14:10:42 -0800130
joshualitt5df175e2015-11-18 13:37:54 -0800131 loc->fX += fOffset.fX;
132 loc->fY += fOffset.fY;
133 SkDEBUGCODE(fDirty = true;)
joshualitt5bf99f12015-03-13 11:47:42 -0700134
joshualitt5df175e2015-11-18 13:37:54 -0800135 return true;
136}
joshualitt5bf99f12015-03-13 11:47:42 -0700137
Brian Salomon943ed792017-10-30 09:37:55 -0400138void GrDrawOpAtlas::Plot::uploadToTexture(GrDeferredTextureUploadWritePixelsFn& writePixels,
Robert Phillipsacaa6072017-07-28 10:54:53 -0400139 GrTextureProxy* proxy) {
joshualitt5df175e2015-11-18 13:37:54 -0800140 // We should only be issuing uploads if we are in fact dirty
Brian Salomonfd98c2c2018-07-31 17:25:29 -0400141 SkASSERT(fDirty && fData && proxy && proxy->peekTexture());
Brian Osman39c08ac2017-07-26 09:36:09 -0400142 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
joshualitt5df175e2015-11-18 13:37:54 -0800143 size_t rowBytes = fBytesPerPixel * fWidth;
jvanverthc3d706f2016-04-20 10:33:27 -0700144 const unsigned char* dataPtr = fData;
Jim Van Vertha8c55fa2018-02-20 15:38:08 -0500145 // Clamp to 4-byte aligned boundaries
146 unsigned int clearBits = 0x3 / fBytesPerPixel;
147 fDirtyRect.fLeft &= ~clearBits;
148 fDirtyRect.fRight += clearBits;
149 fDirtyRect.fRight &= ~clearBits;
150 SkASSERT(fDirtyRect.fRight <= fWidth);
151 // Set up dataPtr
jvanverthc3d706f2016-04-20 10:33:27 -0700152 dataPtr += rowBytes * fDirtyRect.fTop;
153 dataPtr += fBytesPerPixel * fDirtyRect.fLeft;
Robert Phillips42dda082019-05-14 13:29:45 -0400154
Robert Phillipsacaa6072017-07-28 10:54:53 -0400155 writePixels(proxy, fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop,
Robert Phillips42dda082019-05-14 13:29:45 -0400156 fDirtyRect.width(), fDirtyRect.height(), fColorType, dataPtr, rowBytes);
joshualitt5df175e2015-11-18 13:37:54 -0800157 fDirtyRect.setEmpty();
158 SkDEBUGCODE(fDirty = false;)
159}
160
Brian Salomon2ee084e2016-12-16 18:59:19 -0500161void GrDrawOpAtlas::Plot::resetRects() {
Herb Derby73c75872020-01-22 18:09:16 -0500162 fRectanizer.reset();
joshualitt5bf99f12015-03-13 11:47:42 -0700163
joshualitt5df175e2015-11-18 13:37:54 -0800164 fGenID++;
Herb Derby4d721712020-01-24 14:31:16 -0500165 fPlotLocator = CreatePlotLocator(fPageIndex, fPlotIndex, fGenID);
Brian Salomon943ed792017-10-30 09:37:55 -0400166 fLastUpload = GrDeferredUploadToken::AlreadyFlushedToken();
167 fLastUse = GrDeferredUploadToken::AlreadyFlushedToken();
joshualitt5df175e2015-11-18 13:37:54 -0800168
169 // zero out the plot
jvanverthc3d706f2016-04-20 10:33:27 -0700170 if (fData) {
171 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight);
joshualitt5bf99f12015-03-13 11:47:42 -0700172 }
173
joshualitt5df175e2015-11-18 13:37:54 -0800174 fDirtyRect.setEmpty();
175 SkDEBUGCODE(fDirty = false;)
176}
joshualitt5bf99f12015-03-13 11:47:42 -0700177
joshualitt5bf99f12015-03-13 11:47:42 -0700178///////////////////////////////////////////////////////////////////////////////
179
Greg Daniel4065d452018-11-16 15:43:41 -0500180GrDrawOpAtlas::GrDrawOpAtlas(GrProxyProvider* proxyProvider, const GrBackendFormat& format,
Robert Phillips42dda082019-05-14 13:29:45 -0400181 GrColorType colorType, int width, int height,
Jim Van Verthf6206f92018-12-14 08:22:24 -0500182 int plotWidth, int plotHeight, AllowMultitexturing allowMultitexturing)
Greg Daniel4065d452018-11-16 15:43:41 -0500183 : fFormat(format)
Robert Phillips42dda082019-05-14 13:29:45 -0400184 , fColorType(colorType)
Jim Van Verthd74f3f22017-08-31 16:44:08 -0400185 , fTextureWidth(width)
186 , fTextureHeight(height)
Jim Van Verthf6206f92018-12-14 08:22:24 -0500187 , fPlotWidth(plotWidth)
188 , fPlotHeight(plotHeight)
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400189 , fAtlasGeneration(kInvalidAtlasGeneration + 1)
Brian Salomon943ed792017-10-30 09:37:55 -0400190 , fPrevFlushToken(GrDeferredUploadToken::AlreadyFlushedToken())
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500191 , fMaxPages(AllowMultitexturing::kYes == allowMultitexturing ? kMaxMultitexturePages : 1)
Robert Phillips4bc70112018-03-01 10:24:02 -0500192 , fNumActivePages(0) {
Jim Van Verthf6206f92018-12-14 08:22:24 -0500193 int numPlotsX = width/plotWidth;
194 int numPlotsY = height/plotHeight;
Herb Derbybbf5fb52018-10-15 16:39:39 -0400195 SkASSERT(numPlotsX * numPlotsY <= GrDrawOpAtlas::kMaxPlots);
Jim Van Verthd74f3f22017-08-31 16:44:08 -0400196 SkASSERT(fPlotWidth * numPlotsX == fTextureWidth);
197 SkASSERT(fPlotHeight * numPlotsY == fTextureHeight);
robertphillips2b0536f2015-11-06 14:10:42 -0800198
Jim Van Verth06f593c2018-02-20 11:30:10 -0500199 fNumPlots = numPlotsX * numPlotsY;
joshualitt5bf99f12015-03-13 11:47:42 -0700200
Robert Phillips4bc70112018-03-01 10:24:02 -0500201 this->createPages(proxyProvider);
joshualitt5bf99f12015-03-13 11:47:42 -0700202}
203
Herb Derby4d721712020-01-24 14:31:16 -0500204inline void GrDrawOpAtlas::processEviction(PlotLocator plotLocator) {
Herb Derby1a496c52020-01-22 17:26:56 -0500205 for (auto evictor : fEvictionCallbacks) {
Herb Derby4d721712020-01-24 14:31:16 -0500206 evictor->evict(plotLocator);
joshualitt5bf99f12015-03-13 11:47:42 -0700207 }
Herb Derby1a496c52020-01-22 17:26:56 -0500208
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400209 ++fAtlasGeneration;
joshualitt5bf99f12015-03-13 11:47:42 -0700210}
211
Herb Derby4d721712020-01-24 14:31:16 -0500212inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target,
213 PlotLocator* plotLocator, Plot* plot) {
214 int pageIdx = GetPageIndexFromID(plot->plotLocator());
Jim Van Vertha950b632017-09-12 11:54:11 -0400215 this->makeMRU(plot, pageIdx);
joshualitt5bf99f12015-03-13 11:47:42 -0700216
217 // If our most recent upload has already occurred then we have to insert a new
218 // upload. Otherwise, we already have a scheduled upload that hasn't yet ocurred.
219 // This new update will piggy back on that previously scheduled update.
Robert Phillips40a29d72018-01-18 12:59:22 -0500220 if (plot->lastUploadToken() < target->tokenTracker()->nextTokenToFlush()) {
jvanverthc3d706f2016-04-20 10:33:27 -0700221 // With c+14 we could move sk_sp into lamba to only ref once.
Brian Salomon2ee084e2016-12-16 18:59:19 -0500222 sk_sp<Plot> plotsp(SkRef(plot));
Robert Phillips256c37b2017-03-01 14:32:46 -0500223
Greg Daniel9715b6c2019-12-10 15:03:10 -0500224 GrTextureProxy* proxy = fViews[pageIdx].asTextureProxy();
225 SkASSERT(proxy && proxy->isInstantiated()); // This is occurring at flush time
Robert Phillips256c37b2017-03-01 14:32:46 -0500226
Brian Salomon29b60c92017-10-31 14:42:10 -0400227 GrDeferredUploadToken lastUploadToken = target->addASAPUpload(
Brian Salomon943ed792017-10-30 09:37:55 -0400228 [plotsp, proxy](GrDeferredTextureUploadWritePixelsFn& writePixels) {
229 plotsp->uploadToTexture(writePixels, proxy);
230 });
Robert Phillips256c37b2017-03-01 14:32:46 -0500231 plot->setLastUploadToken(lastUploadToken);
joshualitt5bf99f12015-03-13 11:47:42 -0700232 }
Herb Derby4d721712020-01-24 14:31:16 -0500233 *plotLocator = plot->plotLocator();
Robert Phillips256c37b2017-03-01 14:32:46 -0500234 return true;
joshualitt5bf99f12015-03-13 11:47:42 -0700235}
236
Herb Derby4d721712020-01-24 14:31:16 -0500237bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, PlotLocator* plotLocator,
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400238 GrDeferredUploadTarget* target, int width, int height,
239 const void* image, SkIPoint16* loc) {
Greg Daniel9715b6c2019-12-10 15:03:10 -0500240 SkASSERT(fViews[pageIdx].proxy() && fViews[pageIdx].proxy()->isInstantiated());
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500241
242 // look through all allocated plots for one we can share, in Most Recently Refed order
243 PlotList::Iter plotIter;
244 plotIter.init(fPages[pageIdx].fPlotList, PlotList::Iter::kHead_IterStart);
245
246 for (Plot* plot = plotIter.get(); plot; plot = plotIter.next()) {
Greg Daniel9715b6c2019-12-10 15:03:10 -0500247 SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) == plot->bpp());
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500248
249 if (plot->addSubImage(width, height, image, loc)) {
Herb Derby4d721712020-01-24 14:31:16 -0500250 return this->updatePlot(target, plotLocator, plot);
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500251 }
252 }
253
254 return false;
255}
256
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400257// Number of atlas-related flushes beyond which we consider a plot to no longer be in use.
258//
259// This value is somewhat arbitrary -- the idea is to keep it low enough that
260// a page with unused plots will get removed reasonably quickly, but allow it
261// to hang around for a bit in case it's needed. The assumption is that flushes
262// are rare; i.e., we are not continually refreshing the frame.
Derek Sollenberger90196cc2017-10-09 15:00:33 -0400263static constexpr auto kRecentlyUsedCount = 256;
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400264
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500265GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceProvider,
Herb Derby4d721712020-01-24 14:31:16 -0500266 PlotLocator* plotLocator,
267 GrDeferredUploadTarget* target,
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500268 int width, int height,
269 const void* image, SkIPoint16* loc) {
bsalomon6d6b6ad2016-07-13 14:45:28 -0700270 if (width > fPlotWidth || height > fPlotHeight) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500271 return ErrorCode::kError;
bsalomon6d6b6ad2016-07-13 14:45:28 -0700272 }
joshualitt5bf99f12015-03-13 11:47:42 -0700273
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400274 const GrCaps& caps = *resourceProvider->caps();
275
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400276 // Look through each page to see if we can upload without having to flush
277 // We prioritize this upload to the first pages, not the most recently used, to make it easier
278 // to remove unused pages in reverse page order.
Robert Phillips4bc70112018-03-01 10:24:02 -0500279 for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) {
Herb Derby4d721712020-01-24 14:31:16 -0500280 if (this->uploadToPage(caps, pageIdx, plotLocator, target, width, height, image, loc)) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500281 return ErrorCode::kSucceeded;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400282 }
Jim Van Verth712fe732017-09-25 16:53:49 -0400283 }
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400284
Jim Van Verth712fe732017-09-25 16:53:49 -0400285 // If the above fails, then see if the least recently used plot per page has already been
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400286 // flushed to the gpu if we're at max page allocation, or if the plot has aged out otherwise.
287 // We wait until we've grown to the full number of pages to begin evicting already flushed
288 // plots so that we can maximize the opportunity for reuse.
Jim Van Verth712fe732017-09-25 16:53:49 -0400289 // As before we prioritize this upload to the first pages, not the most recently used.
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500290 if (fNumActivePages == this->maxPages()) {
291 for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) {
292 Plot* plot = fPages[pageIdx].fPlotList.tail();
293 SkASSERT(plot);
Jim Van Verthba98b7d2018-12-05 12:33:43 -0500294 if (plot->lastUseToken() < target->tokenTracker()->nextTokenToFlush()) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500295 this->processEvictionAndResetRects(plot);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500296 SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) ==
297 plot->bpp());
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500298 SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc);
299 SkASSERT(verify);
Herb Derby4d721712020-01-24 14:31:16 -0500300 if (!this->updatePlot(target, plotLocator, plot)) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500301 return ErrorCode::kError;
302 }
303 return ErrorCode::kSucceeded;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400304 }
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500305 }
306 } else {
307 // If we haven't activated all the available pages, try to create a new one and add to it
308 if (!this->activateNewPage(resourceProvider)) {
309 return ErrorCode::kError;
310 }
311
Herb Derby4d721712020-01-24 14:31:16 -0500312 if (this->uploadToPage(
313 caps, fNumActivePages-1, plotLocator, target, width, height, image, loc)) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500314 return ErrorCode::kSucceeded;
315 } else {
316 // If we fail to upload to a newly activated page then something has gone terribly
317 // wrong - return an error
318 return ErrorCode::kError;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400319 }
320 }
321
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500322 if (!fNumActivePages) {
323 return ErrorCode::kError;
joshualitt5bf99f12015-03-13 11:47:42 -0700324 }
325
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400326 // Try to find a plot that we can perform an inline upload to.
327 // We prioritize this upload in reverse order of pages to counterbalance the order above.
328 Plot* plot = nullptr;
Robert Phillips6250f292018-03-01 10:53:45 -0500329 for (int pageIdx = ((int)fNumActivePages)-1; pageIdx >= 0; --pageIdx) {
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400330 Plot* currentPlot = fPages[pageIdx].fPlotList.tail();
Robert Phillips40a29d72018-01-18 12:59:22 -0500331 if (currentPlot->lastUseToken() != target->tokenTracker()->nextDrawToken()) {
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400332 plot = currentPlot;
333 break;
Robert Phillips256c37b2017-03-01 14:32:46 -0500334 }
joshualitt5bf99f12015-03-13 11:47:42 -0700335 }
336
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400337 // If we can't find a plot that is not used in a draw currently being prepared by an op, then
338 // we have to fail. This gives the op a chance to enqueue the draw, and call back into this
339 // function. When that draw is enqueued, the draw token advances, and the subsequent call will
340 // continue past this branch and prepare an inline upload that will occur after the enqueued
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500341 // draw which references the plot's pre-upload content.
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400342 if (!plot) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500343 return ErrorCode::kTryAgain;
joshualitt5bf99f12015-03-13 11:47:42 -0700344 }
345
Herb Derby4d721712020-01-24 14:31:16 -0500346 this->processEviction(plot->plotLocator());
347 int pageIdx = GetPageIndexFromID(plot->plotLocator());
Jim Van Vertha950b632017-09-12 11:54:11 -0400348 fPages[pageIdx].fPlotList.remove(plot);
349 sk_sp<Plot>& newPlot = fPages[pageIdx].fPlotArray[plot->index()];
robertphillips2b0536f2015-11-06 14:10:42 -0800350 newPlot.reset(plot->clone());
joshualitt5bf99f12015-03-13 11:47:42 -0700351
Jim Van Vertha950b632017-09-12 11:54:11 -0400352 fPages[pageIdx].fPlotList.addToHead(newPlot.get());
Greg Daniel9715b6c2019-12-10 15:03:10 -0500353 SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) == newPlot->bpp());
robertphillips2b0536f2015-11-06 14:10:42 -0800354 SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc);
joshualitt5bf99f12015-03-13 11:47:42 -0700355 SkASSERT(verify);
robertphillips2b0536f2015-11-06 14:10:42 -0800356
robertphillips1f0e3502015-11-10 10:19:50 -0800357 // Note that this plot will be uploaded inline with the draws whereas the
Brian Salomon29b60c92017-10-31 14:42:10 -0400358 // one it displaced most likely was uploaded ASAP.
Brian Salomon2ee084e2016-12-16 18:59:19 -0500359 // With c+14 we could move sk_sp into lambda to only ref once.
360 sk_sp<Plot> plotsp(SkRef(newPlot.get()));
Robert Phillips4bc70112018-03-01 10:24:02 -0500361
Greg Daniel9715b6c2019-12-10 15:03:10 -0500362 GrTextureProxy* proxy = fViews[pageIdx].asTextureProxy();
363 SkASSERT(proxy && proxy->isInstantiated());
bsalomon342bfc22016-04-01 06:06:20 -0700364
Brian Salomon943ed792017-10-30 09:37:55 -0400365 GrDeferredUploadToken lastUploadToken = target->addInlineUpload(
366 [plotsp, proxy](GrDeferredTextureUploadWritePixelsFn& writePixels) {
367 plotsp->uploadToTexture(writePixels, proxy);
368 });
Robert Phillips256c37b2017-03-01 14:32:46 -0500369 newPlot->setLastUploadToken(lastUploadToken);
370
Herb Derby4d721712020-01-24 14:31:16 -0500371 *plotLocator = newPlot->plotLocator();
robertphillips2b0536f2015-11-06 14:10:42 -0800372
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500373 return ErrorCode::kSucceeded;
joshualitt5bf99f12015-03-13 11:47:42 -0700374}
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400375
Brian Salomon943ed792017-10-30 09:37:55 -0400376void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500377 if (fNumActivePages <= 1) {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400378 fPrevFlushToken = startTokenForNextFlush;
379 return;
380 }
381
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400382 // For all plots, reset number of flushes since used if used this frame.
Jim Van Verth106b5c42017-09-26 12:45:29 -0400383 PlotList::Iter plotIter;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400384 bool atlasUsedThisFlush = false;
Robert Phillips4bc70112018-03-01 10:24:02 -0500385 for (uint32_t pageIndex = 0; pageIndex < fNumActivePages; ++pageIndex) {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400386 plotIter.init(fPages[pageIndex].fPlotList, PlotList::Iter::kHead_IterStart);
387 while (Plot* plot = plotIter.get()) {
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400388 // Reset number of flushes since used
Jim Van Verth106b5c42017-09-26 12:45:29 -0400389 if (plot->lastUseToken().inInterval(fPrevFlushToken, startTokenForNextFlush)) {
390 plot->resetFlushesSinceLastUsed();
391 atlasUsedThisFlush = true;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400392 }
393
394 plotIter.next();
395 }
396 }
397
398 // We only try to compact if the atlas was used in the recently completed flush.
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400399 // This is to handle the case where a lot of text or path rendering has occurred but then just
400 // a blinking cursor is drawn.
Jim Van Verth106b5c42017-09-26 12:45:29 -0400401 // TODO: consider if we should also do this if it's been a long time since the last atlas use
402 if (atlasUsedThisFlush) {
Jim Van Verthcad0acf2018-02-16 18:41:41 -0500403 SkTArray<Plot*> availablePlots;
Robert Phillips4bc70112018-03-01 10:24:02 -0500404 uint32_t lastPageIndex = fNumActivePages - 1;
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400405
406 // For all plots but the last one, update number of flushes since used, and check to see
407 // if there are any in the first pages that the last page can safely upload to.
408 for (uint32_t pageIndex = 0; pageIndex < lastPageIndex; ++pageIndex) {
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400409#ifdef DUMP_ATLAS_DATA
410 if (gDumpAtlasData) {
411 SkDebugf("page %d: ", pageIndex);
412 }
413#endif
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400414 plotIter.init(fPages[pageIndex].fPlotList, PlotList::Iter::kHead_IterStart);
415 while (Plot* plot = plotIter.get()) {
416 // Update number of flushes since plot was last used
417 // We only increment the 'sinceLastUsed' count for flushes where the atlas was used
418 // to avoid deleting everything when we return to text drawing in the blinking
419 // cursor case
420 if (!plot->lastUseToken().inInterval(fPrevFlushToken, startTokenForNextFlush)) {
421 plot->incFlushesSinceLastUsed();
422 }
423
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400424#ifdef DUMP_ATLAS_DATA
425 if (gDumpAtlasData) {
426 SkDebugf("%d ", plot->flushesSinceLastUsed());
427 }
428#endif
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400429 // Count plots we can potentially upload to in all pages except the last one
430 // (the potential compactee).
431 if (plot->flushesSinceLastUsed() > kRecentlyUsedCount) {
Jim Van Verthcad0acf2018-02-16 18:41:41 -0500432 availablePlots.push_back() = plot;
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400433 }
434
435 plotIter.next();
436 }
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400437#ifdef DUMP_ATLAS_DATA
438 if (gDumpAtlasData) {
439 SkDebugf("\n");
440 }
441#endif
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400442 }
443
Jim Van Verth06f593c2018-02-20 11:30:10 -0500444 // Count recently used plots in the last page and evict any that are no longer in use.
445 // Since we prioritize uploading to the first pages, this will eventually
Jim Van Verth106b5c42017-09-26 12:45:29 -0400446 // clear out usage of this page unless we have a large need.
447 plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart);
Jim Van Verth06f593c2018-02-20 11:30:10 -0500448 unsigned int usedPlots = 0;
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400449#ifdef DUMP_ATLAS_DATA
450 if (gDumpAtlasData) {
451 SkDebugf("page %d: ", lastPageIndex);
452 }
453#endif
Jim Van Verth106b5c42017-09-26 12:45:29 -0400454 while (Plot* plot = plotIter.get()) {
Jim Van Verth62ea0cd2017-09-27 12:59:45 -0400455 // Update number of flushes since plot was last used
456 if (!plot->lastUseToken().inInterval(fPrevFlushToken, startTokenForNextFlush)) {
457 plot->incFlushesSinceLastUsed();
458 }
459
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400460#ifdef DUMP_ATLAS_DATA
461 if (gDumpAtlasData) {
462 SkDebugf("%d ", plot->flushesSinceLastUsed());
463 }
464#endif
Jim Van Verth106b5c42017-09-26 12:45:29 -0400465 // If this plot was used recently
466 if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) {
467 usedPlots++;
Brian Salomon943ed792017-10-30 09:37:55 -0400468 } else if (plot->lastUseToken() != GrDeferredUploadToken::AlreadyFlushedToken()) {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400469 // otherwise if aged out just evict it.
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400470 this->processEvictionAndResetRects(plot);
Jim Van Verth106b5c42017-09-26 12:45:29 -0400471 }
472 plotIter.next();
473 }
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400474#ifdef DUMP_ATLAS_DATA
475 if (gDumpAtlasData) {
476 SkDebugf("\n");
477 }
478#endif
Jim Van Verth06f593c2018-02-20 11:30:10 -0500479
480 // If recently used plots in the last page are using less than a quarter of the page, try
481 // to evict them if there's available space in earlier pages. Since we prioritize uploading
482 // to the first pages, this will eventually clear out usage of this page unless we have a
483 // large need.
484 if (availablePlots.count() && usedPlots && usedPlots <= fNumPlots / 4) {
485 plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart);
486 while (Plot* plot = plotIter.get()) {
487 // If this plot was used recently
488 if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) {
489 // See if there's room in an earlier page and if so evict.
490 // We need to be somewhat harsh here so that a handful of plots that are
491 // consistently in use don't end up locking the page in memory.
492 if (availablePlots.count() > 0) {
493 this->processEvictionAndResetRects(plot);
494 this->processEvictionAndResetRects(availablePlots.back());
495 availablePlots.pop_back();
496 --usedPlots;
497 }
498 if (!usedPlots || !availablePlots.count()) {
499 break;
500 }
501 }
502 plotIter.next();
503 }
504 }
505
Jim Van Verth106b5c42017-09-26 12:45:29 -0400506 // If none of the plots in the last page have been used recently, delete it.
507 if (!usedPlots) {
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400508#ifdef DUMP_ATLAS_DATA
509 if (gDumpAtlasData) {
510 SkDebugf("delete %d\n", fNumPages-1);
511 }
512#endif
Robert Phillips4bc70112018-03-01 10:24:02 -0500513 this->deactivateLastPage();
Jim Van Verth106b5c42017-09-26 12:45:29 -0400514 }
515 }
516
517 fPrevFlushToken = startTokenForNextFlush;
518}
519
Robert Phillips4bc70112018-03-01 10:24:02 -0500520bool GrDrawOpAtlas::createPages(GrProxyProvider* proxyProvider) {
521 SkASSERT(SkIsPow2(fTextureWidth) && SkIsPow2(fTextureHeight));
Robert Phillips0bd24dc2018-01-16 08:06:32 -0500522
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400523 GrSurfaceDesc desc;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400524 desc.fWidth = fTextureWidth;
525 desc.fHeight = fTextureHeight;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400526
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400527 int numPlotsX = fTextureWidth/fPlotWidth;
528 int numPlotsY = fTextureHeight/fPlotHeight;
529
Robert Phillips4bc70112018-03-01 10:24:02 -0500530 for (uint32_t i = 0; i < this->maxPages(); ++i) {
Greg Daniel47c20e82020-01-21 14:29:57 -0500531 GrSwizzle swizzle = proxyProvider->caps()->getReadSwizzle(fFormat, fColorType);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500532 sk_sp<GrSurfaceProxy> proxy = proxyProvider->createProxy(
Greg Daniel47c20e82020-01-21 14:29:57 -0500533 fFormat, desc, swizzle, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin,
534 GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo,
Brian Salomonbeb7f522019-08-30 16:19:42 -0400535 GrInternalSurfaceFlags::kNone, GrSurfaceProxy::UseAllocator::kNo);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500536 if (!proxy) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500537 return false;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400538 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500539 fViews[i] = GrSurfaceProxyView(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle);
Robert Phillips4bc70112018-03-01 10:24:02 -0500540
541 // set up allocated plots
542 fPages[i].fPlotArray.reset(new sk_sp<Plot>[ numPlotsX * numPlotsY ]);
543
544 sk_sp<Plot>* currPlot = fPages[i].fPlotArray.get();
545 for (int y = numPlotsY - 1, r = 0; y >= 0; --y, ++r) {
546 for (int x = numPlotsX - 1, c = 0; x >= 0; --x, ++c) {
547 uint32_t plotIndex = r * numPlotsX + c;
548 currPlot->reset(new Plot(i, plotIndex, 1, x, y, fPlotWidth, fPlotHeight,
Robert Phillips42dda082019-05-14 13:29:45 -0400549 fColorType));
Robert Phillips4bc70112018-03-01 10:24:02 -0500550
551 // build LRU list
552 fPages[i].fPlotList.addToHead(currPlot->get());
553 ++currPlot;
554 }
555 }
556
557 }
558
559 return true;
560}
561
562
563bool GrDrawOpAtlas::activateNewPage(GrResourceProvider* resourceProvider) {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500564 SkASSERT(fNumActivePages < this->maxPages());
Robert Phillips4bc70112018-03-01 10:24:02 -0500565
Greg Daniel9715b6c2019-12-10 15:03:10 -0500566 if (!fViews[fNumActivePages].proxy()->instantiate(resourceProvider)) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500567 return false;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400568 }
569
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400570#ifdef DUMP_ATLAS_DATA
571 if (gDumpAtlasData) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500572 SkDebugf("activated page#: %d\n", fNumActivePages);
Jim Van Verthc3269ae2017-09-28 15:04:00 -0400573 }
574#endif
Robert Phillips4bc70112018-03-01 10:24:02 -0500575
576 ++fNumActivePages;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400577 return true;
578}
Jim Van Verth106b5c42017-09-26 12:45:29 -0400579
Robert Phillips4bc70112018-03-01 10:24:02 -0500580
581inline void GrDrawOpAtlas::deactivateLastPage() {
582 SkASSERT(fNumActivePages);
583
584 uint32_t lastPageIndex = fNumActivePages - 1;
585
586 int numPlotsX = fTextureWidth/fPlotWidth;
587 int numPlotsY = fTextureHeight/fPlotHeight;
588
Jim Van Verth106b5c42017-09-26 12:45:29 -0400589 fPages[lastPageIndex].fPlotList.reset();
Robert Phillips6250f292018-03-01 10:53:45 -0500590 for (int r = 0; r < numPlotsY; ++r) {
591 for (int c = 0; c < numPlotsX; ++c) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500592 uint32_t plotIndex = r * numPlotsX + c;
593
594 Plot* currPlot = fPages[lastPageIndex].fPlotArray[plotIndex].get();
595 currPlot->resetRects();
596 currPlot->resetFlushesSinceLastUsed();
597
598 // rebuild the LRU list
599 SkDEBUGCODE(currPlot->fPrev = currPlot->fNext = nullptr);
600 SkDEBUGCODE(currPlot->fList = nullptr);
601 fPages[lastPageIndex].fPlotList.addToHead(currPlot);
602 }
603 }
604
605 // remove ref to the backing texture
Greg Daniel9715b6c2019-12-10 15:03:10 -0500606 fViews[lastPageIndex].proxy()->deinstantiate();
Robert Phillips4bc70112018-03-01 10:24:02 -0500607 --fNumActivePages;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400608}
Herb Derby15d9ef22018-10-18 13:41:32 -0400609
Jim Van Verthf6206f92018-12-14 08:22:24 -0500610GrDrawOpAtlasConfig::GrDrawOpAtlasConfig(int maxTextureSize, size_t maxBytes) {
611 static const SkISize kARGBDimensions[] = {
612 {256, 256}, // maxBytes < 2^19
613 {512, 256}, // 2^19 <= maxBytes < 2^20
614 {512, 512}, // 2^20 <= maxBytes < 2^21
615 {1024, 512}, // 2^21 <= maxBytes < 2^22
616 {1024, 1024}, // 2^22 <= maxBytes < 2^23
617 {2048, 1024}, // 2^23 <= maxBytes
618 };
Herb Derby15d9ef22018-10-18 13:41:32 -0400619
Jim Van Verthf6206f92018-12-14 08:22:24 -0500620 // Index 0 corresponds to maxBytes of 2^18, so start by dividing it by that
621 maxBytes >>= 18;
622 // Take the floor of the log to get the index
623 int index = maxBytes > 0
624 ? SkTPin<int>(SkPrevLog2(maxBytes), 0, SK_ARRAY_COUNT(kARGBDimensions) - 1)
625 : 0;
Herb Derby15d9ef22018-10-18 13:41:32 -0400626
Jim Van Verthf6206f92018-12-14 08:22:24 -0500627 SkASSERT(kARGBDimensions[index].width() <= kMaxAtlasDim);
628 SkASSERT(kARGBDimensions[index].height() <= kMaxAtlasDim);
629 fARGBDimensions.set(SkTMin<int>(kARGBDimensions[index].width(), maxTextureSize),
630 SkTMin<int>(kARGBDimensions[index].height(), maxTextureSize));
631 fMaxTextureSize = SkTMin<int>(maxTextureSize, kMaxAtlasDim);
Herb Derby15d9ef22018-10-18 13:41:32 -0400632}
633
634SkISize GrDrawOpAtlasConfig::atlasDimensions(GrMaskFormat type) const {
Jim Van Verthf6206f92018-12-14 08:22:24 -0500635 if (kA8_GrMaskFormat == type) {
636 // A8 is always 2x the ARGB dimensions, clamped to the max allowed texture size
637 return { SkTMin<int>(2 * fARGBDimensions.width(), fMaxTextureSize),
638 SkTMin<int>(2 * fARGBDimensions.height(), fMaxTextureSize) };
639 } else {
640 return fARGBDimensions;
641 }
Herb Derby15d9ef22018-10-18 13:41:32 -0400642}
643
Jim Van Verthf6206f92018-12-14 08:22:24 -0500644SkISize GrDrawOpAtlasConfig::plotDimensions(GrMaskFormat type) const {
645 if (kA8_GrMaskFormat == type) {
646 SkISize atlasDimensions = this->atlasDimensions(type);
647 // For A8 we want to grow the plots at larger texture sizes to accept more of the
648 // larger SDF glyphs. Since the largest SDF glyph can be 170x170 with padding, this
649 // allows us to pack 3 in a 512x256 plot, or 9 in a 512x512 plot.
Herb Derby15d9ef22018-10-18 13:41:32 -0400650
Jim Van Verth578b0892018-12-20 20:48:55 +0000651 // This will give us 512x256 plots for 2048x1024, 512x512 plots for 2048x2048,
652 // and 256x256 plots otherwise.
Jim Van Verthf6206f92018-12-14 08:22:24 -0500653 int plotWidth = atlasDimensions.width() >= 2048 ? 512 : 256;
Jim Van Verth578b0892018-12-20 20:48:55 +0000654 int plotHeight = atlasDimensions.height() >= 2048 ? 512 : 256;
Herb Derby15d9ef22018-10-18 13:41:32 -0400655
Jim Van Verthf6206f92018-12-14 08:22:24 -0500656 return { plotWidth, plotHeight };
657 } else {
658 // ARGB and LCD always use 256x256 plots -- this has been shown to be faster
659 return { 256, 256 };
660 }
Herb Derby15d9ef22018-10-18 13:41:32 -0400661}
662
Jim Van Verthf6206f92018-12-14 08:22:24 -0500663constexpr int GrDrawOpAtlasConfig::kMaxAtlasDim;