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

Side by Side Diff: ash/desktop_background/desktop_background_controller.cc

Issue 10837089: Use low resolution wallpaper for small screens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review 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
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 "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 int index_;
sky 2012/08/03 18:16:15 const on this and 96 if you can.
bshe 2012/08/03 19:35:11 Done.
89 95
96 WallpaperResolution resolution_;
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
99 DesktopBackgroundController::~DesktopBackgroundController() { 107 DesktopBackgroundController::~DesktopBackgroundController() {
(...skipping 16 matching lines...) Expand all
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 if ((wallpaper_width < root_window_size.width() ||
138 wallpaper_height < root_window_size.height()) &&
139 current_wallpaper_->index != -1 &&
140 current_wallpaper_->layout != TILE)
141 SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true);
142 else
143 SetDesktopBackgroundImage(root_window);
127 } else { 144 } else {
128 internal::CreateDesktopBackground(root_window); 145 internal::CreateDesktopBackground(root_window);
129 } 146 }
130 break; 147 break;
131 case BACKGROUND_SOLID_COLOR: 148 case BACKGROUND_SOLID_COLOR:
132 SetDesktopBackgroundSolidColorMode(background_color_); 149 SetDesktopBackgroundSolidColorMode(background_color_);
133 break; 150 break;
134 } 151 }
135 } 152 }
136 153
137 void DesktopBackgroundController::SetDefaultWallpaper(int index) { 154 void DesktopBackgroundController::SetDefaultWallpaper(int index,
155 bool force_reload) {
138 // We should not change background when index is invalid. For instance, at 156 // We should not change background when index is invalid. For instance, at
139 // login screen or stub_user login. 157 // login screen or stub_user login.
140 if (index == ash::GetInvalidWallpaperIndex()) { 158 if (index == ash::GetInvalidWallpaperIndex()) {
141 CreateEmptyWallpaper(); 159 CreateEmptyWallpaper();
142 return; 160 return;
143 } else if (index == ash::GetSolidColorIndex()) { 161 } else if (index == ash::GetSolidColorIndex()) {
144 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); 162 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor);
145 return; 163 return;
146 } 164 }
147 165
148 if (current_wallpaper_.get() && current_wallpaper_->wallpaper_index == index) 166 if (!force_reload && current_wallpaper_.get() &&
167 current_wallpaper_->wallpaper_index == index)
149 return; 168 return;
150 169
151 CancelPendingWallpaperOperation(); 170 CancelPendingWallpaperOperation();
152 171
153 wallpaper_op_ = new WallpaperOperation(index); 172 WallpaperResolution resolution = SMALL;
173 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
174 for (Shell::RootWindowList::iterator iter = root_windows.begin();
175 iter != root_windows.end(); ++iter) {
176 gfx::Size root_window_size = (*iter)->GetHostSize();
177 if (root_window_size.width() > kSmallWallpaperMaximalWidth ||
178 root_window_size.height() > kSmallWallpaperMaximalHeight)
179 resolution = LARGE;
180 }
181
182 wallpaper_op_ = new WallpaperOperation(index, resolution);
154 base::WorkerPool::PostTaskAndReply( 183 base::WorkerPool::PostTaskAndReply(
155 FROM_HERE, 184 FROM_HERE,
156 base::Bind(&WallpaperOperation::Run, wallpaper_op_), 185 base::Bind(&WallpaperOperation::Run, wallpaper_op_),
157 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, 186 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted,
158 weak_ptr_factory_.GetWeakPtr(), 187 weak_ptr_factory_.GetWeakPtr(),
159 wallpaper_op_), 188 wallpaper_op_),
160 true /* task_is_slow */); 189 true /* task_is_slow */);
161 } 190 }
162 191
163 void DesktopBackgroundController::SetCustomWallpaper( 192 void DesktopBackgroundController::SetCustomWallpaper(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 current_wallpaper_.reset(NULL); 264 current_wallpaper_.reset(NULL);
236 desktop_background_mode_ = BACKGROUND_IMAGE; 265 desktop_background_mode_ = BACKGROUND_IMAGE;
237 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 266 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
238 for (Shell::RootWindowList::iterator iter = root_windows.begin(); 267 for (Shell::RootWindowList::iterator iter = root_windows.begin();
239 iter != root_windows.end(); ++iter) { 268 iter != root_windows.end(); ++iter) {
240 internal::CreateDesktopBackground(*iter); 269 internal::CreateDesktopBackground(*iter);
241 } 270 }
242 } 271 }
243 272
244 } // namespace ash 273 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698