display_transform.cc 1.7 KB

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