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