blob: de6fa790bd75d16e8cffdcfef473eba1040a1c69 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2019 The Chromium Authors
Michael Spang8e7b6c02019-12-06 22:23:532// 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 Wennborg8586102b2020-05-05 13:43:297#include "base/notreached.h"
Michael Spang8e7b6c02019-12-06 22:23:538#include "ui/gfx/overlay_transform_utils.h"
9
10namespace display {
11
12gfx::Transform CreateRotationTransform(display::Display::Rotation rotation,
13 const gfx::SizeF& size_to_rotate) {
14 return OverlayTransformToTransform(
15 DisplayRotationToOverlayTransform(rotation), size_to_rotate);
16}
17
18gfx::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:
punithnayak316d5fb2023-12-14 04:03:2635 return gfx::OVERLAY_TRANSFORM_ROTATE_CLOCKWISE_90;
Michael Spang8e7b6c02019-12-06 22:23:5336 case display::Display::ROTATE_180:
punithnayak316d5fb2023-12-14 04:03:2637 return gfx::OVERLAY_TRANSFORM_ROTATE_CLOCKWISE_180;
Michael Spang8e7b6c02019-12-06 22:23:5338 case display::Display::ROTATE_270:
punithnayak316d5fb2023-12-14 04:03:2639 return gfx::OVERLAY_TRANSFORM_ROTATE_CLOCKWISE_270;
Michael Spang8e7b6c02019-12-06 22:23:5340 }
Peter Boströme4f1aef52024-10-29 23:42:0341 NOTREACHED();
Michael Spang8e7b6c02019-12-06 22:23:5342}
43
44} // namespace display