Merge "hwc: Unblank primary display on bootup."
diff --git a/libcopybit/Android.mk b/libcopybit/Android.mk
index 73bfa86..b125f11 100644
--- a/libcopybit/Android.mk
+++ b/libcopybit/Android.mk
@@ -35,5 +35,9 @@
             LOCAL_SRC_FILES := software_converter.cpp copybit.cpp
             include $(BUILD_SHARED_LIBRARY)
         endif
+        ifeq ($(call is-board-platform-in-list,msm8610),true)
+            LOCAL_SRC_FILES := software_converter.cpp copybit.cpp
+            include $(BUILD_SHARED_LIBRARY)
+        endif
     endif
 endif
diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp
index ed302f1..43b90d1 100644
--- a/libcopybit/copybit.cpp
+++ b/libcopybit/copybit.cpp
@@ -42,15 +42,8 @@
 
 /******************************************************************************/
 
-#if defined(COPYBIT_MSM7K)
 #define MAX_SCALE_FACTOR    (4)
 #define MAX_DIMENSION       (4096)
-#elif defined(COPYBIT_QSD8K)
-#define MAX_SCALE_FACTOR    (8)
-#define MAX_DIMENSION       (2048)
-#else
-#error "Unsupported MDP version"
-#endif
 
 /******************************************************************************/
 
@@ -394,6 +387,7 @@
             struct mdp_blit_req req[12];
         } list;
 
+        memset(&list, 0, sizeof(list));
         if (ctx->mAlpha < 255) {
             switch (src->format) {
                 // we don't support plane alpha with RGBA formats
@@ -428,7 +422,7 @@
 
         if(src->format ==  HAL_PIXEL_FORMAT_YV12) {
             int usage =
-            GRALLOC_USAGE_PRIVATE_CAMERA_HEAP|GRALLOC_USAGE_PRIVATE_UNCACHED;
+            GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | GRALLOC_USAGE_PRIVATE_UNCACHED;
             if (0 == alloc_buffer(&yv12_handle,src->w,src->h,
                                   src->format, usage)){
                 if(0 == convertYV12toYCrCb420SP(src,yv12_handle)){
@@ -509,6 +503,7 @@
 static int finish_copybit(struct copybit_device_t *dev)
 {
     // NOP for MDP copybit
+    return 0;
 }
 
 /*****************************************************************************/
@@ -524,6 +519,11 @@
     return 0;
 }
 
+static int flush_get_fence(struct copybit_device_t *dev, int* fd)
+{
+    return -1;
+}
+
 /** Open a new instance of a copybit device using name */
 static int open_copybit(const struct hw_module_t* module, const char* name,
                         struct hw_device_t** device)
@@ -542,6 +542,7 @@
     ctx->device.blit = blit_copybit;
     ctx->device.stretch = stretch_copybit;
     ctx->device.finish = finish_copybit;
+    ctx->device.flush_get_fence = flush_get_fence;
     ctx->mAlpha = MDP_ALPHA_NOP;
     ctx->mFlags = 0;
     ctx->mFD = open("/dev/graphics/fb0", O_RDWR, 0);
@@ -551,25 +552,8 @@
               status, strerror(status));
         status = -status;
     } else {
-        struct fb_fix_screeninfo finfo;
-        if (ioctl(ctx->mFD, FBIOGET_FSCREENINFO, &finfo) == 0) {
-            if (strncmp(finfo.id, "msmfb", 5) == 0) {
-                /* Success */
-                status = 0;
-            } else {
-                ALOGE("Error not msm frame buffer");
-                status = -EINVAL;
-            }
-        } else {
-            ALOGE("Error executing ioctl for screen info");
-            status = -errno;
-        }
-    }
-
-    if (status == 0) {
+        status = 0;
         *device = &ctx->device.common;
-    } else {
-        close_copybit(&ctx->device.common);
     }
     return status;
 }
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 677bb4e..bcae381 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -182,6 +182,12 @@
 IonController::IonController()
 {
     mIonAlloc = new IonAlloc();
+    mUseTZProtection = false;
+    char property[PROPERTY_VALUE_MAX];
+    if ((property_get("persist.gralloc.cp.level3", property, NULL) <= 0) ||
+                            (atoi(property) != 1)) {
+        mUseTZProtection = true;
+    }
 }
 
 int IonController::allocate(alloc_data& data, int usage)
@@ -201,26 +207,28 @@
     if(usage & GRALLOC_USAGE_PRIVATE_IOMMU_HEAP)
         ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
 
-    //MM Heap is exclusively a secure heap.
-    if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
-        //XXX: Right now the MM heap is the only secure heap we have. When we
-        //have other secure heaps, we can change this.
-        if(usage & GRALLOC_USAGE_PROTECTED) {
+    if(usage & GRALLOC_USAGE_PROTECTED) {
+        if ((mUseTZProtection) && (usage & GRALLOC_USAGE_PRIVATE_MM_HEAP)) {
             ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID);
             ionFlags |= ION_SECURE;
-        }
-        else {
-            ALOGW("GRALLOC_USAGE_PRIVATE_MM_HEAP \
-                  cannot be used as an insecure heap!\
-                  trying to use IOMMU instead !!");
+        } else {
+            // for targets/OEMs which do not need HW level protection
+            // do not set ion secure flag & MM heap. Fallback to IOMMU heap.
             ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
         }
+    } else if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP) {
+        //MM Heap is exclusively a secure heap.
+        //If it is used for non secure cases, fallback to IOMMU heap
+        ALOGW("GRALLOC_USAGE_PRIVATE_MM_HEAP \
+                                cannot be used as an insecure heap!\
+                                trying to use IOMMU instead !!");
+        ionFlags |= ION_HEAP(ION_IOMMU_HEAP_ID);
     }
 
     if(usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP)
         ionFlags |= ION_HEAP(ION_ADSP_HEAP_ID);
 
