diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 21:07:34 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 21:07:34 +0000 |
commit | f5fb0b881ef3a0aaacb05e4192e151c1383ff910 (patch) | |
tree | 53800b8f211a34e58c017a6d3eaf72c60ee61191 /chrome | |
parent | aaebafb1692dccdde86e5489059f6c6f09060e6f (diff) | |
download | chromium_src-f5fb0b881ef3a0aaacb05e4192e151c1383ff910.zip chromium_src-f5fb0b881ef3a0aaacb05e4192e151c1383ff910.tar.gz chromium_src-f5fb0b881ef3a0aaacb05e4192e151c1383ff910.tar.bz2 |
Allow wider than tall clipping as good clipping and add kTooWiderThanTall.
This CL changes ThumbnailGenerator to accept wider than tall pages as good clipping, and penalize its boring score instead.
On devices with a small display (and especially under Aura shell), most pages are wider than tall, so good clipping is rarely obtained and almost every tab switching causes to generate thumbnail without this change.
BUG=96351
TEST=Manually checked that wider than tall bitmap is accepted as good clipping in ThumbnailGenerator.
Review URL: http://codereview.chromium.org/9720039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/tab_contents/thumbnail_generator.cc | 10 | ||||
-rw-r--r-- | chrome/browser/tab_contents/thumbnail_generator.h | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/thumbnail_generator_unittest.cc | 19 | ||||
-rw-r--r-- | chrome/common/thumbnail_score.cc | 3 | ||||
-rw-r--r-- | chrome/common/thumbnail_score.h | 13 | ||||
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.cc | 3 |
6 files changed, 40 insertions, 10 deletions
diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index e9b4356..9e7ed79 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -446,8 +446,11 @@ SkBitmap ThumbnailGenerator::GetClippedBitmap(const SkBitmap& bitmap, S16CPU new_width = static_cast<S16CPU>(bitmap.height() * dest_aspect); S16CPU x_offset = (bitmap.width() - new_width) / 2; src_rect.set(x_offset, 0, new_width + x_offset, bitmap.height()); - if (clip_result) - *clip_result = ThumbnailGenerator::kWiderThanTall; + if (clip_result) { + *clip_result = (src_aspect >= ThumbnailScore::kTooWideAspectRatio) ? + ThumbnailGenerator::kTooWiderThanTall : + ThumbnailGenerator::kWiderThanTall; + } } else if (src_aspect < dest_aspect) { src_rect.set(0, 0, bitmap.width(), static_cast<S16CPU>(bitmap.width() / dest_aspect)); @@ -502,7 +505,8 @@ void ThumbnailGenerator::UpdateThumbnail( (web_contents->GetRenderViewHost()->GetLastScrollOffset().y() == 0); score.boring_score = ThumbnailGenerator::CalculateBoringScore(thumbnail); score.good_clipping = - (clip_result == ThumbnailGenerator::kTallerThanWide || + (clip_result == ThumbnailGenerator::kWiderThanTall || + clip_result == ThumbnailGenerator::kTallerThanWide || clip_result == ThumbnailGenerator::kNotClipped); score.load_completed = (!load_interrupted_ && !web_contents->IsLoading()); diff --git a/chrome/browser/tab_contents/thumbnail_generator.h b/chrome/browser/tab_contents/thumbnail_generator.h index bf905dd..481e5da 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.h +++ b/chrome/browser/tab_contents/thumbnail_generator.h @@ -43,6 +43,8 @@ class ThumbnailGenerator : public content::NotificationObserver, enum ClipResult { // The source image is smaller. kSourceIsSmaller, + // Wider than tall by twice or more, clip horizontally. + kTooWiderThanTall, // Wider than tall, clip horizontally. kWiderThanTall, // Taller than wide, clip vertically. diff --git a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc index 8fbe7ed..e79b77d 100644 --- a/chrome/browser/tab_contents/thumbnail_generator_unittest.cc +++ b/chrome/browser/tab_contents/thumbnail_generator_unittest.cc @@ -76,7 +76,7 @@ TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_TallerThanWide) { TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_WiderThanTall) { // The input bitmap is horizontally long. - gfx::Canvas canvas(gfx::Size(90, 40), true); + gfx::Canvas canvas(gfx::Size(70, 40), true); SkBitmap bitmap = skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); @@ -91,6 +91,23 @@ TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_WiderThanTall) { EXPECT_EQ(ThumbnailGenerator::kWiderThanTall, clip_result); } +TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_TooWiderThanTall) { + // The input bitmap is horizontally very long. + gfx::Canvas canvas(gfx::Size(90, 40), true); + SkBitmap bitmap = + skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(false); + + // The desired size is square. + ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped; + SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( + bitmap, 10, 10, &clip_result); + // The clipped bitmap should be square. + EXPECT_EQ(40, clipped_bitmap.width()); + EXPECT_EQ(40, clipped_bitmap.height()); + // The input was wider than tall. + EXPECT_EQ(ThumbnailGenerator::kTooWiderThanTall, clip_result); +} + TEST_F(ThumbnailGeneratorTest, GetClippedBitmap_NotClipped) { // The input bitmap is square. gfx::Canvas canvas(gfx::Size(40, 40), true); diff --git a/chrome/common/thumbnail_score.cc b/chrome/common/thumbnail_score.cc index 39657f1..bff3e35 100644 --- a/chrome/common/thumbnail_score.cc +++ b/chrome/common/thumbnail_score.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,7 @@ using base::TimeDelta; const int64 ThumbnailScore::kUpdateThumbnailTimeDays = 1; const double ThumbnailScore::kThumbnailMaximumBoringness = 0.94; const double ThumbnailScore::kThumbnailDegradePerHour = 0.01; +const double ThumbnailScore::kTooWideAspectRatio = 2.0; // Calculates a numeric score from traits about where a snapshot was // taken. The lower the better. We store the raw components in the diff --git a/chrome/common/thumbnail_score.h b/chrome/common/thumbnail_score.h index 3472028..56d7d42 100644 --- a/chrome/common/thumbnail_score.h +++ b/chrome/common/thumbnail_score.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,9 +44,10 @@ struct ThumbnailScore { // browser window size. double boring_score; - // Whether the thumbnail was taken with height greater then - // width. In cases where we don't have |good_clipping|, the - // thumbnails are either clipped from the horizontal center of the + // Whether the thumbnail was taken with height greater than + // width or width greater than height and the aspect ratio less than + // kTooWideAspectRatio. In cases where we don't have |good_clipping|, + // the thumbnails are either clipped from the horizontal center of the // window, or are otherwise weirdly stretched. bool good_clipping; @@ -95,6 +96,10 @@ struct ThumbnailScore { // Penalty of how much more boring a thumbnail should be per hour. static const double kThumbnailDegradePerHour; + // If a thumbnail is taken with the aspect ratio greater than or equal to + // this value, |good_clipping| is to false. + static const double kTooWideAspectRatio; + // Checks whether we should consider updating a new thumbnail based on // this score. For instance, we don't have to update a new thumbnail // if the current thumbnail is new and interesting enough. diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index 61fa311..1b14e5a 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -938,7 +938,8 @@ bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view, S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); S16CPU x_offset = (src_bmp_width - new_width) / 2; src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); - score->good_clipping = false; + score->good_clipping = + (src_aspect >= ThumbnailScore::kTooWideAspectRatio) ? false : true; } else { src_rect.set(0, 0, src_bmp_width, static_cast<S16CPU>(src_bmp_width / dest_aspect)); |