Update minui to support overlay graphics

Fix path in minuitwrp for includes

Change-Id: I9e9e5f67e8574cdcbc6f8873ceeb56eab71143ed
diff --git a/minui/Android.mk b/minui/Android.mk
index 704e541..e8c1b9c 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -1,7 +1,7 @@
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := events.c resources.c
+LOCAL_SRC_FILES := graphics_overlay.c events.c resources.c
 ifneq ($(BOARD_CUSTOM_GRAPHICS),)
   LOCAL_SRC_FILES += $(BOARD_CUSTOM_GRAPHICS)
 else
@@ -11,6 +11,19 @@
 LOCAL_C_INCLUDES +=\
     external/libpng\
     external/zlib
+
+ifeq ($(TW_TARGET_USES_QCOM_BSP), true)
+  LOCAL_CFLAGS += -DMSM_BSP
+  ifeq ($(TARGET_PREBUILT_KERNEL),)
+    LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+    LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+  else
+    LOCAL_C_INCLUDES += bootable/recovery/minui/include
+  endif
+else
+  LOCAL_C_INCLUDES += bootable/recovery/minui/include
+endif
+
 LOCAL_STATIC_LIBRARY := libpng
 LOCAL_MODULE := libminui
 
@@ -44,3 +57,65 @@
 endif
 
 include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := graphics_overlay.c events.c resources.c
+ifneq ($(BOARD_CUSTOM_GRAPHICS),)
+  LOCAL_SRC_FILES += $(BOARD_CUSTOM_GRAPHICS)
+else
+  LOCAL_SRC_FILES += graphics.c
+endif
+
+ifeq ($(TW_TARGET_USES_QCOM_BSP), true)
+  LOCAL_CFLAGS += -DMSM_BSP
+  ifeq ($(TARGET_PREBUILT_KERNEL),)
+    LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+    LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+  else
+    LOCAL_C_INCLUDES += bootable/recovery/minui/include
+  endif
+else
+  LOCAL_C_INCLUDES += bootable/recovery/minui/include
+endif
+
+LOCAL_C_INCLUDES +=\
+    external/libpng\
+    external/zlib
+
+LOCAL_MODULE := libminui
+
+LOCAL_ARM_MODE:= arm
+LOCAL_SHARED_LIBRARIES := libpng libpixelflinger
+# This used to compare against values in double-quotes (which are just
+# ordinary characters in this context).  Strip double-quotes from the
+# value so that either will work.
+
+ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBX_8888)
+  LOCAL_CFLAGS += -DRECOVERY_RGBX
+endif
+ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),BGRA_8888)
+  LOCAL_CFLAGS += -DRECOVERY_BGRA
+endif
+
+ifneq ($(TARGET_RECOVERY_OVERSCAN_PERCENT),)
+  LOCAL_CFLAGS += -DOVERSCAN_PERCENT=$(TARGET_RECOVERY_OVERSCAN_PERCENT)
+else
+  LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0
+endif
+
+ifneq ($(TW_BRIGHTNESS_PATH),)
+  LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=\"$(TW_BRIGHTNESS_PATH)\"
+endif
+ifneq ($(TW_MAX_BRIGHTNESS),)
+  LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=$(TW_MAX_BRIGHTNESS)
+else
+  LOCAL_CFLAGS += -DTW_MAX_BRIGHTNESS=255
+endif
+ifneq ($(TW_NO_SCREEN_BLANK),)
+  LOCAL_CFLAGS += -DTW_NO_SCREEN_BLANK
+endif
+
+LOCAL_CFLAGS += -DFASTMMI_FEATURE
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/minui/graphics.c b/minui/graphics.c
index 00fbb1e..8f95175 100644
--- a/minui/graphics.c
+++ b/minui/graphics.c
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 
@@ -69,6 +70,15 @@
 static struct fb_var_screeninfo vi;
 static struct fb_fix_screeninfo fi;
 
+static bool has_overlay = false;
+
+bool target_has_overlay(char *version);
+int free_ion_mem(void);
+int alloc_ion_mem(unsigned int size);
+int allocate_overlay(int fd, GGLSurface gr_fb[]);
+int free_overlay(int fd);
+int overlay_display_frame(int fd, GGLubyte* data, size_t size);
+
 static int get_framebuffer(GGLSurface *fb)
 {
     int fd;
@@ -127,11 +137,15 @@
         return -1;
     }
 
