OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrAtlas.h" | 8 #include "GrAtlas.h" |
9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
10 #include "GrRectanizer.h" | 10 #include "GrRectanizer.h" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 325 |
326 // alloc storage for distance field glyph | 326 // alloc storage for distance field glyph |
327 size_t dfSize = dfWidth * dfHeight * bytesPerPixel; | 327 size_t dfSize = dfWidth * dfHeight * bytesPerPixel; |
328 SkAutoSMalloc<1024> dfStorage(dfSize); | 328 SkAutoSMalloc<1024> dfStorage(dfSize); |
329 | 329 |
330 if (1 == bytesPerPixel) { | 330 if (1 == bytesPerPixel) { |
331 (void) SkGenerateDistanceFieldFromImage((unsigned char*)dfStorage.ge
t(), | 331 (void) SkGenerateDistanceFieldFromImage((unsigned char*)dfStorage.ge
t(), |
332 (unsigned char*)storage.get(
), | 332 (unsigned char*)storage.get(
), |
333 width, height, DISTANCE_FIEL
D_RANGE); | 333 width, height, DISTANCE_FIEL
D_RANGE); |
334 } else { | 334 } else { |
335 // TODO: Fix color emoji | 335 // distance fields should only be used to represent alpha masks |
336 // for now, copy glyph into distance field storage | 336 SkASSERT(false); |
337 // this is not correct, but it won't crash | 337 return false; |
338 sk_bzero(dfStorage.get(), dfSize); | |
339 unsigned char* ptr = (unsigned char*) storage.get(); | |
340 unsigned char* dfPtr = (unsigned char*) dfStorage.get(); | |
341 size_t dfStride = dfWidth*bytesPerPixel; | |
342 dfPtr += DISTANCE_FIELD_RANGE*dfStride; | |
343 dfPtr += DISTANCE_FIELD_RANGE*bytesPerPixel; | |
344 | |
345 for (int i = 0; i < height; ++i) { | |
346 memcpy(dfPtr, ptr, stride); | |
347 | |
348 dfPtr += dfStride; | |
349 ptr += stride; | |
350 } | |
351 } | 338 } |
352 | 339 |
353 // copy to atlas | 340 // copy to atlas |
354 plot = fAtlasMgr->addToAtlas(&fAtlas, dfWidth, dfHeight, dfStorage.get()
, | 341 plot = fAtlasMgr->addToAtlas(&fAtlas, dfWidth, dfHeight, dfStorage.get()
, |
355 &glyph->fAtlasLocation); | 342 &glyph->fAtlasLocation); |
356 | 343 |
357 } else { | 344 } else { |
358 size_t size = glyph->fBounds.area() * bytesPerPixel; | 345 size_t size = glyph->fBounds.area() * bytesPerPixel; |
359 SkAutoSMalloc<1024> storage(size); | 346 SkAutoSMalloc<1024> storage(size); |
360 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), | 347 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), |
361 glyph->height(), | 348 glyph->height(), |
362 glyph->width() * bytesPerPixel, | 349 glyph->width() * bytesPerPixel, |
363 storage.get())) { | 350 storage.get())) { |
364 return false; | 351 return false; |
365 } | 352 } |
366 | 353 |
367 plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), | 354 plot = fAtlasMgr->addToAtlas(&fAtlas, glyph->width(), |
368 glyph->height(), storage.get(), | 355 glyph->height(), storage.get(), |
369 &glyph->fAtlasLocation); | 356 &glyph->fAtlasLocation); |
370 } | 357 } |
371 | 358 |
372 if (NULL == plot) { | 359 if (NULL == plot) { |
373 return false; | 360 return false; |
374 } | 361 } |
375 | 362 |
376 glyph->fPlot = plot; | 363 glyph->fPlot = plot; |
377 return true; | 364 return true; |
378 } | 365 } |
OLD | NEW |