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

Side by Side Diff: ash/utility/transformer_util.cc

Issue 2790583004: Add second copy request after screen rotation to flatten the layers in animation. (Closed)
Patch Set: Move some functions to ash/utility/transformer_util. Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/utility/transformer_util.h"
6
7 #include <cmath>
8
9 #include "ash/magnifier/magnification_controller.h"
10 #include "ash/shell.h"
11 #include "third_party/skia/include/core/SkMatrix44.h"
12 #include "ui/base/class_property.h"
13 #include "ui/display/manager/display_manager.h"
14 #include "ui/display/manager/managed_display_info.h"
15 #include "ui/gfx/geometry/insets.h"
16 #include "ui/gfx/transform.h"
17
18 DECLARE_UI_CLASS_PROPERTY_TYPE(display::Display::Rotation);
19
20 namespace ash {
21
22 #if defined(OS_WIN)
23 DEFINE_UI_CLASS_PROPERTY_KEY(display::Display::Rotation,
24 kRotationPropertyKey,
25 display::Display::ROTATE_0);
26 #endif
oshima 2017/04/13 23:51:45 you can remove OS_WIN part as ash no longer suppor
wutao 2017/04/14 00:17:54 Done.
27
28 // Round near zero value to zero.
29 void RoundNearZero(gfx::Transform* transform) {
30 const float kEpsilon = 0.001f;
31 SkMatrix44& matrix = transform->matrix();
32 for (int x = 0; x < 4; ++x) {
33 for (int y = 0; y < 4; ++y) {
34 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon)
35 matrix.set(x, y, SkFloatToMScalar(0.0f));
36 }
37 }
38 }
39
40 gfx::Transform CreateRotationTransform(display::Display::Rotation old_rotation,
41 display::Display::Rotation new_rotation,
42 const display::Display& display) {
43 const int rotation_angle = 90 * (((new_rotation - old_rotation) + 4) % 4);
44 gfx::Transform rotate;
45 // The origin is (0, 0), so the translate width/height must be reduced by
46 // 1 pixel.
47 float one_pixel = 1.0f / display.device_scale_factor();
48 switch (rotation_angle) {
49 case 0:
50 break;
51 case 90:
52 rotate.Translate(display.bounds().height() - one_pixel, 0);
53 rotate.Rotate(90);
54 break;
55 case 180:
56 rotate.Translate(display.bounds().width() - one_pixel,
57 display.bounds().height() - one_pixel);
58 rotate.Rotate(180);
59 break;
60 case 270:
61 rotate.Translate(0, display.bounds().width() - one_pixel);
62 rotate.Rotate(270);
63 break;
64 }
65
66 RoundNearZero(&rotate);
67 return rotate;
68 }
69
70 // TODO(oshima): Transformers should be able to adjust itself
71 // when the device scale factor is changed, instead of
72 // precalculating the transform using fixed value.
73
74 gfx::Transform CreateRootWindowRotationTransform(
75 aura::Window* root_window,
76 const display::Display& display) {
77 display::ManagedDisplayInfo info =
78 Shell::Get()->display_manager()->GetDisplayInfo(display.id());
79
80 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade)
81 #if defined(OS_WIN)
82 // Windows 8 bots refused to resize the host window, and
83 // updating the transform results in incorrectly resizing
84 // the root window. Don't apply the transform unless
85 // necessary so that unit tests pass on win8 bots.
86 if (info.GetActiveRotation() ==
87 root_window->GetProperty(kRotationPropertyKey)) {
88 return gfx::Transform();
89 }
90 root_window->SetProperty(kRotationPropertyKey, info.GetActiveRotation());
91 #endif
92
93 return CreateRotationTransform(display::Display::ROTATE_0,
94 info.GetActiveRotation(), display);
95 }
oshima 2017/04/13 23:51:45 do you have to move these other than CreateRotatio
wutao 2017/04/14 00:17:54 I do not. I only need CreateRotationTransform. I c
96
97 gfx::Transform CreateMagnifierTransform(aura::Window* root_window) {
98 MagnificationController* magnifier = Shell::Get()->magnification_controller();
99 float magnifier_scale = 1.f;
100 gfx::Point magnifier_offset;
101 if (magnifier && magnifier->IsEnabled()) {
102 magnifier_scale = magnifier->GetScale();
103 magnifier_offset = magnifier->GetWindowPosition();
104 }
105 gfx::Transform transform;
106 if (magnifier_scale != 1.f) {
107 transform.Scale(magnifier_scale, magnifier_scale);
108 transform.Translate(-magnifier_offset.x(), -magnifier_offset.y());
109 }
110 return transform;
111 }
112
113 gfx::Transform CreateInsetsAndScaleTransform(const gfx::Insets& insets,
114 float device_scale_factor,
115 float ui_scale) {
116 gfx::Transform transform;
117 if (insets.top() != 0 || insets.left() != 0) {
118 float x_offset = insets.left() / device_scale_factor;
119 float y_offset = insets.top() / device_scale_factor;
120 transform.Translate(x_offset, y_offset);
121 }
122 float inverted_scale = 1.0f / ui_scale;
123 transform.Scale(inverted_scale, inverted_scale);
124 return transform;
125 }
126
127 gfx::Transform CreateMirrorTransform(const display::Display& display) {
128 gfx::Transform transform;
129 transform.matrix().set3x3(-1, 0, 0, 0, 1, 0, 0, 0, 1);
130 transform.Translate(-display.size().width(), 0);
131 return transform;
132 }
133
134 } // namespace ash
OLDNEW
« ash/utility/transformer_util.h ('K') | « ash/utility/transformer_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698