minui: Use runtime properties instead of build time vars.

This CL removes the use of the following build time macros, and uses the
runtime property values instead.
- TARGET_RECOVERY_PIXEL_FORMAT
- TARGET_RECOVERY_OVERSCAN_PERCENT
- TARGET_RECOVERY_DEFAULT_ROTATION

Bug: 110380063
Test: Set up taimen with `TARGET_RECOVERY_DEFAULT_ROTATION := ROTATION_LEFT`.
      Build and check recovery UI.
Test: Set up taimen with `TARGET_RECOVERY_PIXEL_FORMAT := ABGR_8888`.
      Build and check recovery UI.
Change-Id: I4439556a03fde4805a18011ef72eff1373f31d47
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 9df058e..4fe0fdc 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -23,6 +23,8 @@
 
 #include <memory>
 
+#include <android-base/properties.h>
+
 #include "graphics_adf.h"
 #include "graphics_drm.h"
 #include "graphics_fbdev.h"
@@ -31,7 +33,6 @@
 static GRFont* gr_font = nullptr;
 static MinuiBackend* gr_backend = nullptr;
 
-static int overscan_percent = OVERSCAN_PERCENT;
 static int overscan_offset_x = 0;
 static int overscan_offset_y = 0;
 
@@ -41,6 +42,7 @@
 // gr_draw is owned by backends.
 static const GRSurface* gr_draw = nullptr;
 static GRRotation rotation = GRRotation::NONE;
+static PixelFormat pixel_format = PixelFormat::UNKNOWN;
 
 static bool outside(int x, int y) {
   auto swapped = (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT);
@@ -52,6 +54,10 @@
   return gr_font;
 }
 
+PixelFormat gr_pixel_format() {
+  return pixel_format;
+}
+
 int gr_measure(const GRFont* font, const char* s) {
   if (font == nullptr) {
     return -1;
@@ -203,11 +209,11 @@
 
 void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
   uint32_t r32 = r, g32 = g, b32 = b, a32 = a;
-#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
-  gr_current = (a32 << 24) | (r32 << 16) | (g32 << 8) | b32;
-#else
-  gr_current = (a32 << 24) | (b32 << 16) | (g32 << 8) | r32;
-#endif
+  if (pixel_format == PixelFormat::ABGR || pixel_format == PixelFormat::BGRA) {
+    gr_current = (a32 << 24) | (r32 << 16) | (g32 << 8) | b32;
+  } else {
+    gr_current = (a32 << 24) | (b32 << 16) | (g32 << 8) | r32;
+  }
 }
 
 void gr_clear() {
@@ -335,6 +341,18 @@
 }
 
 int gr_init() {
+  // pixel_format needs to be set before loading any resources or initializing backends.
+  std::string format = android::base::GetProperty("ro.recovery.ui.pixel_format", "");
+  if (format == "ABGR_8888") {
+    pixel_format = PixelFormat::ABGR;
+  } else if (format == "RGBX_8888") {
+    pixel_format = PixelFormat::RGBX;
+  } else if (format == "BGRA_8888") {
+    pixel_format = PixelFormat::BGRA;
+  } else {
+    pixel_format = PixelFormat::UNKNOWN;
+  }
+
   int ret = gr_init_font("font", &gr_font);
   if (ret != 0) {
     printf("Failed to init font: %d, continuing graphic backend initialization without font file\n",
@@ -360,6 +378,7 @@
 
   gr_backend = backend.release();
 
+  int overscan_percent = android::base::GetIntProperty("ro.recovery.ui.overscan_percent", 0);
   overscan_offset_x = gr_draw->width * overscan_percent / 100;
   overscan_offset_y = gr_draw->height * overscan_percent / 100;
 
@@ -370,17 +389,15 @@
     return -1;
   }
 
-#define __STRINGIFY(x) #x
-#define STRINGIFY(x) __STRINGIFY(x)
-
-  std::string rotation_str(STRINGIFY(DEFAULT_ROTATION));
+  std::string rotation_str =
+      android::base::GetProperty("ro.recovery.ui.default_rotation", "ROTATION_NONE");
   if (rotation_str == "ROTATION_RIGHT") {
     gr_rotate(GRRotation::RIGHT);
   } else if (rotation_str == "ROTATION_DOWN") {
     gr_rotate(GRRotation::DOWN);
   } else if (rotation_str == "ROTATION_LEFT") {
     gr_rotate(GRRotation::LEFT);
-  } else {  // "ROTATION_NONE"
+  } else {  // "ROTATION_NONE" or unknown string
     gr_rotate(GRRotation::NONE);
   }