-    bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-    if (bits == MAP_FAILED) {
-        perror("failed to mmap framebuffer");
-        close(fd);
-        return -1;
+    has_overlay = target_has_overlay(fi.id);
+
+    if (!has_overlay) {
+        bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+        if (bits == MAP_FAILED) {
+            perror("failed to mmap framebuffer");
+            close(fd);
+            return -1;
+        }
     }
 
     overscan_offset_x = vi.xres * overscan_percent / 100;
@@ -141,9 +155,11 @@
     fb->width = vi.xres;
     fb->height = vi.yres;
     fb->stride = fi.line_length/PIXEL_SIZE;
-    fb->data = bits;
     fb->format = PIXEL_FORMAT;
-    memset(fb->data, 0, vi.yres * fi.line_length);
+    if (!has_overlay) {
+        fb->data = bits;
+        memset(fb->data, 0, vi.yres * fi.line_length);
+    }
 
     fb++;
 
@@ -157,9 +173,11 @@
     fb->width = vi.xres;
     fb->height = vi.yres;
     fb->stride = fi.line_length/PIXEL_SIZE;
-    fb->data = (void*) (((unsigned) bits) + vi.yres * fi.line_length);
     fb->format = PIXEL_FORMAT;
-    memset(fb->data, 0, vi.yres * fi.line_length);
+    if (!has_overlay) {
+        fb->data = (void*) (((unsigned) bits) + vi.yres * fi.line_length);
+        memset(fb->data, 0, vi.yres * fi.line_length);
+    }
 
     return fd;
 }
@@ -186,19 +204,22 @@
 
 void gr_flip(void)
 {
-    GGLContext *gl = gr_context;
+    if (-EINVAL == overlay_display_frame(gr_fb_fd, gr_mem_surface.data,
+                                         (fi.line_length * vi.yres))) {
+        GGLContext *gl = gr_context;
 
-    /* swap front and back buffers */
-    if (double_buffering)
-        gr_active_fb = (gr_active_fb + 1) & 1;
+        /* swap front and back buffers */
+        if (double_buffering)
+            gr_active_fb = (gr_active_fb + 1) & 1;
 
-    /* copy data from the in-memory surface to the buffer we're about
-     * to make active. */
-    memcpy(gr_framebuffer[gr_active_fb].data, gr_mem_surface.data,
-           fi.line_length * vi.yres);
+        /* copy data from the in-memory surface to the buffer we're about
+         * to make active. */
+        memcpy(gr_framebuffer[gr_active_fb].data, gr_mem_surface.data,
+               fi.line_length * vi.yres);
 
-    /* inform the display driver */
-    set_active_framebuffer(gr_active_fb);
+        /* inform the display driver */
+        set_active_framebuffer(gr_active_fb);
+    }
 }
 
 void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
@@ -390,12 +411,13 @@
 
     get_memory_surface(&gr_mem_surface);
 
-    printf("framebuffer: fd %d (%d x %d)\n",
-           gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height);
+    fprintf(stderr, "framebuffer: fd %d (%d x %d)\n",
+            gr_fb_fd, gr_framebuffer[0].width, gr_framebuffer[0].height);
 
-        /* start with 0 as front (displayed) and 1 as back (drawing) */
+    /* start with 0 as front (displayed) and 1 as back (drawing) */
     gr_active_fb = 0;
-    set_active_framebuffer(0);
+    if (!has_overlay)
+        set_active_framebuffer(0);
     gl->colorBuffer(gl, &gr_mem_surface);
 
     gl->activeTexture(gl, 0);
@@ -405,11 +427,17 @@
     gr_fb_blank(true);
     gr_fb_blank(false);
 
+    if (!alloc_ion_mem(fi.line_length * vi.yres))
+        allocate_overlay(gr_fb_fd, gr_framebuffer);
+
     return 0;
 }
 
 void gr_exit(void)
 {
+    free_overlay(gr_fb_fd);
+    free_ion_mem();
+
     close(gr_fb_fd);
     gr_fb_fd = -1;
 
@@ -451,9 +479,19 @@
     close(fd);
 #else
     int ret;
+    if (blank)
+        free_overlay(gr_fb_fd);
 
     ret = ioctl(gr_fb_fd, FBIOBLANK, blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK);
     if (ret < 0)
         perror("ioctl(): blank");
+
+    if (!blank)
+        allocate_overlay(gr_fb_fd, gr_framebuffer);
 #endif
 }
