summaryrefslogtreecommitdiffstats
path: root/ash/desktop_background/desktop_background_controller.cc
diff options
context:
space:
mode:
authorbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-04 03:46:24 +0000
committerbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-04 03:46:24 +0000
commite430a7ceeb0d3b368ab3ec2b2b90b4750ec18f46 (patch)
tree9a377380681d88cf717bc90d8ac42a698377634b /ash/desktop_background/desktop_background_controller.cc
parenteb5c96871668a7952c24c1266005c4d3cbdcb005 (diff)
downloadchromium_src-e430a7ceeb0d3b368ab3ec2b2b90b4750ec18f46.zip
chromium_src-e430a7ceeb0d3b368ab3ec2b2b90b4750ec18f46.tar.gz
chromium_src-e430a7ceeb0d3b368ab3ec2b2b90b4750ec18f46.tar.bz2
Resize Wallpaper to reduce memory usage
This CL resizes the decoded wallpaper to a size that perfectly fit into all connected screens. By doing this, we could reduce the memory usage of wallpaper and sometimes speedup the wallpaper OnPaint function (if resize operation finishes before OnPaint get called). BUG=174156 Review URL: https://chromiumcodereview.appspot.com/12258011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/desktop_background/desktop_background_controller.cc')
-rw-r--r--ash/desktop_background/desktop_background_controller.cc48
1 files changed, 18 insertions, 30 deletions
diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc
index 4e64345..9c89b71 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -8,6 +8,7 @@
#include "ash/desktop_background/desktop_background_view.h"
#include "ash/desktop_background/desktop_background_widget_controller.h"
#include "ash/desktop_background/user_wallpaper_delegate.h"
+#include "ash/desktop_background/wallpaper_resizer.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_factory.h"
@@ -21,7 +22,6 @@
#include "grit/ash_wallpaper_resources.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
-#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/image/image.h"
@@ -69,21 +69,6 @@ const int kLargeWallpaperMaxHeight = 1700;
const int kWallpaperThumbnailWidth = 108;
const int kWallpaperThumbnailHeight = 68;
-// Stores the current wallpaper data.
-struct DesktopBackgroundController::WallpaperData {
- explicit WallpaperData(const WallpaperInfo& info)
- : wallpaper_info(info),
- wallpaper_image(*(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
- info.idr).ToImageSkia())) {
- }
- WallpaperData(const WallpaperInfo& info, const gfx::ImageSkia& image)
- : wallpaper_info(info),
- wallpaper_image(image) {
- }
- const WallpaperInfo wallpaper_info;
- const gfx::ImageSkia wallpaper_image;
-};
-
// DesktopBackgroundController::WallpaperLoader wraps background wallpaper
// loading.
class DesktopBackgroundController::WallpaperLoader
@@ -107,8 +92,8 @@ class DesktopBackgroundController::WallpaperLoader
return info_.idr;
}
- WallpaperData* ReleaseWallpaperData() {
- return wallpaper_data_.release();
+ WallpaperResizer* ReleaseWallpaperResizer() {
+ return wallpaper_resizer_.release();
}
private:
@@ -118,14 +103,14 @@ class DesktopBackgroundController::WallpaperLoader
void LoadingWallpaper() {
if (cancel_flag_.IsSet())
return;
- wallpaper_data_.reset(new WallpaperData(info_));
+ wallpaper_resizer_.reset(new WallpaperResizer(info_));
}
~WallpaperLoader() {}
base::CancellationFlag cancel_flag_;
- scoped_ptr<WallpaperData> wallpaper_data_;
+ scoped_ptr<WallpaperResizer> wallpaper_resizer_;
const WallpaperInfo info_;
@@ -145,7 +130,7 @@ DesktopBackgroundController::~DesktopBackgroundController() {
gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const {
if (current_wallpaper_.get())
- return current_wallpaper_->wallpaper_image;
+ return current_wallpaper_->wallpaper_image();
return gfx::ImageSkia();
}
@@ -161,7 +146,7 @@ void DesktopBackgroundController::RemoveObserver(
WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const {
if (current_wallpaper_.get())
- return current_wallpaper_->wallpaper_info.layout;
+ return current_wallpaper_->wallpaper_info().layout;
return WALLPAPER_LAYOUT_CENTER_CROPPED;
}
@@ -175,7 +160,7 @@ int DesktopBackgroundController::GetWallpaperIDR() const {
if (wallpaper_loader_.get())
return wallpaper_loader_->idr();
else if (current_wallpaper_.get())
- return current_wallpaper_->wallpaper_info.idr;
+ return current_wallpaper_->wallpaper_info().idr;
else
return -1;
}
@@ -190,10 +175,12 @@ void DesktopBackgroundController::OnRootWindowAdded(
if (BACKGROUND_IMAGE == desktop_background_mode_ &&
current_wallpaper_.get()) {
gfx::Size root_window_size = root_window->GetHostSize();
- // Loads a higher resolution wallpaper if new root window is larger than
- // small screen.
- if (kSmallWallpaperMaxWidth < root_window_size.width() ||
- kSmallWallpaperMaxHeight < root_window_size.height()) {
+ int width = current_wallpaper_->wallpaper_image().width();
+ int height = current_wallpaper_->wallpaper_image().height();
+ // Reloads wallpaper if current wallpaper is smaller than the new added root
+ // window.
+ if (width < root_window_size.width() ||
+ height < root_window_size.height()) {
current_wallpaper_.reset(NULL);
ash::Shell::GetInstance()->user_wallpaper_delegate()->
UpdateWallpaper();
@@ -223,12 +210,13 @@ void DesktopBackgroundController::SetCustomWallpaper(
WallpaperLayout layout) {
CancelPendingWallpaperOperation();
if (current_wallpaper_.get() &&
- current_wallpaper_->wallpaper_image.BackedBySameObjectAs(wallpaper)) {
+ current_wallpaper_->wallpaper_image().BackedBySameObjectAs(wallpaper)) {
return;
}
WallpaperInfo info = { -1, layout };
- current_wallpaper_.reset(new WallpaperData(info, wallpaper));
+ current_wallpaper_.reset(new WallpaperResizer(info, wallpaper));
+ current_wallpaper_->StartResize();
FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
OnWallpaperDataChanged());
SetDesktopBackgroundImageMode();
@@ -301,7 +289,7 @@ void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
void DesktopBackgroundController::OnWallpaperLoadCompleted(
scoped_refptr<WallpaperLoader> wl) {
- current_wallpaper_.reset(wl->ReleaseWallpaperData());
+ current_wallpaper_.reset(wl->ReleaseWallpaperResizer());
FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
OnWallpaperDataChanged());