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

Side by Side Diff: chrome/browser/chromeos/login/wallpaper_manager.cc

Issue 10823358: image: Specify the resize-method when resizing ImageSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: deep-copy Created 8 years, 4 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
« no previous file with comments | « ash/system/user/tray_user.cc ('k') | chrome/browser/icon_loader_chromeos.cc » ('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) 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/chromeos/login/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
6 6
7 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/prefs/scoped_user_pref_update.h" 25 #include "chrome/browser/prefs/scoped_user_pref_update.h"
26 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 30 #include "chromeos/dbus/dbus_thread_manager.h"
31 #include "chromeos/dbus/power_manager_client.h" 31 #include "chromeos/dbus/power_manager_client.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
34 #include "skia/ext/image_operations.h"
35 #include "ui/gfx/codec/png_codec.h" 34 #include "ui/gfx/codec/png_codec.h"
35 #include "ui/gfx/image/image_skia_operations.h"
36 #include "ui/gfx/skia_util.h" 36 #include "ui/gfx/skia_util.h"
37 37
38 using content::BrowserThread; 38 using content::BrowserThread;
39 39
40 namespace { 40 namespace {
41 41
42 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; 42 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60;
43 43
44 const char kWallpaperTypeNodeName[] = "type"; 44 const char kWallpaperTypeNodeName[] = "type";
45 const char kWallpaperIndexNodeName[] = "index"; 45 const char kWallpaperIndexNodeName[] = "index";
(...skipping 13 matching lines...) Expand all
59 #else 59 #else
60 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0 60 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_ROMAINGUY_0
61 #endif 61 #endif
62 62
63 // Names of nodes with info about wallpaper. 63 // Names of nodes with info about wallpaper.
64 const char kNewWallpaperDateNodeName[] = "date"; 64 const char kNewWallpaperDateNodeName[] = "date";
65 const char kNewWallpaperLayoutNodeName[] = "layout"; 65 const char kNewWallpaperLayoutNodeName[] = "layout";
66 const char kNewWallpaperFileNodeName[] = "file"; 66 const char kNewWallpaperFileNodeName[] = "file";
67 const char kNewWallpaperTypeNodeName[] = "type"; 67 const char kNewWallpaperTypeNodeName[] = "type";
68 68
69 gfx::ImageSkia GetWallpaperThumbnail(const gfx::ImageSkia& wallpaper) {
70 gfx::ImageSkia thumbnail = gfx::ImageSkiaOperations::CreateResizedImage(
71 wallpaper,
72 skia::ImageOperations::RESIZE_LANCZOS3,
73 gfx::Size(kThumbnailWidth, kThumbnailHeight));
74
75 // Ideally, this would call thumbnail.GetRepresentations(). But since that
76 // isn't exposed on non-mac yet, we have to do this here.
77 std::vector<ui::ScaleFactor> scales = ui::GetSupportedScaleFactors();
78 for (size_t i = 0; i < scales.size(); ++i) {
79 if (wallpaper.HasRepresentation(scales[i]))
80 thumbnail.GetRepresentation(scales[i]);
81 }
82
83 return thumbnail;
84 }
85
86 gfx::ImageSkia ImageSkiaDeepCopy(const gfx::ImageSkia& image) {
sadrul 2012/08/16 20:32:56 Perhaps this should be ImageSkia::DeepCopy instead
87 gfx::ImageSkia copy;
88 std::vector<gfx::ImageSkiaRep> reps = image.image_reps();
89 for (std::vector<gfx::ImageSkiaRep>::iterator iter = reps.begin();
90 iter != reps.end(); ++iter) {
91 copy.AddRepresentation(*iter);
92 }
93 return copy;
94 }
95
69 } // namespace 96 } // namespace
70 97
71 namespace chromeos { 98 namespace chromeos {
72 99
73 static WallpaperManager* g_wallpaper_manager = NULL; 100 static WallpaperManager* g_wallpaper_manager = NULL;
74 101
75 // WallpaperManager, public: --------------------------------------------------- 102 // WallpaperManager, public: ---------------------------------------------------
76 103
77 // static 104 // static
78 WallpaperManager* WallpaperManager::Get() { 105 WallpaperManager* WallpaperManager::Get() {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 531
505 void WallpaperManager::CacheWallpaper(const std::string& email, 532 void WallpaperManager::CacheWallpaper(const std::string& email,
506 const UserImage& wallpaper) { 533 const UserImage& wallpaper) {
507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
508 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end()); 535 DCHECK(custom_wallpaper_cache_.find(email) == custom_wallpaper_cache_.end());
509 536
510 BrowserThread::PostTask( 537 BrowserThread::PostTask(
511 BrowserThread::FILE, 538 BrowserThread::FILE,
512 FROM_HERE, 539 FROM_HERE,
513 base::Bind(&WallpaperManager::CacheThumbnail, 540 base::Bind(&WallpaperManager::CacheThumbnail,
514 base::Unretained(this), email, wallpaper.image())); 541 base::Unretained(this), email,
542 ImageSkiaDeepCopy(wallpaper.image())));
515 543
516 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); 544 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image()));
517 } 545 }
518 546
519 void WallpaperManager::CacheThumbnail(const std::string& email, 547 void WallpaperManager::CacheThumbnail(const std::string& email,
520 const gfx::ImageSkia& wallpaper) { 548 const gfx::ImageSkia& wallpaper) {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
522 gfx::ImageSkia thumbnail = 550 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper);
523 skia::ImageOperations::Resize(wallpaper,
524 skia::ImageOperations::RESIZE_LANCZOS3,
525 kThumbnailWidth, kThumbnailHeight);
526 custom_wallpaper_thumbnail_cache_[email] = thumbnail;
527 } 551 }
528 552
529 void WallpaperManager::FetchWallpaper(const std::string& email, 553 void WallpaperManager::FetchWallpaper(const std::string& email,
530 ash::WallpaperLayout layout, 554 ash::WallpaperLayout layout,
531 const UserImage& wallpaper) { 555 const UserImage& wallpaper) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
533 557
534 BrowserThread::PostTask( 558 BrowserThread::PostTask(
535 BrowserThread::FILE, 559 BrowserThread::FILE,
536 FROM_HERE, 560 FROM_HERE,
537 base::Bind(&WallpaperManager::CacheThumbnail, 561 base::Bind(&WallpaperManager::CacheThumbnail,
538 base::Unretained(this), email, wallpaper.image())); 562 base::Unretained(this), email,
563 ImageSkiaDeepCopy(wallpaper.image())));
539 564
540 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image())); 565 custom_wallpaper_cache_.insert(std::make_pair(email, wallpaper.image()));
541 ash::Shell::GetInstance()->desktop_background_controller()-> 566 ash::Shell::GetInstance()->desktop_background_controller()->
542 SetCustomWallpaper(wallpaper.image(), layout); 567 SetCustomWallpaper(wallpaper.image(), layout);
543 } 568 }
544 569
545 void WallpaperManager::GetUserWallpaperProperties(const std::string& email, 570 void WallpaperManager::GetUserWallpaperProperties(const std::string& email,
546 User::WallpaperType* type, 571 User::WallpaperType* type,
547 int* index, 572 int* index,
548 base::Time* last_modification_date) { 573 base::Time* last_modification_date) {
(...skipping 26 matching lines...) Expand all
575 } 600 }
576 } 601 }
577 } 602 }
578 603
579 void WallpaperManager::GenerateUserWallpaperThumbnail( 604 void WallpaperManager::GenerateUserWallpaperThumbnail(
580 const std::string& email, 605 const std::string& email,
581 User::WallpaperType type, 606 User::WallpaperType type,
582 base::WeakPtr<WallpaperDelegate> delegate, 607 base::WeakPtr<WallpaperDelegate> delegate,
583 const gfx::ImageSkia& wallpaper) { 608 const gfx::ImageSkia& wallpaper) {
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
585 gfx::ImageSkia thumbnail = 610 custom_wallpaper_thumbnail_cache_[email] = GetWallpaperThumbnail(wallpaper);
586 skia::ImageOperations::Resize(wallpaper,
587 skia::ImageOperations::RESIZE_LANCZOS3,
588 kThumbnailWidth, kThumbnailHeight);
589
590 custom_wallpaper_thumbnail_cache_[email] = thumbnail;
591 611
592 // Notify thumbnail is ready. 612 // Notify thumbnail is ready.
593 BrowserThread::PostTask( 613 BrowserThread::PostTask(
594 BrowserThread::UI, 614 BrowserThread::UI,
595 FROM_HERE, 615 FROM_HERE,
596 base::Bind(&WallpaperManager::OnThumbnailUpdated, 616 base::Bind(&WallpaperManager::OnThumbnailUpdated,
597 base::Unretained(this), delegate)); 617 base::Unretained(this), delegate));
598 } 618 }
599 619
600 void WallpaperManager::OnThumbnailUpdated( 620 void WallpaperManager::OnThumbnailUpdated(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 base::Unretained(this), username, type, delegate, 657 base::Unretained(this), username, type, delegate,
638 wallpaper.image())); 658 wallpaper.image()));
639 659
640 ash::Shell::GetInstance()->desktop_background_controller()-> 660 ash::Shell::GetInstance()->desktop_background_controller()->
641 SetCustomWallpaper(wallpaper.image(), layout); 661 SetCustomWallpaper(wallpaper.image(), layout);
642 SaveUserWallpaperProperties(username, type, layout); 662 SaveUserWallpaperProperties(username, type, layout);
643 } 663 }
644 664
645 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, 665 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout,
646 const UserImage& user_image) { 666 const UserImage& user_image) {
647 const SkBitmap& wallpaper = user_image.image(); 667 SetWallpaperFromImageSkia(user_image.image(), layout);
648 SetWallpaperFromImageSkia(wallpaper, layout);
649 } 668 }
650 669
651 void WallpaperManager::SystemResumed() { 670 void WallpaperManager::SystemResumed() {
652 BatchUpdateWallpaper(); 671 BatchUpdateWallpaper();
653 } 672 }
654 673
655 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { 674 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) {
656 RestartTimer(); 675 RestartTimer();
657 } 676 }
658 677
659 } // chromeos 678 } // chromeos
OLDNEW
« no previous file with comments | « ash/system/user/tray_user.cc ('k') | chrome/browser/icon_loader_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698