hwc: more error checks

-- numHwLayers==1 means that there is only the FB_TARGET which HWC shouldn't
   draw. Also check for blank in set.  Checking for this in prepare prevents us
   from acquiring pipes.
-- add null check for private handle
-- print out vsync timestamp data on error

bug: 7274417
related-to-bug: 7288769
Change-Id: I8dae0d0748c5226fdc33ed8f5cc5259835dec2de
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index f5c3013..12c880a 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -87,7 +87,7 @@
         hwc_display_contents_1_t *list) {
     hwc_context_t* ctx = (hwc_context_t*)(dev);
     ctx->overlayInUse[HWC_DISPLAY_PRIMARY] = false;
-    if (LIKELY(list && list->numHwLayers)) {
+    if (LIKELY(list && list->numHwLayers > 1)) {
         uint32_t last = list->numHwLayers - 1;
         hwc_layer_1_t *fblayer = &list->hwLayers[last];
         setListStats(ctx, list, HWC_DISPLAY_PRIMARY);
@@ -108,7 +108,7 @@
     hwc_context_t* ctx = (hwc_context_t*)(dev);
     ctx->overlayInUse[HWC_DISPLAY_EXTERNAL] = false;
 
-    if (LIKELY(list && list->numHwLayers) &&
+    if (LIKELY(list && list->numHwLayers > 1) &&
         ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
         ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
 
@@ -256,7 +256,8 @@
     if(!ctx->overlayInUse[HWC_DISPLAY_PRIMARY])
         ctx->mOverlay[HWC_DISPLAY_PRIMARY]->setState(ovutils::OV_CLOSED);
 
-    if (LIKELY(list && list->numHwLayers)) {
+    if (LIKELY(list && list->numHwLayers > 1) &&
+        ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive) {
         uint32_t last = list->numHwLayers - 1;
         hwc_layer_1_t *fbLayer = &list->hwLayers[last];
 
@@ -280,7 +281,7 @@
     if(!ctx->overlayInUse[HWC_DISPLAY_EXTERNAL])
         ctx->mOverlay[HWC_DISPLAY_EXTERNAL]->setState(ovutils::OV_CLOSED);
 
-    if (LIKELY(list && list->numHwLayers) &&
+    if (LIKELY(list && list->numHwLayers > 1) &&
         ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive &&
         ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected) {
         uint32_t last = list->numHwLayers - 1;