blob: 883ef4633f4e0ef1bab32ed9f11cdfdee28cc733 [file] [log] [blame]
Michael Spang8e7b6c02019-12-06 22:23:531// Copyright 2019 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 "ui/display/display_transform.h"
6
7#include "ui/gfx/overlay_transform_utils.h"
8
9namespace display {
10
11gfx::Transform CreateRotationTransform(display::Display::Rotation rotation,
12 const gfx::SizeF& size_to_rotate) {
13 return OverlayTransformToTransform(
14 DisplayRotationToOverlayTransform(rotation), size_to_rotate);
15}
16
17gfx::OverlayTransform DisplayRotationToOverlayTransform(
18 display::Display::Rotation rotation) {
19 // Note that the angle provided by |rotation| here is the opposite direction
20 // of the physical rotation of the device, which is the space in which the UI
21 // prepares the scene (see
22 // https://developer.android.com/reference/android/view/Display#getRotation()
23 // for details).
24 //
25 // The rotation which needs to be applied by the display compositor to allow
26 // the buffers produced by it to be used directly by the system compositor
27 // needs to be the inverse of this rotation. Since display::Rotation is in
28 // clockwise direction while gfx::OverlayTransform is anti-clockwise, directly
29 // mapping them below performs this inversion.
30 switch (rotation) {
31 case display::Display::ROTATE_0:
32 return gfx::OVERLAY_TRANSFORM_NONE;
33 case display::Display::ROTATE_90:
34 return gfx::OVERLAY_TRANSFORM_ROTATE_90;
35 case display::Display::ROTATE_180:
36 return gfx::OVERLAY_TRANSFORM_ROTATE_180;
37 case display::Display::ROTATE_270:
38 return gfx::OVERLAY_TRANSFORM_ROTATE_270;
39 }
40 NOTREACHED();
41 return gfx::OVERLAY_TRANSFORM_NONE;
42}
43
44} // namespace display