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

Unified Diff: src/core/SkImageCacherator.cpp

Issue 1334033004: formalize generate->bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/core/SkImageCacherator.cpp
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 8c0e415770fb7539c50370f4541708c99bc9a519..bdcd64f56ddedd896ea6d3f5a66274d6f2468b0f 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -70,55 +70,19 @@ static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {
return true;
}
-static void release_malloc_proc(void* pixels, void* ctx) {
- sk_free(pixels);
-}
-
-static bool generate_a_bitmap(SkBitmap* bitmap, SkImageGenerator* gen, const SkImageInfo& info) {
- const size_t rowBytes = info.minRowBytes();
- const size_t pixelSize = info.getSafeSize(rowBytes);
- if (0 == pixelSize) {
- return false;
- }
-
- SkAutoFree pixelStorage(sk_malloc_flags(pixelSize, 0));
- void* pixels = pixelStorage.get();
- if (!pixels) {
- return false;
- }
-
- SkPMColor ctStorage[256];
- int ctCount = 0;
-
- if (!gen->getPixels(info, pixels, rowBytes, ctStorage, &ctCount)) {
- return false;
- }
-
- SkAutoTUnref<SkColorTable> ctable;
- if (ctCount > 0) {
- SkASSERT(kIndex_8_SkColorType == info.colorType());
- ctable.reset(new SkColorTable(ctStorage, ctCount));
- } else {
- SkASSERT(kIndex_8_SkColorType != info.colorType());
- }
-
- return bitmap->installPixels(info, pixelStorage.detach(), rowBytes, ctable,
- release_malloc_proc, nullptr);
-}
-
bool SkImageCacherator::generateBitmap(SkBitmap* bitmap) {
ScopedGenerator generator(this);
const SkImageInfo& genInfo = generator->getInfo();
if (fInfo.dimensions() == genInfo.dimensions()) {
SkASSERT(fOrigin.x() == 0 && fOrigin.y() == 0);
// fast-case, no copy needed
- return generate_a_bitmap(bitmap, generator, fInfo);
+ return generator->tryGenerateBitmap(bitmap, fInfo);
} else {
// need to handle subsetting, so we first generate the full size version, and then
// "read" from it to get our subset. See skbug.com/4213
SkBitmap full;
- if (!generate_a_bitmap(&full, generator, genInfo)) {
+ if (!generator->tryGenerateBitmap(&full, genInfo)) {
return false;
}
if (!bitmap->tryAllocPixels(fInfo, nullptr, full.getColorTable())) {

Powered by Google App Engine
This is Rietveld 408576698