+
+void gr_get_memory_surface(gr_surface surface)
+{
+    get_memory_surface( (GGLSurface*) surface);
+}
diff --git a/minui/graphics_overlay.c b/minui/graphics_overlay.c
new file mode 100644
index 0000000..02ef0b9
--- /dev/null
+++ b/minui/graphics_overlay.c
@@ -0,0 +1,311 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#include <linux/fb.h>
+#include <linux/kd.h>
+
+#ifdef MSM_BSP
+#include <linux/msm_mdp.h>
+#include <linux/msm_ion.h>
+#endif
+
+#include <pixelflinger/pixelflinger.h>
+
+#include "minui.h"
+
+#define MDP_V4_0 400
+
+#ifdef MSM_BSP
+#define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1))
+
+typedef struct {
+    unsigned char *mem_buf;
+    int size;
+    int ion_fd;
+    int mem_fd;
+    struct ion_handle_data handle_data;
+} memInfo;
+
+static int overlay_id = MSMFB_NEW_REQUEST;
+static memInfo mem_info;
+
+static int map_mdp_pixel_format()
+{
+    int format = MDP_RGB_565;
+#if defined(RECOVERY_BGRA)
+    format = MDP_BGRA_8888;
+#elif defined(RECOVERY_RGBX)
+    format = MDP_RGBA_8888;
+#endif
+    return format;
+}
+#endif // #ifdef MSM_BSP
+
+static bool overlay_supported = false;
+
+bool target_has_overlay(char *version)
+{
+    int ret;
+    int mdp_version;
+
+    if (strlen(version) >= 8) {
+        if(!strncmp(version, "msmfb", strlen("msmfb"))) {
+            char str_ver[4];
+            memcpy(str_ver, version + strlen("msmfb"), 3);
+            str_ver[3] = '\0';
+            mdp_version = atoi(str_ver);
+            if (mdp_version >= MDP_V4_0) {
+                overlay_supported = true;
+            }
+        } else if (!strncmp(version, "mdssfb", strlen("mdssfb"))) {
+            overlay_supported = true;
+        }
+    }
+
+    return overlay_supported;
+}
+
+#ifdef MSM_BSP
+
+int free_ion_mem(void) {
+    if (!overlay_supported)
+        return -EINVAL;
+
+    int ret = 0;
+
+    if (mem_info.mem_buf)
+        munmap(mem_info.mem_buf, mem_info.size);
+
+    if (mem_info.ion_fd >= 0) {
+        ret = ioctl(mem_info.ion_fd, ION_IOC_FREE, &mem_info.handle_data);
+        if (ret < 0)
+            perror("free_mem failed ");
+    }
+
+    if (mem_info.mem_fd >= 0)
+        close(mem_info.mem_fd);
+    if (mem_info.ion_fd >= 0)
+        close(mem_info.ion_fd);
+
+    memset(&mem_info, 0, sizeof(mem_info));
+    mem_info.mem_fd = -1;
+    mem_info.ion_fd = -1;
+    return 0;
+}
+
+int alloc_ion_mem(unsigned int size)
+{
+    if (!overlay_supported)
+        return -EINVAL;
+    int result;
+    struct ion_fd_data fd_data;
+    struct ion_allocation_data ionAllocData;
+
+    mem_info.ion_fd = open("/dev/ion", O_RDWR|O_DSYNC);
+    if (mem_info.ion_fd < 0) {
+        perror("ERROR: Can't open ion ");
+        return -errno;
+    }
+
+    ionAllocData.flags = 0;
+    ionAllocData.len = size;
+    ionAllocData.align = sysconf(_SC_PAGESIZE);
+    ionAllocData.heap_mask =
+            ION_HEAP(ION_IOMMU_HEAP_ID) |
+            ION_HEAP(ION_SYSTEM_CONTIG_HEAP_ID);
+
+    result = ioctl(mem_info.ion_fd, ION_IOC_ALLOC,  &ionAllocData);
+    if(result){
+        perror("ION_IOC_ALLOC Failed ");
+        close(mem_info.ion_fd);
+        return result;
+    }
+
+    fd_data.handle = ionAllocData.handle;
+    mem_info.handle_data.handle = ionAllocData.handle;
+    result = ioctl(mem_info.ion_fd, ION_IOC_MAP, &fd_data);
+    if (result) {
+        perror("ION_IOC_MAP Failed ");
+        free_ion_mem();
+        return result;
+    }
+    mem_info.mem_buf = (unsigned char *)mmap(NULL, size, PROT_READ |
+                PROT_WRITE, MAP_SHARED, fd_data.fd, 0);
+    mem_info.mem_fd = fd_data.fd;
+
+    if (!mem_info.mem_buf) {
+        perror("ERROR: mem_buf MAP_FAILED ");
+        free_ion_mem();
+        return -ENOMEM;
+    }
+
+    return 0;
+}
+
+int allocate_overlay(int fd, GGLSurface gr_fb[])
+{
+    if (!overlay_supported)
+        return -EINVAL;
+
+    struct mdp_overlay overlay;
+    int ret = 0;
+
+    memset(&overlay, 0 , sizeof (struct mdp_overlay));
+
+    /* Fill Overlay Data */
+
+    overlay.src.width  = ALIGN(gr_fb[0].width, 32);
+    overlay.src.height = gr_fb[0].height;
+    overlay.src.format = map_mdp_pixel_format();
+    overlay.src_rect.w = gr_fb[0].width;
+    overlay.src_rect.h = gr_fb[0].height;
+    overlay.dst_rect.w = gr_fb[0].width;
+    overlay.dst_rect.h = gr_fb[0].height;
+    overlay.alpha = 0xFF;
+    overlay.transp_mask = MDP_TRANSP_NOP;
+    overlay.id = MSMFB_NEW_REQUEST;
+    ret = ioctl(fd, MSMFB_OVERLAY_SET, &overlay);
+    if (ret < 0) {
+        perror("Overlay Set Failed");
+        return ret;
+    }
+
+    overlay_id = overlay.id;
+    return 0;
+}
+
+int free_overlay(int fd)
+{
+    if (!overlay_supported)
+        return -EINVAL;
+
+    int ret = 0;
+    struct mdp_display_commit ext_commit;
+
+    if (overlay_id != MSMFB_NEW_REQUEST) {
+        ret = ioctl(fd, MSMFB_OVERLAY_UNSET, &overlay_id);
+        if (ret) {
+            perror("Overlay Unset Failed");
+            overlay_id = MSMFB_NEW_REQUEST;
+            return ret;
+        }
+
+        memset(&ext_commit, 0, sizeof(struct mdp_display_commit));
+        ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY;
+        ext_commit.wait_for_finish = 1;
+        ret = ioctl(fd, MSMFB_DISPLAY_COMMIT, &ext_commit);
+        if (ret < 0) {
+            perror("ERROR: Clear MSMFB_DISPLAY_COMMIT failed!");
+            overlay_id = MSMFB_NEW_REQUEST;
+            return ret;
+        }
+
+        overlay_id = MSMFB_NEW_REQUEST;
+    }
+    return 0;
+}
+
+int overlay_display_frame(int fd, GGLubyte* data, size_t size)
+{
+    if (!overlay_supported)
+        return -EINVAL;
+    int ret = 0;
+    struct msmfb_overlay_data ovdata;
+    struct mdp_display_commit ext_commit;
+
+    if (overlay_id == MSMFB_NEW_REQUEST) {
+        perror("display_frame failed, no overlay\n");
+        return 0;
+    }
+
+    memcpy(mem_info.mem_buf, data, size);
+
+    memset(&ovdata, 0, sizeof(struct msmfb_overlay_data));
+
+    ovdata.id = overlay_id;
+    ovdata.data.flags = 0;
+    ovdata.data.offset = 0;
+    ovdata.data.memory_id = mem_info.mem_fd;
+    ret = ioctl(fd, MSMFB_OVERLAY_PLAY, &ovdata);
+    if (ret < 0) {
+        perror("overlay_display_frame failed, overlay play Failed\n");
+        return 0;
+    }
+
+    memset(&ext_commit, 0, sizeof(struct mdp_display_commit));
+    ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY;
+    ext_commit.wait_for_finish = 1;
+    ret = ioctl(fd, MSMFB_DISPLAY_COMMIT, &ext_commit);
+    if (ret < 0) {
+        perror("overlay_display_frame failed, overlay commit Failed\n!");
+        return 0;
+    }
+
+    return 0;
+}
+
+#else
+
+int free_ion_mem(void) {
+    return -EINVAL;
+}
+
+int alloc_ion_mem(unsigned int size)
+{
+    return -EINVAL;
+}
+
+int allocate_overlay(int fd, GGLSurface gr_fb[])
+{
+    return -EINVAL;
+}
+
+int free_overlay(int fd)
+{
+    return -EINVAL;
+}
+
+int overlay_display_frame(int fd, GGLubyte* data, size_t size)
+{
+    return -EINVAL;
+}
+
+#endif //#ifdef MSM_BSP
diff --git a/minuitwrp/include/msm_ion.h b/minui/include/linux/msm_ion.h
similarity index 100%
copy from minuitwrp/include/msm_ion.h
copy to minui/include/linux/msm_ion.h
diff --git a/minuitwrp/include/msm_mdp.h b/minui/include/linux/msm_mdp.h
similarity index 100%
copy from minuitwrp/include/msm_mdp.h
copy to minui/include/linux/msm_mdp.h
diff --git a/minui/minui.h b/minui/minui.h
index b8ca40b..103318a 100644
--- a/minui/minui.h
+++ b/minui/minui.h
@@ -46,6 +46,7 @@
  void gr_texticon(int x, int y, gr_surface icon);
 int gr_measure(const char *s);
 void gr_font_size(int *x, int *y);
