| OLD | NEW |
| 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 "ash/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_view.h" | 7 #include "ash/desktop_background/desktop_background_view.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_factory.h" | 9 #include "ash/shell_factory.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/root_window_layout_manager.h" | 11 #include "ash/wm/root_window_layout_manager.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/synchronization/cancellation_flag.h" | 14 #include "base/synchronization/cancellation_flag.h" |
| 15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
| 16 #include "grit/ui_resources.h" | 16 #include "grit/ui_resources.h" |
| 17 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
| 21 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace { | 25 namespace { |
| 26 |
| 27 const int kSmallWallpaperMaximalWidth = 1366; |
| 28 const int kSmallWallpaperMaximalHeight = 800; |
| 29 |
| 26 internal::RootWindowLayoutManager* GetRootWindowLayoutManager( | 30 internal::RootWindowLayoutManager* GetRootWindowLayoutManager( |
| 27 aura::RootWindow* root_window) { | 31 aura::RootWindow* root_window) { |
| 28 return static_cast<internal::RootWindowLayoutManager*>( | 32 return static_cast<internal::RootWindowLayoutManager*>( |
| 29 root_window->layout_manager()); | 33 root_window->layout_manager()); |
| 30 } | 34 } |
| 31 } // namespace | 35 } // namespace |
| 32 | 36 |
| 33 // Stores the current wallpaper data. | 37 // Stores the current wallpaper data. |
| 34 struct DesktopBackgroundController::WallpaperData { | 38 struct DesktopBackgroundController::WallpaperData { |
| 35 explicit WallpaperData(int index) | 39 WallpaperData(int index, WallpaperResolution resolution) |
| 36 : wallpaper_index(index), | 40 : wallpaper_index(index), |
| 37 wallpaper_layout(GetWallpaperInfo(index).layout), | 41 wallpaper_layout(GetWallpaperViewInfo(index, resolution).layout), |
| 38 wallpaper_image(*(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 42 wallpaper_image(*(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 39 GetWallpaperInfo(index).id).ToImageSkia())) { | 43 GetWallpaperViewInfo(index, resolution).id).ToImageSkia())) { |
| 40 } | 44 } |
| 41 WallpaperData(WallpaperLayout layout, const gfx::ImageSkia& image) | 45 WallpaperData(WallpaperLayout layout, const gfx::ImageSkia& image) |
| 42 : wallpaper_index(-1), | 46 : wallpaper_index(-1), |
| 43 wallpaper_layout(layout), | 47 wallpaper_layout(layout), |
| 44 wallpaper_image(image) { | 48 wallpaper_image(image) { |
| 45 } | 49 } |
| 46 const int wallpaper_index; | 50 const int wallpaper_index; |
| 47 const WallpaperLayout wallpaper_layout; | 51 const WallpaperLayout wallpaper_layout; |
| 48 const gfx::ImageSkia wallpaper_image; | 52 const gfx::ImageSkia wallpaper_image; |
| 49 }; | 53 }; |
| 50 | 54 |
| 51 // DesktopBackgroundController::WallpaperOperation wraps background wallpaper | 55 // DesktopBackgroundController::WallpaperOperation wraps background wallpaper |
| 52 // loading. | 56 // loading. |
| 53 class DesktopBackgroundController::WallpaperOperation | 57 class DesktopBackgroundController::WallpaperOperation |
| 54 : public base::RefCountedThreadSafe< | 58 : public base::RefCountedThreadSafe< |
| 55 DesktopBackgroundController::WallpaperOperation> { | 59 DesktopBackgroundController::WallpaperOperation> { |
| 56 public: | 60 public: |
| 57 explicit WallpaperOperation(int index) : index_(index) { | 61 WallpaperOperation(int index, WallpaperResolution resolution) |
| 62 : index_(index), |
| 63 resolution_(resolution) { |
| 58 } | 64 } |
| 59 | 65 |
| 60 static void Run(scoped_refptr<WallpaperOperation> wo) { | 66 static void Run(scoped_refptr<WallpaperOperation> wo) { |
| 61 wo->LoadingWallpaper(); | 67 wo->LoadingWallpaper(); |
| 62 } | 68 } |
| 63 | 69 |
| 64 void LoadingWallpaper() { | 70 void LoadingWallpaper() { |
| 65 if (cancel_flag_.IsSet()) | 71 if (cancel_flag_.IsSet()) |
| 66 return; | 72 return; |
| 67 wallpaper_data_.reset(new WallpaperData(index_)); | 73 wallpaper_data_.reset(new WallpaperData(index_, resolution_)); |
| 68 } | 74 } |
| 69 | 75 |
| 70 void Cancel() { | 76 void Cancel() { |
| 71 cancel_flag_.Set(); | 77 cancel_flag_.Set(); |
| 72 } | 78 } |
| 73 | 79 |
| 74 WallpaperData* ReleaseWallpaperData() { | 80 WallpaperData* ReleaseWallpaperData() { |
| 75 return wallpaper_data_.release(); | 81 return wallpaper_data_.release(); |
| 76 } | 82 } |
| 77 | 83 |
| 78 private: | 84 private: |
| 79 friend class base::RefCountedThreadSafe< | 85 friend class base::RefCountedThreadSafe< |
| 80 DesktopBackgroundController::WallpaperOperation>; | 86 DesktopBackgroundController::WallpaperOperation>; |
| 81 | 87 |
| 82 ~WallpaperOperation() {} | 88 ~WallpaperOperation() {} |
| 83 | 89 |
| 84 base::CancellationFlag cancel_flag_; | 90 base::CancellationFlag cancel_flag_; |
| 85 | 91 |
| 86 scoped_ptr<WallpaperData> wallpaper_data_; | 92 scoped_ptr<WallpaperData> wallpaper_data_; |
| 87 | 93 |
| 88 int index_; | 94 const int index_; |
| 95 |
| 96 const WallpaperResolution resolution_; |
| 89 | 97 |
| 90 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); | 98 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); |
| 91 }; | 99 }; |
| 92 | 100 |
| 93 DesktopBackgroundController::DesktopBackgroundController() | 101 DesktopBackgroundController::DesktopBackgroundController() |
| 94 : desktop_background_mode_(BACKGROUND_IMAGE), | 102 : desktop_background_mode_(BACKGROUND_IMAGE), |
| 95 background_color_(SK_ColorGRAY), | 103 background_color_(SK_ColorGRAY), |
| 96 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 104 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 97 } | 105 } |
| 98 | 106 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 116 if (desktop_background_mode_ != BACKGROUND_IMAGE) | 124 if (desktop_background_mode_ != BACKGROUND_IMAGE) |
| 117 return SkBitmap(); | 125 return SkBitmap(); |
| 118 return GetWallpaper(); | 126 return GetWallpaper(); |
| 119 } | 127 } |
| 120 | 128 |
| 121 void DesktopBackgroundController::OnRootWindowAdded( | 129 void DesktopBackgroundController::OnRootWindowAdded( |
| 122 aura::RootWindow* root_window) { | 130 aura::RootWindow* root_window) { |
| 123 switch (desktop_background_mode_) { | 131 switch (desktop_background_mode_) { |
| 124 case BACKGROUND_IMAGE: | 132 case BACKGROUND_IMAGE: |
| 125 if (current_wallpaper_.get()) { | 133 if (current_wallpaper_.get()) { |
| 126 SetDesktopBackgroundImage(root_window); | 134 gfx::Size root_window_size = root_window->GetHostSize(); |
| 135 int wallpaper_width = current_wallpaper_->wallpaper_image.width(); |
| 136 int wallpaper_height = current_wallpaper_->wallpaper_image.height(); |
| 137 // Loads a higher resolution wallpaper if needed. |
| 138 if ((wallpaper_width < root_window_size.width() || |
| 139 wallpaper_height < root_window_size.height()) && |
| 140 current_wallpaper_->wallpaper_index != -1 && |
| 141 current_wallpaper_->wallpaper_layout != TILE) |
| 142 SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true); |
| 143 else |
| 144 SetDesktopBackgroundImage(root_window); |
| 127 } else { | 145 } else { |
| 128 internal::CreateDesktopBackground(root_window); | 146 internal::CreateDesktopBackground(root_window); |
| 129 } | 147 } |
| 130 break; | 148 break; |
| 131 case BACKGROUND_SOLID_COLOR: | 149 case BACKGROUND_SOLID_COLOR: |
| 132 SetDesktopBackgroundSolidColorMode(background_color_); | 150 SetDesktopBackgroundSolidColorMode(background_color_); |
| 133 break; | 151 break; |
| 134 } | 152 } |
| 135 } | 153 } |
| 136 | 154 |
| 137 void DesktopBackgroundController::SetDefaultWallpaper(int index) { | 155 void DesktopBackgroundController::SetDefaultWallpaper(int index, |
| 156 bool force_reload) { |
| 138 // We should not change background when index is invalid. For instance, at | 157 // We should not change background when index is invalid. For instance, at |
| 139 // login screen or stub_user login. | 158 // login screen or stub_user login. |
| 140 if (index == ash::GetInvalidWallpaperIndex()) { | 159 if (index == ash::GetInvalidWallpaperIndex()) { |
| 141 CreateEmptyWallpaper(); | 160 CreateEmptyWallpaper(); |
| 142 return; | 161 return; |
| 143 } else if (index == ash::GetSolidColorIndex()) { | 162 } else if (index == ash::GetSolidColorIndex()) { |
| 144 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); | 163 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); |
| 145 return; | 164 return; |
| 146 } | 165 } |
| 147 | 166 |
| 148 if (current_wallpaper_.get() && current_wallpaper_->wallpaper_index == index) | 167 if (!force_reload && current_wallpaper_.get() && |
| 168 current_wallpaper_->wallpaper_index == index) |
| 149 return; | 169 return; |
| 150 | 170 |
| 151 CancelPendingWallpaperOperation(); | 171 CancelPendingWallpaperOperation(); |
| 152 | 172 |
| 153 wallpaper_op_ = new WallpaperOperation(index); | 173 WallpaperResolution resolution = SMALL; |
| 174 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 175 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 176 iter != root_windows.end(); ++iter) { |
| 177 gfx::Size root_window_size = (*iter)->GetHostSize(); |
| 178 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
| 179 root_window_size.height() > kSmallWallpaperMaximalHeight) |
| 180 resolution = LARGE; |
| 181 } |
| 182 |
| 183 wallpaper_op_ = new WallpaperOperation(index, resolution); |
| 154 base::WorkerPool::PostTaskAndReply( | 184 base::WorkerPool::PostTaskAndReply( |
| 155 FROM_HERE, | 185 FROM_HERE, |
| 156 base::Bind(&WallpaperOperation::Run, wallpaper_op_), | 186 base::Bind(&WallpaperOperation::Run, wallpaper_op_), |
| 157 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, | 187 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, |
| 158 weak_ptr_factory_.GetWeakPtr(), | 188 weak_ptr_factory_.GetWeakPtr(), |
| 159 wallpaper_op_), | 189 wallpaper_op_), |
| 160 true /* task_is_slow */); | 190 true /* task_is_slow */); |
| 161 } | 191 } |
| 162 | 192 |
| 163 void DesktopBackgroundController::SetCustomWallpaper( | 193 void DesktopBackgroundController::SetCustomWallpaper( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 current_wallpaper_.reset(NULL); | 265 current_wallpaper_.reset(NULL); |
| 236 desktop_background_mode_ = BACKGROUND_IMAGE; | 266 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 237 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 267 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 238 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 268 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 239 iter != root_windows.end(); ++iter) { | 269 iter != root_windows.end(); ++iter) { |
| 240 internal::CreateDesktopBackground(*iter); | 270 internal::CreateDesktopBackground(*iter); |
| 241 } | 271 } |
| 242 } | 272 } |
| 243 | 273 |
| 244 } // namespace ash | 274 } // namespace ash |
| OLD | NEW |