Commit 1c7abf7a authored by bshe@chromium.org's avatar bshe@chromium.org

Use low resolution wallpapers for small screens

BUG=140336
TBR=jhawkins

Review URL: https://chromiumcodereview.appspot.com/10837089

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149915 0039d316-1c4b-4281-b951-d872f2087c98
parent f861b390
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
namespace ash { namespace ash {
namespace { namespace {
const int kSmallWallpaperMaximalWidth = 1366;
const int kSmallWallpaperMaximalHeight = 800;
internal::RootWindowLayoutManager* GetRootWindowLayoutManager( internal::RootWindowLayoutManager* GetRootWindowLayoutManager(
aura::RootWindow* root_window) { aura::RootWindow* root_window) {
return static_cast<internal::RootWindowLayoutManager*>( return static_cast<internal::RootWindowLayoutManager*>(
...@@ -32,11 +36,11 @@ internal::RootWindowLayoutManager* GetRootWindowLayoutManager( ...@@ -32,11 +36,11 @@ internal::RootWindowLayoutManager* GetRootWindowLayoutManager(
// Stores the current wallpaper data. // Stores the current wallpaper data.
struct DesktopBackgroundController::WallpaperData { struct DesktopBackgroundController::WallpaperData {
explicit WallpaperData(int index) WallpaperData(int index, WallpaperResolution resolution)
: wallpaper_index(index), : wallpaper_index(index),
wallpaper_layout(GetWallpaperInfo(index).layout), wallpaper_layout(GetWallpaperViewInfo(index, resolution).layout),
wallpaper_image(*(ui::ResourceBundle::GetSharedInstance().GetImageNamed( wallpaper_image(*(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
GetWallpaperInfo(index).id).ToImageSkia())) { GetWallpaperViewInfo(index, resolution).id).ToImageSkia())) {
} }
WallpaperData(WallpaperLayout layout, const gfx::ImageSkia& image) WallpaperData(WallpaperLayout layout, const gfx::ImageSkia& image)
: wallpaper_index(-1), : wallpaper_index(-1),
...@@ -54,7 +58,9 @@ class DesktopBackgroundController::WallpaperOperation ...@@ -54,7 +58,9 @@ class DesktopBackgroundController::WallpaperOperation
: public base::RefCountedThreadSafe< : public base::RefCountedThreadSafe<
DesktopBackgroundController::WallpaperOperation> { DesktopBackgroundController::WallpaperOperation> {
public: public:
explicit WallpaperOperation(int index) : index_(index) { WallpaperOperation(int index, WallpaperResolution resolution)
: index_(index),
resolution_(resolution) {
} }
static void Run(scoped_refptr<WallpaperOperation> wo) { static void Run(scoped_refptr<WallpaperOperation> wo) {
...@@ -64,7 +70,7 @@ class DesktopBackgroundController::WallpaperOperation ...@@ -64,7 +70,7 @@ class DesktopBackgroundController::WallpaperOperation
void LoadingWallpaper() { void LoadingWallpaper() {
if (cancel_flag_.IsSet()) if (cancel_flag_.IsSet())
return; return;
wallpaper_data_.reset(new WallpaperData(index_)); wallpaper_data_.reset(new WallpaperData(index_, resolution_));
} }
void Cancel() { void Cancel() {
...@@ -85,7 +91,9 @@ class DesktopBackgroundController::WallpaperOperation ...@@ -85,7 +91,9 @@ class DesktopBackgroundController::WallpaperOperation
scoped_ptr<WallpaperData> wallpaper_data_; scoped_ptr<WallpaperData> wallpaper_data_;
int index_; const int index_;
const WallpaperResolution resolution_;
DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); DISALLOW_COPY_AND_ASSIGN(WallpaperOperation);
}; };
...@@ -123,6 +131,16 @@ void DesktopBackgroundController::OnRootWindowAdded( ...@@ -123,6 +131,16 @@ void DesktopBackgroundController::OnRootWindowAdded(
switch (desktop_background_mode_) { switch (desktop_background_mode_) {
case BACKGROUND_IMAGE: case BACKGROUND_IMAGE:
if (current_wallpaper_.get()) { if (current_wallpaper_.get()) {
gfx::Size root_window_size = root_window->GetHostSize();
int wallpaper_width = current_wallpaper_->wallpaper_image.width();
int wallpaper_height = current_wallpaper_->wallpaper_image.height();
// Loads a higher resolution wallpaper if needed.
if ((wallpaper_width < root_window_size.width() ||
wallpaper_height < root_window_size.height()) &&
current_wallpaper_->wallpaper_index != -1 &&
current_wallpaper_->wallpaper_layout != TILE)
SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true);
else
SetDesktopBackgroundImage(root_window); SetDesktopBackgroundImage(root_window);
} else { } else {
internal::CreateDesktopBackground(root_window); internal::CreateDesktopBackground(root_window);
...@@ -134,7 +152,8 @@ void DesktopBackgroundController::OnRootWindowAdded( ...@@ -134,7 +152,8 @@ void DesktopBackgroundController::OnRootWindowAdded(
} }
} }
void DesktopBackgroundController::SetDefaultWallpaper(int index) { void DesktopBackgroundController::SetDefaultWallpaper(int index,
bool force_reload) {
// We should not change background when index is invalid. For instance, at // We should not change background when index is invalid. For instance, at
// login screen or stub_user login. // login screen or stub_user login.
if (index == ash::GetInvalidWallpaperIndex()) { if (index == ash::GetInvalidWallpaperIndex()) {
...@@ -145,12 +164,23 @@ void DesktopBackgroundController::SetDefaultWallpaper(int index) { ...@@ -145,12 +164,23 @@ void DesktopBackgroundController::SetDefaultWallpaper(int index) {
return; return;
} }
if (current_wallpaper_.get() && current_wallpaper_->wallpaper_index == index) if (!force_reload && current_wallpaper_.get() &&
current_wallpaper_->wallpaper_index == index)
return; return;
CancelPendingWallpaperOperation(); CancelPendingWallpaperOperation();
wallpaper_op_ = new WallpaperOperation(index); WallpaperResolution resolution = SMALL;
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
for (Shell::RootWindowList::iterator iter = root_windows.begin();
iter != root_windows.end(); ++iter) {
gfx::Size root_window_size = (*iter)->GetHostSize();
if (root_window_size.width() > kSmallWallpaperMaximalWidth ||
root_window_size.height() > kSmallWallpaperMaximalHeight)
resolution = LARGE;
}
wallpaper_op_ = new WallpaperOperation(index, resolution);
base::WorkerPool::PostTaskAndReply( base::WorkerPool::PostTaskAndReply(
FROM_HERE, FROM_HERE,
base::Bind(&WallpaperOperation::Run, wallpaper_op_), base::Bind(&WallpaperOperation::Run, wallpaper_op_),
......
...@@ -71,8 +71,10 @@ class ASH_EXPORT DesktopBackgroundController { ...@@ -71,8 +71,10 @@ class ASH_EXPORT DesktopBackgroundController {
void OnRootWindowAdded(aura::RootWindow* root_window); void OnRootWindowAdded(aura::RootWindow* root_window);
// Loads default wallpaper at |index| asynchronously and sets to current // Loads default wallpaper at |index| asynchronously and sets to current
// wallpaper after loaded. // wallpaper after loaded. When |force_reload| is true, reload wallpaper
void SetDefaultWallpaper(int index); // for all root windows even if |index| is the same as current wallpaper. It
// must be true when a different resolution of current wallpaper is needed.
void SetDefaultWallpaper(int index, bool force_reload);
// Sets the user selected custom wallpaper. Called when user selected a file // Sets the user selected custom wallpaper. Called when user selected a file
// from file system or changed the layout of wallpaper. // from file system or changed the layout of wallpaper.
......
...@@ -19,10 +19,21 @@ enum WallpaperLayout { ...@@ -19,10 +19,21 @@ enum WallpaperLayout {
TILE, TILE,
}; };
struct ASH_EXPORT WallpaperInfo { enum WallpaperResolution {
LARGE,
SMALL
};
// Encapsulates wallpaper infomation needed by desktop background view.
struct ASH_EXPORT WallpaperViewInfo {
int id; int id;
int thumb_id;
WallpaperLayout layout; WallpaperLayout layout;
};
struct ASH_EXPORT WallpaperInfo {
WallpaperViewInfo large;
WallpaperViewInfo small;
int thumb_id;
// TODO(bshe): author member should be encoded to UTF16. We need to use i18n // TODO(bshe): author member should be encoded to UTF16. We need to use i18n
// string for this member after M19. // string for this member after M19.
const char* author; const char* author;
...@@ -39,6 +50,8 @@ ASH_EXPORT int GetNextWallpaperIndex(int index); ...@@ -39,6 +50,8 @@ ASH_EXPORT int GetNextWallpaperIndex(int index);
ASH_EXPORT int GetSolidColorIndex(); ASH_EXPORT int GetSolidColorIndex();
ASH_EXPORT int GetWallpaperCount(); ASH_EXPORT int GetWallpaperCount();
ASH_EXPORT const WallpaperInfo& GetWallpaperInfo(int index); ASH_EXPORT const WallpaperInfo& GetWallpaperInfo(int index);
ASH_EXPORT const WallpaperViewInfo& GetWallpaperViewInfo(int index,
WallpaperResolution resolution);
} // namespace ash } // namespace ash
......
...@@ -206,7 +206,7 @@ void WallpaperManager::InitializeWallpaper() { ...@@ -206,7 +206,7 @@ void WallpaperManager::InitializeWallpaper() {
// TODO(nkostylev): Add switch to disable wallpaper transition on OOBE. // TODO(nkostylev): Add switch to disable wallpaper transition on OOBE.
// Should be used on test images so that they are not slowed down. // Should be used on test images so that they are not slowed down.
ash::Shell::GetInstance()->desktop_background_controller()-> ash::Shell::GetInstance()->desktop_background_controller()->
SetDefaultWallpaper(kDefaultOOBEWallpaperIndex); SetDefaultWallpaper(kDefaultOOBEWallpaperIndex, false);
} else { } else {
bool show_users = true; bool show_users = true;
bool result = CrosSettings::Get()->GetBoolean( bool result = CrosSettings::Get()->GetBoolean(
...@@ -215,7 +215,7 @@ void WallpaperManager::InitializeWallpaper() { ...@@ -215,7 +215,7 @@ void WallpaperManager::InitializeWallpaper() {
<< kAccountsPrefShowUserNamesOnSignIn; << kAccountsPrefShowUserNamesOnSignIn;
if (!show_users) { if (!show_users) {
ash::Shell::GetInstance()->desktop_background_controller()-> ash::Shell::GetInstance()->desktop_background_controller()->
SetDefaultWallpaper(ash::GetSolidColorIndex()); SetDefaultWallpaper(ash::GetSolidColorIndex(), false);
} }
} }
} }
...@@ -307,7 +307,7 @@ void WallpaperManager::SetInitialUserWallpaper(const std::string& username) { ...@@ -307,7 +307,7 @@ void WallpaperManager::SetInitialUserWallpaper(const std::string& username) {
// crash and speed up the tests by avoid loading wallpaper. // crash and speed up the tests by avoid loading wallpaper.
if (ash::Shell::HasInstance()) { if (ash::Shell::HasInstance()) {
ash::Shell::GetInstance()->desktop_background_controller()-> ash::Shell::GetInstance()->desktop_background_controller()->
SetDefaultWallpaper(current_user_wallpaper_index_); SetDefaultWallpaper(current_user_wallpaper_index_, false);
} }
} }
...@@ -366,7 +366,7 @@ void WallpaperManager::SetUserWallpaper(const std::string& email) { ...@@ -366,7 +366,7 @@ void WallpaperManager::SetUserWallpaper(const std::string& email) {
return; return;
} }
ash::Shell::GetInstance()->desktop_background_controller()-> ash::Shell::GetInstance()->desktop_background_controller()->
SetDefaultWallpaper(index); SetDefaultWallpaper(index, false);
SetLastSelectedUser(email); SetLastSelectedUser(email);
} }
...@@ -381,7 +381,7 @@ void WallpaperManager::OnUserDeselected() { ...@@ -381,7 +381,7 @@ void WallpaperManager::OnUserDeselected() {
if (!UserManager::Get()->IsUserLoggedIn()) { if (!UserManager::Get()->IsUserLoggedIn()) {
// This will set default login wallpaper (#fefefe). // This will set default login wallpaper (#fefefe).
ash::Shell::GetInstance()->desktop_background_controller()-> ash::Shell::GetInstance()->desktop_background_controller()->
SetDefaultWallpaper(ash::GetSolidColorIndex()); SetDefaultWallpaper(ash::GetSolidColorIndex(), false);
} }
} }
......
...@@ -248,7 +248,7 @@ void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) { ...@@ -248,7 +248,7 @@ void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) {
index = ash::GetNextWallpaperIndex(index); index = ash::GetNextWallpaperIndex(index);
UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index); UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index);
ash::Shell::GetInstance()->desktop_background_controller()-> ash::Shell::GetInstance()->desktop_background_controller()->
SetDefaultWallpaper(index); SetDefaultWallpaper(index, false);
base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index));
base::FundamentalValue is_daily(true); base::FundamentalValue is_daily(true);
web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage",
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment