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

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

Issue 24751003: GrAtlas refactor: Replace GrMaskFormat usage in GrAtlas with GrPixelConfig. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix nits Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrTextStrike.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 9
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #ifdef SK_DEBUG 43 #ifdef SK_DEBUG
44 static int gCounter; 44 static int gCounter;
45 #endif 45 #endif
46 46
47 // for testing 47 // for testing
48 #define FONT_CACHE_STATS 0 48 #define FONT_CACHE_STATS 0
49 #if FONT_CACHE_STATS 49 #if FONT_CACHE_STATS
50 static int g_UploadCount = 0; 50 static int g_UploadCount = 0;
51 #endif 51 #endif
52 52
53 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, GrMaskFormat format) : 53 GrAtlas::GrAtlas(GrAtlasMgr* mgr, int plotX, int plotY, int bpp) :
54 fDrawToken(NULL, 0) { 54 fDrawToken(NULL, 0) {
55 fAtlasMgr = mgr; // just a pointer, not an owner 55 fAtlasMgr = mgr; // just a pointer, not an owner
56 fNext = NULL; 56 fNext = NULL;
57 57
58 fTexture = mgr->getTexture(); // we're not an owner, just a pointer 58 fTexture = mgr->getTexture(); // we're not an owner, just a pointer
59 fPlot.set(plotX, plotY); 59 fPlot.set(plotX, plotY);
60 60
61 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, 61 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER,
62 GR_ATLAS_HEIGHT - BORDER); 62 GR_ATLAS_HEIGHT - BORDER);
63 63
64 fMaskFormat = format; 64 fBytesPerPixel = bpp;
65 65
66 #ifdef SK_DEBUG 66 #ifdef SK_DEBUG
67 // GrPrintf(" GrAtlas %p [%d %d] %d\n", this, plotX, plotY, gCounter); 67 // GrPrintf(" GrAtlas %p [%d %d] %d\n", this, plotX, plotY, gCounter);
68 gCounter += 1; 68 gCounter += 1;
69 #endif 69 #endif
70 } 70 }
71 71
72 GrAtlas::~GrAtlas() { 72 GrAtlas::~GrAtlas() {
73 fAtlasMgr->freePlot(fPlot.fX, fPlot.fY); 73 fAtlasMgr->freePlot(fPlot.fX, fPlot.fY);
74 74
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 bool GrAtlas::addSubImage(int width, int height, const void* image, 116 bool GrAtlas::addSubImage(int width, int height, const void* image,
117 GrIPoint16* loc) { 117 GrIPoint16* loc) {
118 if (!fRects->addRect(width + BORDER, height + BORDER, loc)) { 118 if (!fRects->addRect(width + BORDER, height + BORDER, loc)) {
119 return false; 119 return false;
120 } 120 }
121 121
122 SkAutoSMalloc<1024> storage; 122 SkAutoSMalloc<1024> storage;
123 int dstW = width + 2*BORDER; 123 int dstW = width + 2*BORDER;
124 int dstH = height + 2*BORDER; 124 int dstH = height + 2*BORDER;
125 if (BORDER) { 125 if (BORDER) {
126 const int bpp = GrMaskFormatBytesPerPixel(fMaskFormat); 126 const size_t dstRB = dstW * fBytesPerPixel;
127 const size_t dstRB = dstW * bpp;
128 uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB); 127 uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB);
129 Gr_bzero(dst, dstRB); // zero top row 128 Gr_bzero(dst, dstRB); // zero top row
130 dst += dstRB; 129 dst += dstRB;
131 for (int y = 0; y < height; y++) { 130 for (int y = 0; y < height; y++) {
132 dst = zerofill(dst, bpp); // zero left edge 131 dst = zerofill(dst, fBytesPerPixel); // zero left edge
133 memcpy(dst, image, width * bpp); 132 memcpy(dst, image, width * fBytesPerPixel);
134 dst += width * bpp; 133 dst += width * fBytesPerPixel;
135 dst = zerofill(dst, bpp); // zero right edge 134 dst = zerofill(dst, fBytesPerPixel); // zero right edge
136 image = (const void*)((const char*)image + width * bpp); 135 image = (const void*)((const char*)image + width * fBytesPerPixel);
137 } 136 }
138 Gr_bzero(dst, dstRB); // zero bottom row 137 Gr_bzero(dst, dstRB); // zero bottom row
139 image = storage.get(); 138 image = storage.get();
140 } 139 }
141 adjustForPlot(loc, fPlot); 140 adjustForPlot(loc, fPlot);
142 GrContext* context = fTexture->getContext(); 141 GrContext* context = fTexture->getContext();
143 // We pass the flag that does not force a flush. We assume our caller is 142 // We pass the flag that does not force a flush. We assume our caller is
144 // smart and hasn't referenced the part of the texture we're about to update 143 // smart and hasn't referenced the part of the texture we're about to update
145 // since the last flush. 144 // since the last flush.
146 context->writeTexturePixels(fTexture, 145 context->writeTexturePixels(fTexture,
147 loc->fX, loc->fY, dstW, dstH, 146 loc->fX, loc->fY, dstW, dstH,
148 fTexture->config(), image, 0, 147 fTexture->config(), image, 0,
149 GrContext::kDontFlush_PixelOpsFlag); 148 GrContext::kDontFlush_PixelOpsFlag);
150 149
151 // now tell the caller to skip the top/left BORDER 150 // now tell the caller to skip the top/left BORDER
152 loc->fX += BORDER; 151 loc->fX += BORDER;
153 loc->fY += BORDER; 152 loc->fY += BORDER;
154 153
155 #if FONT_CACHE_STATS 154 #if FONT_CACHE_STATS
156 ++g_UploadCount; 155 ++g_UploadCount;
157 #endif 156 #endif
158 157
159 return true; 158 return true;
160 } 159 }
161 160
162 /////////////////////////////////////////////////////////////////////////////// 161 ///////////////////////////////////////////////////////////////////////////////
163 162
164 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrMaskFormat format) { 163 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config) {
165 fGpu = gpu; 164 fGpu = gpu;
166 fMaskFormat = format; 165 fPixelConfig = config;
167 gpu->ref(); 166 gpu->ref();
168 fTexture = NULL; 167 fTexture = NULL;
169 fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT)); 168 fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
170 } 169 }
171 170
172 GrAtlasMgr::~GrAtlasMgr() { 171 GrAtlasMgr::~GrAtlasMgr() {
173 SkSafeUnref(fTexture); 172 SkSafeUnref(fTexture);
174 delete fPlotMgr; 173 delete fPlotMgr;
175 174
176 fGpu->unref(); 175 fGpu->unref();
177 #if FONT_CACHE_STATS 176 #if FONT_CACHE_STATS
178 GrPrintf("Num uploads: %d\n", g_UploadCount); 177 GrPrintf("Num uploads: %d\n", g_UploadCount);
179 #endif 178 #endif
180 } 179 }
181 180
182 static GrPixelConfig maskformat2pixelconfig(GrMaskFormat format) {
183 switch (format) {
184 case kA8_GrMaskFormat:
185 return kAlpha_8_GrPixelConfig;
186 case kA565_GrMaskFormat:
187 return kRGB_565_GrPixelConfig;
188 case kA888_GrMaskFormat:
189 return kSkia8888_GrPixelConfig;
190 default:
191 SkDEBUGFAIL("unknown maskformat");
192 }
193 return kUnknown_GrPixelConfig;
194 }
195
196 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas, 181 GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas** atlas,
197 int width, int height, const void* image, 182 int width, int height, const void* image,
198 GrIPoint16* loc) { 183 GrIPoint16* loc) {
199 // iterate through entire atlas list, see if we can find a hole 184 // iterate through entire atlas list, see if we can find a hole
200 GrAtlas* atlasIter = *atlas; 185 GrAtlas* atlasIter = *atlas;
201 while (atlasIter) { 186 while (atlasIter) {
202 if (atlasIter->addSubImage(width, height, image, loc)) { 187 if (atlasIter->addSubImage(width, height, image, loc)) {
203 return atlasIter; 188 return atlasIter;
204 } 189 }
205 atlasIter = atlasIter->fNext; 190 atlasIter = atlasIter->fNext;
206 } 191 }
207 192
208 // If the above fails, then either we have no starting atlas, or the current 193 // If the above fails, then either we have no starting atlas, or the current
209 // atlas list is full. Either way we need to allocate a new atlas 194 // atlas list is full. Either way we need to allocate a new atlas
210 195
211 GrIPoint16 plot; 196 GrIPoint16 plot;
212 if (!fPlotMgr->newPlot(&plot)) { 197 if (!fPlotMgr->newPlot(&plot)) {
213 return NULL; 198 return NULL;
214 } 199 }
215 200
216 if (NULL == fTexture) { 201 if (NULL == fTexture) {
217 // TODO: Update this to use the cache rather than directly creating a te xture. 202 // TODO: Update this to use the cache rather than directly creating a te xture.
218 GrTextureDesc desc; 203 GrTextureDesc desc;
219 desc.fFlags = kDynamicUpdate_GrTextureFlagBit; 204 desc.fFlags = kDynamicUpdate_GrTextureFlagBit;
220 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; 205 desc.fWidth = GR_ATLAS_TEXTURE_WIDTH;
221 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; 206 desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT;
222 desc.fConfig = maskformat2pixelconfig(fMaskFormat); 207 desc.fConfig = fPixelConfig;
223 208
224 fTexture = fGpu->createTexture(desc, NULL, 0); 209 fTexture = fGpu->createTexture(desc, NULL, 0);
225 if (NULL == fTexture) { 210 if (NULL == fTexture) {
226 return NULL; 211 return NULL;
227 } 212 }
228 } 213 }
229 214
230 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, fMaskFormat )); 215 int bpp = GrBytesPerPixel(fPixelConfig);
216 GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, bpp));
231 if (!newAtlas->addSubImage(width, height, image, loc)) { 217 if (!newAtlas->addSubImage(width, height, image, loc)) {
232 delete newAtlas; 218 delete newAtlas;
233 return NULL; 219 return NULL;
234 } 220 }
235 221
236 // new atlas, put at head 222 // new atlas, put at head
237 newAtlas->fNext = *atlas; 223 newAtlas->fNext = *atlas;
238 *atlas = newAtlas; 224 *atlas = newAtlas;
239 225
240 return newAtlas; 226 return newAtlas;
241 } 227 }
242 228
243 void GrAtlasMgr::freePlot(int x, int y) { 229 void GrAtlasMgr::freePlot(int x, int y) {
244 SkASSERT(fPlotMgr->isBusy(x, y)); 230 SkASSERT(fPlotMgr->isBusy(x, y));
245 fPlotMgr->freePlot(x, y); 231 fPlotMgr->freePlot(x, y);
246 } 232 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlas.h ('k') | src/gpu/GrTextStrike.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698