summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authormazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 05:58:35 +0000
committermazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 05:58:35 +0000
commit3a2df50b66ced0548aa2b86ab0e88424b18f3808 (patch)
tree2274c799eadb04d1445c95a8480f9ed42231f2f2 /chrome/browser/tab_contents
parented7cde2b856aa5000ce4fb737c3a59cdc964addb (diff)
downloadchromium_src-3a2df50b66ced0548aa2b86ab0e88424b18f3808.zip
chromium_src-3a2df50b66ced0548aa2b86ab0e88424b18f3808.tar.gz
chromium_src-3a2df50b66ced0548aa2b86ab0e88424b18f3808.tar.bz2
Copy a shrinked image from the backing store or compositing surface for generating thumbnail.
Also changed the resize method to Lanczos3 for better quality. This will make RenderWidgetHost::CopyFromBackingStore about 6 times faster on Lumpy while retaining the quality of thumbnail. BUG=96351,118571 TEST=Manually checked the thumbnail generated properly with --enable-in-browser-thumbnailing. Review URL: http://codereview.chromium.org/9703113 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/thumbnail_generator.cc34
1 files changed, 32 insertions, 2 deletions
diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc
index 398c2af..e9b4356 100644
--- a/chrome/browser/tab_contents/thumbnail_generator.cc
+++ b/chrome/browser/tab_contents/thumbnail_generator.cc
@@ -21,6 +21,7 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
#include "skia/ext/image_operations.h"
@@ -60,8 +61,31 @@ namespace {
static const int kThumbnailWidth = 212;
static const int kThumbnailHeight = 132;
+// This factor determines the number of pixels to be copied by
+// RenderWidgetHost::CopyFromBackingStore for generating thumbnail.
+// Smaller scale is good for performance, but too small scale causes aliasing
+// because the resampling method is not good enough to retain the image quality.
+// TODO(mazda): the Improve resampling method and use a smaller scale
+// (http://crbug.com/118571).
+static const double kThumbnailCopyScale = 2.0;
+
static const char kThumbnailHistogramName[] = "Thumbnail.ComputeMS";
+// Calculates the size used by RenderWidgetHost::CopyFromBackingStore.
+// The result is computed as the minimum size that satisfies the following
+// conditions.
+// result.width : result.height == view_size.width : view_size.height
+// result.width >= kThumbnailCopyScale * desired_size.width
+// result.height >= kThumbnailCopyScale * desired_size.height
+gfx::Size GetCopySizeForThumbnail(const gfx::Size& view_size,
+ const gfx::Size& desired_size) {
+ const double scale = kThumbnailCopyScale *
+ std::max(static_cast<double>(desired_size.width()) / view_size.width(),
+ static_cast<double>(desired_size.height()) / view_size.height());
+ return gfx::Size(static_cast<int>(scale * view_size.width()),
+ static_cast<int>(scale * view_size.height()));
+}
+
// Creates a downsampled thumbnail for the given RenderWidgetHost's backing
// store. The returned bitmap will be isNull if there was an error creating it.
SkBitmap GetBitmapForRenderWidgetHost(
@@ -77,9 +101,15 @@ SkBitmap GetBitmapForRenderWidgetHost(
// Get the bitmap as a Skia object so we can resample it. This is a large
// allocation and we can tolerate failure here, so give up if the allocation
// fails.
- // TODO(mazda): Copy a shrinked size of image instead of the whole view size.
skia::PlatformCanvas temp_canvas;
- if (!render_widget_host->CopyFromBackingStore(gfx::Size(), &temp_canvas))
+ content::RenderWidgetHostView* view = render_widget_host->GetView();
+ if (!view)
+ return result;
+ const gfx::Size copy_size =
+ GetCopySizeForThumbnail(view->GetViewBounds().size(),
+ gfx::Size(desired_width, desired_height));
+ if (!render_widget_host->CopyFromBackingStore(
+ gfx::Rect(), copy_size, &temp_canvas))
return result;
const SkBitmap& bmp_with_scrollbars =
skia::GetTopDevice(temp_canvas)->accessBitmap(false);