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

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

Issue 871773004: Use floor instead of ceil for the size of the wallpaper layer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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"
11 #include "ash/desktop_background/desktop_background_widget_controller.h" 11 #include "ash/desktop_background/desktop_background_widget_controller.h"
12 #include "ash/desktop_background/user_wallpaper_delegate.h" 12 #include "ash/desktop_background/user_wallpaper_delegate.h"
13 #include "ash/display/display_manager.h" 13 #include "ash/display/display_manager.h"
14 #include "ash/root_window_controller.h" 14 #include "ash/root_window_controller.h"
15 #include "ash/session/session_state_delegate.h" 15 #include "ash/session/session_state_delegate.h"
16 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/shell_window_ids.h" 17 #include "ash/shell_window_ids.h"
18 #include "ash/wm/overview/window_selector_controller.h" 18 #include "ash/wm/overview/window_selector_controller.h"
19 #include "ash/wm/window_animations.h" 19 #include "ash/wm/window_animations.h"
20 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "ui/aura/window_event_dispatcher.h" 22 #include "ui/aura/window_event_dispatcher.h"
23 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
24 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/geometry/safe_integer_conversions.h"
25 #include "ui/gfx/geometry/size_conversions.h" 26 #include "ui/gfx/geometry/size_conversions.h"
26 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/transform.h" 28 #include "ui/gfx/transform.h"
28 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
29 30
30 using wallpaper::WallpaperLayout; 31 using wallpaper::WallpaperLayout;
31 using wallpaper::WALLPAPER_LAYOUT_CENTER; 32 using wallpaper::WALLPAPER_LAYOUT_CENTER;
32 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; 33 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
33 using wallpaper::WALLPAPER_LAYOUT_STRETCH; 34 using wallpaper::WALLPAPER_LAYOUT_STRETCH;
34 using wallpaper::WALLPAPER_LAYOUT_TILE; 35 using wallpaper::WALLPAPER_LAYOUT_TILE;
35 36
36 namespace ash { 37 namespace ash {
37 namespace { 38 namespace {
38 39
39 // For our scaling ratios we need to round positive numbers.
40 int RoundPositive(double x) {
41 return static_cast<int>(floor(x + 0.5));
42 }
43
44 // A view that controls the child view's layer so that the layer 40 // A view that controls the child view's layer so that the layer
45 // always has the same size as the display's original, un-scaled size 41 // always has the same size as the display's original, un-scaled size
46 // in DIP. The layer then transformed to fit to the virtual screen 42 // in DIP. The layer then transformed to fit to the virtual screen
47 // size when laid-out. 43 // size when laid-out.
48 // This is to avoid scaling the image at painting time, then scaling 44 // This is to avoid scaling the image at painting time, then scaling
49 // it back to the screen size in the compositor. 45 // it back to the screen size in the compositor.
50 class LayerControlView : public views::View { 46 class LayerControlView : public views::View {
51 public: 47 public:
52 explicit LayerControlView(views::View* view) { 48 explicit LayerControlView(views::View* view) {
53 AddChildView(view); 49 AddChildView(view);
54 view->SetPaintToLayer(true); 50 view->SetPaintToLayer(true);
55 } 51 }
56 52
57 // Overrides views::View. 53 // Overrides views::View.
58 void Layout() override { 54 void Layout() override {
59 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( 55 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(
60 GetWidget()->GetNativeView()); 56 GetWidget()->GetNativeView());
61 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 57 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
62 DisplayInfo info = display_manager->GetDisplayInfo(display.id()); 58 DisplayInfo info = display_manager->GetDisplayInfo(display.id());
63 float ui_scale = info.GetEffectiveUIScale(); 59 float ui_scale = info.GetEffectiveUIScale();
64 gfx::SizeF pixel_size = display.size(); 60 gfx::SizeF pixel_size = display.size();
65 pixel_size.Scale(1.0f / ui_scale); 61 pixel_size.Scale(1.0f / ui_scale);
66 gfx::Size rounded_size = gfx::ToCeiledSize(pixel_size); 62 gfx::Size rounded_size = gfx::ToFlooredSize(pixel_size);
67 DCHECK_EQ(1, child_count()); 63 DCHECK_EQ(1, child_count());
68 views::View* child = child_at(0); 64 views::View* child = child_at(0);
69 child->SetBounds(0, 0, rounded_size.width(), rounded_size.height()); 65 child->SetBounds(0, 0, rounded_size.width(), rounded_size.height());
70 gfx::Transform transform; 66 gfx::Transform transform;
71 transform.Scale(ui_scale, ui_scale); 67 transform.Scale(ui_scale, ui_scale);
72 child->SetTransform(transform); 68 child->SetTransform(transform);
73 } 69 }
74 70
75 private: 71 private:
76 DISALLOW_COPY_AND_ASSIGN(LayerControlView); 72 DISALLOW_COPY_AND_ASSIGN(LayerControlView);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // The dimension with the smallest ratio must be cropped, the other one 158 // The dimension with the smallest ratio must be cropped, the other one
163 // is preserved. Both are set in gfx::Size cropped_size. 159 // is preserved. Both are set in gfx::Size cropped_size.
164 double horizontal_ratio = static_cast<double>(width()) / 160 double horizontal_ratio = static_cast<double>(width()) /
165 static_cast<double>(wallpaper.width()); 161 static_cast<double>(wallpaper.width());
166 double vertical_ratio = static_cast<double>(height()) / 162 double vertical_ratio = static_cast<double>(height()) /
167 static_cast<double>(wallpaper.height()); 163 static_cast<double>(wallpaper.height());
168 164
169 gfx::Size cropped_size; 165 gfx::Size cropped_size;
170 if (vertical_ratio > horizontal_ratio) { 166 if (vertical_ratio > horizontal_ratio) {
171 cropped_size = gfx::Size( 167 cropped_size = gfx::Size(
172 RoundPositive(static_cast<double>(width()) / vertical_ratio), 168 gfx::ToFlooredInt(static_cast<double>(width()) / vertical_ratio),
173 wallpaper.height()); 169 wallpaper.height());
174 } else { 170 } else {
175 cropped_size = gfx::Size(wallpaper.width(), 171 cropped_size = gfx::Size(
176 RoundPositive(static_cast<double>(height()) / horizontal_ratio)); 172 wallpaper.width(),
173 gfx::ToFlooredInt(static_cast<double>(height()) / horizontal_ratio));
177 } 174 }
178 175
179 gfx::Rect wallpaper_cropped_rect( 176 gfx::Rect wallpaper_cropped_rect(
180 0, 0, wallpaper.width(), wallpaper.height()); 177 0, 0, wallpaper.width(), wallpaper.height());
181 wallpaper_cropped_rect.ClampToCenteredSize(cropped_size); 178 wallpaper_cropped_rect.ClampToCenteredSize(cropped_size);
182 canvas->DrawImageInt(wallpaper, 179 canvas->DrawImageInt(wallpaper,
183 wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), 180 wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(),
184 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), 181 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(),
185 0, 0, width(), height(), 182 0, 0, width(), height(),
186 true); 183 true);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Disable animation if transition to login screen from an empty background. 257 // Disable animation if transition to login screen from an empty background.
261 wm::SetWindowVisibilityAnimationTransition( 258 wm::SetWindowVisibilityAnimationTransition(
262 desktop_widget->GetNativeView(), wm::ANIMATE_NONE); 259 desktop_widget->GetNativeView(), wm::ANIMATE_NONE);
263 } 260 }
264 261
265 desktop_widget->SetBounds(params.parent->bounds()); 262 desktop_widget->SetBounds(params.parent->bounds());
266 return desktop_widget; 263 return desktop_widget;
267 } 264 }
268 265
269 } // namespace ash 266 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698