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

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"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Creates a downsampled thumbnail for the given RenderWidgetHost's backing 63 // 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. 64 // store. The returned bitmap will be isNull if there was an error creating it.
65 SkBitmap GetBitmapForRenderWidgetHost( 65 SkBitmap GetBitmapForRenderWidgetHost(
66 RenderWidgetHost* render_widget_host, 66 RenderWidgetHost* render_widget_host,
67 int desired_width, 67 int desired_width,
68 int desired_height, 68 int desired_height,
69 int options, 69 int options,
70 ThumbnailGenerator::ClipResult* clip_result) { 70 ThumbnailGenerator::ClipResult* clip_result) {
71 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now(); 71 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now();
72 72
73 SkBitmap result; 73 bool is_accelerated_compositing_active = false;
74 content::RenderWidgetHostView* view = render_widget_host->view();
75 if (view) {
76 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::FromRWHV(view);
77 is_accelerated_compositing_active =
78 rwhi->is_accelerated_compositing_active();
79 }
74 80
75 // Get the bitmap as a Skia object so we can resample it. This is a large 81 // 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 82 // allocation and we can tolerate failure here, so give up if the allocation
77 // fails. 83 // fails.
78 skia::PlatformCanvas temp_canvas; 84 skia::PlatformCanvas temp_canvas;
79 if (!render_widget_host->CopyFromBackingStore(&temp_canvas)) 85 const bool copy_result = is_accelerated_compositing_active ?
80 return result; 86 render_widget_host->CopyFromCompositingSurface(&temp_canvas) :
87 render_widget_host->CopyFromBackingStore(&temp_canvas);
88 if (!copy_result)
89 return SkBitmap();
90
81 const SkBitmap& bmp_with_scrollbars = 91 const SkBitmap& bmp_with_scrollbars =
82 skia::GetTopDevice(temp_canvas)->accessBitmap(false); 92 skia::GetTopDevice(temp_canvas)->accessBitmap(false);
83 // Clip the edgemost 15 pixels as that will commonly hold a scrollbar, which 93 // Clip the edgemost 15 pixels as that will commonly hold a scrollbar, which
84 // looks bad in thumbnails. 94 // looks bad in thumbnails.
85 SkIRect scrollbarless_rect = 95 SkIRect scrollbarless_rect =
86 { 0, 0, 96 { 0, 0,
87 std::max(1, bmp_with_scrollbars.width() - 15), 97 std::max(1, bmp_with_scrollbars.width() - 15),
88 std::max(1, bmp_with_scrollbars.height() - 15) }; 98 std::max(1, bmp_with_scrollbars.height() - 15) };
89 SkBitmap bmp; 99 SkBitmap bmp;
90 bmp_with_scrollbars.extractSubset(&bmp, scrollbarless_rect); 100 bmp_with_scrollbars.extractSubset(&bmp, scrollbarless_rect);
91 101
102 SkBitmap result;
92 // Check if a clipped thumbnail is requested. 103 // Check if a clipped thumbnail is requested.
93 if (options & ThumbnailGenerator::kClippedThumbnail) { 104 if (options & ThumbnailGenerator::kClippedThumbnail) {
94 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( 105 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap(
95 bmp, desired_width, desired_height, clip_result); 106 bmp, desired_width, desired_height, clip_result);
96 107
97 // Need to resize it to the size we want, so downsample until it's 108 // 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. 109 // close, and let the caller make it the exact size if desired.
99 result = SkBitmapOperations::DownsampleByTwoUntilSize( 110 result = SkBitmapOperations::DownsampleByTwoUntilSize(
100 clipped_bitmap, desired_width, desired_height); 111 clipped_bitmap, desired_width, desired_height);
101 // This is a bit subtle. SkBitmaps are refcounted, but the magic 112 // This is a bit subtle. SkBitmaps are refcounted, but the magic
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 522
512 void ThumbnailGenerator::DidStartLoading() { 523 void ThumbnailGenerator::DidStartLoading() {
513 load_interrupted_ = false; 524 load_interrupted_ = false;
514 } 525 }
515 526
516 void ThumbnailGenerator::StopNavigation() { 527 void ThumbnailGenerator::StopNavigation() {
517 // This function gets called when the page loading is interrupted by the 528 // This function gets called when the page loading is interrupted by the
518 // stop button. 529 // stop button.
519 load_interrupted_ = true; 530 load_interrupted_ = true;
520 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698