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

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

Issue 1142263002: small cleanup of GrAtlas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tidy Created 5 years, 7 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/GrDrawTarget.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() 23 GrPlot::GrPlot()
24 : fDrawToken(NULL, 0) 24 : fID(-1)
25 , fID(-1)
26 , fTexture(NULL) 25 , fTexture(NULL)
27 , fRects(NULL) 26 , fRects(NULL)
28 , fAtlas(NULL) 27 , fAtlas(NULL)
29 , fBytesPerPixel(1) 28 , fBytesPerPixel(1)
30 , fDirty(false) 29 , fDirty(false)
31 , fBatchUploads(false) 30 , fBatchUploads(false)
32 { 31 {
33 fOffset.set(0, 0); 32 fOffset.set(0, 0);
34 } 33 }
35 34
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 adjust_for_offset(loc, fOffset); 98 adjust_for_offset(loc, fOffset);
100 } 99 }
101 100
102 #if FONT_CACHE_STATS 101 #if FONT_CACHE_STATS
103 ++g_UploadCount; 102 ++g_UploadCount;
104 #endif 103 #endif
105 104
106 return true; 105 return true;
107 } 106 }
108 107
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) {
116 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrPlot::uploadToTex ture");
117 SkASSERT(fTexture);
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 up date
120 // since the last flush.
121 size_t rowBytes = fBytesPerPixel*fRects->width();
122 const unsigned char* dataPtr = fPlotData;
123 dataPtr += rowBytes*fDirtyRect.fTop;
124 dataPtr += fBytesPerPixel*fDirtyRect.fLeft;
125 fTexture->writePixels(fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirty Rect.fTop,
126 fDirtyRect.width(), fDirtyRect.height(), fTexture- >config(), dataPtr,
127 rowBytes, GrContext::kDontFlush_PixelOpsFlag);
128 fDirtyRect.setEmpty();
129 fDirty = false;
130 // If the Plot is nearly full, anything else we add will probably be sma ll 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
139 void GrPlot::resetRects() { 108 void GrPlot::resetRects() {
140 SkASSERT(fRects); 109 SkASSERT(fRects);
141 fRects->reset(); 110 fRects->reset();
142 } 111 }
143 112
144 /////////////////////////////////////////////////////////////////////////////// 113 ///////////////////////////////////////////////////////////////////////////////
145 114
146 GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, GrSurfaceFlags flags, 115 GrAtlas::GrAtlas(GrGpu* gpu, GrPixelConfig config, GrSurfaceFlags flags,
147 const SkISize& backingTextureSize, 116 const SkISize& backingTextureSize,
148 int numPlotsX, int numPlotsY, bool batchUploads) { 117 int numPlotsX, int numPlotsY, bool batchUploads) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // If the above fails, then the current plot list has no room 220 // If the above fails, then the current plot list has no room
252 return NULL; 221 return NULL;
253 } 222 }
254 223
255 void GrAtlas::RemovePlot(ClientPlotUsage* usage, const GrPlot* plot) { 224 void GrAtlas::RemovePlot(ClientPlotUsage* usage, const GrPlot* plot) {
256 int index = usage->fPlots.find(const_cast<GrPlot*>(plot)); 225 int index = usage->fPlots.find(const_cast<GrPlot*>(plot));
257 if (index >= 0) { 226 if (index >= 0) {
258 usage->fPlots.remove(index); 227 usage->fPlots.remove(index);
259 } 228 }
260 } 229 }
261
262 // get a plot that's not being used by the current draw
263 GrPlot* GrAtlas::getUnusedPlot() {
264 GrPlotList::Iter plotIter;
265 plotIter.init(fPlotList, GrPlotList::Iter::kTail_IterStart);
266 GrPlot* plot;
267 while ((plot = plotIter.get())) {
268 if (plot->drawToken().isIssued()) {
269 return plot;
270 }
271 plotIter.prev();
272 }
273
274 return NULL;
275 }
276
277 void GrAtlas::uploadPlotsToTexture() {
278 if (fBatchUploads) {
279 GrPlotList::Iter plotIter;
280 plotIter.init(fPlotList, GrPlotList::Iter::kHead_IterStart);
281 GrPlot* plot;
282 while ((plot = plotIter.get())) {
283 plot->uploadToTexture();
284 plotIter.next();
285 }
286 }
287 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698