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