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

Unified Diff: chrome/browser/android/thumbnail/thumbnail_store.cc

Issue 598593003: Fix DecompressionTask with power-of-two expanded thumbnails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/thumbnail/thumbnail_store.cc
diff --git a/chrome/browser/android/thumbnail/thumbnail_store.cc b/chrome/browser/android/thumbnail/thumbnail_store.cc
index afcd6873864daa972e1197cd15e9fd0a7e032c42..1923b77ca9518b8d6183590b0519e9381aac94a3 100644
--- a/chrome/browser/android/thumbnail/thumbnail_store.cc
+++ b/chrome/browser/android/thumbnail/thumbnail_store.cc
@@ -840,33 +840,54 @@ void ThumbnailStore::DecompressionTask(
post_decompression_callback,
skia::RefPtr<SkPixelRef> compressed_data,
float scale,
- const gfx::Size& encoded_size) {
- SkBitmap raw_data;
+ const gfx::Size& content_size) {
+ SkBitmap raw_data_small;
bool success = false;
if (compressed_data.get()) {
- size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config.
- size_t stride = pixel_size * encoded_size.width();
-
- raw_data.allocPixels(SkImageInfo::Make(encoded_size.width(),
- encoded_size.height(),
- kRGBA_8888_SkColorType,
- kOpaque_SkAlphaType));
+ gfx::Size buffer_size = gfx::Size(compressed_data->info().width(),
+ compressed_data->info().height());
+
+ SkBitmap raw_data;
+ raw_data.allocPixels(SkImageInfo::Make(buffer_size.width(),
+ buffer_size.height(),
+ kRGBA_8888_SkColorType,
+ kOpaque_SkAlphaType));
SkAutoLockPixels raw_data_lock(raw_data);
+ compressed_data->lockPixels();
success = etc1_decode_image(
reinterpret_cast<unsigned char*>(compressed_data->pixels()),
reinterpret_cast<unsigned char*>(raw_data.getPixels()),
- encoded_size.width(),
- encoded_size.height(),
- pixel_size,
- stride);
+ buffer_size.width(),
+ buffer_size.height(),
+ raw_data.bytesPerPixel(),
+ raw_data.rowBytes());
+ compressed_data->unlockPixels();
raw_data.setImmutable();
+
+ if (!success) {
+ // Leave raw_data_small empty for consistency with other failure modes.
+ } else if (content_size == buffer_size) {
+ // Shallow copy the pixel reference.
+ raw_data_small = raw_data;
+ } else {
+ // The content size is smaller than the buffer size (likely because of
+ // a power-of-two rounding), so deep copy the bitmap.
+ raw_data_small.allocPixels(SkImageInfo::Make(content_size.width(),
+ content_size.height(),
+ kRGBA_8888_SkColorType,
+ kOpaque_SkAlphaType));
+ SkAutoLockPixels raw_data_small_lock(raw_data_small);
+ SkCanvas small_canvas(raw_data_small);
+ small_canvas.drawBitmap(raw_data, 0, 0);
+ raw_data_small.setImmutable();
+ }
}
content::BrowserThread::PostTask(
content::BrowserThread::UI,
FROM_HERE,
- base::Bind(post_decompression_callback, success, raw_data));
+ base::Bind(post_decompression_callback, success, raw_data_small));
}
ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698