Fix Droid and animation color in recovery mode

[Problem]
Droid and animation color in recovery mode are incorrect

[Modify]
- Add support for flipping (zero copy) with RECOVERY_ABGR.
- Decodes PNG files to BGRA directly, and other fills, text and alpha blending are also done directly in BGRA (i.e. blits can still bypass conversion)
- Remove the BGRA workaround added previous for single buffer mode (f766396)

Bug:19216535
Change-Id: Ie864419fc6da776ff58b2d02e130f203c194500f
Signed-off-by: Tony Kuo <tony.kuo@mediatek.com>
diff --git a/minui/Android.mk b/minui/Android.mk
index aee2a34..ddee165 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -16,6 +16,9 @@
 # ordinary characters in this context).  Strip double-quotes from the
 # value so that either will work.
 
+ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),ABGR_8888)
+  LOCAL_CFLAGS += -DRECOVERY_ABGR
+endif
 ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBX_8888)
   LOCAL_CFLAGS += -DRECOVERY_RGBX
 endif
diff --git a/minui/graphics.c b/minui/graphics.c
index ec39433..870ffa0 100644
--- a/minui/graphics.c
+++ b/minui/graphics.c
@@ -161,10 +161,17 @@
 
 void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 {
+#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
+    gr_current_r = b;
+    gr_current_g = g;
+    gr_current_b = r;
+    gr_current_a = a;
+#else
     gr_current_r = r;
     gr_current_g = g;
     gr_current_b = b;
     gr_current_a = a;
+#endif
 }
 
 void gr_clear()
diff --git a/minui/graphics_adf.c b/minui/graphics_adf.c
index 289c3be..c023d4d 100644
--- a/minui/graphics_adf.c
+++ b/minui/graphics_adf.c
@@ -142,7 +142,9 @@
     ssize_t n_dev_ids, i;
     gr_surface ret;
 
-#if defined(RECOVERY_BGRA)
+#if defined(RECOVERY_ABGR)
+    pdata->format = DRM_FORMAT_ABGR8888;
+#elif defined(RECOVERY_BGRA)
     pdata->format = DRM_FORMAT_BGRA8888;
 #elif defined(RECOVERY_RGBX)
     pdata->format = DRM_FORMAT_RGBX8888;
diff --git a/minui/graphics_fbdev.c b/minui/graphics_fbdev.c
index a087899..ecd40c3 100644
--- a/minui/graphics_fbdev.c
+++ b/minui/graphics_fbdev.c
@@ -187,21 +187,8 @@
         set_displayed_framebuffer(1-displayed_buffer);
     } else {
         // Copy from the in-memory surface to the framebuffer.
-
-#if defined(RECOVERY_BGRA)
-        unsigned int idx;
-        unsigned char* ucfb_vaddr = (unsigned char*)gr_framebuffer[0].data;
-        unsigned char* ucbuffer_vaddr = (unsigned char*)gr_draw->data;
-        for (idx = 0 ; idx < (gr_draw->height * gr_draw->row_bytes); idx += 4) {
-            ucfb_vaddr[idx    ] = ucbuffer_vaddr[idx + 2];
-            ucfb_vaddr[idx + 1] = ucbuffer_vaddr[idx + 1];
-            ucfb_vaddr[idx + 2] = ucbuffer_vaddr[idx    ];
-            ucfb_vaddr[idx + 3] = ucbuffer_vaddr[idx + 3];
-        }
-#else
         memcpy(gr_framebuffer[0].data, gr_draw->data,
                gr_draw->height * gr_draw->row_bytes);
-#endif
     }
     return gr_draw;
 }
diff --git a/minui/resources.c b/minui/resources.c
index f645c4b..886c325 100644
--- a/minui/resources.c
+++ b/minui/resources.c
@@ -216,6 +216,10 @@
         goto exit;
     }
 
+#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
+    png_set_bgr(png_ptr);
+#endif
+
     unsigned char* p_row = malloc(width * 4);
     unsigned int y;
     for (y = 0; y < height; ++y) {
@@ -279,6 +283,10 @@
         }
     }
 
+#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
+    png_set_bgr(png_ptr);
+#endif
+
     unsigned char* p_row = malloc(width * 4);
     unsigned int y;
     for (y = 0; y < height; ++y) {
@@ -334,6 +342,10 @@
     surface->row_bytes = width;
     surface->pixel_bytes = 1;
 
+#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA)
+    png_set_bgr(png_ptr);
+#endif
+
     unsigned char* p_row;
     unsigned int y;
     for (y = 0; y < height; ++y) {