TW_ROTATION: add flag to handle hardware-rotated display panels

* The existence of TW_ROTATION that implements this feature at the
  level of calls to libpixelflinger API closely mirrors the existence of
  ro.sf.hwrotation for surfaceflinger in LineageOS.
* A brute-force approach was previously attempted via the
  BOARD_HAS_FLIPPED_SCREEN makefile flag. That code iterated over the
  active display surface in a double-buffered setup, and performed a
  "smart" memcpy from the UI drawing surface (gr_draw) onto the display
  surface. The problem was that, without heavy loop optimizations, that
  code could have never scaled for 90 and 270 degree rotation.
  I tried and you could literally see the for loop with the naked eye
  while the display surface was updating.
* That code is now gone, but support for BOARD_HAS_FLIPPED_SCREEN := true
  is still there (now means TW_ROTATION := 180).
* This patch relies on the assumption that it is impossibly difficult
  and non-portable to rotate whole framebuffer display surfaces, in a
  way that is not dependent upon the graphics backend (adf, fbdev, drm,
  overlay etc). Therefore, it identifies the rendering primitives that
  the TWRP graphics stack exposes to the GUI application above, and
  implements hwrotation inside each of those calls instead:
    - gr_line(), gr_fill() - 2D geometric shapes (lines, rectangles)
    - gr_blit() - graphical image resources
    - gr_ttf_textExWH() - font rendering
    - gr_fb_width(), gr_fb_height() - framebuffer resolution
* The gist is to keep the backend and framebuffer (dimensions, row size
  etc) unchanged (because making changes there is asking for trouble),
  but present an altogether different reality to the calling API,
  according to the compile-time constant TW_ROTATION.
* All (x, y) API coordinates and shapes are transformed before being
  actually rendered as (x_disp, y_disp) display coordinates.
* With TW_ROTATION := 90 or 270 you can turn a landscape device into
  a portrait one, because the GUI is fooled by the reversed dimensions
  reported by gr_fb_width() and gr_fb_height() and renders the UI as
  for a different device.
* For blit and text rendering operations, figuring out the transformed
  coordinates in display space is not enough, as the surfaces that are
  to be rendered have to be rotated themselves. This is handled by
  allocating an intermediary rotated surface on each rendering
  operation (not ideal), so the code with the intermediary surface
  is compiled out for the TW_ROTATION := 0 case.
* This is still not as bad as rotating the whole framebuffer though, and
  on a msm8976 device the performance hit is not even noticeable (for
  software rendering).
* Currently there is no attempt to make a connection between the
  TW_ROTATION and the { RECOVERY_TOUCHSCREEN_SWAP_XY,
  RECOVERY_TOUCHSCREEN_FLIP_X, RECOVERY_TOUCHSCREEN_FLIP_Y } settings.

Change-Id: Ic8966ad5360c8a499649fdb16e242286640fd992
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
7 files changed
tree: b61769e4756a3500a7ccc1fe9399b7de0af4d47c
  1. .github/
  2. adbbu/
  3. applypatch/
  4. attr/
  5. bmlutils/
  6. boot_control/
  7. bootloader_message/
  8. bootloader_message_twrp/
  9. crypto/
  10. dosfstools/
  11. edify/
  12. etc/
  13. exfat/
  14. fb2png/
  15. flashutils/
  16. fonts/
  17. fuse/
  18. gpt/
  19. gui/
  20. htcdumlock/
  21. injecttwrp/
  22. libblkid/
  23. libcrecovery/
  24. libmincrypt/
  25. libpixelflinger/
  26. libtar/
  27. minadbd/
  28. minadbd21/
  29. minui/
  30. minui21/
  31. minuitwrp/
  32. minzip/
  33. mmcutils/
  34. mtdutils/
  35. mtp/
  36. openaes/
  37. orscmd/
  38. otafault/
  39. otautil/
  40. pigz/
  41. prebuilt/
  42. private/
  43. res/
  44. res-hdpi/
  45. res-mdpi/
  46. res-xhdpi/
  47. res-xxhdpi/
  48. res-xxxhdpi/
  49. scripts/
  50. sepolicy/
  51. simg2img/
  52. tests/
  53. toolbox/
  54. tools/
  55. toybox/
  56. twrpDigest/
  57. twrpTarMain/
  58. uncrypt/
  59. update_verifier/
  60. updater/
  61. verifier24/
  62. .clang-format
  63. .gitignore
  64. adb_install.cpp
  65. adb_install.h
  66. Android.bp
  67. Android.mk
  68. asn1_decoder.cpp
  69. asn1_decoder.h
  70. BasePartition.cpp
  71. bootloader.h
  72. CleanSpec.mk
  73. common.h
  74. data.cpp
  75. data.hpp
  76. default_device.cpp
  77. device.cpp
  78. device.h
  79. exclude.cpp
  80. exclude.hpp
  81. find_file.cpp
  82. find_file.hpp
  83. fixContexts.cpp
  84. fixContexts.hpp
  85. fuse.h
  86. fuse_sdcard_provider.cpp
  87. fuse_sdcard_provider.h
  88. fuse_sideload.cpp
  89. fuse_sideload.h
  90. fuse_sideload22.cpp
  91. fuse_sideload22.h
  92. infomanager.cpp
  93. infomanager.hpp
  94. install.cpp
  95. install.h
  96. installcommand.cpp
  97. installcommand.h
  98. interlace-frames.py
  99. legacy_properties.h
  100. legacy_property_service.cpp
  101. legacy_property_service.h
  102. mounts.c
  103. mounts.cpp
  104. mounts.h
  105. mounts.h~HEAD
  106. NOTICE
  107. openrecoveryscript.cpp
  108. openrecoveryscript.hpp
  109. OWNERS
  110. partition.cpp
  111. partitionmanager.cpp
  112. partitions.hpp
  113. PREUPLOAD.cfg
  114. progresstracking.cpp
  115. progresstracking.hpp
  116. README.md
  117. recovery-persist.cpp
  118. recovery-persist.rc
  119. recovery-refresh.cpp
  120. recovery-refresh.rc
  121. recovery.cpp
  122. recovery_ui.h
  123. roots.cpp
  124. roots.h
  125. rotate_logs.cpp
  126. rotate_logs.h
  127. screen_ui.cpp
  128. screen_ui.h
  129. set_metadata.cpp
  130. set_metadata.h
  131. stub_ui.h
  132. tarWrite.c
  133. tarWrite.h
  134. tw_atomic.cpp
  135. tw_atomic.hpp
  136. twcommon.h
  137. twinstall.cpp
  138. twinstall.h
  139. twinstallorig.cpp
  140. twinstallorig.h
  141. twrp-functions.cpp
  142. twrp-functions.hpp
  143. twrp.cpp
  144. twrpAdbBuFifo.cpp
  145. twrpAdbBuFifo.hpp
  146. twrpDigestDriver.cpp
  147. twrpDigestDriver.hpp
  148. twrpTar.cpp
  149. twrpTar.h
  150. twrpTar.hpp
  151. ui.cpp
  152. ui.h
  153. variables.h
  154. verifier.cpp
  155. verifier.h
  156. vr_device.cpp
  157. vr_ui.cpp
  158. vr_ui.h
  159. wear_device.cpp
  160. wear_ui.cpp
  161. wear_ui.h
  162. zipwrap.cpp
  163. zipwrap.hpp
README.md

Team Win Recovery Project (TWRP)

You can find a compiling guide here.