Update minuitwrp graphics in line with latest minui

Note: events.cpp is still old code renamed to cpp to make it
easier to call functions like gr_fb_width().

I had to modify AOSP fbdev code to provide a separate memory
surface for drawing to as drawing directly to the framebuffer
resulted in rendering taking about 5 times longer.

I also modified AOSP adf code to provide a separate memory surface
for drawing for the same performance reasons. The Nexus 9 supports
adf graphics.

Overlay graphics work on at least one device. Overlay provides a
separate memory buffer already so performance is good.

I do not have a drm device yet that I know of. I made some attempt
to update the drm code to determine the correct pixel format based
on the drm graphics format, but what is available in pixel flinger
and what is available in drm do not line up all that well. Reports
are that the Pixel C is using drm graphics, but performance is
slow, likely due to the use of a mmap instead of a memory buffyer.

Change-Id: Ibd45bccca6ac2cb826037aa9b2aa5065cf683eed
diff --git a/minuitwrp/Android.mk b/minuitwrp/Android.mk
index 01225c3..39c61c4 100644
--- a/minuitwrp/Android.mk
+++ b/minuitwrp/Android.mk
@@ -2,12 +2,20 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := events.c resources.c graphics_overlay.c graphics_utils.c truetype.c
+LOCAL_SRC_FILES := \
+    graphics.cpp \
+    graphics_fbdev.cpp \
+    resources.cpp \
+    graphics_overlay.cpp \
+    truetype.cpp \
+    graphics_utils.cpp \
+    events.cpp
 
 ifneq ($(TW_BOARD_CUSTOM_GRAPHICS),)
-    LOCAL_SRC_FILES += $(TW_BOARD_CUSTOM_GRAPHICS)
-else
-    LOCAL_SRC_FILES += graphics.c
+    $(warning ****************************************************************************)
+    $(warning * TW_BOARD_CUSTOM_GRAPHICS support has been deprecated in TWRP.            *)
+    $(warning ****************************************************************************)
+    $(error stopping)
 endif
 
 ifeq ($(TW_TARGET_USES_QCOM_BSP), true)
@@ -17,25 +25,39 @@
     LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
   else
     ifeq ($(TARGET_CUSTOM_KERNEL_HEADERS),)
-      LOCAL_C_INCLUDES += $(commands_recovery_local_path)/minuitwrp/include
+      LOCAL_C_INCLUDES += $(commands_recovery_local_path)/minui/include
     else
       LOCAL_C_INCLUDES += $(TARGET_CUSTOM_KERNEL_HEADERS)
     endif
   endif
 else
-  LOCAL_C_INCLUDES += $(commands_recovery_local_path)/minuitwrp/include
+  LOCAL_C_INCLUDES += $(commands_recovery_local_path)/minui/include
+  # The header files required for adf graphics can cause compile errors
+  # with adf graphics.
+  ifneq ($(wildcard system/core/adf/Android.mk),)
+    LOCAL_CFLAGS += -DHAS_ADF
+    LOCAL_SRC_FILES += graphics_adf.cpp
+    LOCAL_WHOLE_STATIC_LIBRARIES += libadf
+  endif
 endif
 
 ifeq ($(TW_NEW_ION_HEAP), true)
   LOCAL_CFLAGS += -DNEW_ION_HEAP
 endif
 
+ifneq ($(wildcard external/libdrm/Android.mk),)
+  LOCAL_CFLAGS += -DHAS_DRM
+  LOCAL_SRC_FILES += graphics_drm.cpp
+  LOCAL_WHOLE_STATIC_LIBRARIES += libdrm
+endif
+
 LOCAL_C_INCLUDES += \
     external/libpng \
     external/zlib \
     system/core/include \
     external/jpeg \
-    external/freetype/include
+    external/freetype/include \
+    external/libcxx/include
 
 ifeq ($(RECOVERY_TOUCHSCREEN_SWAP_XY), true)
 LOCAL_CFLAGS += -DRECOVERY_TOUCHSCREEN_SWAP_XY
@@ -76,6 +98,12 @@
   LOCAL_CFLAGS += -DRECOVERY_RGB_565
 endif
 
+ifneq ($(TARGET_RECOVERY_OVERSCAN_PERCENT),)
+  LOCAL_CFLAGS += -DOVERSCAN_PERCENT=$(TARGET_RECOVERY_OVERSCAN_PERCENT)
+else
+  LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0
+endif
+
 ifeq ($(TARGET_RECOVERY_PIXEL_FORMAT),"RGBX_8888")
   LOCAL_CFLAGS += -DRECOVERY_RGBX
 endif
@@ -120,6 +148,8 @@
     $(error stopping)
 endif
 
+LOCAL_CLANG := true
+
 LOCAL_CFLAGS += -DTWRES=\"$(TWRES_PATH)\"
 LOCAL_SHARED_LIBRARIES += libft2 libz libc libcutils libjpeg libpng libutils
 LOCAL_STATIC_LIBRARIES += libpixelflinger_twrp