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

Side by Side Diff: chrome/browser/tab_contents/thumbnail_generator.cc

Issue 2976008: Bar (Closed)
Patch Set: rebase Created 10 years, 5 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
« no previous file with comments | « chrome/browser/tab_contents/thumbnail_generator.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
198 fprintf(stderr, "expecting dib data %d %d %d %d %p\n",
199 page_size.width(), page_size.height(), desired_size.width(), desired_size.heigh t(), thumbnail_dib->memory());
196 linked_ptr<AsyncRequestInfo> request_info(new AsyncRequestInfo); 200 linked_ptr<AsyncRequestInfo> request_info(new AsyncRequestInfo);
197 request_info->callback.reset(callback); 201 request_info->callback.reset(callback);
198 request_info->thumbnail_dib.reset(thumbnail_dib); 202 request_info->thumbnail_dib.reset(thumbnail_dib);
199 request_info->renderer = renderer; 203 request_info->renderer = renderer;
200 ThumbnailCallbackMap::value_type new_value(thumbnail_dib->handle(), 204 ThumbnailCallbackMap::value_type new_value(sequence_num, request_info);
201 request_info);
202 std::pair<ThumbnailCallbackMap::iterator, bool> result = 205 std::pair<ThumbnailCallbackMap::iterator, bool> result =
203 callback_map_.insert(new_value); 206 callback_map_.insert(new_value);
204 if (!result.second) { 207 if (!result.second) {
205 NOTREACHED() << "Callback already registered?"; 208 NOTREACHED() << "Callback already registered?";
206 return; 209 return;
207 } 210 }
208 211
209 renderer->PaintAtSize(thumbnail_dib->handle(), page_size, desired_size); 212 renderer->PaintAtSize(
213 thumbnail_dib->handle(), sequence_num, page_size, desired_size);
210 } 214 }
211 215
212 SkBitmap ThumbnailGenerator::GetThumbnailForRenderer( 216 SkBitmap ThumbnailGenerator::GetThumbnailForRenderer(
213 RenderWidgetHost* renderer) const { 217 RenderWidgetHost* renderer) const {
214 WidgetThumbnail* wt = GetDataForHost(renderer); 218 WidgetThumbnail* wt = GetDataForHost(renderer);
215 219
216 BackingStore* backing_store = renderer->GetBackingStore(false); 220 BackingStore* backing_store = renderer->GetBackingStore(false);
217 if (!backing_store) { 221 if (!backing_store) {
218 // 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
219 // 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 return; // TODO(brettw) schedule thumbnail generation for this renderer in 287 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 288 // case we don't get a paint for it after the time slop, but it's
285 // still visible. 289 // still visible.
286 290
287 // Clear the thumbnail, since it's now out of date. 291 // Clear the thumbnail, since it's now out of date.
288 wt->thumbnail = SkBitmap(); 292 wt->thumbnail = SkBitmap();
289 } 293 }
290 294
291 void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck( 295 void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck(
292 RenderWidgetHost* widget, 296 RenderWidgetHost* widget,
293 const TransportDIB::Handle& dib_handle, 297 int sequence_num,
294 const gfx::Size& size) { 298 const gfx::Size& size) {
299 fprintf(stderr, "ThumbnailGenerator got ack %d %d %d\n", size.width(), size.heig ht(), sequence_num);
295 // Lookup the callback, run it, and erase it. 300 // Lookup the callback, run it, and erase it.
296 ThumbnailCallbackMap::iterator item = callback_map_.find(dib_handle); 301 ThumbnailCallbackMap::iterator item = callback_map_.find(sequence_num);
297 if (item != callback_map_.end()) { 302 if (item != callback_map_.end()) {
298 TransportDIB* dib = item->second->thumbnail_dib.get(); 303 TransportDIB* dib = item->second->thumbnail_dib.get();
299 DCHECK(dib); 304 DCHECK(dib);
300 if (!dib) { 305 if (!dib) {
306 fprintf(stderr, "not found in map\n");
301 return; 307 return;
302 } 308 }
303 309
304 // Create an SkBitmap from the DIB. 310 // Create an SkBitmap from the DIB.
305 SkBitmap non_owned_bitmap; 311 SkBitmap non_owned_bitmap;
306 SkBitmap result; 312 SkBitmap result;
307 313
308 // Fill out the non_owned_bitmap with the right config. Note that 314 // Fill out the non_owned_bitmap with the right config. Note that
309 // this code assumes that the transport dib is a 32-bit ARGB 315 // this code assumes that the transport dib is a 32-bit ARGB
310 // image. 316 // image.
311 non_owned_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 317 non_owned_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
312 size.width(), size.height()); 318 size.width(), size.height());
313 non_owned_bitmap.setPixels(dib->memory()); 319 non_owned_bitmap.setPixels(dib->memory());
320 fprintf(stderr, "received dib data %d %d %p\n", size.width(), size.height(), dib ->memory());
314 321
315 // Now alloc/copy the memory so we own it and can pass it around, 322 // Now alloc/copy the memory so we own it and can pass it around,
316 // and the memory won't go away when the DIB goes away. 323 // and the memory won't go away when the DIB goes away.
317 // TODO: Figure out a way to avoid this copy? 324 // TODO: Figure out a way to avoid this copy?
318 non_owned_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); 325 non_owned_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config);
319 326
327 fprintf(stderr, "running callback\n");
320 item->second->callback->Run(result); 328 item->second->callback->Run(result);
321 329
322 // We're done with the callback, and with the DIB, so delete both. 330 // We're done with the callback, and with the DIB, so delete both.
323 callback_map_.erase(item); 331 callback_map_.erase(item);
324 } 332 }
325 } 333 }
326 334
327 void ThumbnailGenerator::Observe(NotificationType type, 335 void ThumbnailGenerator::Observe(NotificationType type,
328 const NotificationSource& source, 336 const NotificationSource& source,
329 const NotificationDetails& details) { 337 const NotificationDetails& details) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 &ThumbnailGenerator::ShownDelayHandler); 451 &ThumbnailGenerator::ShownDelayHandler);
444 } 452 }
445 } 453 }
446 454
447 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { 455 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) {
448 std::vector<RenderWidgetHost*>::iterator found = 456 std::vector<RenderWidgetHost*>::iterator found =
449 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); 457 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget);
450 if (found != shown_hosts_.end()) 458 if (found != shown_hosts_.end())
451 shown_hosts_.erase(found); 459 shown_hosts_.erase(found);
452 } 460 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/thumbnail_generator.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698