| 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 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SimpleThumbnailCrop::ProcessBitmap( | 40 void SimpleThumbnailCrop::ProcessBitmap( |
| 41 scoped_refptr<ThumbnailingContext> context, | 41 scoped_refptr<ThumbnailingContext> context, |
| 42 const ConsumerCallback& callback, | 42 const ConsumerCallback& callback, |
| 43 const SkBitmap& bitmap) { | 43 const SkBitmap& bitmap) { |
| 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 45 if (bitmap.isNull() || bitmap.empty()) | 45 if (bitmap.isNull() || bitmap.empty()) |
| 46 return; | 46 return; |
| 47 | 47 |
| 48 ClipResult clip_result; | |
| 49 SkBitmap thumbnail = CreateThumbnail( | 48 SkBitmap thumbnail = CreateThumbnail( |
| 50 bitmap, | 49 bitmap, |
| 51 ComputeTargetSizeAtMaximumScale(target_size_), | 50 ComputeTargetSizeAtMaximumScale(target_size_), |
| 52 &clip_result); | 51 &context->clip_result); |
| 53 | 52 |
| 54 context->SetBoringScore(color_utils::CalculateBoringScore(thumbnail)); | 53 context->score.boring_score = color_utils::CalculateBoringScore(thumbnail); |
| 55 context->set_clip_result(clip_result); | 54 context->score.good_clipping = |
| 56 bool good_clipping = | 55 (context->clip_result == CLIP_RESULT_WIDER_THAN_TALL || |
| 57 (clip_result == CLIP_RESULT_WIDER_THAN_TALL || | 56 context->clip_result == CLIP_RESULT_TALLER_THAN_WIDE || |
| 58 clip_result == CLIP_RESULT_TALLER_THAN_WIDE || | 57 context->clip_result == CLIP_RESULT_NOT_CLIPPED); |
| 59 clip_result == CLIP_RESULT_NOT_CLIPPED); | |
| 60 context->SetGoodClipping(good_clipping); | |
| 61 | 58 |
| 62 callback.Run(*context.get(), thumbnail); | 59 callback.Run(*context.get(), thumbnail); |
| 63 } | 60 } |
| 64 | 61 |
| 65 SkBitmap SimpleThumbnailCrop::GetClippedBitmap(const SkBitmap& bitmap, | 62 SkBitmap SimpleThumbnailCrop::GetClippedBitmap(const SkBitmap& bitmap, |
| 66 int desired_width, | 63 int desired_width, |
| 67 int desired_height, | 64 int desired_height, |
| 68 ClipResult* clip_result) { | 65 ClipResult* clip_result) { |
| 69 gfx::Rect clipping_rect = | 66 gfx::Rect clipping_rect = |
| 70 GetClippingRect(gfx::Size(bitmap.width(), bitmap.height()), | 67 GetClippingRect(gfx::Size(bitmap.width(), bitmap.height()), |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 clipped_bitmap.height() == result.height()) | 194 clipped_bitmap.height() == result.height()) |
| 198 clipped_bitmap.copyTo(&result, kN32_SkColorType); | 195 clipped_bitmap.copyTo(&result, kN32_SkColorType); |
| 199 #endif | 196 #endif |
| 200 | 197 |
| 201 LOCAL_HISTOGRAM_TIMES(kThumbnailHistogramName, | 198 LOCAL_HISTOGRAM_TIMES(kThumbnailHistogramName, |
| 202 base::TimeTicks::Now() - begin_compute_thumbnail); | 199 base::TimeTicks::Now() - begin_compute_thumbnail); |
| 203 return result; | 200 return result; |
| 204 } | 201 } |
| 205 | 202 |
| 206 } // namespace thumbnails | 203 } // namespace thumbnails |
| OLD | NEW |