| 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/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 delete callback; | 184 delete callback; |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 // Now, if the backing store didn't exist, we will still try and | 187 // Now, if the backing store didn't exist, we will still try and |
| 188 // render asynchronously. | 188 // render asynchronously. |
| 189 } | 189 } |
| 190 | 190 |
| 191 // We are going to render the thumbnail asynchronously now, so keep | 191 // We are going to render the thumbnail asynchronously now, so keep |
| 192 // this callback for later lookup when the rendering is done. | 192 // this callback for later lookup when the rendering is done. |
| 193 static int sequence_num = 0; | 193 static int sequence_num = 0; |
| 194 sequence_num++; |
| 194 TransportDIB* thumbnail_dib = TransportDIB::Create( | 195 TransportDIB* thumbnail_dib = TransportDIB::Create( |
| 195 desired_size.width() * desired_size.height() * 4, sequence_num++); | 196 desired_size.width() * desired_size.height() * 4, sequence_num); |
| 197 |
| 196 linked_ptr<AsyncRequestInfo> request_info(new AsyncRequestInfo); | 198 linked_ptr<AsyncRequestInfo> request_info(new AsyncRequestInfo); |
| 197 request_info->callback.reset(callback); | 199 request_info->callback.reset(callback); |
| 198 request_info->thumbnail_dib.reset(thumbnail_dib); | 200 request_info->thumbnail_dib.reset(thumbnail_dib); |
| 199 request_info->renderer = renderer; | 201 request_info->renderer = renderer; |
| 200 ThumbnailCallbackMap::value_type new_value(thumbnail_dib->handle(), | 202 ThumbnailCallbackMap::value_type new_value(sequence_num, request_info); |
| 201 request_info); | |
| 202 std::pair<ThumbnailCallbackMap::iterator, bool> result = | 203 std::pair<ThumbnailCallbackMap::iterator, bool> result = |
| 203 callback_map_.insert(new_value); | 204 callback_map_.insert(new_value); |
| 204 if (!result.second) { | 205 if (!result.second) { |
| 205 NOTREACHED() << "Callback already registered?"; | 206 NOTREACHED() << "Callback already registered?"; |
| 206 return; | 207 return; |
| 207 } | 208 } |
| 208 | 209 |
| 209 renderer->PaintAtSize(thumbnail_dib->handle(), page_size, desired_size); | 210 renderer->PaintAtSize( |
| 211 thumbnail_dib->handle(), sequence_num, page_size, desired_size); |
| 210 } | 212 } |
| 211 | 213 |
| 212 SkBitmap ThumbnailGenerator::GetThumbnailForRenderer( | 214 SkBitmap ThumbnailGenerator::GetThumbnailForRenderer( |
| 213 RenderWidgetHost* renderer) const { | 215 RenderWidgetHost* renderer) const { |
| 214 WidgetThumbnail* wt = GetDataForHost(renderer); | 216 WidgetThumbnail* wt = GetDataForHost(renderer); |
| 215 | 217 |
| 216 BackingStore* backing_store = renderer->GetBackingStore(false); | 218 BackingStore* backing_store = renderer->GetBackingStore(false); |
| 217 if (!backing_store) { | 219 if (!backing_store) { |
| 218 // When we have no backing store, there's no choice in what to use. We | 220 // When we have no backing store, there's no choice in what to use. We |
| 219 // have to return either the existing thumbnail or the empty one if there | 221 // have to return either the existing thumbnail or the empty one if there |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 return; // TODO(brettw) schedule thumbnail generation for this renderer in | 285 return; // TODO(brettw) schedule thumbnail generation for this renderer in |
| 284 // case we don't get a paint for it after the time slop, but it's | 286 // case we don't get a paint for it after the time slop, but it's |
| 285 // still visible. | 287 // still visible. |
| 286 | 288 |
| 287 // Clear the thumbnail, since it's now out of date. | 289 // Clear the thumbnail, since it's now out of date. |
| 288 wt->thumbnail = SkBitmap(); | 290 wt->thumbnail = SkBitmap(); |
| 289 } | 291 } |
| 290 | 292 |
| 291 void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck( | 293 void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck( |
| 292 RenderWidgetHost* widget, | 294 RenderWidgetHost* widget, |
| 293 const TransportDIB::Handle& dib_handle, | 295 int sequence_num, |
| 294 const gfx::Size& size) { | 296 const gfx::Size& size) { |
| 295 // Lookup the callback, run it, and erase it. | 297 // Lookup the callback, run it, and erase it. |
| 296 ThumbnailCallbackMap::iterator item = callback_map_.find(dib_handle); | 298 ThumbnailCallbackMap::iterator item = callback_map_.find(sequence_num); |
| 297 if (item != callback_map_.end()) { | 299 if (item != callback_map_.end()) { |
| 298 TransportDIB* dib = item->second->thumbnail_dib.get(); | 300 TransportDIB* dib = item->second->thumbnail_dib.get(); |
| 299 DCHECK(dib); | 301 DCHECK(dib); |
| 300 if (!dib) { | 302 if (!dib) { |
| 301 return; | 303 return; |
| 302 } | 304 } |
| 303 | 305 |
| 304 // Create an SkBitmap from the DIB. | 306 // Create an SkBitmap from the DIB. |
| 305 SkBitmap non_owned_bitmap; | 307 SkBitmap non_owned_bitmap; |
| 306 SkBitmap result; | 308 SkBitmap result; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 &ThumbnailGenerator::ShownDelayHandler); | 445 &ThumbnailGenerator::ShownDelayHandler); |
| 444 } | 446 } |
| 445 } | 447 } |
| 446 | 448 |
| 447 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { | 449 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { |
| 448 std::vector<RenderWidgetHost*>::iterator found = | 450 std::vector<RenderWidgetHost*>::iterator found = |
| 449 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); | 451 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); |
| 450 if (found != shown_hosts_.end()) | 452 if (found != shown_hosts_.end()) |
| 451 shown_hosts_.erase(found); | 453 shown_hosts_.erase(found); |
| 452 } | 454 } |
| OLD | NEW |