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

Side by Side Diff: ash/display/root_window_transformers.cc

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/display/root_window_transformers.h" 5 #include "ash/display/root_window_transformers.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/display_info.h" 10 #include "ash/display/display_info.h"
11 #include "ash/display/display_manager.h" 11 #include "ash/display/display_manager.h"
12 #include "ash/host/root_window_transformer.h" 12 #include "ash/host/root_window_transformer.h"
13 #include "ash/magnifier/magnification_controller.h" 13 #include "ash/magnifier/magnification_controller.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "third_party/skia/include/utils/SkMatrix44.h" 16 #include "third_party/skia/include/utils/SkMatrix44.h"
17 #include "ui/aura/window_event_dispatcher.h" 17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/aura/window_property.h" 18 #include "ui/aura/window_property.h"
19 #include "ui/compositor/dip_util.h" 19 #include "ui/compositor/dip_util.h"
20 #include "ui/gfx/display.h" 20 #include "ui/display/display.h"
21 #include "ui/display/screen.h"
21 #include "ui/gfx/geometry/insets.h" 22 #include "ui/gfx/geometry/insets.h"
22 #include "ui/gfx/geometry/size_conversions.h" 23 #include "ui/gfx/geometry/size_conversions.h"
23 #include "ui/gfx/screen.h"
24 #include "ui/gfx/transform.h" 24 #include "ui/gfx/transform.h"
25 #include "ui/gfx/transform.h" 25 #include "ui/gfx/transform.h"
26 26
27 DECLARE_WINDOW_PROPERTY_TYPE(gfx::Display::Rotation); 27 DECLARE_WINDOW_PROPERTY_TYPE(display::Display::Rotation);
28 28
29 namespace ash { 29 namespace ash {
30 namespace { 30 namespace {
31 31
32 #if defined(OS_WIN) 32 #if defined(OS_WIN)
33 DEFINE_WINDOW_PROPERTY_KEY(gfx::Display::Rotation, kRotationPropertyKey, 33 DEFINE_WINDOW_PROPERTY_KEY(display::Display::Rotation,
34 gfx::Display::ROTATE_0); 34 kRotationPropertyKey,
35 display::Display::ROTATE_0);
35 #endif 36 #endif
36 37
37 // Round near zero value to zero. 38 // Round near zero value to zero.
38 void RoundNearZero(gfx::Transform* transform) { 39 void RoundNearZero(gfx::Transform* transform) {
39 const float kEpsilon = 0.001f; 40 const float kEpsilon = 0.001f;
40 SkMatrix44& matrix = transform->matrix(); 41 SkMatrix44& matrix = transform->matrix();
41 for (int x = 0; x < 4; ++x) { 42 for (int x = 0; x < 4; ++x) {
42 for (int y = 0; y < 4; ++y) { 43 for (int y = 0; y < 4; ++y) {
43 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon) 44 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon)
44 matrix.set(x, y, SkFloatToMScalar(0.0f)); 45 matrix.set(x, y, SkFloatToMScalar(0.0f));
45 } 46 }
46 } 47 }
47 } 48 }
48 49
49 // TODO(oshima): Transformers should be able to adjust itself 50 // TODO(oshima): Transformers should be able to adjust itself
50 // when the device scale factor is changed, instead of 51 // when the device scale factor is changed, instead of
51 // precalculating the transform using fixed value. 52 // precalculating the transform using fixed value.
52 53
53 gfx::Transform CreateRotationTransform(aura::Window* root_window, 54 gfx::Transform CreateRotationTransform(aura::Window* root_window,
54 const gfx::Display& display) { 55 const display::Display& display) {
55 DisplayInfo info = 56 DisplayInfo info =
56 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); 57 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
57 58
58 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) 59 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade)
59 #if defined(OS_WIN) 60 #if defined(OS_WIN)
60 // Windows 8 bots refused to resize the host window, and 61 // Windows 8 bots refused to resize the host window, and
61 // updating the transform results in incorrectly resizing 62 // updating the transform results in incorrectly resizing
62 // the root window. Don't apply the transform unless 63 // the root window. Don't apply the transform unless
63 // necessary so that unit tests pass on win8 bots. 64 // necessary so that unit tests pass on win8 bots.
64 if (info.GetActiveRotation() == 65 if (info.GetActiveRotation() ==
65 root_window->GetProperty(kRotationPropertyKey)) { 66 root_window->GetProperty(kRotationPropertyKey)) {
66 return gfx::Transform(); 67 return gfx::Transform();
67 } 68 }
68 root_window->SetProperty(kRotationPropertyKey, info.GetActiveRotation()); 69 root_window->SetProperty(kRotationPropertyKey, info.GetActiveRotation());
69 #endif 70 #endif
70 71
71 gfx::Transform rotate; 72 gfx::Transform rotate;
72 // The origin is (0, 0), so the translate width/height must be reduced by 73 // The origin is (0, 0), so the translate width/height must be reduced by
73 // 1 pixel. 74 // 1 pixel.
74 float one_pixel = 1.0f / display.device_scale_factor(); 75 float one_pixel = 1.0f / display.device_scale_factor();
75 switch (info.GetActiveRotation()) { 76 switch (info.GetActiveRotation()) {
76 case gfx::Display::ROTATE_0: 77 case display::Display::ROTATE_0:
77 break; 78 break;
78 case gfx::Display::ROTATE_90: 79 case display::Display::ROTATE_90:
79 rotate.Translate(display.bounds().height() - one_pixel, 0); 80 rotate.Translate(display.bounds().height() - one_pixel, 0);
80 rotate.Rotate(90); 81 rotate.Rotate(90);
81 break; 82 break;
82 case gfx::Display::ROTATE_270: 83 case display::Display::ROTATE_270:
83 rotate.Translate(0, display.bounds().width() - one_pixel); 84 rotate.Translate(0, display.bounds().width() - one_pixel);
84 rotate.Rotate(270); 85 rotate.Rotate(270);
85 break; 86 break;
86 case gfx::Display::ROTATE_180: 87 case display::Display::ROTATE_180:
87 rotate.Translate(display.bounds().width() - one_pixel, 88 rotate.Translate(display.bounds().width() - one_pixel,
88 display.bounds().height() - one_pixel); 89 display.bounds().height() - one_pixel);
89 rotate.Rotate(180); 90 rotate.Rotate(180);
90 break; 91 break;
91 } 92 }
92 93
93 RoundNearZero(&rotate); 94 RoundNearZero(&rotate);
94 return rotate; 95 return rotate;
95 } 96 }
96 97
(...skipping 21 matching lines...) Expand all
118 if (insets.top() != 0 || insets.left() != 0) { 119 if (insets.top() != 0 || insets.left() != 0) {
119 float x_offset = insets.left() / device_scale_factor; 120 float x_offset = insets.left() / device_scale_factor;
120 float y_offset = insets.top() / device_scale_factor; 121 float y_offset = insets.top() / device_scale_factor;
121 transform.Translate(x_offset, y_offset); 122 transform.Translate(x_offset, y_offset);
122 } 123 }
123 float inverted_scale = 1.0f / ui_scale; 124 float inverted_scale = 1.0f / ui_scale;
124 transform.Scale(inverted_scale, inverted_scale); 125 transform.Scale(inverted_scale, inverted_scale);
125 return transform; 126 return transform;
126 } 127 }
127 128
128 gfx::Transform CreateMirrorTransform(const gfx::Display& display) { 129 gfx::Transform CreateMirrorTransform(const display::Display& display) {
129 gfx::Transform transform; 130 gfx::Transform transform;
130 transform.matrix().set3x3(-1, 0, 0, 131 transform.matrix().set3x3(-1, 0, 0,
131 0, 1, 0, 132 0, 1, 0,
132 0, 0, 1); 133 0, 0, 1);
133 transform.Translate(-display.size().width(), 0); 134 transform.Translate(-display.size().width(), 0);
134 return transform; 135 return transform;
135 } 136 }
136 137
137 // RootWindowTransformer for ash environment. 138 // RootWindowTransformer for ash environment.
138 class AshRootWindowTransformer : public RootWindowTransformer { 139 class AshRootWindowTransformer : public RootWindowTransformer {
139 public: 140 public:
140 AshRootWindowTransformer(aura::Window* root, 141 AshRootWindowTransformer(aura::Window* root, const display::Display& display)
141 const gfx::Display& display)
142 : root_window_(root) { 142 : root_window_(root) {
143 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 143 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
144 DisplayInfo info = display_manager->GetDisplayInfo(display.id()); 144 DisplayInfo info = display_manager->GetDisplayInfo(display.id());
145 host_insets_ = info.GetOverscanInsetsInPixel(); 145 host_insets_ = info.GetOverscanInsetsInPixel();
146 root_window_ui_scale_ = info.GetEffectiveUIScale(); 146 root_window_ui_scale_ = info.GetEffectiveUIScale();
147 root_window_bounds_transform_ = 147 root_window_bounds_transform_ =
148 CreateInsetsAndScaleTransform(host_insets_, 148 CreateInsetsAndScaleTransform(host_insets_,
149 display.device_scale_factor(), 149 display.device_scale_factor(),
150 root_window_ui_scale_) * 150 root_window_ui_scale_) *
151 CreateRotationTransform(root, display); 151 CreateRotationTransform(root, display);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 gfx::Transform transform_; 270 gfx::Transform transform_;
271 gfx::Rect root_bounds_; 271 gfx::Rect root_bounds_;
272 gfx::Insets insets_; 272 gfx::Insets insets_;
273 273
274 DISALLOW_COPY_AND_ASSIGN(MirrorRootWindowTransformer); 274 DISALLOW_COPY_AND_ASSIGN(MirrorRootWindowTransformer);
275 }; 275 };
276 276
277 class PartialBoundsRootWindowTransformer : public RootWindowTransformer { 277 class PartialBoundsRootWindowTransformer : public RootWindowTransformer {
278 public: 278 public:
279 PartialBoundsRootWindowTransformer(const gfx::Rect& screen_bounds, 279 PartialBoundsRootWindowTransformer(const gfx::Rect& screen_bounds,
280 const gfx::Display& display) { 280 const display::Display& display) {
281 gfx::Display unified_display = 281 display::Display unified_display =
282 gfx::Screen::GetScreen()->GetPrimaryDisplay(); 282 display::Screen::GetScreen()->GetPrimaryDisplay();
283 DisplayInfo display_info = 283 DisplayInfo display_info =
284 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); 284 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id());
285 root_bounds_ = gfx::Rect(display_info.bounds_in_native().size()); 285 root_bounds_ = gfx::Rect(display_info.bounds_in_native().size());
286 float scale = root_bounds_.height() / 286 float scale = root_bounds_.height() /
287 static_cast<float>(screen_bounds.height()) / 287 static_cast<float>(screen_bounds.height()) /
288 unified_display.device_scale_factor(); 288 unified_display.device_scale_factor();
289 transform_.Scale(scale, scale); 289 transform_.Scale(scale, scale);
290 transform_.Translate(-SkIntToMScalar(display.bounds().x()), 290 transform_.Translate(-SkIntToMScalar(display.bounds().x()),
291 -SkIntToMScalar(display.bounds().y())); 291 -SkIntToMScalar(display.bounds().y()));
292 } 292 }
(...skipping 14 matching lines...) Expand all
307 gfx::Transform transform_; 307 gfx::Transform transform_;
308 gfx::Rect root_bounds_; 308 gfx::Rect root_bounds_;
309 309
310 DISALLOW_COPY_AND_ASSIGN(PartialBoundsRootWindowTransformer); 310 DISALLOW_COPY_AND_ASSIGN(PartialBoundsRootWindowTransformer);
311 }; 311 };
312 312
313 } // namespace 313 } // namespace
314 314
315 RootWindowTransformer* CreateRootWindowTransformerForDisplay( 315 RootWindowTransformer* CreateRootWindowTransformerForDisplay(
316 aura::Window* root, 316 aura::Window* root,
317 const gfx::Display& display) { 317 const display::Display& display) {
318 return new AshRootWindowTransformer(root, display); 318 return new AshRootWindowTransformer(root, display);
319 } 319 }
320 320
321 RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay( 321 RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay(
322 const DisplayInfo& source_display_info, 322 const DisplayInfo& source_display_info,
323 const DisplayInfo& mirror_display_info) { 323 const DisplayInfo& mirror_display_info) {
324 return new MirrorRootWindowTransformer(source_display_info, 324 return new MirrorRootWindowTransformer(source_display_info,
325 mirror_display_info); 325 mirror_display_info);
326 } 326 }
327 327
328 RootWindowTransformer* CreateRootWindowTransformerForUnifiedDesktop( 328 RootWindowTransformer* CreateRootWindowTransformerForUnifiedDesktop(
329 const gfx::Rect& screen_bounds, 329 const gfx::Rect& screen_bounds,
330 const gfx::Display& display) { 330 const display::Display& display) {
331 return new PartialBoundsRootWindowTransformer(screen_bounds, display); 331 return new PartialBoundsRootWindowTransformer(screen_bounds, display);
332 } 332 }
333 333
334 } // namespace ash 334 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/root_window_transformers.h ('k') | ash/display/root_window_transformers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698