Merge "libexternal: fix mode selection"
diff --git a/common.mk b/common.mk
index b48a38c..3fb003b 100644
--- a/common.mk
+++ b/common.mk
@@ -37,8 +37,12 @@
 
 # Executed only on QCOM BSPs
 ifeq ($(TARGET_USES_QCOM_BSP),true)
+# On jb_mr2- dont enable QCOM Display features
+ifneq ($(call is-platform-sdk-version-at-least,18),true)
 # This flag is used to compile out any features that depend on framework changes
     common_flags += -DQCOM_BSP
+    common_flags += -DANDROID_JELLYBEAN_MR1=1
+endif
 endif
 ifeq ($(call is-vendor-board-platform,QCOM),true)
 # This check is to pick the kernel headers from the right location.
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 0e7576e..1f757bc 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -26,7 +26,6 @@
 #include "memalloc.h"
 #include "alloc_controller.h"
 #include <qdMetaData.h>
-#include "mdp_version.h"
 
 using namespace gralloc;
 
@@ -69,11 +68,13 @@
         data.align = getpagesize();
 
     /* force 1MB alignment selectively for secure buffers, MDP5 onwards */
-    if ((qdutils::MDPVersion::getInstance().getMDPVersion() >= \
-         qdutils::MDSS_V5) && (usage & GRALLOC_USAGE_PROTECTED)) {
+#ifdef MDSS_TARGET
+    if (usage & GRALLOC_USAGE_PROTECTED) {
         data.align = ALIGN(data.align, SZ_1M);
         size = ALIGN(size, data.align);
     }
+#endif
+
     data.size = size;
     data.pHandle = (unsigned int) pHandle;
     err = mAllocCtrl->allocate(data, usage);
@@ -105,16 +106,15 @@
 
         if (bufferType == BUFFER_TYPE_VIDEO) {
             if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) {
-                if ((qdutils::MDPVersion::getInstance().getMDPVersion() <
-                     qdutils::MDSS_V5)) { //A-Family
-                    flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
-                } else {
+#ifndef MDSS_TARGET
+                flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
+#else
                     if (usage & (GRALLOC_USAGE_HW_TEXTURE |
                                  GRALLOC_USAGE_HW_VIDEO_ENCODER))
                         flags |= private_handle_t::PRIV_FLAGS_ITU_R_709;
                     else if (usage & GRALLOC_USAGE_HW_CAMERA_ZSL)
                         flags |= private_handle_t::PRIV_FLAGS_ITU_R_601_FR;
-                }
+#endif
             } else {
                 flags |= private_handle_t::PRIV_FLAGS_ITU_R_601;
             }
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 5a32975..10d372a 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -222,16 +222,17 @@
             pthread_mutex_unlock(lock);
         }
         *vaddr = (void*)hnd->base;
-        //Invalidate if reading in software. No need to do this for the metadata
-        //buffer as it is only read/written in software.
-        IMemAlloc* memalloc = getAllocator(hnd->flags) ;
-        err = memalloc->clean_buffer((void*)hnd->base,
-                                     hnd->size, hnd->offset, hnd->fd,
-                                     CACHE_INVALIDATE);
-        if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) &&
-            !(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
-            // Mark the buffer to be flushed after cpu read/write
-            hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
+        if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
+            //Invalidate if reading in software. No need to do this for the
+            //metadata buffer as it is only read/written in software.
+            IMemAlloc* memalloc = getAllocator(hnd->flags) ;
+            err = memalloc->clean_buffer((void*)hnd->base,
+                                         hnd->size, hnd->offset, hnd->fd,
+                                         CACHE_INVALIDATE);
+            if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
+                // Mark the buffer to be flushed after cpu read/write
+                hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
+            }
         }
     } else {
         hnd->flags |= private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
@@ -248,19 +249,21 @@
     private_handle_t* hnd = (private_handle_t*)handle;
     IMemAlloc* memalloc = getAllocator(hnd->flags);
 
-    if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
-        err = memalloc->clean_buffer((void*)hnd->base,
-                                     hnd->size, hnd->offset, hnd->fd,
-                                     CACHE_CLEAN_AND_INVALIDATE);
-        hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
-    } else if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
-        hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
-    } else {
-        //Probably a round about way to do this, but this avoids adding new
-        //flags
-        err = memalloc->clean_buffer((void*)hnd->base,
-                                     hnd->size, hnd->offset, hnd->fd,
-                                     CACHE_INVALIDATE);
+    if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
+        if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
+            err = memalloc->clean_buffer((void*)hnd->base,
+                                         hnd->size, hnd->offset, hnd->fd,
+                                         CACHE_CLEAN_AND_INVALIDATE);
+            hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
+        } else if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
+            hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
+        } else {
+            //Probably a round about way to do this, but this avoids adding new
+            //flags
+            err = memalloc->clean_buffer((void*)hnd->base,
+                                         hnd->size, hnd->offset, hnd->fd,
+                                         CACHE_INVALIDATE);
+        }
     }
 
     return err;
diff --git a/liboverlay/overlayMdp.cpp b/liboverlay/overlayMdp.cpp
index 71e7e5b..61bfb19 100644
--- a/liboverlay/overlayMdp.cpp
+++ b/liboverlay/overlayMdp.cpp
@@ -29,10 +29,12 @@
         return ((int)(f1*100) == (int)(f2*100)) ? true : false;
 }
 
-//Since this is unavailable on Android, defining it in terms of base 10
+#ifdef ANDROID_JELLYBEAN_MR1
+//Since this is unavailable on Android 4.2.2, defining it in terms of base 10
 static inline float log2f(const float& x) {
     return log(x) / log(2);
 }
+#endif
 
 namespace ovutils = overlay::utils;
 namespace overlay {