OLD | NEW |
(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 "third_party/skia/include/core/SkMatrix44.h" |
| 10 #include "ui/gfx/transform.h" |
| 11 |
| 12 namespace ash { |
| 13 |
| 14 // Round near zero value to zero. |
| 15 void RoundNearZero(gfx::Transform* transform) { |
| 16 const float kEpsilon = 0.001f; |
| 17 SkMatrix44& matrix = transform->matrix(); |
| 18 for (int x = 0; x < 4; ++x) { |
| 19 for (int y = 0; y < 4; ++y) { |
| 20 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon) |
| 21 matrix.set(x, y, SkFloatToMScalar(0.0f)); |
| 22 } |
| 23 } |
| 24 } |
| 25 |
| 26 gfx::Transform CreateRotationTransform(display::Display::Rotation old_rotation, |
| 27 display::Display::Rotation new_rotation, |
| 28 const display::Display& display) { |
| 29 const int rotation_angle = 90 * (((new_rotation - old_rotation) + 4) % 4); |
| 30 gfx::Transform rotate; |
| 31 // The origin is (0, 0), so the translate width/height must be reduced by |
| 32 // 1 pixel. |
| 33 float one_pixel = 1.0f / display.device_scale_factor(); |
| 34 switch (rotation_angle) { |
| 35 case 0: |
| 36 break; |
| 37 case 90: |
| 38 rotate.Translate(display.bounds().height() - one_pixel, 0); |
| 39 rotate.Rotate(90); |
| 40 break; |
| 41 case 180: |
| 42 rotate.Translate(display.bounds().width() - one_pixel, |
| 43 display.bounds().height() - one_pixel); |
| 44 rotate.Rotate(180); |
| 45 break; |
| 46 case 270: |
| 47 rotate.Translate(0, display.bounds().width() - one_pixel); |
| 48 rotate.Rotate(270); |
| 49 break; |
| 50 } |
| 51 |
| 52 RoundNearZero(&rotate); |
| 53 return rotate; |
| 54 } |
| 55 |
| 56 } // namespace ash |
OLD | NEW |