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_view.h" | 5 #include "ash/desktop_background/desktop_background_view.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { | 131 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { |
132 // Scale the image while maintaining the aspect ratio, cropping as | 132 // Scale the image while maintaining the aspect ratio, cropping as |
133 // necessary to fill the background. Ideally the image should be larger | 133 // necessary to fill the background. Ideally the image should be larger |
134 // than the largest display supported, if not we will scale and center it if | 134 // than the largest display supported, if not we will scale and center it if |
135 // the layout is WALLPAPER_LAYOUT_CENTER_CROPPED. | 135 // the layout is WALLPAPER_LAYOUT_CENTER_CROPPED. |
136 DesktopBackgroundController* controller = | 136 DesktopBackgroundController* controller = |
137 Shell::GetInstance()->desktop_background_controller(); | 137 Shell::GetInstance()->desktop_background_controller(); |
138 gfx::ImageSkia wallpaper = controller->GetWallpaper(); | 138 gfx::ImageSkia wallpaper = controller->GetWallpaper(); |
139 WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout(); | 139 WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout(); |
140 | 140 |
141 if (wallpaper.isNull()) { | 141 // Wallpapers with png format could be partially transparent. |
142 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); | 142 // Fill the canvas with black background to make it opaque |
| 143 // before painting wallpaper |
| 144 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); |
| 145 |
| 146 if (wallpaper.isNull()) |
143 return; | 147 return; |
144 } | |
145 | 148 |
146 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) { | 149 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) { |
147 // The dimension with the smallest ratio must be cropped, the other one | 150 // The dimension with the smallest ratio must be cropped, the other one |
148 // is preserved. Both are set in gfx::Size cropped_size. | 151 // is preserved. Both are set in gfx::Size cropped_size. |
149 double horizontal_ratio = static_cast<double>(width()) / | 152 double horizontal_ratio = static_cast<double>(width()) / |
150 static_cast<double>(wallpaper.width()); | 153 static_cast<double>(wallpaper.width()); |
151 double vertical_ratio = static_cast<double>(height()) / | 154 double vertical_ratio = static_cast<double>(height()) / |
152 static_cast<double>(wallpaper.height()); | 155 static_cast<double>(wallpaper.height()); |
153 | 156 |
154 gfx::Size cropped_size; | 157 gfx::Size cropped_size; |
(...skipping 15 matching lines...) Expand all Loading... |
170 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), | 173 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), |
171 0, 0, width(), height(), | 174 0, 0, width(), height(), |
172 true); | 175 true); |
173 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { | 176 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { |
174 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); | 177 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); |
175 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { | 178 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { |
176 // This is generally not recommended as it may show artifacts. | 179 // This is generally not recommended as it may show artifacts. |
177 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), | 180 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), |
178 wallpaper.height(), 0, 0, width(), height(), true); | 181 wallpaper.height(), 0, 0, width(), height(), true); |
179 } else { | 182 } else { |
180 // Fill with black to make sure that the entire area is opaque. | |
181 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); | |
182 float image_scale = canvas->image_scale(); | 183 float image_scale = canvas->image_scale(); |
183 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, | 184 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, |
184 wallpaper.height() / image_scale); | 185 wallpaper.height() / image_scale); |
185 // All other are simply centered, and not scaled (but may be clipped). | 186 // All other are simply centered, and not scaled (but may be clipped). |
186 canvas->DrawImageInt( | 187 canvas->DrawImageInt( |
187 wallpaper, | 188 wallpaper, |
188 0, 0, wallpaper.width(), wallpaper.height(), | 189 0, 0, wallpaper.width(), wallpaper.height(), |
189 (width() - wallpaper_rect.width()) / 2, | 190 (width() - wallpaper_rect.width()) / 2, |
190 (height() - wallpaper_rect.height()) / 2, | 191 (height() - wallpaper_rect.height()) / 2, |
191 wallpaper_rect.width(), | 192 wallpaper_rect.width(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // Disable animation if transition to login screen from an empty background. | 250 // Disable animation if transition to login screen from an empty background. |
250 ::wm::SetWindowVisibilityAnimationTransition( | 251 ::wm::SetWindowVisibilityAnimationTransition( |
251 desktop_widget->GetNativeView(), ::wm::ANIMATE_NONE); | 252 desktop_widget->GetNativeView(), ::wm::ANIMATE_NONE); |
252 } | 253 } |
253 | 254 |
254 desktop_widget->SetBounds(params.parent->bounds()); | 255 desktop_widget->SetBounds(params.parent->bounds()); |
255 return desktop_widget; | 256 return desktop_widget; |
256 } | 257 } |
257 | 258 |
258 } // namespace ash | 259 } // namespace ash |
OLD | NEW |