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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/thumbnail/thumbnail_store.h" 5 #include "chrome/browser/android/thumbnail/thumbnail_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/big_endian.h" 10 #include "base/big_endian.h"
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 Remove(tab_id); 833 Remove(tab_id);
834 } 834 }
835 return; 835 return;
836 } 836 }
837 837
838 void ThumbnailStore::DecompressionTask( 838 void ThumbnailStore::DecompressionTask(
839 const base::Callback<void(bool, SkBitmap)>& 839 const base::Callback<void(bool, SkBitmap)>&
840 post_decompression_callback, 840 post_decompression_callback,
841 skia::RefPtr<SkPixelRef> compressed_data, 841 skia::RefPtr<SkPixelRef> compressed_data,
842 float scale, 842 float scale,
843 const gfx::Size& encoded_size) { 843 const gfx::Size& content_size) {
844 SkBitmap raw_data; 844 SkBitmap raw_data_small;
845 bool success = false; 845 bool success = false;
846 846
847 if (compressed_data.get()) { 847 if (compressed_data.get()) {
848 gfx::Size buffer_size = gfx::Size(compressed_data->info().width(),
849 compressed_data->info().height());
850
848 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. 851 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config.
849 size_t stride = pixel_size * encoded_size.width(); 852 size_t stride = pixel_size * buffer_size.width();
850 853
851 raw_data.allocPixels(SkImageInfo::Make(encoded_size.width(), 854 SkBitmap raw_data;
852 encoded_size.height(), 855 raw_data.allocPixels(SkImageInfo::Make(buffer_size.width(),
853 kRGBA_8888_SkColorType, 856 buffer_size.height(),
854 kOpaque_SkAlphaType)); 857 kRGBA_8888_SkColorType,
858 kOpaque_SkAlphaType));
855 SkAutoLockPixels raw_data_lock(raw_data); 859 SkAutoLockPixels raw_data_lock(raw_data);
860 compressed_data->lockPixels();
856 success = etc1_decode_image( 861 success = etc1_decode_image(
857 reinterpret_cast<unsigned char*>(compressed_data->pixels()), 862 reinterpret_cast<unsigned char*>(compressed_data->pixels()),
858 reinterpret_cast<unsigned char*>(raw_data.getPixels()), 863 reinterpret_cast<unsigned char*>(raw_data.getPixels()),
859 encoded_size.width(), 864 buffer_size.width(),
860 encoded_size.height(), 865 buffer_size.height(),
861 pixel_size, 866 pixel_size,
862 stride); 867 stride);
868 compressed_data->unlockPixels();
863 raw_data.setImmutable(); 869 raw_data.setImmutable();
870
871 if (!success || content_size == buffer_size) {
872 // Shallow copy the pixel reference.
873 raw_data_small = raw_data;
874 } else {
875 // The content size is smaller than the buffer size (likely because of
876 // a power-of-two rounding), so deep copy the bitmap.
877 raw_data_small.allocPixels(SkImageInfo::Make(content_size.width(),
Yusuf 2014/09/23 23:52:49 indent +4
878 content_size.height(),
879 kRGBA_8888_SkColorType,
880 kOpaque_SkAlphaType));
881 SkAutoLockPixels raw_data_small_lock(raw_data_small);
882 SkCanvas small_canvas(raw_data_small);
883 small_canvas.drawBitmap(raw_data, 0, 0);
884 raw_data_small.setImmutable();
885 }
864 } 886 }
865 887
866 content::BrowserThread::PostTask( 888 content::BrowserThread::PostTask(
867 content::BrowserThread::UI, 889 content::BrowserThread::UI,
868 FROM_HERE, 890 FROM_HERE,
869 base::Bind(post_decompression_callback, success, raw_data)); 891 base::Bind(post_decompression_callback, success, raw_data_small));
870 } 892 }
871 893
872 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData() { 894 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData() {
873 } 895 }
874 896
875 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData( 897 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData(
876 const base::Time& current_time, 898 const base::Time& current_time,
877 const GURL& url) 899 const GURL& url)
878 : capture_time_(current_time), url_(url) { 900 : capture_time_(current_time), url_(url) {
879 } 901 }
(...skipping 16 matching lines...) Expand all
896 dst_bitmap.eraseColor(0); 918 dst_bitmap.eraseColor(0);
897 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); 919 SkAutoLockPixels dst_bitmap_lock(dst_bitmap);
898 920
899 SkCanvas canvas(dst_bitmap); 921 SkCanvas canvas(dst_bitmap);
900 canvas.scale(new_scale, new_scale); 922 canvas.scale(new_scale, new_scale);
901 canvas.drawBitmap(bitmap, 0, 0, NULL); 923 canvas.drawBitmap(bitmap, 0, 0, NULL);
902 dst_bitmap.setImmutable(); 924 dst_bitmap.setImmutable();
903 925
904 return std::make_pair(dst_bitmap, new_scale * scale); 926 return std::make_pair(dst_bitmap, new_scale * scale);
905 } 927 }
OLDNEW
« 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