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

Unified Diff: ash/utility/transformer_util.cc

Issue 2790583004: Add second copy request after screen rotation to flatten the layers in animation. (Closed)
Patch Set: Separate the two test sets for slow/smooth animation. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/utility/transformer_util.h ('k') | testing/buildbot/filters/ash_mus_unittests.filter » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/utility/transformer_util.cc
diff --git a/ash/utility/transformer_util.cc b/ash/utility/transformer_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5499b3f948474b5bd147a6874f3c63ec2b5bc61
--- /dev/null
+++ b/ash/utility/transformer_util.cc
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/utility/transformer_util.h"
+
+#include <cmath>
+
+#include "third_party/skia/include/core/SkMatrix44.h"
+#include "ui/gfx/transform.h"
+
+namespace ash {
+
+// Round near zero value to zero.
+void RoundNearZero(gfx::Transform* transform) {
+ const float kEpsilon = 0.001f;
+ SkMatrix44& matrix = transform->matrix();
+ for (int x = 0; x < 4; ++x) {
+ for (int y = 0; y < 4; ++y) {
+ if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon)
+ matrix.set(x, y, SkFloatToMScalar(0.0f));
+ }
+ }
+}
+
+gfx::Transform CreateRotationTransform(display::Display::Rotation old_rotation,
+ display::Display::Rotation new_rotation,
+ const display::Display& display) {
+ const int rotation_angle = 90 * (((new_rotation - old_rotation) + 4) % 4);
+ gfx::Transform rotate;
+ // The origin is (0, 0), so the translate width/height must be reduced by
+ // 1 pixel.
+ float one_pixel = 1.0f / display.device_scale_factor();
+ switch (rotation_angle) {
+ case 0:
+ break;
+ case 90:
+ rotate.Translate(display.bounds().height() - one_pixel, 0);
+ rotate.Rotate(90);
+ break;
+ case 180:
+ rotate.Translate(display.bounds().width() - one_pixel,
+ display.bounds().height() - one_pixel);
+ rotate.Rotate(180);
+ break;
+ case 270:
+ rotate.Translate(0, display.bounds().width() - one_pixel);
+ rotate.Rotate(270);
+ break;
+ }
+
+ RoundNearZero(&rotate);
+ return rotate;
+}
+
+} // namespace ash
« no previous file with comments | « ash/utility/transformer_util.h ('k') | testing/buildbot/filters/ash_mus_unittests.filter » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698