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

Side by Side Diff: chrome/browser/thumbnails/thumbnail_tab_helper.cc

Issue 11031055: Introduce PlatformBitmap, which is a minimal helper class that wraps an SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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/thumbnails/thumbnail_tab_helper.h" 5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/history/top_sites.h" 9 #include "chrome/browser/history/top_sites.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); 397 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size());
398 // Clip the pixels that will commonly hold a scrollbar, which looks bad in 398 // Clip the pixels that will commonly hold a scrollbar, which looks bad in
399 // thumbnails. 399 // thumbnails.
400 int scrollbar_size = gfx::scrollbar_size(); 400 int scrollbar_size = gfx::scrollbar_size();
401 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); 401 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size);
402 ClipResult clip_result = ThumbnailTabHelper::kUnprocessed; 402 ClipResult clip_result = ThumbnailTabHelper::kUnprocessed;
403 copy_rect = GetClippingRect(copy_rect.size(), 403 copy_rect = GetClippingRect(copy_rect.size(),
404 gfx::Size(kThumbnailWidth, kThumbnailHeight), 404 gfx::Size(kThumbnailWidth, kThumbnailHeight),
405 &clip_result); 405 &clip_result);
406 gfx::Size copy_size = GetCopySizeForThumbnail(view); 406 gfx::Size copy_size = GetCopySizeForThumbnail(view);
407 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; 407 skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap;
408 render_widget_host->CopyFromBackingStore( 408 render_widget_host->CopyFromBackingStore(
409 copy_rect, 409 copy_rect,
410 copy_size, 410 copy_size,
411 base::Bind(&ThumbnailTabHelper::UpdateThumbnailWithCanvas, 411 base::Bind(&ThumbnailTabHelper::UpdateThumbnailWithCanvas,
412 weak_factory_.GetWeakPtr(), 412 weak_factory_.GetWeakPtr(),
413 web_contents, 413 web_contents,
414 clip_result, 414 clip_result,
415 base::Owned(temp_canvas)), 415 base::Owned(temp_bitmap)),
416 temp_canvas); 416 temp_bitmap);
417 } 417 }
418 418
419 void ThumbnailTabHelper::UpdateThumbnailWithBitmap( 419 void ThumbnailTabHelper::UpdateThumbnailWithBitmap(
420 WebContents* web_contents, 420 WebContents* web_contents,
421 ClipResult clip_result, 421 ClipResult clip_result,
422 const SkBitmap& bitmap) { 422 const SkBitmap& bitmap) {
423 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 423 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
424 if (bitmap.isNull() || bitmap.empty()) 424 if (bitmap.isNull() || bitmap.empty())
425 return; 425 return;
426 426
427 SkBitmap thumbnail = CreateThumbnail(bitmap, 427 SkBitmap thumbnail = CreateThumbnail(bitmap,
428 GetThumbnailSizeInPixel(), 428 GetThumbnailSizeInPixel(),
429 &clip_result); 429 &clip_result);
430 UpdateThumbnail(web_contents, thumbnail, clip_result); 430 UpdateThumbnail(web_contents, thumbnail, clip_result);
431 } 431 }
432 432
433 void ThumbnailTabHelper::UpdateThumbnailWithCanvas( 433 void ThumbnailTabHelper::UpdateThumbnailWithCanvas(
434 WebContents* web_contents, 434 WebContents* web_contents,
435 ClipResult clip_result, 435 ClipResult clip_result,
436 skia::PlatformCanvas* temp_canvas, 436 skia::PlatformBitmap* temp_bitmap,
437 bool succeeded) { 437 bool succeeded) {
438 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 438 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
439 if (!succeeded) 439 if (!succeeded)
440 return; 440 return;
441 441
442 SkBitmap bitmap = skia::GetTopDevice(*temp_canvas)->accessBitmap(false); 442 SkBitmap bitmap = temp_bitmap->GetBitmap();
443 UpdateThumbnailWithBitmap(web_contents, clip_result, bitmap); 443 UpdateThumbnailWithBitmap(web_contents, clip_result, bitmap);
444 } 444 }
445 445
446 bool ThumbnailTabHelper::ShouldUpdateThumbnail(Profile* profile, 446 bool ThumbnailTabHelper::ShouldUpdateThumbnail(Profile* profile,
447 history::TopSites* top_sites, 447 history::TopSites* top_sites,
448 const GURL& url) { 448 const GURL& url) {
449 if (!profile || !top_sites) 449 if (!profile || !top_sites)
450 return false; 450 return false;
451 // Skip if it's in the incognito mode. 451 // Skip if it's in the incognito mode.
452 if (profile->IsOffTheRecord()) 452 if (profile->IsOffTheRecord())
(...skipping 22 matching lines...) Expand all
475 void ThumbnailTabHelper::DidStartLoading( 475 void ThumbnailTabHelper::DidStartLoading(
476 content::RenderViewHost* render_view_host) { 476 content::RenderViewHost* render_view_host) {
477 load_interrupted_ = false; 477 load_interrupted_ = false;
478 } 478 }
479 479
480 void ThumbnailTabHelper::StopNavigation() { 480 void ThumbnailTabHelper::StopNavigation() {
481 // This function gets called when the page loading is interrupted by the 481 // This function gets called when the page loading is interrupted by the
482 // stop button. 482 // stop button.
483 load_interrupted_ = true; 483 load_interrupted_ = true;
484 } 484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698