| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/thumbnails/simple_thumbnail_crop.h" | 5 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
| 10 #include "ui/base/layout.h" | 10 #include "ui/base/layout.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ui::ScaleFactor scale_factor, | 83 ui::ScaleFactor scale_factor, |
| 84 const gfx::Size& thumbnail_size) { | 84 const gfx::Size& thumbnail_size) { |
| 85 // The copy size returned is the pixel equivalent of |thumbnail_size|, which | 85 // The copy size returned is the pixel equivalent of |thumbnail_size|, which |
| 86 // is in DIPs. | 86 // is in DIPs. |
| 87 if (scale_factor == ui::SCALE_FACTOR_100P) { | 87 if (scale_factor == ui::SCALE_FACTOR_100P) { |
| 88 // In the case of 1x devices, we get a thumbnail twice as big and reduce | 88 // In the case of 1x devices, we get a thumbnail twice as big and reduce |
| 89 // it at serve time to improve quality. | 89 // it at serve time to improve quality. |
| 90 scale_factor = ui::SCALE_FACTOR_200P; | 90 scale_factor = ui::SCALE_FACTOR_200P; |
| 91 } | 91 } |
| 92 float scale = GetScaleForScaleFactor(scale_factor); | 92 float scale = GetScaleForScaleFactor(scale_factor); |
| 93 return gfx::ToFlooredSize(gfx::ScaleSize(thumbnail_size, scale)); | 93 return gfx::ScaleToFlooredSize(thumbnail_size, scale); |
| 94 } | 94 } |
| 95 | 95 |
| 96 gfx::Rect SimpleThumbnailCrop::GetClippingRect(const gfx::Size& source_size, | 96 gfx::Rect SimpleThumbnailCrop::GetClippingRect(const gfx::Size& source_size, |
| 97 const gfx::Size& desired_size, | 97 const gfx::Size& desired_size, |
| 98 ClipResult* clip_result) { | 98 ClipResult* clip_result) { |
| 99 DCHECK(clip_result); | 99 DCHECK(clip_result); |
| 100 | 100 |
| 101 float desired_aspect = | 101 float desired_aspect = |
| 102 static_cast<float>(desired_size.width()) / desired_size.height(); | 102 static_cast<float>(desired_size.width()) / desired_size.height(); |
| 103 | 103 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 134 } | 134 } |
| 135 return clipping_rect; | 135 return clipping_rect; |
| 136 } | 136 } |
| 137 | 137 |
| 138 // static | 138 // static |
| 139 gfx::Size SimpleThumbnailCrop::ComputeTargetSizeAtMaximumScale( | 139 gfx::Size SimpleThumbnailCrop::ComputeTargetSizeAtMaximumScale( |
| 140 const gfx::Size& given_size) { | 140 const gfx::Size& given_size) { |
| 141 // TODO(mazda|oshima): Update thumbnail when the max scale factor changes. | 141 // TODO(mazda|oshima): Update thumbnail when the max scale factor changes. |
| 142 // crbug.com/159157. | 142 // crbug.com/159157. |
| 143 float max_scale_factor = gfx::ImageSkia::GetMaxSupportedScale(); | 143 float max_scale_factor = gfx::ImageSkia::GetMaxSupportedScale(); |
| 144 return gfx::ToFlooredSize(gfx::ScaleSize(given_size, max_scale_factor)); | 144 return gfx::ScaleToFlooredSize(given_size, max_scale_factor); |
| 145 } | 145 } |
| 146 | 146 |
| 147 SimpleThumbnailCrop::~SimpleThumbnailCrop() { | 147 SimpleThumbnailCrop::~SimpleThumbnailCrop() { |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Creates a downsampled thumbnail from the given bitmap. | 150 // Creates a downsampled thumbnail from the given bitmap. |
| 151 // store. The returned bitmap will be isNull if there was an error creating it. | 151 // store. The returned bitmap will be isNull if there was an error creating it. |
| 152 SkBitmap SimpleThumbnailCrop::CreateThumbnail(const SkBitmap& bitmap, | 152 SkBitmap SimpleThumbnailCrop::CreateThumbnail(const SkBitmap& bitmap, |
| 153 const gfx::Size& desired_size, | 153 const gfx::Size& desired_size, |
| 154 ClipResult* clip_result) { | 154 ClipResult* clip_result) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 clipped_bitmap.height() == result.height()) | 194 clipped_bitmap.height() == result.height()) |
| 195 clipped_bitmap.copyTo(&result, kN32_SkColorType); | 195 clipped_bitmap.copyTo(&result, kN32_SkColorType); |
| 196 #endif | 196 #endif |
| 197 | 197 |
| 198 LOCAL_HISTOGRAM_TIMES(kThumbnailHistogramName, | 198 LOCAL_HISTOGRAM_TIMES(kThumbnailHistogramName, |
| 199 base::TimeTicks::Now() - begin_compute_thumbnail); | 199 base::TimeTicks::Now() - begin_compute_thumbnail); |
| 200 return result; | 200 return result; |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace thumbnails | 203 } // namespace thumbnails |
| OLD | NEW |