| 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 | 9 |
| 10 #include "base/android/path_utils.h" | 10 #include "base/android/path_utils.h" |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 } | 907 } |
| 908 | 908 |
| 909 std::pair<SkBitmap, float> ThumbnailCache::CreateApproximation( | 909 std::pair<SkBitmap, float> ThumbnailCache::CreateApproximation( |
| 910 const SkBitmap& bitmap, | 910 const SkBitmap& bitmap, |
| 911 float scale) { | 911 float scale) { |
| 912 DCHECK(!bitmap.empty()); | 912 DCHECK(!bitmap.empty()); |
| 913 DCHECK_GT(scale, 0); | 913 DCHECK_GT(scale, 0); |
| 914 SkAutoLockPixels bitmap_lock(bitmap); | 914 SkAutoLockPixels bitmap_lock(bitmap); |
| 915 float new_scale = 1.f / kApproximationScaleFactor; | 915 float new_scale = 1.f / kApproximationScaleFactor; |
| 916 | 916 |
| 917 gfx::Size dst_size = gfx::ToFlooredSize( | 917 gfx::Size dst_size = gfx::ScaleToFlooredSize( |
| 918 gfx::ScaleSize(gfx::Size(bitmap.width(), bitmap.height()), new_scale)); | 918 gfx::Size(bitmap.width(), bitmap.height()), new_scale); |
| 919 SkBitmap dst_bitmap; | 919 SkBitmap dst_bitmap; |
| 920 dst_bitmap.allocPixels(SkImageInfo::Make(dst_size.width(), | 920 dst_bitmap.allocPixels(SkImageInfo::Make(dst_size.width(), |
| 921 dst_size.height(), | 921 dst_size.height(), |
| 922 bitmap.info().colorType(), | 922 bitmap.info().colorType(), |
| 923 bitmap.info().alphaType())); | 923 bitmap.info().alphaType())); |
| 924 dst_bitmap.eraseColor(0); | 924 dst_bitmap.eraseColor(0); |
| 925 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); | 925 SkAutoLockPixels dst_bitmap_lock(dst_bitmap); |
| 926 | 926 |
| 927 SkCanvas canvas(dst_bitmap); | 927 SkCanvas canvas(dst_bitmap); |
| 928 canvas.scale(new_scale, new_scale); | 928 canvas.scale(new_scale, new_scale); |
| 929 canvas.drawBitmap(bitmap, 0, 0, NULL); | 929 canvas.drawBitmap(bitmap, 0, 0, NULL); |
| 930 dst_bitmap.setImmutable(); | 930 dst_bitmap.setImmutable(); |
| 931 | 931 |
| 932 return std::make_pair(dst_bitmap, new_scale * scale); | 932 return std::make_pair(dst_bitmap, new_scale * scale); |
| 933 } | 933 } |
| OLD | NEW |