Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/tab_contents/thumbnail_generator.cc

Issue 9582003: Support browser side thumbnailing for GPU composited pages on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tab_contents/thumbnail_generator.h" 5 #include "chrome/browser/tab_contents/thumbnail_generator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/history/top_sites.h" 16 #include "chrome/browser/history/top_sites.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/thumbnail_score.h" 18 #include "chrome/common/thumbnail_score.h"
19 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
26 #include "skia/ext/image_operations.h" 27 #include "skia/ext/image_operations.h"
27 #include "skia/ext/platform_canvas.h" 28 #include "skia/ext/platform_canvas.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 29 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "ui/gfx/color_utils.h" 30 #include "ui/gfx/color_utils.h"
30 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
31 #include "ui/gfx/skbitmap_operations.h" 32 #include "ui/gfx/skbitmap_operations.h"
32 33
33 // Overview 34 // Overview
(...skipping 29 matching lines...) Expand all
63 // Creates a downsampled thumbnail for the given RenderWidgetHost's backing 64 // Creates a downsampled thumbnail for the given RenderWidgetHost's backing
64 // store. The returned bitmap will be isNull if there was an error creating it. 65 // store. The returned bitmap will be isNull if there was an error creating it.
65 SkBitmap GetBitmapForRenderWidgetHost( 66 SkBitmap GetBitmapForRenderWidgetHost(
66 RenderWidgetHost* render_widget_host, 67 RenderWidgetHost* render_widget_host,
67 int desired_width, 68 int desired_width,
68 int desired_height, 69 int desired_height,
69 int options, 70 int options,
70 ThumbnailGenerator::ClipResult* clip_result) { 71 ThumbnailGenerator::ClipResult* clip_result) {
71 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now(); 72 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now();
72 73
73 SkBitmap result;
74
75 // Get the bitmap as a Skia object so we can resample it. This is a large 74 // Get the bitmap as a Skia object so we can resample it. This is a large
76 // allocation and we can tolerate failure here, so give up if the allocation 75 // allocation and we can tolerate failure here, so give up if the allocation
77 // fails. 76 // fails. First try to read from the compositing surface, then to read from
77 // the backing store.
78 content::RenderWidgetHostView* view = render_widget_host->GetView();
78 skia::PlatformCanvas temp_canvas; 79 skia::PlatformCanvas temp_canvas;
79 if (!render_widget_host->CopyFromBackingStore(&temp_canvas)) 80 bool copy_result = false;
80 return result; 81 // TODO(mazda): Copy the shrinked size of compositing surface instead of the
82 // view size for better performance.
83 if (view)
apatrick_chromium 2012/03/07 20:39:37 nit: braces around multiline body.
mazda 2012/03/08 13:14:28 Done.
84 copy_result = render_widget_host->CopyFromCompositingSurface(
85 view->GetViewBounds().size(),
86 &temp_canvas);
87 if (!copy_result)
88 copy_result = render_widget_host->CopyFromBackingStore(&temp_canvas);
89 if (!copy_result)
90 return SkBitmap();
91
81 const SkBitmap& bmp_with_scrollbars = 92 const SkBitmap& bmp_with_scrollbars =
82 skia::GetTopDevice(temp_canvas)->accessBitmap(false); 93 skia::GetTopDevice(temp_canvas)->accessBitmap(false);
83 // Clip the edgemost 15 pixels as that will commonly hold a scrollbar, which 94 // Clip the edgemost 15 pixels as that will commonly hold a scrollbar, which
84 // looks bad in thumbnails. 95 // looks bad in thumbnails.
85 SkIRect scrollbarless_rect = 96 SkIRect scrollbarless_rect =
86 { 0, 0, 97 { 0, 0,
87 std::max(1, bmp_with_scrollbars.width() - 15), 98 std::max(1, bmp_with_scrollbars.width() - 15),
88 std::max(1, bmp_with_scrollbars.height() - 15) }; 99 std::max(1, bmp_with_scrollbars.height() - 15) };
89 SkBitmap bmp; 100 SkBitmap bmp;
90 bmp_with_scrollbars.extractSubset(&bmp, scrollbarless_rect); 101 bmp_with_scrollbars.extractSubset(&bmp, scrollbarless_rect);
91 102
103 SkBitmap result;
92 // Check if a clipped thumbnail is requested. 104 // Check if a clipped thumbnail is requested.
93 if (options & ThumbnailGenerator::kClippedThumbnail) { 105 if (options & ThumbnailGenerator::kClippedThumbnail) {
94 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( 106 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
95 bmp, desired_width, desired_height, clip_result); 107 bmp, desired_width, desired_height, clip_result);
96 108
97 // Need to resize it to the size we want, so downsample until it's 109 // Need to resize it to the size we want, so downsample until it's
98 // close, and let the caller make it the exact size if desired. 110 // close, and let the caller make it the exact size if desired.
99 result = SkBitmapOperations::DownsampleByTwoUntilSize( 111 result = SkBitmapOperations::DownsampleByTwoUntilSize(
100 clipped_bitmap, desired_width, desired_height); 112 clipped_bitmap, desired_width, desired_height);
101 // This is a bit subtle. SkBitmaps are refcounted, but the magic 113 // This is a bit subtle. SkBitmaps are refcounted, but the magic
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 523
512 void ThumbnailGenerator::DidStartLoading() { 524 void ThumbnailGenerator::DidStartLoading() {
513 load_interrupted_ = false; 525 load_interrupted_ = false;
514 } 526 }
515 527
516 void ThumbnailGenerator::StopNavigation() { 528 void ThumbnailGenerator::StopNavigation() {
517 // This function gets called when the page loading is interrupted by the 529 // This function gets called when the page loading is interrupted by the
518 // stop button. 530 // stop button.
519 load_interrupted_ = true; 531 load_interrupted_ = true;
520 } 532 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/gpu/gpu_surface_reader_win.h » ('j') | content/browser/gpu/gpu_surface_reader_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698