epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 9 | #include "GrAtlas.h" |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #include "GrGpu.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 12 | #include "GrRectanizer.h" |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 13 | #include "GrTracing.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | /////////////////////////////////////////////////////////////////////////////// |
| 16 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 17 | // for testing |
| 18 | #define FONT_CACHE_STATS 0 |
| 19 | #if FONT_CACHE_STATS |
| 20 | static int g_UploadCount = 0; |
| 21 | #endif |
| 22 | |
robertphillips | 17dabfc | 2014-07-16 13:26:24 -0700 | [diff] [blame] | 23 | GrPlot::GrPlot() |
| 24 | : fDrawToken(NULL, 0) |
| 25 | , fID(-1) |
| 26 | , fTexture(NULL) |
| 27 | , fRects(NULL) |
| 28 | , fAtlas(NULL) |
| 29 | , fBytesPerPixel(1) |
| 30 | , fDirty(false) |
| 31 | , fBatchUploads(false) |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 32 | { |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 33 | fOffset.set(0, 0); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | } |
| 35 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 36 | GrPlot::~GrPlot() { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 37 | SkDELETE_ARRAY(fPlotData); |
| 38 | fPlotData = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 39 | delete fRects; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | } |
| 41 | |
robertphillips | 17dabfc | 2014-07-16 13:26:24 -0700 | [diff] [blame] | 42 | void GrPlot::init(GrAtlas* atlas, int id, int offX, int offY, int width, int height, size_t bpp, |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 43 | bool batchUploads) { |
robertphillips | 17dabfc | 2014-07-16 13:26:24 -0700 | [diff] [blame] | 44 | fID = id; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 45 | fRects = GrRectanizer::Factory(width, height); |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 46 | fAtlas = atlas; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 47 | fOffset.set(offX * width, offY * height); |
| 48 | fBytesPerPixel = bpp; |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 49 | fPlotData = NULL; |
| 50 | fDirtyRect.setEmpty(); |
| 51 | fDirty = false; |
| 52 | fBatchUploads = batchUploads; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 53 | } |
| 54 | |
robertphillips | d537341 | 2014-06-02 10:20:14 -0700 | [diff] [blame] | 55 | static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset) { |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 56 | loc->fX += offset.fX; |
| 57 | loc->fY += offset.fY; |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 58 | } |
| 59 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 60 | bool GrPlot::addSubImage(int width, int height, const void* image, SkIPoint16* loc) { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 61 | float percentFull = fRects->percentFull(); |
commit-bot@chromium.org | f952924 | 2014-02-14 18:41:47 +0000 | [diff] [blame] | 62 | if (!fRects->addRect(width, height, loc)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | return false; |
| 64 | } |
| 65 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 66 | // if batching uploads, create backing memory on first use |
| 67 | // once the plot is nearly full we will revert to uploading each subimage individually |
| 68 | int plotWidth = fRects->width(); |
| 69 | int plotHeight = fRects->height(); |
| 70 | if (fBatchUploads && NULL == fPlotData && 0.0f == percentFull) { |
| 71 | fPlotData = SkNEW_ARRAY(unsigned char, fBytesPerPixel*plotWidth*plotHeight); |
| 72 | memset(fPlotData, 0, fBytesPerPixel*plotWidth*plotHeight); |
| 73 | } |
| 74 | |
| 75 | // if we have backing memory, copy to the memory and set for future upload |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 76 | if (fPlotData) { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 77 | const unsigned char* imagePtr = (const unsigned char*) image; |
| 78 | // point ourselves at the right starting spot |
| 79 | unsigned char* dataPtr = fPlotData; |
| 80 | dataPtr += fBytesPerPixel*plotWidth*loc->fY; |
| 81 | dataPtr += fBytesPerPixel*loc->fX; |
| 82 | // copy into the data buffer |
| 83 | for (int i = 0; i < height; ++i) { |
| 84 | memcpy(dataPtr, imagePtr, fBytesPerPixel*width); |
| 85 | dataPtr += fBytesPerPixel*plotWidth; |
| 86 | imagePtr += fBytesPerPixel*width; |
| 87 | } |
| 88 | |
| 89 | fDirtyRect.join(loc->fX, loc->fY, loc->fX + width, loc->fY + height); |
| 90 | adjust_for_offset(loc, fOffset); |
| 91 | fDirty = true; |
| 92 | // otherwise, just upload the image directly |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 93 | } else if (image) { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 94 | adjust_for_offset(loc, fOffset); |
| 95 | GrContext* context = fTexture->getContext(); |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 96 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTexture"); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 97 | context->writeTexturePixels(fTexture, |
| 98 | loc->fX, loc->fY, width, height, |
| 99 | fTexture->config(), image, 0, |
| 100 | GrContext::kDontFlush_PixelOpsFlag); |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 101 | } else { |
| 102 | adjust_for_offset(loc, fOffset); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 103 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 104 | |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 105 | #if FONT_CACHE_STATS |
| 106 | ++g_UploadCount; |
| 107 | #endif |
| 108 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 109 | return true; |
| 110 | } |
| 111 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 112 | void GrPlot::uploadToTexture() { |
| 113 | static const float kNearlyFullTolerance = 0.85f; |
| 114 | |
| 115 | // should only do this if batching is enabled |
| 116 | SkASSERT(fBatchUploads); |
| 117 | |
| 118 | if (fDirty) { |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 119 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTexture"); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 120 | SkASSERT(fTexture); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 121 | GrContext* context = fTexture->getContext(); |
| 122 | // We pass the flag that does not force a flush. We assume our caller is |
| 123 | // smart and hasn't referenced the part of the texture we're about to update |
| 124 | // since the last flush. |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 125 | size_t rowBytes = fBytesPerPixel*fRects->width(); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 126 | const unsigned char* dataPtr = fPlotData; |
| 127 | dataPtr += rowBytes*fDirtyRect.fTop; |
| 128 | dataPtr += fBytesPerPixel*fDirtyRect.fLeft; |
| 129 | context->writeTexturePixels(fTexture, |
skia.committer@gmail.com | a1633da | 2014-05-15 03:03:58 +0000 | [diff] [blame] | 130 | fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop, |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 131 | fDirtyRect.width(), fDirtyRect.height(), |
skia.committer@gmail.com | a1633da | 2014-05-15 03:03:58 +0000 | [diff] [blame] | 132 | fTexture->config(), dataPtr, |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 133 | rowBytes, |
| 134 | GrContext::kDontFlush_PixelOpsFlag); |
| 135 | fDirtyRect.setEmpty(); |
| 136 | fDirty = false; |
| 137 | // If the Plot is nearly full, anything else we add will probably be small and one |
| 138 | // at a time, so free up the memory and after this upload any new images directly. |
| 139 | if (fRects->percentFull() > kNearlyFullTolerance) { |
| 140 | SkDELETE_ARRAY(fPlotData); |
| 141 | fPlotData = NULL; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 146 | void GrPlot::resetRects() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 147 | SkASSERT(fRects); |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 148 | fRects->reset(); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 149 | } |
| 150 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 151 | /////////////////////////////////////////////////////////////////////////////// |
| 152 | |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 153 | GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, GrTextureFlags flags, |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 154 | const SkISize& backingTextureSize, |
| 155 | int numPlotsX, int numPlotsY, bool batchUploads) { |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 156 | fGpu = SkRef(gpu); |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 157 | fPixelConfig = config; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 158 | fFlags = flags; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 159 | fBackingTextureSize = backingTextureSize; |
| 160 | fNumPlotsX = numPlotsX; |
| 161 | fNumPlotsY = numPlotsY; |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 162 | fBatchUploads = batchUploads; |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 163 | fTexture = NULL; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 165 | int textureWidth = fBackingTextureSize.width(); |
| 166 | int textureHeight = fBackingTextureSize.height(); |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 167 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 168 | int plotWidth = textureWidth / fNumPlotsX; |
| 169 | int plotHeight = textureHeight / fNumPlotsY; |
| 170 | |
| 171 | SkASSERT(plotWidth * fNumPlotsX == textureWidth); |
| 172 | SkASSERT(plotHeight * fNumPlotsY == textureHeight); |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 173 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 174 | // We currently do not support compressed atlases... |
| 175 | SkASSERT(!GrPixelConfigIsCompressed(config)); |
| 176 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 177 | // set up allocated plots |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 178 | size_t bpp = GrBytesPerPixel(fPixelConfig); |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 179 | fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY)); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 180 | |
| 181 | GrPlot* currPlot = fPlotArray; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 182 | for (int y = numPlotsY-1; y >= 0; --y) { |
| 183 | for (int x = numPlotsX-1; x >= 0; --x) { |
robertphillips | 17dabfc | 2014-07-16 13:26:24 -0700 | [diff] [blame] | 184 | currPlot->init(this, y*numPlotsX+x, x, y, plotWidth, plotHeight, bpp, batchUploads); |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 185 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 186 | // build LRU list |
| 187 | fPlotList.addToHead(currPlot); |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 188 | ++currPlot; |
| 189 | } |
| 190 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 191 | } |
| 192 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 193 | GrAtlas::~GrAtlas() { |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 194 | SkSafeUnref(fTexture); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 195 | SkDELETE_ARRAY(fPlotArray); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 196 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 197 | fGpu->unref(); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 198 | #if FONT_CACHE_STATS |
| 199 | GrPrintf("Num uploads: %d\n", g_UploadCount); |
| 200 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 201 | } |
| 202 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 203 | void GrAtlas::makeMRU(GrPlot* plot) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 204 | if (fPlotList.head() == plot) { |
| 205 | return; |
| 206 | } |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 207 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 208 | fPlotList.remove(plot); |
| 209 | fPlotList.addToHead(plot); |
| 210 | }; |
| 211 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 212 | GrPlot* GrAtlas::addToAtlas(ClientPlotUsage* usage, |
| 213 | int width, int height, const void* image, |
| 214 | SkIPoint16* loc) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 215 | // iterate through entire plot list for this atlas, see if we can find a hole |
| 216 | // last one was most recently added and probably most empty |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 217 | for (int i = usage->fPlots.count()-1; i >= 0; --i) { |
| 218 | GrPlot* plot = usage->fPlots[i]; |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 219 | if (plot->addSubImage(width, height, image, loc)) { |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 220 | this->makeMRU(plot); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 221 | return plot; |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 222 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 223 | } |
| 224 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 225 | // before we get a new plot, make sure we have a backing texture |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 226 | if (NULL == fTexture) { |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 227 | // TODO: Update this to use the cache rather than directly creating a texture. |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 228 | GrTextureDesc desc; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 229 | desc.fFlags = fFlags | kDynamicUpdate_GrTextureFlagBit; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 230 | desc.fWidth = fBackingTextureSize.width(); |
| 231 | desc.fHeight = fBackingTextureSize.height(); |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 232 | desc.fConfig = fPixelConfig; |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 233 | |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 234 | fTexture = fGpu->createTexture(desc, NULL, 0); |
| 235 | if (NULL == fTexture) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 236 | return NULL; |
| 237 | } |
| 238 | } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 239 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 240 | // now look through all allocated plots for one we can share, in MRU order |
| 241 | GrPlotList::Iter plotIter; |
| 242 | plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); |
| 243 | GrPlot* plot; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 244 | while ((plot = plotIter.get())) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 245 | // make sure texture is set for quick lookup |
| 246 | plot->fTexture = fTexture; |
| 247 | if (plot->addSubImage(width, height, image, loc)) { |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 248 | this->makeMRU(plot); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 249 | // new plot for atlas, put at end of array |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 250 | SkASSERT(!usage->fPlots.contains(plot)); |
| 251 | *(usage->fPlots.append()) = plot; |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 252 | return plot; |
| 253 | } |
| 254 | plotIter.next(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 255 | } |
| 256 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 257 | // If the above fails, then the current plot list has no room |
| 258 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 259 | } |
| 260 | |
robertphillips | c4f30b1 | 2014-07-13 10:09:42 -0700 | [diff] [blame] | 261 | void GrAtlas::RemovePlot(ClientPlotUsage* usage, const GrPlot* plot) { |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 262 | int index = usage->fPlots.find(const_cast<GrPlot*>(plot)); |
| 263 | if (index >= 0) { |
| 264 | usage->fPlots.remove(index); |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 265 | } |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 266 | } |
| 267 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 268 | // get a plot that's not being used by the current draw |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 269 | GrPlot* GrAtlas::getUnusedPlot() { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 270 | GrPlotList::Iter plotIter; |
| 271 | plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart); |
| 272 | GrPlot* plot; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 273 | while ((plot = plotIter.get())) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 274 | if (plot->drawToken().isIssued()) { |
| 275 | return plot; |
| 276 | } |
| 277 | plotIter.prev(); |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 278 | } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 279 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 280 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 281 | } |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 282 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 283 | void GrAtlas::uploadPlotsToTexture() { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 284 | if (fBatchUploads) { |
| 285 | GrPlotList::Iter plotIter; |
| 286 | plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); |
| 287 | GrPlot* plot; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 288 | while ((plot = plotIter.get())) { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 289 | plot->uploadToTexture(); |
| 290 | plotIter.next(); |
| 291 | } |
| 292 | } |
| 293 | } |