joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrDrawOpAtlas.h" |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrContext.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 11 | #include "src/core/SkOpts.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrContextPriv.h" |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 15 | #include "src/gpu/GrOpFlushState.h" |
| 16 | #include "src/gpu/GrProxyProvider.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrResourceProvider.h" |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrResourceProviderPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 20 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrTracing.h" |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 22 | |
Jim Van Verth | fb39510 | 2020-02-03 10:11:19 -0500 | [diff] [blame] | 23 | #ifdef DUMP_ATLAS_DATA |
| 24 | static bool gDumpAtlasData = false; |
| 25 | #endif |
| 26 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 27 | std::array<uint16_t, 4> GrDrawOpAtlas::AtlasLocator::getUVs(int padding) const { |
| 28 | |
| 29 | uint16_t left = fRect.fLeft + padding; |
| 30 | uint16_t top = fRect.fTop + padding; |
| 31 | uint16_t right = fRect.fRight - padding; |
| 32 | uint16_t bottom = fRect.fBottom - padding; |
| 33 | |
| 34 | // We pack the 2bit page index in the low bit of the u and v texture coords |
| 35 | uint32_t pageIndex = this->pageIndex(); |
| 36 | std::tie(left, bottom) = GrDrawOpAtlas::PackIndexInTexCoords(left, bottom, pageIndex); |
| 37 | std::tie(right, top) = GrDrawOpAtlas::PackIndexInTexCoords(right, top, pageIndex); |
| 38 | return { left, top, right, bottom }; |
| 39 | } |
| 40 | |
Robert Phillips | e87106d | 2020-04-09 14:21:33 -0400 | [diff] [blame] | 41 | #ifdef SK_DEBUG |
| 42 | void GrDrawOpAtlas::AtlasLocator::validate(const GrDrawOpAtlas* drawOpAtlas) const { |
| 43 | // Verify that the plotIndex stored in the PlotLocator is consistent with the glyph rectangle |
| 44 | int numPlotsX = drawOpAtlas->fTextureWidth / drawOpAtlas->fPlotWidth; |
| 45 | int numPlotsY = drawOpAtlas->fTextureHeight / drawOpAtlas->fPlotHeight; |
| 46 | |
| 47 | int plotIndex = this->plotIndex(); |
| 48 | int plotX = fRect.fLeft / drawOpAtlas->fPlotWidth; |
| 49 | int plotY = fRect.fTop / drawOpAtlas->fPlotHeight; |
| 50 | SkASSERT(plotIndex == (numPlotsY - plotY - 1) * numPlotsX + (numPlotsX - plotX - 1)); |
| 51 | } |
| 52 | #endif |
| 53 | |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 54 | // When proxy allocation is deferred until flush time the proxies acting as atlases require |
| 55 | // special handling. This is because the usage that can be determined from the ops themselves |
| 56 | // isn't sufficient. Independent of the ops there will be ASAP and inline uploads to the |
| 57 | // atlases. Extending the usage interval of any op that uses an atlas to the start of the |
| 58 | // flush (as is done for proxies that are used for sw-generated masks) also won't work because |
| 59 | // the atlas persists even beyond the last use in an op - for a given flush. Given this, atlases |
| 60 | // must explicitly manage the lifetime of their backing proxies via the onFlushCallback system |
| 61 | // (which calls this method). |
| 62 | void GrDrawOpAtlas::instantiate(GrOnFlushResourceProvider* onFlushResourceProvider) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 63 | for (uint32_t i = 0; i < fNumActivePages; ++i) { |
| 64 | // All the atlas pages are now instantiated at flush time in the activeNewPage method. |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 65 | SkASSERT(fViews[i].proxy() && fViews[i].proxy()->isInstantiated()); |
Robert Phillips | cd5099c | 2018-02-09 09:56:56 -0500 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 69 | std::unique_ptr<GrDrawOpAtlas> GrDrawOpAtlas::Make(GrProxyProvider* proxyProvider, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 70 | const GrBackendFormat& format, |
Robert Phillips | 42dda08 | 2019-05-14 13:29:45 -0400 | [diff] [blame] | 71 | GrColorType colorType, int width, |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 72 | int height, int plotWidth, int plotHeight, |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 73 | GenerationCounter* generationCounter, |
Brian Salomon | 9f545bc | 2017-11-06 10:36:57 -0500 | [diff] [blame] | 74 | AllowMultitexturing allowMultitexturing, |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 75 | EvictionCallback* evictor) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 76 | if (!format.isValid()) { |
| 77 | return nullptr; |
| 78 | } |
| 79 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 80 | std::unique_ptr<GrDrawOpAtlas> atlas(new GrDrawOpAtlas(proxyProvider, format, colorType, |
| 81 | width, height, plotWidth, plotHeight, |
| 82 | generationCounter, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 83 | allowMultitexturing)); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 84 | if (!atlas->getViews()[0].proxy()) { |
Jim Van Verth | d74f3f2 | 2017-08-31 16:44:08 -0400 | [diff] [blame] | 85 | return nullptr; |
| 86 | } |
| 87 | |
Herb Derby | a90ed95 | 2020-01-28 15:55:58 -0500 | [diff] [blame] | 88 | if (evictor != nullptr) { |
| 89 | atlas->fEvictionCallbacks.emplace_back(evictor); |
| 90 | } |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 91 | return atlas; |
| 92 | } |
| 93 | |
Jim Van Verth | fb39510 | 2020-02-03 10:11:19 -0500 | [diff] [blame] | 94 | // The two bits that make up the texture index are packed into the lower bits of the u and v |
| 95 | // coordinate respectively. |
| 96 | std::pair<uint16_t, uint16_t> GrDrawOpAtlas::PackIndexInTexCoords(uint16_t u, uint16_t v, |
| 97 | int pageIndex) { |
| 98 | SkASSERT(pageIndex >= 0 && pageIndex < 4); |
| 99 | uint16_t uBit = (pageIndex >> 1u) & 0x1u; |
| 100 | uint16_t vBit = pageIndex & 0x1u; |
| 101 | u <<= 1u; |
| 102 | u |= uBit; |
| 103 | v <<= 1u; |
| 104 | v |= vBit; |
| 105 | return std::make_pair(u, v); |
| 106 | } |
| 107 | |
| 108 | std::tuple<uint16_t, uint16_t, int> GrDrawOpAtlas::UnpackIndexFromTexCoords(uint16_t u, |
| 109 | uint16_t v) { |
| 110 | int pageIndex = 0; |
| 111 | if (u & 0x1) { |
| 112 | pageIndex |= 0x2; |
| 113 | } |
| 114 | if (v & 0x1) { |
| 115 | pageIndex |= 0x1; |
| 116 | } |
| 117 | return std::make_tuple(u >> 1, v >> 1, pageIndex); |
| 118 | } |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 119 | |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 120 | //////////////////////////////////////////////////////////////////////////////// |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 121 | GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, GenerationCounter* generationCounter, |
| 122 | int offX, int offY, int width, int height, GrColorType colorType) |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 123 | : fLastUpload(GrDeferredUploadToken::AlreadyFlushedToken()) |
| 124 | , fLastUse(GrDeferredUploadToken::AlreadyFlushedToken()) |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 125 | , fFlushesSinceLastUse(0) |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 126 | , fPageIndex(pageIndex) |
| 127 | , fPlotIndex(plotIndex) |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 128 | , fGenerationCounter(generationCounter) |
| 129 | , fGenID(fGenerationCounter->next()) |
Robert Phillips | bf5bf74 | 2020-04-13 09:29:08 -0400 | [diff] [blame] | 130 | , fPlotLocator(fPageIndex, fPlotIndex, fGenID) |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 131 | , fData(nullptr) |
| 132 | , fWidth(width) |
| 133 | , fHeight(height) |
| 134 | , fX(offX) |
| 135 | , fY(offY) |
Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 136 | , fRectanizer(width, height) |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 137 | , fOffset(SkIPoint16::Make(fX * fWidth, fY * fHeight)) |
Robert Phillips | 42dda08 | 2019-05-14 13:29:45 -0400 | [diff] [blame] | 138 | , fColorType(colorType) |
| 139 | , fBytesPerPixel(GrColorTypeBytesPerPixel(colorType)) |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 140 | #ifdef SK_DEBUG |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 141 | , fDirty(false) |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 142 | #endif |
| 143 | { |
Jim Van Verth | a8c55fa | 2018-02-20 15:38:08 -0500 | [diff] [blame] | 144 | // We expect the allocated dimensions to be a multiple of 4 bytes |
| 145 | SkASSERT(((width*fBytesPerPixel) & 0x3) == 0); |
| 146 | // The padding for faster uploads only works for 1, 2 and 4 byte texels |
| 147 | SkASSERT(fBytesPerPixel != 3 && fBytesPerPixel <= 4); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 148 | fDirtyRect.setEmpty(); |
| 149 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 150 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 151 | GrDrawOpAtlas::Plot::~Plot() { |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 152 | sk_free(fData); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 153 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 154 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 155 | bool GrDrawOpAtlas::Plot::addSubImage(int width, int height, const void* image, GrIRect16* rect) { |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 156 | SkASSERT(width <= fWidth && height <= fHeight); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 157 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 158 | SkIPoint16 loc; |
| 159 | if (!fRectanizer.addRect(width, height, &loc)) { |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 160 | return false; |
joshualitt | b4c507e | 2015-04-08 08:07:59 -0700 | [diff] [blame] | 161 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 162 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 163 | *rect = GrIRect16::MakeXYWH(loc.fX, loc.fY, width, height); |
| 164 | |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 165 | if (!fData) { |
| 166 | fData = reinterpret_cast<unsigned char*>(sk_calloc_throw(fBytesPerPixel * fWidth * |
| 167 | fHeight)); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 168 | } |
| 169 | size_t rowBytes = width * fBytesPerPixel; |
| 170 | const unsigned char* imagePtr = (const unsigned char*)image; |
| 171 | // point ourselves at the right starting spot |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 172 | unsigned char* dataPtr = fData; |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 173 | dataPtr += fBytesPerPixel * fWidth * rect->fTop; |
| 174 | dataPtr += fBytesPerPixel * rect->fLeft; |
Brian Osman | cce3e58 | 2016-10-14 11:42:20 -0400 | [diff] [blame] | 175 | // copy into the data buffer, swizzling as we go if this is ARGB data |
Greg Daniel | b58a3c7 | 2020-01-23 10:05:14 -0500 | [diff] [blame] | 176 | if (4 == fBytesPerPixel && kN32_SkColorType == kBGRA_8888_SkColorType) { |
Brian Osman | cce3e58 | 2016-10-14 11:42:20 -0400 | [diff] [blame] | 177 | for (int i = 0; i < height; ++i) { |
Mike Klein | 6e78ae5 | 2018-09-19 13:37:16 -0400 | [diff] [blame] | 178 | SkOpts::RGBA_to_BGRA((uint32_t*)dataPtr, (const uint32_t*)imagePtr, width); |
Brian Osman | cce3e58 | 2016-10-14 11:42:20 -0400 | [diff] [blame] | 179 | dataPtr += fBytesPerPixel * fWidth; |
| 180 | imagePtr += rowBytes; |
| 181 | } |
| 182 | } else { |
| 183 | for (int i = 0; i < height; ++i) { |
| 184 | memcpy(dataPtr, imagePtr, rowBytes); |
| 185 | dataPtr += fBytesPerPixel * fWidth; |
| 186 | imagePtr += rowBytes; |
| 187 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 190 | fDirtyRect.join({rect->fLeft, rect->fTop, rect->fRight, rect->fBottom}); |
robertphillips | 2b0536f | 2015-11-06 14:10:42 -0800 | [diff] [blame] | 191 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 192 | rect->offset(fOffset.fX, fOffset.fY); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 193 | SkDEBUGCODE(fDirty = true;) |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 194 | |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 195 | return true; |
| 196 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 197 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 198 | void GrDrawOpAtlas::Plot::uploadToTexture(GrDeferredTextureUploadWritePixelsFn& writePixels, |
Robert Phillips | acaa607 | 2017-07-28 10:54:53 -0400 | [diff] [blame] | 199 | GrTextureProxy* proxy) { |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 200 | // We should only be issuing uploads if we are in fact dirty |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 201 | SkASSERT(fDirty && fData && proxy && proxy->peekTexture()); |
Brian Osman | 39c08ac | 2017-07-26 09:36:09 -0400 | [diff] [blame] | 202 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 203 | size_t rowBytes = fBytesPerPixel * fWidth; |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 204 | const unsigned char* dataPtr = fData; |
Jim Van Verth | a8c55fa | 2018-02-20 15:38:08 -0500 | [diff] [blame] | 205 | // Clamp to 4-byte aligned boundaries |
| 206 | unsigned int clearBits = 0x3 / fBytesPerPixel; |
| 207 | fDirtyRect.fLeft &= ~clearBits; |
| 208 | fDirtyRect.fRight += clearBits; |
| 209 | fDirtyRect.fRight &= ~clearBits; |
| 210 | SkASSERT(fDirtyRect.fRight <= fWidth); |
| 211 | // Set up dataPtr |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 212 | dataPtr += rowBytes * fDirtyRect.fTop; |
| 213 | dataPtr += fBytesPerPixel * fDirtyRect.fLeft; |
Robert Phillips | 42dda08 | 2019-05-14 13:29:45 -0400 | [diff] [blame] | 214 | |
Robert Phillips | acaa607 | 2017-07-28 10:54:53 -0400 | [diff] [blame] | 215 | writePixels(proxy, fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop, |
Robert Phillips | 42dda08 | 2019-05-14 13:29:45 -0400 | [diff] [blame] | 216 | fDirtyRect.width(), fDirtyRect.height(), fColorType, dataPtr, rowBytes); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 217 | fDirtyRect.setEmpty(); |
| 218 | SkDEBUGCODE(fDirty = false;) |
| 219 | } |
| 220 | |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 221 | void GrDrawOpAtlas::Plot::resetRects() { |
Herb Derby | 73c7587 | 2020-01-22 18:09:16 -0500 | [diff] [blame] | 222 | fRectanizer.reset(); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 223 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 224 | fGenID = fGenerationCounter->next(); |
Robert Phillips | bf5bf74 | 2020-04-13 09:29:08 -0400 | [diff] [blame] | 225 | fPlotLocator = PlotLocator(fPageIndex, fPlotIndex, fGenID); |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 226 | fLastUpload = GrDeferredUploadToken::AlreadyFlushedToken(); |
| 227 | fLastUse = GrDeferredUploadToken::AlreadyFlushedToken(); |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 228 | |
| 229 | // zero out the plot |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 230 | if (fData) { |
| 231 | sk_bzero(fData, fBytesPerPixel * fWidth * fHeight); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 232 | } |
| 233 | |
joshualitt | 5df175e | 2015-11-18 13:37:54 -0800 | [diff] [blame] | 234 | fDirtyRect.setEmpty(); |
| 235 | SkDEBUGCODE(fDirty = false;) |
| 236 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 237 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 238 | /////////////////////////////////////////////////////////////////////////////// |
| 239 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 240 | GrDrawOpAtlas::GrDrawOpAtlas( |
| 241 | GrProxyProvider* proxyProvider, const GrBackendFormat& format, |
| 242 | GrColorType colorType, int width, int height, int plotWidth, int plotHeight, |
| 243 | GenerationCounter* generationCounter, AllowMultitexturing allowMultitexturing) |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 244 | : fFormat(format) |
Robert Phillips | 42dda08 | 2019-05-14 13:29:45 -0400 | [diff] [blame] | 245 | , fColorType(colorType) |
Jim Van Verth | d74f3f2 | 2017-08-31 16:44:08 -0400 | [diff] [blame] | 246 | , fTextureWidth(width) |
| 247 | , fTextureHeight(height) |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 248 | , fPlotWidth(plotWidth) |
| 249 | , fPlotHeight(plotHeight) |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 250 | , fGenerationCounter(generationCounter) |
| 251 | , fAtlasGeneration(fGenerationCounter->next()) |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 252 | , fPrevFlushToken(GrDeferredUploadToken::AlreadyFlushedToken()) |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 253 | , fFlushesSinceLastUse(0) |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 254 | , fMaxPages(AllowMultitexturing::kYes == allowMultitexturing ? kMaxMultitexturePages : 1) |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 255 | , fNumActivePages(0) { |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 256 | int numPlotsX = width/plotWidth; |
| 257 | int numPlotsY = height/plotHeight; |
Herb Derby | bbf5fb5 | 2018-10-15 16:39:39 -0400 | [diff] [blame] | 258 | SkASSERT(numPlotsX * numPlotsY <= GrDrawOpAtlas::kMaxPlots); |
Jim Van Verth | d74f3f2 | 2017-08-31 16:44:08 -0400 | [diff] [blame] | 259 | SkASSERT(fPlotWidth * numPlotsX == fTextureWidth); |
| 260 | SkASSERT(fPlotHeight * numPlotsY == fTextureHeight); |
robertphillips | 2b0536f | 2015-11-06 14:10:42 -0800 | [diff] [blame] | 261 | |
Jim Van Verth | 06f593c | 2018-02-20 11:30:10 -0500 | [diff] [blame] | 262 | fNumPlots = numPlotsX * numPlotsY; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 263 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 264 | this->createPages(proxyProvider, generationCounter); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 267 | inline void GrDrawOpAtlas::processEviction(PlotLocator plotLocator) { |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 268 | for (auto evictor : fEvictionCallbacks) { |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 269 | evictor->evict(plotLocator); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 270 | } |
Herb Derby | 1a496c5 | 2020-01-22 17:26:56 -0500 | [diff] [blame] | 271 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 272 | fAtlasGeneration = fGenerationCounter->next(); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 275 | inline bool GrDrawOpAtlas::updatePlot(GrDeferredUploadTarget* target, |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 276 | AtlasLocator* atlasLocator, Plot* plot) { |
| 277 | int pageIdx = plot->pageIndex(); |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 278 | this->makeMRU(plot, pageIdx); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 279 | |
| 280 | // If our most recent upload has already occurred then we have to insert a new |
| 281 | // upload. Otherwise, we already have a scheduled upload that hasn't yet ocurred. |
| 282 | // This new update will piggy back on that previously scheduled update. |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 283 | if (plot->lastUploadToken() < target->tokenTracker()->nextTokenToFlush()) { |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 284 | // With c+14 we could move sk_sp into lamba to only ref once. |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 285 | sk_sp<Plot> plotsp(SkRef(plot)); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 286 | |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 287 | GrTextureProxy* proxy = fViews[pageIdx].asTextureProxy(); |
| 288 | SkASSERT(proxy && proxy->isInstantiated()); // This is occurring at flush time |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 289 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 290 | GrDeferredUploadToken lastUploadToken = target->addASAPUpload( |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 291 | [plotsp, proxy](GrDeferredTextureUploadWritePixelsFn& writePixels) { |
| 292 | plotsp->uploadToTexture(writePixels, proxy); |
| 293 | }); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 294 | plot->setLastUploadToken(lastUploadToken); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 295 | } |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 296 | atlasLocator->fPlotLocator = plot->plotLocator(); |
Robert Phillips | e87106d | 2020-04-09 14:21:33 -0400 | [diff] [blame] | 297 | SkDEBUGCODE(atlasLocator->validate(this);) |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 298 | return true; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 301 | bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 302 | GrDeferredUploadTarget* target, int width, int height, |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 303 | const void* image, AtlasLocator* atlasLocator) { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 304 | SkASSERT(fViews[pageIdx].proxy() && fViews[pageIdx].proxy()->isInstantiated()); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 305 | |
| 306 | // look through all allocated plots for one we can share, in Most Recently Refed order |
| 307 | PlotList::Iter plotIter; |
| 308 | plotIter.init(fPages[pageIdx].fPlotList, PlotList::Iter::kHead_IterStart); |
| 309 | |
| 310 | for (Plot* plot = plotIter.get(); plot; plot = plotIter.next()) { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 311 | SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) == plot->bpp()); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 312 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 313 | if (plot->addSubImage(width, height, image, &atlasLocator->fRect)) { |
| 314 | return this->updatePlot(target, atlasLocator, plot); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | return false; |
| 319 | } |
| 320 | |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 321 | // Number of atlas-related flushes beyond which we consider a plot to no longer be in use. |
| 322 | // |
| 323 | // This value is somewhat arbitrary -- the idea is to keep it low enough that |
| 324 | // a page with unused plots will get removed reasonably quickly, but allow it |
| 325 | // to hang around for a bit in case it's needed. The assumption is that flushes |
| 326 | // are rare; i.e., we are not continually refreshing the frame. |
Jonathan Backer | 40c683a | 2020-05-04 15:00:02 -0400 | [diff] [blame^] | 327 | static constexpr auto kPlotRecentlyUsedCount = 32; |
| 328 | static constexpr auto kAtlasRecentlyUsedCount = 128; |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 329 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 330 | GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceProvider, |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 331 | GrDeferredUploadTarget* target, |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 332 | int width, int height, const void* image, |
| 333 | AtlasLocator* atlasLocator) { |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 334 | if (width > fPlotWidth || height > fPlotHeight) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 335 | return ErrorCode::kError; |
bsalomon | 6d6b6ad | 2016-07-13 14:45:28 -0700 | [diff] [blame] | 336 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 337 | |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 338 | const GrCaps& caps = *resourceProvider->caps(); |
| 339 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 340 | // Look through each page to see if we can upload without having to flush |
| 341 | // We prioritize this upload to the first pages, not the most recently used, to make it easier |
| 342 | // to remove unused pages in reverse page order. |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 343 | for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) { |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 344 | if (this->uploadToPage(caps, pageIdx, target, width, height, image, atlasLocator)) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 345 | return ErrorCode::kSucceeded; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 346 | } |
Jim Van Verth | 712fe73 | 2017-09-25 16:53:49 -0400 | [diff] [blame] | 347 | } |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 348 | |
Jim Van Verth | 712fe73 | 2017-09-25 16:53:49 -0400 | [diff] [blame] | 349 | // If the above fails, then see if the least recently used plot per page has already been |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 350 | // flushed to the gpu if we're at max page allocation, or if the plot has aged out otherwise. |
| 351 | // We wait until we've grown to the full number of pages to begin evicting already flushed |
| 352 | // plots so that we can maximize the opportunity for reuse. |
Jim Van Verth | 712fe73 | 2017-09-25 16:53:49 -0400 | [diff] [blame] | 353 | // As before we prioritize this upload to the first pages, not the most recently used. |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 354 | if (fNumActivePages == this->maxPages()) { |
| 355 | for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) { |
| 356 | Plot* plot = fPages[pageIdx].fPlotList.tail(); |
| 357 | SkASSERT(plot); |
Jim Van Verth | ba98b7d | 2018-12-05 12:33:43 -0500 | [diff] [blame] | 358 | if (plot->lastUseToken() < target->tokenTracker()->nextTokenToFlush()) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 359 | this->processEvictionAndResetRects(plot); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 360 | SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) == |
| 361 | plot->bpp()); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 362 | SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, |
| 363 | &atlasLocator->fRect); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 364 | SkASSERT(verify); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 365 | if (!this->updatePlot(target, atlasLocator, plot)) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 366 | return ErrorCode::kError; |
| 367 | } |
| 368 | return ErrorCode::kSucceeded; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 369 | } |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 370 | } |
| 371 | } else { |
| 372 | // If we haven't activated all the available pages, try to create a new one and add to it |
| 373 | if (!this->activateNewPage(resourceProvider)) { |
| 374 | return ErrorCode::kError; |
| 375 | } |
| 376 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 377 | if (this->uploadToPage(caps, fNumActivePages-1, target, width, height, image, |
| 378 | atlasLocator)) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 379 | return ErrorCode::kSucceeded; |
| 380 | } else { |
| 381 | // If we fail to upload to a newly activated page then something has gone terribly |
| 382 | // wrong - return an error |
| 383 | return ErrorCode::kError; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 387 | if (!fNumActivePages) { |
| 388 | return ErrorCode::kError; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 391 | // Try to find a plot that we can perform an inline upload to. |
| 392 | // We prioritize this upload in reverse order of pages to counterbalance the order above. |
| 393 | Plot* plot = nullptr; |
Robert Phillips | 6250f29 | 2018-03-01 10:53:45 -0500 | [diff] [blame] | 394 | for (int pageIdx = ((int)fNumActivePages)-1; pageIdx >= 0; --pageIdx) { |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 395 | Plot* currentPlot = fPages[pageIdx].fPlotList.tail(); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 396 | if (currentPlot->lastUseToken() != target->tokenTracker()->nextDrawToken()) { |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 397 | plot = currentPlot; |
| 398 | break; |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 399 | } |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 402 | // If we can't find a plot that is not used in a draw currently being prepared by an op, then |
| 403 | // we have to fail. This gives the op a chance to enqueue the draw, and call back into this |
| 404 | // function. When that draw is enqueued, the draw token advances, and the subsequent call will |
| 405 | // continue past this branch and prepare an inline upload that will occur after the enqueued |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 406 | // draw which references the plot's pre-upload content. |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 407 | if (!plot) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 408 | return ErrorCode::kTryAgain; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Herb Derby | 4d72171 | 2020-01-24 14:31:16 -0500 | [diff] [blame] | 411 | this->processEviction(plot->plotLocator()); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 412 | int pageIdx = plot->pageIndex(); |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 413 | fPages[pageIdx].fPlotList.remove(plot); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 414 | sk_sp<Plot>& newPlot = fPages[pageIdx].fPlotArray[plot->plotIndex()]; |
robertphillips | 2b0536f | 2015-11-06 14:10:42 -0800 | [diff] [blame] | 415 | newPlot.reset(plot->clone()); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 416 | |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 417 | fPages[pageIdx].fPlotList.addToHead(newPlot.get()); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 418 | SkASSERT(caps.bytesPerPixel(fViews[pageIdx].proxy()->backendFormat()) == newPlot->bpp()); |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 419 | SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, &atlasLocator->fRect); |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 420 | SkASSERT(verify); |
robertphillips | 2b0536f | 2015-11-06 14:10:42 -0800 | [diff] [blame] | 421 | |
robertphillips | 1f0e350 | 2015-11-10 10:19:50 -0800 | [diff] [blame] | 422 | // Note that this plot will be uploaded inline with the draws whereas the |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 423 | // one it displaced most likely was uploaded ASAP. |
Robert Phillips | e87106d | 2020-04-09 14:21:33 -0400 | [diff] [blame] | 424 | // With c++14 we could move sk_sp into lambda to only ref once. |
Brian Salomon | 2ee084e | 2016-12-16 18:59:19 -0500 | [diff] [blame] | 425 | sk_sp<Plot> plotsp(SkRef(newPlot.get())); |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 426 | |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 427 | GrTextureProxy* proxy = fViews[pageIdx].asTextureProxy(); |
| 428 | SkASSERT(proxy && proxy->isInstantiated()); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 429 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 430 | GrDeferredUploadToken lastUploadToken = target->addInlineUpload( |
| 431 | [plotsp, proxy](GrDeferredTextureUploadWritePixelsFn& writePixels) { |
| 432 | plotsp->uploadToTexture(writePixels, proxy); |
| 433 | }); |
Robert Phillips | 256c37b | 2017-03-01 14:32:46 -0500 | [diff] [blame] | 434 | newPlot->setLastUploadToken(lastUploadToken); |
| 435 | |
Robert Phillips | 6d3bc29 | 2020-04-06 10:29:28 -0400 | [diff] [blame] | 436 | atlasLocator->fPlotLocator = newPlot->plotLocator(); |
Robert Phillips | e87106d | 2020-04-09 14:21:33 -0400 | [diff] [blame] | 437 | SkDEBUGCODE(atlasLocator->validate(this);) |
robertphillips | 2b0536f | 2015-11-06 14:10:42 -0800 | [diff] [blame] | 438 | |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 439 | return ErrorCode::kSucceeded; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 440 | } |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 441 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 442 | void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) { |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 443 | if (fNumActivePages < 1) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 444 | fPrevFlushToken = startTokenForNextFlush; |
| 445 | return; |
| 446 | } |
| 447 | |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 448 | // For all plots, reset number of flushes since used if used this frame. |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 449 | PlotList::Iter plotIter; |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 450 | bool atlasUsedThisFlush = false; |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 451 | for (uint32_t pageIndex = 0; pageIndex < fNumActivePages; ++pageIndex) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 452 | plotIter.init(fPages[pageIndex].fPlotList, PlotList::Iter::kHead_IterStart); |
| 453 | while (Plot* plot = plotIter.get()) { |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 454 | // Reset number of flushes since used |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 455 | if (plot->lastUseToken().inInterval(fPrevFlushToken, startTokenForNextFlush)) { |
| 456 | plot->resetFlushesSinceLastUsed(); |
| 457 | atlasUsedThisFlush = true; |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | plotIter.next(); |
| 461 | } |
| 462 | } |
| 463 | |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 464 | if (atlasUsedThisFlush) { |
| 465 | fFlushesSinceLastUse = 0; |
| 466 | } else { |
| 467 | ++fFlushesSinceLastUse; |
| 468 | } |
| 469 | |
| 470 | // We only try to compact if the atlas was used in the recently completed flush or |
| 471 | // hasn't been used in a long time. |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 472 | // This is to handle the case where a lot of text or path rendering has occurred but then just |
| 473 | // a blinking cursor is drawn. |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 474 | if (atlasUsedThisFlush || fFlushesSinceLastUse > kAtlasRecentlyUsedCount) { |
Jim Van Verth | cad0acf | 2018-02-16 18:41:41 -0500 | [diff] [blame] | 475 | SkTArray<Plot*> availablePlots; |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 476 | uint32_t lastPageIndex = fNumActivePages - 1; |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 477 | |
| 478 | // For all plots but the last one, update number of flushes since used, and check to see |
| 479 | // if there are any in the first pages that the last page can safely upload to. |
| 480 | for (uint32_t pageIndex = 0; pageIndex < lastPageIndex; ++pageIndex) { |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 481 | #ifdef DUMP_ATLAS_DATA |
| 482 | if (gDumpAtlasData) { |
| 483 | SkDebugf("page %d: ", pageIndex); |
| 484 | } |
| 485 | #endif |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 486 | plotIter.init(fPages[pageIndex].fPlotList, PlotList::Iter::kHead_IterStart); |
| 487 | while (Plot* plot = plotIter.get()) { |
| 488 | // Update number of flushes since plot was last used |
| 489 | // We only increment the 'sinceLastUsed' count for flushes where the atlas was used |
| 490 | // to avoid deleting everything when we return to text drawing in the blinking |
| 491 | // cursor case |
| 492 | if (!plot->lastUseToken().inInterval(fPrevFlushToken, startTokenForNextFlush)) { |
| 493 | plot->incFlushesSinceLastUsed(); |
| 494 | } |
| 495 | |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 496 | #ifdef DUMP_ATLAS_DATA |
| 497 | if (gDumpAtlasData) { |
| 498 | SkDebugf("%d ", plot->flushesSinceLastUsed()); |
| 499 | } |
| 500 | #endif |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 501 | // Count plots we can potentially upload to in all pages except the last one |
| 502 | // (the potential compactee). |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 503 | if (plot->flushesSinceLastUsed() > kPlotRecentlyUsedCount) { |
Jim Van Verth | cad0acf | 2018-02-16 18:41:41 -0500 | [diff] [blame] | 504 | availablePlots.push_back() = plot; |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | plotIter.next(); |
| 508 | } |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 509 | #ifdef DUMP_ATLAS_DATA |
| 510 | if (gDumpAtlasData) { |
| 511 | SkDebugf("\n"); |
| 512 | } |
| 513 | #endif |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 514 | } |
| 515 | |
Jim Van Verth | 06f593c | 2018-02-20 11:30:10 -0500 | [diff] [blame] | 516 | // Count recently used plots in the last page and evict any that are no longer in use. |
| 517 | // Since we prioritize uploading to the first pages, this will eventually |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 518 | // clear out usage of this page unless we have a large need. |
| 519 | plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart); |
Jim Van Verth | 06f593c | 2018-02-20 11:30:10 -0500 | [diff] [blame] | 520 | unsigned int usedPlots = 0; |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 521 | #ifdef DUMP_ATLAS_DATA |
| 522 | if (gDumpAtlasData) { |
| 523 | SkDebugf("page %d: ", lastPageIndex); |
| 524 | } |
| 525 | #endif |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 526 | while (Plot* plot = plotIter.get()) { |
Jim Van Verth | 62ea0cd | 2017-09-27 12:59:45 -0400 | [diff] [blame] | 527 | // Update number of flushes since plot was last used |
| 528 | if (!plot->lastUseToken().inInterval(fPrevFlushToken, startTokenForNextFlush)) { |
| 529 | plot->incFlushesSinceLastUsed(); |
| 530 | } |
| 531 | |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 532 | #ifdef DUMP_ATLAS_DATA |
| 533 | if (gDumpAtlasData) { |
| 534 | SkDebugf("%d ", plot->flushesSinceLastUsed()); |
| 535 | } |
| 536 | #endif |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 537 | // If this plot was used recently |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 538 | if (plot->flushesSinceLastUsed() <= kPlotRecentlyUsedCount) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 539 | usedPlots++; |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 540 | } else if (plot->lastUseToken() != GrDeferredUploadToken::AlreadyFlushedToken()) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 541 | // otherwise if aged out just evict it. |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 542 | this->processEvictionAndResetRects(plot); |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 543 | } |
| 544 | plotIter.next(); |
| 545 | } |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 546 | #ifdef DUMP_ATLAS_DATA |
| 547 | if (gDumpAtlasData) { |
| 548 | SkDebugf("\n"); |
| 549 | } |
| 550 | #endif |
Jim Van Verth | 06f593c | 2018-02-20 11:30:10 -0500 | [diff] [blame] | 551 | |
| 552 | // If recently used plots in the last page are using less than a quarter of the page, try |
| 553 | // to evict them if there's available space in earlier pages. Since we prioritize uploading |
| 554 | // to the first pages, this will eventually clear out usage of this page unless we have a |
| 555 | // large need. |
| 556 | if (availablePlots.count() && usedPlots && usedPlots <= fNumPlots / 4) { |
| 557 | plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart); |
| 558 | while (Plot* plot = plotIter.get()) { |
| 559 | // If this plot was used recently |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 560 | if (plot->flushesSinceLastUsed() <= kPlotRecentlyUsedCount) { |
Jim Van Verth | 06f593c | 2018-02-20 11:30:10 -0500 | [diff] [blame] | 561 | // See if there's room in an earlier page and if so evict. |
| 562 | // We need to be somewhat harsh here so that a handful of plots that are |
| 563 | // consistently in use don't end up locking the page in memory. |
| 564 | if (availablePlots.count() > 0) { |
| 565 | this->processEvictionAndResetRects(plot); |
| 566 | this->processEvictionAndResetRects(availablePlots.back()); |
| 567 | availablePlots.pop_back(); |
| 568 | --usedPlots; |
| 569 | } |
| 570 | if (!usedPlots || !availablePlots.count()) { |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | plotIter.next(); |
| 575 | } |
| 576 | } |
| 577 | |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 578 | // If none of the plots in the last page have been used recently, delete it. |
Jim Van Verth | 2665188 | 2020-03-18 15:30:07 +0000 | [diff] [blame] | 579 | if (!usedPlots) { |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 580 | #ifdef DUMP_ATLAS_DATA |
| 581 | if (gDumpAtlasData) { |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 582 | SkDebugf("delete %d\n", fNumActivePages-1); |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 583 | } |
| 584 | #endif |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 585 | this->deactivateLastPage(); |
Jim Van Verth | 77eb96d | 2020-03-18 12:32:34 -0400 | [diff] [blame] | 586 | fFlushesSinceLastUse = 0; |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
| 590 | fPrevFlushToken = startTokenForNextFlush; |
| 591 | } |
| 592 | |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 593 | bool GrDrawOpAtlas::createPages( |
| 594 | GrProxyProvider* proxyProvider, GenerationCounter* generationCounter) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 595 | SkASSERT(SkIsPow2(fTextureWidth) && SkIsPow2(fTextureHeight)); |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 596 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 597 | SkISize dims = {fTextureWidth, fTextureHeight}; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 598 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 599 | int numPlotsX = fTextureWidth/fPlotWidth; |
| 600 | int numPlotsY = fTextureHeight/fPlotHeight; |
| 601 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 602 | for (uint32_t i = 0; i < this->maxPages(); ++i) { |
Greg Daniel | 47c20e8 | 2020-01-21 14:29:57 -0500 | [diff] [blame] | 603 | GrSwizzle swizzle = proxyProvider->caps()->getReadSwizzle(fFormat, fColorType); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 604 | sk_sp<GrSurfaceProxy> proxy = proxyProvider->createProxy( |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 605 | fFormat, dims, GrRenderable::kNo, 1, GrMipMapped::kNo, SkBackingFit::kExact, |
| 606 | SkBudgeted::kYes, GrProtected::kNo, GrInternalSurfaceFlags::kNone, |
| 607 | GrSurfaceProxy::UseAllocator::kNo); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 608 | if (!proxy) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 609 | return false; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 610 | } |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 611 | fViews[i] = GrSurfaceProxyView(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle); |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 612 | |
| 613 | // set up allocated plots |
| 614 | fPages[i].fPlotArray.reset(new sk_sp<Plot>[ numPlotsX * numPlotsY ]); |
| 615 | |
| 616 | sk_sp<Plot>* currPlot = fPages[i].fPlotArray.get(); |
| 617 | for (int y = numPlotsY - 1, r = 0; y >= 0; --y, ++r) { |
| 618 | for (int x = numPlotsX - 1, c = 0; x >= 0; --x, ++c) { |
| 619 | uint32_t plotIndex = r * numPlotsX + c; |
Herb Derby | 0ef780b | 2020-01-24 15:57:11 -0500 | [diff] [blame] | 620 | currPlot->reset(new Plot( |
| 621 | i, plotIndex, generationCounter, x, y, fPlotWidth, fPlotHeight, fColorType)); |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 622 | |
| 623 | // build LRU list |
| 624 | fPages[i].fPlotList.addToHead(currPlot->get()); |
| 625 | ++currPlot; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | } |
| 630 | |
| 631 | return true; |
| 632 | } |
| 633 | |
| 634 | |
| 635 | bool GrDrawOpAtlas::activateNewPage(GrResourceProvider* resourceProvider) { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 636 | SkASSERT(fNumActivePages < this->maxPages()); |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 637 | |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 638 | if (!fViews[fNumActivePages].proxy()->instantiate(resourceProvider)) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 639 | return false; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 640 | } |
| 641 | |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 642 | #ifdef DUMP_ATLAS_DATA |
| 643 | if (gDumpAtlasData) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 644 | SkDebugf("activated page#: %d\n", fNumActivePages); |
Jim Van Verth | c3269ae | 2017-09-28 15:04:00 -0400 | [diff] [blame] | 645 | } |
| 646 | #endif |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 647 | |
| 648 | ++fNumActivePages; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 649 | return true; |
| 650 | } |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 651 | |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 652 | |
| 653 | inline void GrDrawOpAtlas::deactivateLastPage() { |
| 654 | SkASSERT(fNumActivePages); |
| 655 | |
| 656 | uint32_t lastPageIndex = fNumActivePages - 1; |
| 657 | |
| 658 | int numPlotsX = fTextureWidth/fPlotWidth; |
| 659 | int numPlotsY = fTextureHeight/fPlotHeight; |
| 660 | |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 661 | fPages[lastPageIndex].fPlotList.reset(); |
Robert Phillips | 6250f29 | 2018-03-01 10:53:45 -0500 | [diff] [blame] | 662 | for (int r = 0; r < numPlotsY; ++r) { |
| 663 | for (int c = 0; c < numPlotsX; ++c) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 664 | uint32_t plotIndex = r * numPlotsX + c; |
| 665 | |
| 666 | Plot* currPlot = fPages[lastPageIndex].fPlotArray[plotIndex].get(); |
| 667 | currPlot->resetRects(); |
| 668 | currPlot->resetFlushesSinceLastUsed(); |
| 669 | |
| 670 | // rebuild the LRU list |
| 671 | SkDEBUGCODE(currPlot->fPrev = currPlot->fNext = nullptr); |
| 672 | SkDEBUGCODE(currPlot->fList = nullptr); |
| 673 | fPages[lastPageIndex].fPlotList.addToHead(currPlot); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | // remove ref to the backing texture |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 678 | fViews[lastPageIndex].proxy()->deinstantiate(); |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 679 | --fNumActivePages; |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 680 | } |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 681 | |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 682 | GrDrawOpAtlasConfig::GrDrawOpAtlasConfig(int maxTextureSize, size_t maxBytes) { |
| 683 | static const SkISize kARGBDimensions[] = { |
| 684 | {256, 256}, // maxBytes < 2^19 |
| 685 | {512, 256}, // 2^19 <= maxBytes < 2^20 |
| 686 | {512, 512}, // 2^20 <= maxBytes < 2^21 |
| 687 | {1024, 512}, // 2^21 <= maxBytes < 2^22 |
| 688 | {1024, 1024}, // 2^22 <= maxBytes < 2^23 |
| 689 | {2048, 1024}, // 2^23 <= maxBytes |
| 690 | }; |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 691 | |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 692 | // Index 0 corresponds to maxBytes of 2^18, so start by dividing it by that |
| 693 | maxBytes >>= 18; |
| 694 | // Take the floor of the log to get the index |
| 695 | int index = maxBytes > 0 |
| 696 | ? SkTPin<int>(SkPrevLog2(maxBytes), 0, SK_ARRAY_COUNT(kARGBDimensions) - 1) |
| 697 | : 0; |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 698 | |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 699 | SkASSERT(kARGBDimensions[index].width() <= kMaxAtlasDim); |
| 700 | SkASSERT(kARGBDimensions[index].height() <= kMaxAtlasDim); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 701 | fARGBDimensions.set(std::min<int>(kARGBDimensions[index].width(), maxTextureSize), |
| 702 | std::min<int>(kARGBDimensions[index].height(), maxTextureSize)); |
| 703 | fMaxTextureSize = std::min<int>(maxTextureSize, kMaxAtlasDim); |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | SkISize GrDrawOpAtlasConfig::atlasDimensions(GrMaskFormat type) const { |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 707 | if (kA8_GrMaskFormat == type) { |
| 708 | // A8 is always 2x the ARGB dimensions, clamped to the max allowed texture size |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 709 | return { std::min<int>(2 * fARGBDimensions.width(), fMaxTextureSize), |
| 710 | std::min<int>(2 * fARGBDimensions.height(), fMaxTextureSize) }; |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 711 | } else { |
| 712 | return fARGBDimensions; |
| 713 | } |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 716 | SkISize GrDrawOpAtlasConfig::plotDimensions(GrMaskFormat type) const { |
| 717 | if (kA8_GrMaskFormat == type) { |
| 718 | SkISize atlasDimensions = this->atlasDimensions(type); |
| 719 | // For A8 we want to grow the plots at larger texture sizes to accept more of the |
| 720 | // larger SDF glyphs. Since the largest SDF glyph can be 170x170 with padding, this |
| 721 | // allows us to pack 3 in a 512x256 plot, or 9 in a 512x512 plot. |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 722 | |
Jim Van Verth | 578b089 | 2018-12-20 20:48:55 +0000 | [diff] [blame] | 723 | // This will give us 512x256 plots for 2048x1024, 512x512 plots for 2048x2048, |
| 724 | // and 256x256 plots otherwise. |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 725 | int plotWidth = atlasDimensions.width() >= 2048 ? 512 : 256; |
Jim Van Verth | 578b089 | 2018-12-20 20:48:55 +0000 | [diff] [blame] | 726 | int plotHeight = atlasDimensions.height() >= 2048 ? 512 : 256; |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 727 | |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 728 | return { plotWidth, plotHeight }; |
| 729 | } else { |
| 730 | // ARGB and LCD always use 256x256 plots -- this has been shown to be faster |
| 731 | return { 256, 256 }; |
| 732 | } |
Herb Derby | 15d9ef2 | 2018-10-18 13:41:32 -0400 | [diff] [blame] | 733 | } |
| 734 | |
Jim Van Verth | f6206f9 | 2018-12-14 08:22:24 -0500 | [diff] [blame] | 735 | constexpr int GrDrawOpAtlasConfig::kMaxAtlasDim; |