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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
28 #include "skia/ext/image_operations.h" | 28 #include "skia/ext/image_operations.h" |
29 #include "skia/ext/platform_canvas.h" | 29 #include "skia/ext/platform_canvas.h" |
30 #include "third_party/skia/include/core/SkBitmap.h" | 30 #include "third_party/skia/include/core/SkBitmap.h" |
31 #include "ui/base/layout.h" | 31 #include "ui/base/layout.h" |
32 #include "ui/gfx/color_utils.h" | 32 #include "ui/gfx/color_utils.h" |
33 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
| 34 #include "ui/gfx/size_conversions.h" |
34 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
35 #include "ui/gfx/scrollbar_size.h" | 36 #include "ui/gfx/scrollbar_size.h" |
36 #include "ui/gfx/skbitmap_operations.h" | 37 #include "ui/gfx/skbitmap_operations.h" |
37 | 38 |
38 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
39 #include "base/win/windows_version.h" | 40 #include "base/win/windows_version.h" |
40 #endif | 41 #endif |
41 | 42 |
42 // Overview | 43 // Overview |
43 // -------- | 44 // -------- |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // ui::SCALE_FACTOR_200P because the high resolution thumbnail on high density | 101 // ui::SCALE_FACTOR_200P because the high resolution thumbnail on high density |
101 // display alleviates the aliasing. | 102 // display alleviates the aliasing. |
102 // TODO(mazda): Copy the pixels with the smaller size in the case of | 103 // TODO(mazda): Copy the pixels with the smaller size in the case of |
103 // ui::SCALE_FACTOR_100P once the resampling method has been improved. | 104 // ui::SCALE_FACTOR_100P once the resampling method has been improved. |
104 gfx::Size GetCopySizeForThumbnail(content::RenderWidgetHostView* view) { | 105 gfx::Size GetCopySizeForThumbnail(content::RenderWidgetHostView* view) { |
105 gfx::Size copy_size(kThumbnailWidth, kThumbnailHeight); | 106 gfx::Size copy_size(kThumbnailWidth, kThumbnailHeight); |
106 ui::ScaleFactor scale_factor = | 107 ui::ScaleFactor scale_factor = |
107 ui::GetScaleFactorForNativeView(view->GetNativeView()); | 108 ui::GetScaleFactorForNativeView(view->GetNativeView()); |
108 switch (scale_factor) { | 109 switch (scale_factor) { |
109 case ui::SCALE_FACTOR_100P: | 110 case ui::SCALE_FACTOR_100P: |
110 copy_size = | 111 copy_size = gfx::ToFlooredSize( |
111 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)); | 112 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P))); |
112 break; | 113 break; |
113 case ui::SCALE_FACTOR_200P: | 114 case ui::SCALE_FACTOR_200P: |
114 // Use the size as-is. | 115 // Use the size as-is. |
115 break; | 116 break; |
116 default: | 117 default: |
117 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as " | 118 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as " |
118 << "ui::SCALE_FACTOR_100P"; | 119 << "ui::SCALE_FACTOR_100P"; |
119 copy_size = | 120 copy_size = gfx::ToFlooredSize( |
120 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)); | 121 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P))); |
121 break; | 122 break; |
122 } | 123 } |
123 return copy_size; | 124 return copy_size; |
124 } | 125 } |
125 | 126 |
126 // Returns the size of the thumbnail stored in the database in pixel. | 127 // Returns the size of the thumbnail stored in the database in pixel. |
127 gfx::Size GetThumbnailSizeInPixel() { | 128 gfx::Size GetThumbnailSizeInPixel() { |
128 gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); | 129 gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); |
129 // Determine the resolution of the thumbnail based on the primary monitor. | 130 // Determine the resolution of the thumbnail based on the primary monitor. |
130 // TODO(oshima): Use device's default scale factor. | 131 // TODO(oshima): Use device's default scale factor. |
131 gfx::Display primary_display = gfx::Screen::GetPrimaryDisplay(); | 132 gfx::Display primary_display = gfx::Screen::GetPrimaryDisplay(); |
132 return thumbnail_size.Scale(primary_display.device_scale_factor()); | 133 return gfx::ToFlooredSize( |
| 134 thumbnail_size.Scale(primary_display.device_scale_factor())); |
133 } | 135 } |
134 | 136 |
135 // Returns the clipping rectangle that is used for creating a thumbnail with | 137 // Returns the clipping rectangle that is used for creating a thumbnail with |
136 // the size of |desired_size| from the bitmap with the size of |source_size|. | 138 // the size of |desired_size| from the bitmap with the size of |source_size|. |
137 // The type of clipping that needs to be done is assigned to |clip_result|. | 139 // The type of clipping that needs to be done is assigned to |clip_result|. |
138 gfx::Rect GetClippingRect(const gfx::Size& source_size, | 140 gfx::Rect GetClippingRect(const gfx::Size& source_size, |
139 const gfx::Size& desired_size, | 141 const gfx::Size& desired_size, |
140 ThumbnailGenerator::ClipResult* clip_result) { | 142 ThumbnailGenerator::ClipResult* clip_result) { |
141 DCHECK(clip_result); | 143 DCHECK(clip_result); |
142 | 144 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, | 306 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, |
305 const ThumbnailReadyCallback& callback, | 307 const ThumbnailReadyCallback& callback, |
306 gfx::Size page_size, | 308 gfx::Size page_size, |
307 gfx::Size desired_size) { | 309 gfx::Size desired_size) { |
308 // We are going to render the thumbnail asynchronously now, so keep | 310 // We are going to render the thumbnail asynchronously now, so keep |
309 // this callback for later lookup when the rendering is done. | 311 // this callback for later lookup when the rendering is done. |
310 static int sequence_num = 0; | 312 static int sequence_num = 0; |
311 sequence_num++; | 313 sequence_num++; |
312 float scale_factor = ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView( | 314 float scale_factor = ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView( |
313 renderer->GetView()->GetNativeView())); | 315 renderer->GetView()->GetNativeView())); |
314 gfx::Size desired_size_in_pixel = desired_size.Scale(scale_factor); | 316 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize( |
| 317 desired_size.Scale(scale_factor)); |
315 scoped_ptr<TransportDIB> thumbnail_dib(TransportDIB::Create( | 318 scoped_ptr<TransportDIB> thumbnail_dib(TransportDIB::Create( |
316 desired_size_in_pixel.GetArea() * 4, sequence_num)); | 319 desired_size_in_pixel.GetArea() * 4, sequence_num)); |
317 | 320 |
318 #if defined(USE_X11) | 321 #if defined(USE_X11) |
319 // TODO: IPC a handle to the renderer like Windows. | 322 // TODO: IPC a handle to the renderer like Windows. |
320 // http://code.google.com/p/chromium/issues/detail?id=89777 | 323 // http://code.google.com/p/chromium/issues/detail?id=89777 |
321 NOTIMPLEMENTED(); | 324 NOTIMPLEMENTED(); |
322 return; | 325 return; |
323 #else | 326 #else |
324 | 327 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 void ThumbnailGenerator::DidStartLoading( | 640 void ThumbnailGenerator::DidStartLoading( |
638 content::RenderViewHost* render_view_host) { | 641 content::RenderViewHost* render_view_host) { |
639 load_interrupted_ = false; | 642 load_interrupted_ = false; |
640 } | 643 } |
641 | 644 |
642 void ThumbnailGenerator::StopNavigation() { | 645 void ThumbnailGenerator::StopNavigation() { |
643 // This function gets called when the page loading is interrupted by the | 646 // This function gets called when the page loading is interrupted by the |
644 // stop button. | 647 // stop button. |
645 load_interrupted_ = true; | 648 load_interrupted_ = true; |
646 } | 649 } |
OLD | NEW |