hwc: Add non-zero checks. Move warning log.

Add check for presence of non-zero number of layers.
Move the "composition after powerdown" log under that check.
Move the caching of dpy under list non-null check.

Change-Id: I99b9293e671a15ba1fb31692e30413d2bbd97867
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 15b712c..86771bd 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -81,19 +81,18 @@
     hwc_context_t* ctx = (hwc_context_t*)(dev);
     ctx->overlayInUse = false;
 
-    if(ctx->isPoweredDown) {
-        ALOGW("SurfaceFlinger called %s after a POWERDOWN", __FUNCTION__);
-    }
-
-    for (uint32_t i = 0; i <numDisplays; i++) {
-        hwc_display_contents_1_t* list = displays[i];
-        ctx->dpys[i] = list->dpy;
+    for (uint32_t i = 0; i < numDisplays; i++) {
+        hwc_display_contents_1_t *list = displays[i];
         //XXX: Actually handle the multiple displays
-        if (LIKELY(list)) {
+        if (LIKELY(list && list->numHwLayers)) {
+            ctx->dpys[i] = list->dpy;
             //reset for this draw round
             VideoOverlay::reset();
             ExtOnly::reset();
 
+            if(ctx->isPoweredDown)
+                ALOGW("SF called %s after a POWERDOWN", __FUNCTION__);
+
             getLayerStats(ctx, list);
             if(VideoOverlay::prepare(ctx, list)) {
                 ctx->overlayInUse = true;