Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Michael Spang | 8e7b6c0 | 2019-12-06 22:23:53 | [diff] [blame] | 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 "ui/display/display_transform.h" |
| 6 | |
Hans Wennborg | 8586102b | 2020-05-05 13:43:29 | [diff] [blame] | 7 | #include "base/notreached.h" |
Michael Spang | 8e7b6c0 | 2019-12-06 22:23:53 | [diff] [blame] | 8 | #include "ui/gfx/overlay_transform_utils.h" |
| 9 | |
| 10 | namespace display { |
| 11 | |
| 12 | gfx::Transform CreateRotationTransform(display::Display::Rotation rotation, |
| 13 | const gfx::SizeF& size_to_rotate) { |
| 14 | return OverlayTransformToTransform( |
| 15 | DisplayRotationToOverlayTransform(rotation), size_to_rotate); |
| 16 | } |
| 17 | |
| 18 | gfx::OverlayTransform DisplayRotationToOverlayTransform( |
| 19 | display::Display::Rotation rotation) { |
| 20 | // Note that the angle provided by |rotation| here is the opposite direction |
| 21 | // of the physical rotation of the device, which is the space in which the UI |
| 22 | // prepares the scene (see |
| 23 | // https://developer.android.com/reference/android/view/Display#getRotation() |
| 24 | // for details). |
| 25 | // |
| 26 | // The rotation which needs to be applied by the display compositor to allow |
| 27 | // the buffers produced by it to be used directly by the system compositor |
| 28 | // needs to be the inverse of this rotation. Since display::Rotation is in |
| 29 | // clockwise direction while gfx::OverlayTransform is anti-clockwise, directly |
| 30 | // mapping them below performs this inversion. |
| 31 | switch (rotation) { |
| 32 | case display::Display::ROTATE_0: |
| 33 | return gfx::OVERLAY_TRANSFORM_NONE; |
| 34 | case display::Display::ROTATE_90: |
punithnayak | 316d5fb | 2023-12-14 04:03:26 | [diff] [blame] | 35 | return gfx::OVERLAY_TRANSFORM_ROTATE_CLOCKWISE_90; |
Michael Spang | 8e7b6c0 | 2019-12-06 22:23:53 | [diff] [blame] | 36 | case display::Display::ROTATE_180: |
punithnayak | 316d5fb | 2023-12-14 04:03:26 | [diff] [blame] | 37 | return gfx::OVERLAY_TRANSFORM_ROTATE_CLOCKWISE_180; |
Michael Spang | 8e7b6c0 | 2019-12-06 22:23:53 | [diff] [blame] | 38 | case display::Display::ROTATE_270: |
punithnayak | 316d5fb | 2023-12-14 04:03:26 | [diff] [blame] | 39 | return gfx::OVERLAY_TRANSFORM_ROTATE_CLOCKWISE_270; |
Michael Spang | 8e7b6c0 | 2019-12-06 22:23:53 | [diff] [blame] | 40 | } |
Peter Boström | e4f1aef5 | 2024-10-29 23:42:03 | [diff] [blame] | 41 | NOTREACHED(); |
Michael Spang | 8e7b6c0 | 2019-12-06 22:23:53 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | } // namespace display |