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); |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 95 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTexture"); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 96 | fTexture->writePixels(loc->fX, loc->fY, width, height, 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"); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 117 | SkASSERT(fTexture); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 118 | // We pass the flag that does not force a flush. We assume our caller is |
| 119 | // smart and hasn't referenced the part of the texture we're about to update |
| 120 | // since the last flush. |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 121 | size_t rowBytes = fBytesPerPixel*fRects->width(); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 122 | const unsigned char* dataPtr = fPlotData; |
| 123 | dataPtr += rowBytes*fDirtyRect.fTop; |
| 124 | dataPtr += fBytesPerPixel*fDirtyRect.fLeft; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 125 | fTexture->writePixels(fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop, |
| 126 | fDirtyRect.width(), fDirtyRect.height(), fTexture->config(), dataPtr, |
| 127 | rowBytes, GrContext::kDontFlush_PixelOpsFlag); |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 128 | fDirtyRect.setEmpty(); |
| 129 | fDirty = false; |
| 130 | // If the Plot is nearly full, anything else we add will probably be small and one |
| 131 | // at a time, so free up the memory and after this upload any new images directly. |
| 132 | if (fRects->percentFull() > kNearlyFullTolerance) { |
| 133 | SkDELETE_ARRAY(fPlotData); |
| 134 | fPlotData = NULL; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 139 | void GrPlot::resetRects() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 140 | SkASSERT(fRects); |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 141 | fRects->reset(); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 142 | } |
| 143 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 144 | /////////////////////////////////////////////////////////////////////////////// |
| 145 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 146 | GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, GrSurfaceFlags flags, |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 147 | const SkISize& backingTextureSize, |
| 148 | int numPlotsX, int numPlotsY, bool batchUploads) { |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 149 | fGpu = SkRef(gpu); |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 150 | fPixelConfig = config; |
robertphillips | 952841b | 2014-06-30 08:26:50 -0700 | [diff] [blame] | 151 | fFlags = flags; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 152 | fBackingTextureSize = backingTextureSize; |
| 153 | fNumPlotsX = numPlotsX; |
| 154 | fNumPlotsY = numPlotsY; |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 155 | fBatchUploads = batchUploads; |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 156 | fTexture = NULL; |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 157 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 158 | int textureWidth = fBackingTextureSize.width(); |
| 159 | int textureHeight = fBackingTextureSize.height(); |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 160 | |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 161 | int plotWidth = textureWidth / fNumPlotsX; |
| 162 | int plotHeight = textureHeight / fNumPlotsY; |
| 163 | |
| 164 | SkASSERT(plotWidth * fNumPlotsX == textureWidth); |
| 165 | SkASSERT(plotHeight * fNumPlotsY == textureHeight); |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 166 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 167 | // We currently do not support compressed atlases... |
| 168 | SkASSERT(!GrPixelConfigIsCompressed(config)); |
| 169 | |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 170 | // set up allocated plots |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 171 | size_t bpp = GrBytesPerPixel(fPixelConfig); |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 172 | fPlotArray = SkNEW_ARRAY(GrPlot, (fNumPlotsX*fNumPlotsY)); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 173 | |
| 174 | GrPlot* currPlot = fPlotArray; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 175 | for (int y = numPlotsY-1; y >= 0; --y) { |
| 176 | for (int x = numPlotsX-1; x >= 0; --x) { |
robertphillips | 17dabfc | 2014-07-16 13:26:24 -0700 | [diff] [blame] | 177 | 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] | 178 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 179 | // build LRU list |
| 180 | fPlotList.addToHead(currPlot); |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 181 | ++currPlot; |
| 182 | } |
| 183 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 184 | } |
| 185 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 186 | GrAtlas::~GrAtlas() { |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 187 | SkSafeUnref(fTexture); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 188 | SkDELETE_ARRAY(fPlotArray); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 189 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 190 | fGpu->unref(); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 191 | #if FONT_CACHE_STATS |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 192 | SkDebugf("Num uploads: %d\n", g_UploadCount); |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 193 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | } |
| 195 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 196 | void GrAtlas::makeMRU(GrPlot* plot) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 197 | if (fPlotList.head() == plot) { |
| 198 | return; |
| 199 | } |
skia.committer@gmail.com | ade9a34 | 2014-03-04 03:02:32 +0000 | [diff] [blame] | 200 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 201 | fPlotList.remove(plot); |
| 202 | fPlotList.addToHead(plot); |
| 203 | }; |
| 204 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 205 | GrPlot* GrAtlas::addToAtlas(ClientPlotUsage* usage, |
| 206 | int width, int height, const void* image, |
| 207 | SkIPoint16* loc) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 208 | // iterate through entire plot list for this atlas, see if we can find a hole |
| 209 | // last one was most recently added and probably most empty |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 210 | for (int i = usage->fPlots.count()-1; i >= 0; --i) { |
| 211 | GrPlot* plot = usage->fPlots[i]; |
jvanverth | 294c326 | 2014-10-10 11:36:12 -0700 | [diff] [blame] | 212 | // client may have plots from more than one atlas, must check for ours before adding |
| 213 | if (this == plot->fAtlas && plot->addSubImage(width, height, image, loc)) { |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 214 | this->makeMRU(plot); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 215 | return plot; |
commit-bot@chromium.org | 67ed64e | 2013-08-05 19:42:56 +0000 | [diff] [blame] | 216 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 217 | } |
| 218 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 219 | // 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] | 220 | if (NULL == fTexture) { |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 221 | // TODO: Update this to use the cache rather than directly creating a texture. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 222 | GrSurfaceDesc desc; |
| 223 | desc.fFlags = fFlags; |
commit-bot@chromium.org | 53e1e4d | 2014-04-01 16:25:11 +0000 | [diff] [blame] | 224 | desc.fWidth = fBackingTextureSize.width(); |
| 225 | desc.fHeight = fBackingTextureSize.height(); |
commit-bot@chromium.org | 9529441 | 2013-09-26 15:28:40 +0000 | [diff] [blame] | 226 | desc.fConfig = fPixelConfig; |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 227 | |
commit-bot@chromium.org | 3fddf0e | 2013-09-26 12:57:19 +0000 | [diff] [blame] | 228 | fTexture = fGpu->createTexture(desc, NULL, 0); |
| 229 | if (NULL == fTexture) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 230 | return NULL; |
| 231 | } |
| 232 | } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 233 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 234 | // now look through all allocated plots for one we can share, in MRU order |
| 235 | GrPlotList::Iter plotIter; |
| 236 | plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); |
| 237 | GrPlot* plot; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 238 | while ((plot = plotIter.get())) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 239 | // make sure texture is set for quick lookup |
| 240 | plot->fTexture = fTexture; |
| 241 | if (plot->addSubImage(width, height, image, loc)) { |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 242 | this->makeMRU(plot); |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 243 | // new plot for atlas, put at end of array |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 244 | SkASSERT(!usage->fPlots.contains(plot)); |
| 245 | *(usage->fPlots.append()) = plot; |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 246 | return plot; |
| 247 | } |
| 248 | plotIter.next(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 249 | } |
| 250 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 251 | // If the above fails, then the current plot list has no room |
| 252 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 253 | } |
| 254 | |
robertphillips | c4f30b1 | 2014-07-13 10:09:42 -0700 | [diff] [blame] | 255 | void GrAtlas::RemovePlot(ClientPlotUsage* usage, const GrPlot* plot) { |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 256 | int index = usage->fPlots.find(const_cast<GrPlot*>(plot)); |
| 257 | if (index >= 0) { |
| 258 | usage->fPlots.remove(index); |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 259 | } |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 260 | } |
| 261 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 262 | // get a plot that's not being used by the current draw |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 263 | GrPlot* GrAtlas::getUnusedPlot() { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 264 | GrPlotList::Iter plotIter; |
| 265 | plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart); |
| 266 | GrPlot* plot; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 267 | while ((plot = plotIter.get())) { |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 268 | if (plot->drawToken().isIssued()) { |
| 269 | return plot; |
| 270 | } |
| 271 | plotIter.prev(); |
commit-bot@chromium.org | 7d330eb | 2013-09-27 19:39:38 +0000 | [diff] [blame] | 272 | } |
skia.committer@gmail.com | 50df4d0 | 2013-09-28 07:01:33 +0000 | [diff] [blame] | 273 | |
commit-bot@chromium.org | c9b2c88 | 2014-03-03 14:30:25 +0000 | [diff] [blame] | 274 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 275 | } |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 276 | |
robertphillips | 1d86ee8 | 2014-06-24 15:08:49 -0700 | [diff] [blame] | 277 | void GrAtlas::uploadPlotsToTexture() { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 278 | if (fBatchUploads) { |
| 279 | GrPlotList::Iter plotIter; |
| 280 | plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); |
| 281 | GrPlot* plot; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 282 | while ((plot = plotIter.get())) { |
commit-bot@chromium.org | 7801faa | 2014-05-14 15:14:51 +0000 | [diff] [blame] | 283 | plot->uploadToTexture(); |
| 284 | plotIter.next(); |
| 285 | } |
| 286 | } |
| 287 | } |