| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/content_based_thumbnailing_algorithm.h" | 5 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "chrome/browser/thumbnails/content_analysis.h" | 9 #include "chrome/browser/thumbnails/content_analysis.h" |
| 10 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" | 10 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/scrollbar_size.h" | 13 #include "ui/gfx/scrollbar_size.h" |
| 14 #include "ui/gfx/size_conversions.h" | 14 #include "ui/gfx/size_conversions.h" |
| 15 #include "ui/gfx/skbitmap_operations.h" | 15 #include "ui/gfx/skbitmap_operations.h" |
| 16 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char kThumbnailHistogramName[] = "Thumbnail.RetargetMS"; | 20 const char kThumbnailHistogramName[] = "Thumbnail.RetargetMS"; |
| 21 const char kFailureHistogramName[] = "Thumbnail.FailedRetargetMS"; | 21 const char kFailureHistogramName[] = "Thumbnail.FailedRetargetMS"; |
| 22 const float kScoreBoostFromSuccessfulRetargeting = 1.1f; | 22 const float kScoreBoostFromSuccessfulRetargeting = 1.1f; |
| 23 | 23 |
| 24 void CallbackInvocationAdapter( | 24 void CallbackInvocationAdapter( |
| 25 const thumbnails::ThumbnailingAlgorithm::ConsumerCallback& callback, | 25 const thumbnails::ThumbnailingAlgorithm::ConsumerCallback& callback, |
| 26 scoped_refptr<thumbnails::ThumbnailingContext> context, | 26 scoped_refptr<thumbnails::ThumbnailingContext> context, |
| 27 const SkBitmap& source_bitmap) { | 27 const SkBitmap& source_bitmap) { |
| 28 callback.Run(*context, source_bitmap); | 28 callback.Run(*context.get(), source_bitmap); |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 namespace thumbnails { | 33 namespace thumbnails { |
| 34 | 34 |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 | 36 |
| 37 ContentBasedThumbnailingAlgorithm::ContentBasedThumbnailingAlgorithm( | 37 ContentBasedThumbnailingAlgorithm::ContentBasedThumbnailingAlgorithm( |
| 38 const gfx::Size& target_size) | 38 const gfx::Size& target_size) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 *clipping_rect = GetClippingRect( | 53 *clipping_rect = GetClippingRect( |
| 54 source_size, target_thumbnail_size, target_size, &clipping_method); | 54 source_size, target_thumbnail_size, target_size, &clipping_method); |
| 55 return clipping_method; | 55 return clipping_method; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void ContentBasedThumbnailingAlgorithm::ProcessBitmap( | 58 void ContentBasedThumbnailingAlgorithm::ProcessBitmap( |
| 59 scoped_refptr<ThumbnailingContext> context, | 59 scoped_refptr<ThumbnailingContext> context, |
| 60 const ConsumerCallback& callback, | 60 const ConsumerCallback& callback, |
| 61 const SkBitmap& bitmap) { | 61 const SkBitmap& bitmap) { |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 63 DCHECK(context); | 63 DCHECK(context.get()); |
| 64 if (bitmap.isNull() || bitmap.empty()) | 64 if (bitmap.isNull() || bitmap.empty()) |
| 65 return; | 65 return; |
| 66 | 66 |
| 67 gfx::Size target_thumbnail_size = | 67 gfx::Size target_thumbnail_size = |
| 68 SimpleThumbnailCrop::ComputeTargetSizeAtMaximumScale(target_size_); | 68 SimpleThumbnailCrop::ComputeTargetSizeAtMaximumScale(target_size_); |
| 69 | 69 |
| 70 SkBitmap source_bitmap = PrepareSourceBitmap( | 70 SkBitmap source_bitmap = |
| 71 bitmap, target_thumbnail_size, context); | 71 PrepareSourceBitmap(bitmap, target_thumbnail_size, context.get()); |
| 72 | 72 |
| 73 // If the source is same (or smaller) than the target, just return it as | 73 // If the source is same (or smaller) than the target, just return it as |
| 74 // the final result. Otherwise, send the shrinking task to the blocking | 74 // the final result. Otherwise, send the shrinking task to the blocking |
| 75 // thread pool. | 75 // thread pool. |
| 76 if (source_bitmap.width() <= target_thumbnail_size.width() || | 76 if (source_bitmap.width() <= target_thumbnail_size.width() || |
| 77 source_bitmap.height() <= target_thumbnail_size.height()) { | 77 source_bitmap.height() <= target_thumbnail_size.height()) { |
| 78 context->score.boring_score = | 78 context->score.boring_score = |
| 79 SimpleThumbnailCrop::CalculateBoringScore(source_bitmap); | 79 SimpleThumbnailCrop::CalculateBoringScore(source_bitmap); |
| 80 context->score.good_clipping = | 80 context->score.good_clipping = |
| 81 (context->clip_result == CLIP_RESULT_WIDER_THAN_TALL || | 81 (context->clip_result == CLIP_RESULT_WIDER_THAN_TALL || |
| 82 context->clip_result == CLIP_RESULT_TALLER_THAN_WIDE || | 82 context->clip_result == CLIP_RESULT_TALLER_THAN_WIDE || |
| 83 context->clip_result == CLIP_RESULT_NOT_CLIPPED || | 83 context->clip_result == CLIP_RESULT_NOT_CLIPPED || |
| 84 context->clip_result == CLIP_RESULT_SOURCE_SAME_AS_TARGET); | 84 context->clip_result == CLIP_RESULT_SOURCE_SAME_AS_TARGET); |
| 85 | 85 |
| 86 callback.Run(*context, source_bitmap); | 86 callback.Run(*context.get(), source_bitmap); |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 | 89 |
| 90 if (!BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( | 90 if (!BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( |
| 91 FROM_HERE, | 91 FROM_HERE, |
| 92 base::Bind(&CreateRetargetedThumbnail, | 92 base::Bind(&CreateRetargetedThumbnail, |
| 93 source_bitmap, | 93 source_bitmap, |
| 94 target_thumbnail_size, | 94 target_thumbnail_size, |
| 95 context, | 95 context, |
| 96 callback), | 96 callback), |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } else { | 228 } else { |
| 229 clipping_rect = gfx::Rect(source_size); | 229 clipping_rect = gfx::Rect(source_size); |
| 230 target_size->SetSize(source_size.width() / 2, source_size.height() / 2); | 230 target_size->SetSize(source_size.width() / 2, source_size.height() / 2); |
| 231 *clip_result = CLIP_RESULT_NOT_CLIPPED; | 231 *clip_result = CLIP_RESULT_NOT_CLIPPED; |
| 232 } | 232 } |
| 233 | 233 |
| 234 return clipping_rect; | 234 return clipping_rect; |
| 235 } | 235 } |
| 236 | 236 |
| 237 } // namespace thumbnails | 237 } // namespace thumbnails |
| OLD | NEW |