Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/gpu/GrAtlas.cpp

Issue 355673002: Rename GrAtlasMgr to GrAtlas (and other cleanup) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrBitmapTextContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrRectanizer.h" 12 #include "GrRectanizer.h"
13 #include "GrTracing.h" 13 #include "GrTracing.h"
14 14
15 /////////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////////
16 16
17 // for testing 17 // for testing
18 #define FONT_CACHE_STATS 0 18 #define FONT_CACHE_STATS 0
19 #if FONT_CACHE_STATS 19 #if FONT_CACHE_STATS
20 static int g_UploadCount = 0; 20 static int g_UploadCount = 0;
21 #endif 21 #endif
22 22
23 GrPlot::GrPlot() : fDrawToken(NULL, 0) 23 GrPlot::GrPlot() : fDrawToken(NULL, 0)
24 , fTexture(NULL) 24 , fTexture(NULL)
25 , fRects(NULL) 25 , fRects(NULL)
26 , fAtlasMgr(NULL) 26 , fAtlas(NULL)
27 , fBytesPerPixel(1) 27 , fBytesPerPixel(1)
28 , fDirty(false) 28 , fDirty(false)
29 , fBatchUploads(false) 29 , fBatchUploads(false)
30 { 30 {
31 fOffset.set(0, 0); 31 fOffset.set(0, 0);
32 } 32 }
33 33
34 GrPlot::~GrPlot() { 34 GrPlot::~GrPlot() {
35 SkDELETE_ARRAY(fPlotData); 35 SkDELETE_ARRAY(fPlotData);
36 fPlotData = NULL; 36 fPlotData = NULL;
37 delete fRects; 37 delete fRects;
38 } 38 }
39 39
40 void GrPlot::init(GrAtlasMgr* mgr, int offX, int offY, int width, int height, si ze_t bpp, 40 void GrPlot::init(GrAtlas* atlas, int offX, int offY, int width, int height, siz e_t bpp,
41 bool batchUploads) { 41 bool batchUploads) {
42 fRects = GrRectanizer::Factory(width, height); 42 fRects = GrRectanizer::Factory(width, height);
43 fAtlasMgr = mgr; 43 fAtlas = atlas;
44 fOffset.set(offX * width, offY * height); 44 fOffset.set(offX * width, offY * height);
45 fBytesPerPixel = bpp; 45 fBytesPerPixel = bpp;
46 fPlotData = NULL; 46 fPlotData = NULL;
47 fDirtyRect.setEmpty(); 47 fDirtyRect.setEmpty();
48 fDirty = false; 48 fDirty = false;
49 fBatchUploads = batchUploads; 49 fBatchUploads = batchUploads;
50 } 50 }
51 51
52 static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset) { 52 static inline void adjust_for_offset(SkIPoint16* loc, const SkIPoint16& offset) {
53 loc->fX += offset.fX; 53 loc->fX += offset.fX;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 } 140 }
141 141
142 void GrPlot::resetRects() { 142 void GrPlot::resetRects() {
143 SkASSERT(NULL != fRects); 143 SkASSERT(NULL != fRects);
144 fRects->reset(); 144 fRects->reset();
145 } 145 }
146 146
147 /////////////////////////////////////////////////////////////////////////////// 147 ///////////////////////////////////////////////////////////////////////////////
148 148
149 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config, 149 GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config,
150 const SkISize& backingTextureSize, 150 const SkISize& backingTextureSize,
151 int numPlotsX, int numPlotsY, bool batchUploads) { 151 int numPlotsX, int numPlotsY, bool batchUploads) {
152 fGpu = SkRef(gpu); 152 fGpu = SkRef(gpu);
153 fPixelConfig = config; 153 fPixelConfig = config;
154 fBackingTextureSize = backingTextureSize; 154 fBackingTextureSize = backingTextureSize;
155 fNumPlotsX = numPlotsX; 155 fNumPlotsX = numPlotsX;
156 fNumPlotsY = numPlotsY; 156 fNumPlotsY = numPlotsY;
157 fBatchUploads = batchUploads; 157 fBatchUploads = batchUploads;
158 fTexture = NULL; 158 fTexture = NULL;
159 159
160 int textureWidth = fBackingTextureSize.width(); 160 int textureWidth = fBackingTextureSize.width();
161 int textureHeight = fBackingTextureSize.height(); 161 int textureHeight = fBackingTextureSize.height();
(...skipping 16 matching lines...) Expand all
178 for (int x = numPlotsX-1; x >= 0; --x) { 178 for (int x = numPlotsX-1; x >= 0; --x) {
179 currPlot->init(this, x, y, plotWidth, plotHeight, bpp, batchUploads) ; 179 currPlot->init(this, x, y, plotWidth, plotHeight, bpp, batchUploads) ;
180 180
181 // build LRU list 181 // build LRU list
182 fPlotList.addToHead(currPlot); 182 fPlotList.addToHead(currPlot);
183 ++currPlot; 183 ++currPlot;
184 } 184 }
185 } 185 }
186 } 186 }
187 187
188 GrAtlasMgr::~GrAtlasMgr() { 188 GrAtlas::~GrAtlas() {
189 SkSafeUnref(fTexture); 189 SkSafeUnref(fTexture);
190 SkDELETE_ARRAY(fPlotArray); 190 SkDELETE_ARRAY(fPlotArray);
191 191
192 fGpu->unref(); 192 fGpu->unref();
193 #if FONT_CACHE_STATS 193 #if FONT_CACHE_STATS
194 GrPrintf("Num uploads: %d\n", g_UploadCount); 194 GrPrintf("Num uploads: %d\n", g_UploadCount);
195 #endif 195 #endif
196 } 196 }
197 197
198 void GrAtlasMgr::moveToHead(GrPlot* plot) { 198 void GrAtlas::makeMRU(GrPlot* plot) {
199 if (fPlotList.head() == plot) { 199 if (fPlotList.head() == plot) {
200 return; 200 return;
201 } 201 }
202 202
203 fPlotList.remove(plot); 203 fPlotList.remove(plot);
204 fPlotList.addToHead(plot); 204 fPlotList.addToHead(plot);
205 }; 205 };
206 206
207 GrPlot* GrAtlasMgr::addToAtlas(GrAtlas* atlas, 207 GrPlot* GrAtlas::addToAtlas(ClientPlotUsage* usage,
208 int width, int height, const void* image, 208 int width, int height, const void* image,
209 SkIPoint16* loc) { 209 SkIPoint16* loc) {
210 // iterate through entire plot list for this atlas, see if we can find a hol e 210 // iterate through entire plot list for this atlas, see if we can find a hol e
211 // last one was most recently added and probably most empty 211 // last one was most recently added and probably most empty
212 for (int i = atlas->fPlots.count()-1; i >= 0; --i) { 212 for (int i = usage->fPlots.count()-1; i >= 0; --i) {
213 GrPlot* plot = atlas->fPlots[i]; 213 GrPlot* plot = usage->fPlots[i];
214 if (plot->addSubImage(width, height, image, loc)) { 214 if (plot->addSubImage(width, height, image, loc)) {
215 this->moveToHead(plot); 215 this->makeMRU(plot);
216 return plot; 216 return plot;
217 } 217 }
218 } 218 }
219 219
220 // before we get a new plot, make sure we have a backing texture 220 // before we get a new plot, make sure we have a backing texture
221 if (NULL == fTexture) { 221 if (NULL == fTexture) {
222 // TODO: Update this to use the cache rather than directly creating a te xture. 222 // TODO: Update this to use the cache rather than directly creating a te xture.
223 GrTextureDesc desc; 223 GrTextureDesc desc;
224 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; 224 desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
225 desc.fWidth = fBackingTextureSize.width(); 225 desc.fWidth = fBackingTextureSize.width();
226 desc.fHeight = fBackingTextureSize.height(); 226 desc.fHeight = fBackingTextureSize.height();
227 desc.fConfig = fPixelConfig; 227 desc.fConfig = fPixelConfig;
228 228
229 fTexture = fGpu->createTexture(desc, NULL, 0); 229 fTexture = fGpu->createTexture(desc, NULL, 0);
230 if (NULL == fTexture) { 230 if (NULL == fTexture) {
231 return NULL; 231 return NULL;
232 } 232 }
233 } 233 }
234 234
235 // now look through all allocated plots for one we can share, in MRU order 235 // now look through all allocated plots for one we can share, in MRU order
236 GrPlotList::Iter plotIter; 236 GrPlotList::Iter plotIter;
237 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); 237 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart);
238 GrPlot* plot; 238 GrPlot* plot;
239 while (NULL != (plot = plotIter.get())) { 239 while (NULL != (plot = plotIter.get())) {
240 // make sure texture is set for quick lookup 240 // make sure texture is set for quick lookup
241 plot->fTexture = fTexture; 241 plot->fTexture = fTexture;
242 if (plot->addSubImage(width, height, image, loc)) { 242 if (plot->addSubImage(width, height, image, loc)) {
243 this->moveToHead(plot); 243 this->makeMRU(plot);
244 // new plot for atlas, put at end of array 244 // new plot for atlas, put at end of array
245 *(atlas->fPlots.append()) = plot; 245 SkASSERT(!usage->fPlots.contains(plot));
246 *(usage->fPlots.append()) = plot;
246 return plot; 247 return plot;
247 } 248 }
248 plotIter.next(); 249 plotIter.next();
249 } 250 }
250 251
251 // If the above fails, then the current plot list has no room 252 // If the above fails, then the current plot list has no room
252 return NULL; 253 return NULL;
253 } 254 }
254 255
255 bool GrAtlasMgr::removePlot(GrAtlas* atlas, const GrPlot* plot) { 256 void GrAtlas::removePlot(ClientPlotUsage* usage, const GrPlot* plot) {
256 // iterate through plot list for this atlas 257 int index = usage->fPlots.find(const_cast<GrPlot*>(plot));
257 int count = atlas->fPlots.count(); 258 if (index >= 0) {
258 for (int i = 0; i < count; ++i) { 259 usage->fPlots.remove(index);
259 if (plot == atlas->fPlots[i]) {
260 atlas->fPlots.remove(i);
261 return true;
262 }
263 } 260 }
264
265 return false;
266 } 261 }
267 262
268 // get a plot that's not being used by the current draw 263 // get a plot that's not being used by the current draw
269 GrPlot* GrAtlasMgr::getUnusedPlot() { 264 GrPlot* GrAtlas::getUnusedPlot() {
270 GrPlotList::Iter plotIter; 265 GrPlotList::Iter plotIter;
271 plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart); 266 plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart);
272 GrPlot* plot; 267 GrPlot* plot;
273 while (NULL != (plot = plotIter.get())) { 268 while (NULL != (plot = plotIter.get())) {
274 if (plot->drawToken().isIssued()) { 269 if (plot->drawToken().isIssued()) {
275 return plot; 270 return plot;
276 } 271 }
277 plotIter.prev(); 272 plotIter.prev();
278 } 273 }
279 274
280 return NULL; 275 return NULL;
281 } 276 }
282 277
283 void GrAtlasMgr::uploadPlotsToTexture() { 278 void GrAtlas::uploadPlotsToTexture() {
284 if (fBatchUploads) { 279 if (fBatchUploads) {
285 GrPlotList::Iter plotIter; 280 GrPlotList::Iter plotIter;
286 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart); 281 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart);
287 GrPlot* plot; 282 GrPlot* plot;
288 while (NULL != (plot = plotIter.get())) { 283 while (NULL != (plot = plotIter.get())) {
289 plot->uploadToTexture(); 284 plot->uploadToTexture();
290 plotIter.next(); 285 plotIter.next();
291 } 286 }
292 } 287 }
293 } 288 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrBitmapTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698