-    if(usage & GRALLOC_USAGE_PROTECTED)
+    if(ionFlags & ION_SECURE)
          data.allocType |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER;
 
     // if no flags are set, default to
diff --git a/libgralloc/alloc_controller.h b/libgralloc/alloc_controller.h
index 5fe81fa..8954d39 100644
--- a/libgralloc/alloc_controller.h
+++ b/libgralloc/alloc_controller.h
@@ -65,6 +65,7 @@
 
     private:
     IonAlloc* mIonAlloc;
+    bool mUseTZProtection;
 
 };
 } //end namespace gralloc
diff --git a/libgralloc/gralloc.cpp b/libgralloc/gralloc.cpp
index 3bb5533..2567300 100644
--- a/libgralloc/gralloc.cpp
+++ b/libgralloc/gralloc.cpp
@@ -80,7 +80,6 @@
     lock: gralloc_lock,
     unlock: gralloc_unlock,
     perform: gralloc_perform,
-    reserved_proc: {0},
       },
 framebuffer: 0,
 fbFormat: 0,
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index cdcd247..a2ccb12 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -144,13 +144,10 @@
             if(fbZOrder >= 0)
                 ctx->mFBUpdate[dpy]->prepare(ctx, list, fbZOrder);
 
-            /* Temporarily commenting out C2D until we support partial
-               copybit composition for mixed mode MDP
-
-            // Use Copybit, when MDP comp fails
-            if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
-                ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
-            */
+            if (ctx->mMDP.version < qdutils::MDP_V4_0) {
+                if((fbZOrder >= 0) && ctx->mCopyBit[dpy])
+                    ctx->mCopyBit[dpy]->prepare(ctx, list, dpy);
+            }
         }
     }
     return 0;
diff --git a/libhwcomposer/hwc_copybit.cpp b/libhwcomposer/hwc_copybit.cpp
index f1bf756..8589204 100644
--- a/libhwcomposer/hwc_copybit.cpp
+++ b/libhwcomposer/hwc_copybit.cpp
@@ -21,6 +21,7 @@
 #define DEBUG_COPYBIT 0
 #include <copybit.h>
 #include <utils/Timers.h>
+#include <mdp_version.h>
 #include "hwc_copybit.h"
 #include "comptype.h"
 #include "gr.h"
@@ -120,7 +121,9 @@
     //Calculates total rendering area for RGB layers
     unsigned int renderArea = 0;
     unsigned int w=0, h=0;
-    for (unsigned int i=0; i<list->numHwLayers; i++) {
+    // Skipping last layer since FrameBuffer layer should not affect
+    // which composition to choose
+    for (unsigned int i=0; i<list->numHwLayers -1; i++) {
          private_handle_t *hnd = (private_handle_t *)list->hwLayers[i].handle;
          if (hnd) {
              if (BUFFER_TYPE_UI == hnd->bufferType) {
@@ -249,11 +252,13 @@
         mRelFd[0] = -1;
     }
 
-    //Clear the visible region on the render buffer
-    //XXX: Do this only when needed.
-    hwc_rect_t clearRegion;
-    getNonWormholeRegion(list, clearRegion);
-    clear(renderBuffer, clearRegion);
+    if (ctx->mMDP.version >= qdutils::MDP_V4_0) {
+        //Clear the visible region on the render buffer
+        //XXX: Do this only when needed.
+        hwc_rect_t clearRegion;
+        getNonWormholeRegion(list, clearRegion);
+        clear(renderBuffer, clearRegion);
+    }
     // numAppLayers-1, as we iterate from 0th layer index with HWC_COPYBIT flag
     for (int i = 0; i <= (ctx->listStats[dpy].numAppLayers-1); i++) {
         hwc_layer_1_t *layer = &list->hwLayers[i];
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 4cfcc63..b33b744 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -767,10 +767,12 @@
         qdutils::MDSS_V5) {
         uint32_t crop_w = (crop.right - crop.left);
         uint32_t crop_h = (crop.bottom - crop.top);
-        ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
-        ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
-        crop.right = crop.left + crop_w;
-        crop.bottom = crop.top + crop_h;
+        if (ovutils::isYuv(whf.format)) {
+            ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
+            ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
+            crop.right = crop.left + crop_w;
+            crop.bottom = crop.top + crop_h;
+        }
         Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
         rot->setCrop(rotCrop);
     }
@@ -1070,6 +1072,8 @@
             ctx->mExtDisplay->isExternalConnected()) {
         return false;
     }
+    if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
+        return false;
     return true;
 }