+void gr_get_memory_surface(gr_surface);
 
 void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy);
 unsigned int gr_get_width(gr_surface surface);
diff --git a/minui/resources.c b/minui/resources.c
index c0a9cca..39f83c7 100644
--- a/minui/resources.c
+++ b/minui/resources.c
@@ -33,7 +33,11 @@
 
 #include "minui.h"
 
+#ifdef FASTMMI_FEATURE
+char *locale = NULL;
+#else
 extern char* locale;
+#endif
 
 // libpng gives "undefined reference to 'pow'" errors, and I have no
 // idea how to convince the build system to link with -lm.  We don't
@@ -93,13 +97,9 @@
     png_set_sig_bytes(png_ptr, sizeof(header));
     png_read_info(png_ptr, info_ptr);
 
-    int color_type, bit_depth;
-    size_t width, height;
-    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
-            &color_type, NULL, NULL, NULL);
-
-    int channels = png_get_channels(png_ptr, info_ptr);
-
+    int color_type = info_ptr->color_type;
+    int bit_depth = info_ptr->bit_depth;
+    int channels = info_ptr->channels;
     if (!(bit_depth == 8 &&
           ((channels == 3 && color_type == PNG_COLOR_TYPE_RGB) ||
            (channels == 4 && color_type == PNG_COLOR_TYPE_RGBA) ||
@@ -109,6 +109,8 @@
         goto exit;
     }
 
+    size_t width = info_ptr->width;
+    size_t height = info_ptr->height;
     size_t stride = (color_type == PNG_COLOR_TYPE_GRAY ? 1 : 4) * width;
     size_t pixelSize = stride * height;
 
@@ -248,11 +250,13 @@
     png_set_sig_bytes(png_ptr, sizeof(header));
     png_read_info(png_ptr, info_ptr);
 
-    int color_type, bit_depth;
-    size_t width, height;
-    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
-            &color_type, NULL, NULL, NULL);
-    int channels = png_get_channels(png_ptr, info_ptr);
+    size_t width = info_ptr->width;
+    size_t height = info_ptr->height;
+    size_t stride = 4 * width;
+
+    int color_type = info_ptr->color_type;
+    int bit_depth = info_ptr->bit_depth;
+    int channels = info_ptr->channels;
 
     if (!(bit_depth == 8 &&
           (channels == 1 && color_type == PNG_COLOR_TYPE_GRAY))) {
diff --git a/minuitwrp/graphics_overlay.c b/minuitwrp/graphics_overlay.c
index a4cf2f9..961ae27 100644
--- a/minuitwrp/graphics_overlay.c
+++ b/minuitwrp/graphics_overlay.c
@@ -43,8 +43,8 @@
 #include <linux/kd.h>
 
 #ifdef MSM_BSP
-#include <msm_mdp.h>
-#include <msm_ion.h>
+#include <linux/msm_mdp.h>
+#include <linux/msm_ion.h>
 #endif
 
 #include <pixelflinger/pixelflinger.h>
diff --git a/minuitwrp/include/msm_ion.h b/minuitwrp/include/linux/msm_ion.h
similarity index 100%
rename from minuitwrp/include/msm_ion.h
rename to minuitwrp/include/linux/msm_ion.h
diff --git a/minuitwrp/include/msm_mdp.h b/minuitwrp/include/linux/msm_mdp.h
similarity index 100%
rename from minuitwrp/include/msm_mdp.h
rename to minuitwrp/include/linux/msm_mdp.h