OLD | NEW |
---|---|
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 // Creates a downsampled thumbnail for the given RenderWidgetHost's backing | 66 // Creates a downsampled thumbnail for the given RenderWidgetHost's backing |
66 // store. The returned bitmap will be isNull if there was an error creating it. | 67 // store. The returned bitmap will be isNull if there was an error creating it. |
67 SkBitmap GetBitmapForRenderWidgetHost( | 68 SkBitmap GetBitmapForRenderWidgetHost( |
68 RenderWidgetHost* render_widget_host, | 69 RenderWidgetHost* render_widget_host, |
69 int desired_width, | 70 int desired_width, |
70 int desired_height, | 71 int desired_height, |
71 int options, | 72 int options, |
72 ThumbnailGenerator::ClipResult* clip_result) { | 73 ThumbnailGenerator::ClipResult* clip_result) { |
73 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now(); | 74 base::TimeTicks begin_compute_thumbnail = base::TimeTicks::Now(); |
74 | 75 |
75 SkBitmap result; | |
76 | |
77 // Get the bitmap as a Skia object so we can resample it. This is a large | 76 // Get the bitmap as a Skia object so we can resample it. This is a large |
78 // allocation and we can tolerate failure here, so give up if the allocation | 77 // allocation and we can tolerate failure here, so give up if the allocation |
79 // fails. | 78 // fails. First try to read from the compositing surface, then to read from |
79 // the backing store. | |
80 content::RenderWidgetHostView* view = render_widget_host->GetView(); | |
80 skia::PlatformCanvas temp_canvas; | 81 skia::PlatformCanvas temp_canvas; |
81 if (!render_widget_host->CopyFromBackingStore(&temp_canvas)) | 82 bool copy_result = false; |
82 return result; | 83 // TODO(mazda): Copy the shrinked size of compositing surface instead of the |
84 // whole view size. | |
vangelis
2012/03/13 19:40:49
Don't we want to use the desired_width/height here
mazda
2012/03/14 12:07:46
Can I resolve the TODO in another CL? Since this s
| |
85 if (view) { | |
86 copy_result = render_widget_host->CopyFromCompositingSurface( | |
87 view->GetViewBounds().size(), | |
88 &temp_canvas); | |
89 } | |
90 if (!copy_result) | |
91 copy_result = render_widget_host->CopyFromBackingStore(&temp_canvas); | |
92 if (!copy_result) | |
93 return SkBitmap(); | |
94 | |
83 const SkBitmap& bmp_with_scrollbars = | 95 const SkBitmap& bmp_with_scrollbars = |
84 skia::GetTopDevice(temp_canvas)->accessBitmap(false); | 96 skia::GetTopDevice(temp_canvas)->accessBitmap(false); |
85 // Clip the edgemost 15 pixels as that will commonly hold a scrollbar, which | 97 // Clip the edgemost 15 pixels as that will commonly hold a scrollbar, which |
86 // looks bad in thumbnails. | 98 // looks bad in thumbnails. |
87 SkIRect scrollbarless_rect = | 99 SkIRect scrollbarless_rect = |
88 { 0, 0, | 100 { 0, 0, |
89 std::max(1, bmp_with_scrollbars.width() - 15), | 101 std::max(1, bmp_with_scrollbars.width() - 15), |
90 std::max(1, bmp_with_scrollbars.height() - 15) }; | 102 std::max(1, bmp_with_scrollbars.height() - 15) }; |
91 SkBitmap bmp; | 103 SkBitmap bmp; |
92 bmp_with_scrollbars.extractSubset(&bmp, scrollbarless_rect); | 104 bmp_with_scrollbars.extractSubset(&bmp, scrollbarless_rect); |
93 | 105 |
106 SkBitmap result; | |
94 // Check if a clipped thumbnail is requested. | 107 // Check if a clipped thumbnail is requested. |
95 if (options & ThumbnailGenerator::kClippedThumbnail) { | 108 if (options & ThumbnailGenerator::kClippedThumbnail) { |
96 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( | 109 SkBitmap clipped_bitmap = ThumbnailGenerator::GetClippedBitmap( |
97 bmp, desired_width, desired_height, clip_result); | 110 bmp, desired_width, desired_height, clip_result); |
98 | 111 |
99 // Need to resize it to the size we want, so downsample until it's | 112 // Need to resize it to the size we want, so downsample until it's |
100 // close, and let the caller make it the exact size if desired. | 113 // close, and let the caller make it the exact size if desired. |
101 result = SkBitmapOperations::DownsampleByTwoUntilSize( | 114 result = SkBitmapOperations::DownsampleByTwoUntilSize( |
102 clipped_bitmap, desired_width, desired_height); | 115 clipped_bitmap, desired_width, desired_height); |
103 // This is a bit subtle. SkBitmaps are refcounted, but the magic | 116 // This is a bit subtle. SkBitmaps are refcounted, but the magic |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 | 526 |
514 void ThumbnailGenerator::DidStartLoading() { | 527 void ThumbnailGenerator::DidStartLoading() { |
515 load_interrupted_ = false; | 528 load_interrupted_ = false; |
516 } | 529 } |
517 | 530 |
518 void ThumbnailGenerator::StopNavigation() { | 531 void ThumbnailGenerator::StopNavigation() { |
519 // This function gets called when the page loading is interrupted by the | 532 // This function gets called when the page loading is interrupted by the |
520 // stop button. | 533 // stop button. |
521 load_interrupted_ = true; | 534 load_interrupted_ = true; |
522 } | 535 } |
OLD | NEW |