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 52d92059275cf0530bf13f859855bb543ea756be..272f6ab845825a61b0dd0ae515329cdc5eeeb872 100644 |
--- a/chrome/browser/android/thumbnail/thumbnail_store.cc |
+++ b/chrome/browser/android/thumbnail/thumbnail_store.cc |
@@ -38,8 +38,6 @@ const int kCurrentExtraVersion = 1; |
// Indicates whether we prefer to have more free CPU memory over GPU memory. |
const bool kPreferCPUMemory = true; |
-// TODO(): ETC1 texture sizes should be multiples of four, but some drivers only |
-// allow power-of-two ETC1 textures. Find better work around. |
size_t NextPowerOfTwo(size_t x) { |
--x; |
x |= x >> 1; |
@@ -50,10 +48,22 @@ size_t NextPowerOfTwo(size_t x) { |
return x + 1; |
} |
-gfx::Size GetEncodedSize(const gfx::Size& bitmap_size) { |
+size_t RoundUpMod4(size_t x) { |
David Trainor- moved to gerrit
2014/08/21 22:15:00
(x + 3) & ~3 (is what most ETC1 libs use).
aelias_OOO_until_Jul13
2014/08/21 22:56:12
Done.
|
+ size_t mod = x % 4; |
+ if (mod) { |
+ x += 4 - mod; |
+ } |
+ return x; |
+} |
+ |
+gfx::Size GetEncodedSize(const gfx::Size& bitmap_size, bool supports_npot) { |
DCHECK(!bitmap_size.IsEmpty()); |
- return gfx::Size(NextPowerOfTwo(bitmap_size.width()), |
- NextPowerOfTwo(bitmap_size.height())); |
+ if (!supports_npot) |
+ return gfx::Size(NextPowerOfTwo(bitmap_size.width()), |
+ NextPowerOfTwo(bitmap_size.height())); |
+ else |
+ return gfx::Size(RoundUpMod4(bitmap_size.width()), |
+ RoundUpMod4(bitmap_size.height())); |
} |
template<typename T> |
@@ -365,11 +375,16 @@ void ThumbnailStore::CompressThumbnailIfNecessary( |
time_stamp, |
scale); |
- base::WorkerPool::PostTask( |
- FROM_HERE, |
- base::Bind( |
- &ThumbnailStore::CompressionTask, bitmap, post_compression_task), |
- true); |
+ gfx::Size raw_data_size(bitmap.width(), bitmap.height()); |
+ gfx::Size encoded_size = GetEncodedSize( |
+ raw_data_size, ui_resource_provider_->SupportsETC1NonPowerOfTwo()); |
+ |
+ base::WorkerPool::PostTask(FROM_HERE, |
+ base::Bind(&ThumbnailStore::CompressionTask, |
+ bitmap, |
+ encoded_size, |
+ post_compression_task), |
+ true); |
} |
void ThumbnailStore::ReadNextThumbnail() { |
@@ -539,6 +554,7 @@ void ThumbnailStore::PostWriteTask() { |
void ThumbnailStore::CompressionTask( |
SkBitmap raw_data, |
+ gfx::Size encoded_size, |
const base::Callback<void(skia::RefPtr<SkPixelRef>, const gfx::Size&)>& |
post_compression_task) { |
skia::RefPtr<SkPixelRef> compressed_data; |
@@ -550,7 +566,6 @@ void ThumbnailStore::CompressionTask( |
size_t pixel_size = 4; // Pixel size is 4 bytes for kARGB_8888_Config. |
size_t stride = pixel_size * raw_data_size.width(); |
- gfx::Size encoded_size = GetEncodedSize(raw_data_size); |
size_t encoded_bytes = |
etc1_get_encoded_data_size(encoded_size.width(), encoded_size.height()); |
SkImageInfo info = {encoded_size.width(), |