Remove bitmap reuse from SkImageDecoder.
Now that Android is using an SkBitmap::Allocator to reuse bitmap
memory, remove the unnecessary code to handle bitmap reuse inside
the decoders themselves.
Leaves in the code for bitmap reuse in decodeSubset, which still
may reuse bitmaps, and cropBitmap, which is called by decodeSubset.
R=djsollen@google.com
Review URL: https://codereview.chromium.org/17620004
git-svn-id: http://skia.googlecode.com/svn/trunk@9931 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp
index 38aa7fd..0aa752e 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -164,19 +164,12 @@
}
bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm,
- SkBitmap::Config pref, Mode mode, bool reuseBitmap) {
+ SkBitmap::Config pref, Mode mode) {
// we reset this to false before calling onDecode
fShouldCancelDecode = false;
// assign this, for use by getPrefConfig(), in case fUsePrefTable is false
fDefaultPref = pref;
- if (reuseBitmap) {
- SkAutoLockPixels alp(*bm);
- if (NULL != bm->getPixels()) {
- return this->onDecode(stream, bm, mode);
- }
- }
-
// pass a temporary bitmap, so that if we return false, we are assured of
// leaving the caller's bitmap untouched.
SkBitmap tmp;
diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp
index 5c2299b..14b9090 100644
--- a/src/images/SkImageDecoder_libbmp.cpp
+++ b/src/images/SkImageDecoder_libbmp.cpp
@@ -130,19 +130,13 @@
SkScaledBitmapSampler sampler(width, height, getSampleSize());
- if (justBounds) {
- bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
- bm->setIsOpaque(true);
- return true;
- }
- // No Bitmap reuse supported for this format
- if (!bm->isNull()) {
- return false;
- }
-
bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
bm->setIsOpaque(true);
+ if (justBounds) {
+ return true;
+ }
+
if (!this->allocPixelRef(bm, NULL)) {
return false;
}
diff --git a/src/images/SkImageDecoder_libgif.cpp b/src/images/SkImageDecoder_libgif.cpp
index f6c54c2..d368ecc 100644
--- a/src/images/SkImageDecoder_libgif.cpp
+++ b/src/images/SkImageDecoder_libgif.cpp
@@ -202,17 +202,11 @@
return error_return(gif, *bm, "chooseFromOneChoice");
}
+ bm->setConfig(SkBitmap::kIndex8_Config, width, height);
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- bm->setConfig(SkBitmap::kIndex8_Config, width, height);
return true;
}
- // No Bitmap reuse supported for this format
- if (!bm->isNull()) {
- return false;
- }
-
- bm->setConfig(SkBitmap::kIndex8_Config, width, height);
SavedImage* image = &gif->SavedImages[gif->ImageCount-1];
const GifImageDesc& desc = image->ImageDesc;
diff --git a/src/images/SkImageDecoder_libico.cpp b/src/images/SkImageDecoder_libico.cpp
index 195b6ff..6335136 100644
--- a/src/images/SkImageDecoder_libico.cpp
+++ b/src/images/SkImageDecoder_libico.cpp
@@ -232,16 +232,12 @@
//if the andbitmap (mask) is all zeroes, then we can easily do an index bitmap
//however, with small images with large colortables, maybe it's better to still do argb_8888
+ bm->setConfig(SkBitmap::kARGB_8888_Config, w, h, calculateRowBytesFor8888(w, bitCount));
+
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- bm->setConfig(SkBitmap::kARGB_8888_Config, w, h, calculateRowBytesFor8888(w, bitCount));
delete[] colors;
return true;
}
- // No Bitmap reuse supported for this format
- if (!bm->isNull()) {
- return false;
- }
- bm->setConfig(SkBitmap::kARGB_8888_Config, w, h, calculateRowBytesFor8888(w, bitCount));
if (!this->allocPixelRef(bm, NULL))
{
diff --git a/src/images/SkImageDecoder_libjpeg.cpp b/src/images/SkImageDecoder_libjpeg.cpp
index 4818743..bea1e98 100644
--- a/src/images/SkImageDecoder_libjpeg.cpp
+++ b/src/images/SkImageDecoder_libjpeg.cpp
@@ -357,29 +357,13 @@
}
SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampleSize);
-
- bm->lockPixels();
- JSAMPLE* rowptr = (JSAMPLE*)bm->getPixels();
- bm->unlockPixels();
- bool reuseBitmap = (rowptr != NULL);
-
- if (reuseBitmap) {
- if (sampler.scaledWidth() != bm->width() ||
- sampler.scaledHeight() != bm->height()) {
- // Dimensions must match
- return false;
- } else if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- return true;
- }
- } else {
- bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
- bm->setIsOpaque(true);
- if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- return true;
- }
- if (!this->allocPixelRef(bm, NULL)) {
- return return_false(cinfo, *bm, "allocPixelRef");
- }
+ bm->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
+ bm->setIsOpaque(true);
+ if (SkImageDecoder::kDecodeBounds_Mode == mode) {
+ return true;
+ }
+ if (!this->allocPixelRef(bm, NULL)) {
+ return return_false(cinfo, *bm, "allocPixelRef");
}
SkAutoLockPixels alp(*bm);
@@ -394,7 +378,7 @@
(config == SkBitmap::kRGB_565_Config &&
cinfo.out_color_space == JCS_RGB_565)))
{
- rowptr = (JSAMPLE*)bm->getPixels();
+ JSAMPLE* rowptr = (JSAMPLE*)bm->getPixels();
INT32 const bpr = bm->rowBytes();
while (cinfo.output_scanline < cinfo.output_height) {
@@ -409,9 +393,6 @@
}
rowptr += bpr;
}
- if (reuseBitmap) {
- bm->notifyPixelsChanged();
- }
jpeg_finish_decompress(&cinfo);
return true;
}
@@ -481,9 +462,6 @@
cinfo.output_height - cinfo.output_scanline)) {
return return_false(cinfo, *bm, "skip rows");
}
- if (reuseBitmap) {
- bm->notifyPixelsChanged();
- }
jpeg_finish_decompress(&cinfo);
return true;
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index 729f871..d59a67b 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -299,21 +299,8 @@
const int sampleSize = this->getSampleSize();
SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize);
+ decodedBitmap->setConfig(config, sampler.scaledWidth(), sampler.scaledHeight());
- decodedBitmap->lockPixels();
- void* rowptr = (void*) decodedBitmap->getPixels();
- bool reuseBitmap = (rowptr != NULL);
- decodedBitmap->unlockPixels();
- if (reuseBitmap && (sampler.scaledWidth() != decodedBitmap->width() ||
- sampler.scaledHeight() != decodedBitmap->height())) {
- // Dimensions must match
- return false;
- }
-
- if (!reuseBitmap) {
- decodedBitmap->setConfig(config, sampler.scaledWidth(),
- sampler.scaledHeight());
- }
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
@@ -332,11 +319,9 @@
SkAutoUnref aur(colorTable);
- if (!reuseBitmap) {
- if (!this->allocPixelRef(decodedBitmap,
- SkBitmap::kIndex8_Config == config ? colorTable : NULL)) {
- return false;
- }
+ if (!this->allocPixelRef(decodedBitmap,
+ SkBitmap::kIndex8_Config == config ? colorTable : NULL)) {
+ return false;
}
SkAutoLockPixels alp(*decodedBitmap);
@@ -445,9 +430,6 @@
return false;
}
decodedBitmap->setIsOpaque(!reallyHasAlpha);
- if (reuseBitmap) {
- decodedBitmap->notifyPixelsChanged();
- }
return true;
}
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp
index 9cf8449..b0fa7f7 100644
--- a/src/images/SkImageDecoder_libwebp.cpp
+++ b/src/images/SkImageDecoder_libwebp.cpp
@@ -412,25 +412,16 @@
const int sampleSize = this->getSampleSize();
SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize);
-
- // If only bounds are requested, done
- if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- if (!setDecodeConfig(decodedBitmap, sampler.scaledWidth(),
- sampler.scaledHeight())) {
- return false;
- }
- return true;
- }
-
- // No Bitmap reuse supported for this format
- if (!decodedBitmap->isNull()) {
- return false;
- }
if (!setDecodeConfig(decodedBitmap, sampler.scaledWidth(),
sampler.scaledHeight())) {
return false;
}
+ // If only bounds are requested, done
+ if (SkImageDecoder::kDecodeBounds_Mode == mode) {
+ return true;
+ }
+
if (!this->allocPixelRef(decodedBitmap, NULL)) {
return return_false(*decodedBitmap, "allocPixelRef");
}
diff --git a/src/images/SkImageDecoder_wbmp.cpp b/src/images/SkImageDecoder_wbmp.cpp
index db40f59..8b1659b 100644
--- a/src/images/SkImageDecoder_wbmp.cpp
+++ b/src/images/SkImageDecoder_wbmp.cpp
@@ -111,20 +111,13 @@
int width = head.fWidth;
int height = head.fHeight;
- if (SkImageDecoder::kDecodeBounds_Mode == mode) {
- decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height);
- decodedBitmap->setIsOpaque(true);
- return true;
- }
-
- // No Bitmap reuse supported for this format
- if (!decodedBitmap->isNull()) {
- return false;
- }
-
decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height);
decodedBitmap->setIsOpaque(true);
+ if (SkImageDecoder::kDecodeBounds_Mode == mode) {
+ return true;
+ }
+
const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2));
SkAutoUnref aur(ct);