| 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_cache.h" | 5 #include "chrome/browser/android/thumbnail/thumbnail_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return false; | 504 return false; |
| 505 | 505 |
| 506 if (!WriteBigEndianToFile(file, content_size.width())) | 506 if (!WriteBigEndianToFile(file, content_size.width())) |
| 507 return false; | 507 return false; |
| 508 | 508 |
| 509 if (!WriteBigEndianToFile(file, content_size.height())) | 509 if (!WriteBigEndianToFile(file, content_size.height())) |
| 510 return false; | 510 return false; |
| 511 | 511 |
| 512 // Write ETC1 header. | 512 // Write ETC1 header. |
| 513 unsigned char etc1_buffer[ETC_PKM_HEADER_SIZE]; | 513 unsigned char etc1_buffer[ETC_PKM_HEADER_SIZE]; |
| 514 etc1_pkm_format_header(etc1_buffer, | 514 etc1_pkm_format_header(etc1_buffer, compressed_data->width(), |
| 515 compressed_data->info().width(), | 515 compressed_data->height()); |
| 516 compressed_data->info().height()); | |
| 517 | 516 |
| 518 int header_bytes_written = file.WriteAtCurrentPos( | 517 int header_bytes_written = file.WriteAtCurrentPos( |
| 519 reinterpret_cast<char*>(etc1_buffer), ETC_PKM_HEADER_SIZE); | 518 reinterpret_cast<char*>(etc1_buffer), ETC_PKM_HEADER_SIZE); |
| 520 if (header_bytes_written != ETC_PKM_HEADER_SIZE) | 519 if (header_bytes_written != ETC_PKM_HEADER_SIZE) |
| 521 return false; | 520 return false; |
| 522 | 521 |
| 523 int data_size = etc1_get_encoded_data_size( | 522 int data_size = etc1_get_encoded_data_size(compressed_data->width(), |
| 524 compressed_data->info().width(), | 523 compressed_data->height()); |
| 525 compressed_data->info().height()); | |
| 526 int pixel_bytes_written = file.WriteAtCurrentPos( | 524 int pixel_bytes_written = file.WriteAtCurrentPos( |
| 527 reinterpret_cast<char*>(compressed_data->pixels()), | 525 reinterpret_cast<char*>(compressed_data->pixels()), |
| 528 data_size); | 526 data_size); |
| 529 if (pixel_bytes_written != data_size) | 527 if (pixel_bytes_written != data_size) |
| 530 return false; | 528 return false; |
| 531 | 529 |
| 532 if (!WriteBigEndianToFile(file, kCurrentExtraVersion)) | 530 if (!WriteBigEndianToFile(file, kCurrentExtraVersion)) |
| 533 return false; | 531 return false; |
| 534 | 532 |
| 535 if (!WriteBigEndianFloatToFile(file, 1.f / scale)) | 533 if (!WriteBigEndianFloatToFile(file, 1.f / scale)) |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 void ThumbnailCache::DecompressionTask( | 844 void ThumbnailCache::DecompressionTask( |
| 847 const base::Callback<void(bool, SkBitmap)>& | 845 const base::Callback<void(bool, SkBitmap)>& |
| 848 post_decompression_callback, | 846 post_decompression_callback, |
| 849 sk_sp<SkPixelRef> compressed_data, | 847 sk_sp<SkPixelRef> compressed_data, |
| 850 float scale, | 848 float scale, |
| 851 const gfx::Size& content_size) { | 849 const gfx::Size& content_size) { |
| 852 SkBitmap raw_data_small; | 850 SkBitmap raw_data_small; |
| 853 bool success = false; | 851 bool success = false; |
| 854 | 852 |
| 855 if (compressed_data.get()) { | 853 if (compressed_data.get()) { |
| 856 gfx::Size buffer_size = gfx::Size(compressed_data->info().width(), | 854 gfx::Size buffer_size = |
| 857 compressed_data->info().height()); | 855 gfx::Size(compressed_data->width(), compressed_data->height()); |
| 858 | 856 |
| 859 SkBitmap raw_data; | 857 SkBitmap raw_data; |
| 860 raw_data.allocPixels(SkImageInfo::Make(buffer_size.width(), | 858 raw_data.allocPixels(SkImageInfo::Make(buffer_size.width(), |
| 861 buffer_size.height(), | 859 buffer_size.height(), |
| 862 kRGBA_8888_SkColorType, | 860 kRGBA_8888_SkColorType, |
| 863 kOpaque_SkAlphaType)); | 861 kOpaque_SkAlphaType)); |
| 864 success = etc1_decode_image( | 862 success = etc1_decode_image( |
| 865 reinterpret_cast<unsigned char*>(compressed_data->pixels()), | 863 reinterpret_cast<unsigned char*>(compressed_data->pixels()), |
| 866 reinterpret_cast<unsigned char*>(raw_data.getPixels()), | 864 reinterpret_cast<unsigned char*>(raw_data.getPixels()), |
| 867 buffer_size.width(), | 865 buffer_size.width(), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 return std::make_pair(dst_bitmap, new_scale * scale); | 924 return std::make_pair(dst_bitmap, new_scale * scale); |
| 927 } | 925 } |
| 928 | 926 |
| 929 void ThumbnailCache::OnMemoryPressure( | 927 void ThumbnailCache::OnMemoryPressure( |
| 930 base::MemoryPressureListener::MemoryPressureLevel level) { | 928 base::MemoryPressureListener::MemoryPressureLevel level) { |
| 931 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 929 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 932 cache_.Clear(); | 930 cache_.Clear(); |
| 933 approximation_cache_.Clear(); | 931 approximation_cache_.Clear(); |
| 934 } | 932 } |
| 935 } | 933 } |
| OLD | NEW |