OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/renderer_host/backing_store.h" | 13 #include "chrome/browser/renderer_host/backing_store.h" |
| 14 #include "chrome/browser/renderer_host/render_process_host.h" |
14 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/property_bag.h" | 18 #include "chrome/common/property_bag.h" |
18 #include "gfx/rect.h" | 19 #include "gfx/rect.h" |
19 #include "gfx/skbitmap_operations.h" | 20 #include "gfx/skbitmap_operations.h" |
20 #include "skia/ext/platform_canvas.h" | 21 #include "skia/ext/platform_canvas.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
22 | 23 |
23 // Overview | 24 // Overview |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 request_info->renderer = renderer; | 202 request_info->renderer = renderer; |
202 ThumbnailCallbackMap::value_type new_value(sequence_num, request_info); | 203 ThumbnailCallbackMap::value_type new_value(sequence_num, request_info); |
203 std::pair<ThumbnailCallbackMap::iterator, bool> result = | 204 std::pair<ThumbnailCallbackMap::iterator, bool> result = |
204 callback_map_.insert(new_value); | 205 callback_map_.insert(new_value); |
205 if (!result.second) { | 206 if (!result.second) { |
206 NOTREACHED() << "Callback already registered?"; | 207 NOTREACHED() << "Callback already registered?"; |
207 return; | 208 return; |
208 } | 209 } |
209 | 210 |
210 renderer->PaintAtSize( | 211 renderer->PaintAtSize( |
211 thumbnail_dib->handle(), sequence_num, page_size, desired_size); | 212 thumbnail_dib->GetHandleForProcess(renderer->process()->GetHandle()), |
| 213 sequence_num, page_size, desired_size); |
212 } | 214 } |
213 | 215 |
214 SkBitmap ThumbnailGenerator::GetThumbnailForRenderer( | 216 SkBitmap ThumbnailGenerator::GetThumbnailForRenderer( |
215 RenderWidgetHost* renderer) const { | 217 RenderWidgetHost* renderer) const { |
216 WidgetThumbnail* wt = GetDataForHost(renderer); | 218 WidgetThumbnail* wt = GetDataForHost(renderer); |
217 | 219 |
218 BackingStore* backing_store = renderer->GetBackingStore(false); | 220 BackingStore* backing_store = renderer->GetBackingStore(false); |
219 if (!backing_store) { | 221 if (!backing_store) { |
220 // When we have no backing store, there's no choice in what to use. We | 222 // When we have no backing store, there's no choice in what to use. We |
221 // have to return either the existing thumbnail or the empty one if there | 223 // have to return either the existing thumbnail or the empty one if there |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 294 |
293 void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck( | 295 void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck( |
294 RenderWidgetHost* widget, | 296 RenderWidgetHost* widget, |
295 int sequence_num, | 297 int sequence_num, |
296 const gfx::Size& size) { | 298 const gfx::Size& size) { |
297 // Lookup the callback, run it, and erase it. | 299 // Lookup the callback, run it, and erase it. |
298 ThumbnailCallbackMap::iterator item = callback_map_.find(sequence_num); | 300 ThumbnailCallbackMap::iterator item = callback_map_.find(sequence_num); |
299 if (item != callback_map_.end()) { | 301 if (item != callback_map_.end()) { |
300 TransportDIB* dib = item->second->thumbnail_dib.get(); | 302 TransportDIB* dib = item->second->thumbnail_dib.get(); |
301 DCHECK(dib); | 303 DCHECK(dib); |
302 if (!dib) { | 304 if (!dib || !dib->Map()) { |
303 return; | 305 return; |
304 } | 306 } |
305 | 307 |
306 // Create an SkBitmap from the DIB. | 308 // Create an SkBitmap from the DIB. |
307 SkBitmap non_owned_bitmap; | 309 SkBitmap non_owned_bitmap; |
308 SkBitmap result; | 310 SkBitmap result; |
309 | 311 |
310 // Fill out the non_owned_bitmap with the right config. Note that | 312 // Fill out the non_owned_bitmap with the right config. Note that |
311 // this code assumes that the transport dib is a 32-bit ARGB | 313 // this code assumes that the transport dib is a 32-bit ARGB |
312 // image. | 314 // image. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 &ThumbnailGenerator::ShownDelayHandler); | 447 &ThumbnailGenerator::ShownDelayHandler); |
446 } | 448 } |
447 } | 449 } |
448 | 450 |
449 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { | 451 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { |
450 std::vector<RenderWidgetHost*>::iterator found = | 452 std::vector<RenderWidgetHost*>::iterator found = |
451 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); | 453 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); |
452 if (found != shown_hosts_.end()) | 454 if (found != shown_hosts_.end()) |
453 shown_hosts_.erase(found); | 455 shown_hosts_.erase(found); |
454 } | 456 } |
OLD | NEW |