OLD | NEW |
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 Loading... |
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 size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. | 848 gfx::Size buffer_size = gfx::Size(compressed_data->info().width(), |
849 size_t stride = pixel_size * encoded_size.width(); | 849 compressed_data->info().height()); |
850 | 850 |
851 raw_data.allocPixels(SkImageInfo::Make(encoded_size.width(), | 851 SkBitmap raw_data; |
852 encoded_size.height(), | 852 raw_data.allocPixels(SkImageInfo::Make(buffer_size.width(), |
853 kRGBA_8888_SkColorType, | 853 buffer_size.height(), |
854 kOpaque_SkAlphaType)); | 854 kRGBA_8888_SkColorType, |
| 855 kOpaque_SkAlphaType)); |
855 SkAutoLockPixels raw_data_lock(raw_data); | 856 SkAutoLockPixels raw_data_lock(raw_data); |
| 857 compressed_data->lockPixels(); |
856 success = etc1_decode_image( | 858 success = etc1_decode_image( |
857 reinterpret_cast<unsigned char*>(compressed_data->pixels()), | 859 reinterpret_cast<unsigned char*>(compressed_data->pixels()), |
858 reinterpret_cast<unsigned char*>(raw_data.getPixels()), | 860 reinterpret_cast<unsigned char*>(raw_data.getPixels()), |
859 encoded_size.width(), | 861 buffer_size.width(), |
860 encoded_size.height(), | 862 buffer_size.height(), |
861 pixel_size, | 863 raw_data.bytesPerPixel(), |
862 stride); | 864 raw_data.rowBytes()); |
| 865 compressed_data->unlockPixels(); |
863 raw_data.setImmutable(); | 866 raw_data.setImmutable(); |
| 867 |
| 868 if (!success) { |
| 869 // Leave raw_data_small empty for consistency with other failure modes. |
| 870 } else if (content_size == buffer_size) { |
| 871 // Shallow copy the pixel reference. |
| 872 raw_data_small = raw_data; |
| 873 } else { |
| 874 // The content size is smaller than the buffer size (likely because of |
| 875 // a power-of-two rounding), so deep copy the bitmap. |
| 876 raw_data_small.allocPixels(SkImageInfo::Make(content_size.width(), |
| 877 content_size.height(), |
| 878 kRGBA_8888_SkColorType, |
| 879 kOpaque_SkAlphaType)); |
| 880 SkAutoLockPixels raw_data_small_lock(raw_data_small); |
| 881 SkCanvas small_canvas(raw_data_small); |
| 882 small_canvas.drawBitmap(raw_data, 0, 0); |
| 883 raw_data_small.setImmutable(); |
| 884 } |
864 } | 885 } |
865 | 886 |
866 content::BrowserThread::PostTask( | 887 content::BrowserThread::PostTask( |
867 content::BrowserThread::UI, | 888 content::BrowserThread::UI, |
868 FROM_HERE, | 889 FROM_HERE, |
869 base::Bind(post_decompression_callback, success, raw_data)); | 890 base::Bind(post_decompression_callback, success, raw_data_small)); |
870 } | 891 } |
871 | 892 |
872 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData() { | 893 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData() { |
873 } | 894 } |
874 | 895 |
875 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData( | 896 ThumbnailStore::ThumbnailMetaData::ThumbnailMetaData( |
876 const base::Time& current_time, | 897 const base::Time& current_time, |
877 const GURL& url) | 898 const GURL& url) |
878 : capture_time_(current_time), url_(url) { | 899 : capture_time_(current_time), url_(url) { |
879 } | 900 } |
(...skipping 16 matching lines...) Expand all Loading... |
896 dst_bitmap.eraseColor(0); | 917 dst_bitmap.eraseColor(0); |
897 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); | 918 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); |
898 | 919 |
899 SkCanvas canvas(dst_bitmap); | 920 SkCanvas canvas(dst_bitmap); |
900 canvas.scale(new_scale, new_scale); | 921 canvas.scale(new_scale, new_scale); |
901 canvas.drawBitmap(bitmap, 0, 0, NULL); | 922 canvas.drawBitmap(bitmap, 0, 0, NULL); |
902 dst_bitmap.setImmutable(); | 923 dst_bitmap.setImmutable(); |
903 | 924 |
904 return std::make_pair(dst_bitmap, new_scale * scale); | 925 return std::make_pair(dst_bitmap, new_scale * scale); |
905 } | 926 } |
OLD | NEW |