Merge "liboverlay: define log2f only for jb_mr1"
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;