sde: Initialize layer stack based on its usage.

Initialize retire fence for primary/external displays and output buffer
for virtual display.

Change-Id: Id2e628a5265df62f63c92e0414a7d988aac078c1
diff --git a/displayengine/include/core/layer_stack.h b/displayengine/include/core/layer_stack.h
index aa15753..6cae11a 100755
--- a/displayengine/include/core/layer_stack.h
+++ b/displayengine/include/core/layer_stack.h
@@ -217,7 +217,13 @@
   uint32_t layer_count;   //!< Total number of layers.
   LayerStackFlags flags;  //!< Flags associated with this layer set.
 
-  LayerStack() : output_buffer(NULL), layers(NULL), layer_count(0) { }
+  explicit LayerStack(bool need_retire_fence) : layers(NULL), layer_count(0) {
+    if (need_retire_fence) {
+      retire_fence_fd = -1;
+    } else {
+      output_buffer = NULL;
+    }
+  }
 };
 
 }  // namespace sde
diff --git a/displayengine/libs/hwc/hwc_display.cpp b/displayengine/libs/hwc/hwc_display.cpp
index 5e7a637..4fc36dd 100644
--- a/displayengine/libs/hwc/hwc_display.cpp
+++ b/displayengine/libs/hwc/hwc_display.cpp
@@ -34,8 +34,9 @@
 namespace sde {
 
 HWCDisplay::HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type,
-                       int id)
-  : core_intf_(core_intf), hwc_procs_(hwc_procs), type_(type), id_(id), display_intf_(NULL) {
+                       int id, bool need_retire_fence)
+  : core_intf_(core_intf), hwc_procs_(hwc_procs), type_(type), id_(id), display_intf_(NULL),
+    layer_stack_(need_retire_fence), need_retire_fence_(need_retire_fence) {
 }
 
 int HWCDisplay::Init() {
@@ -204,7 +205,7 @@
   uint8_t *current_address = layer_stack_memory_.raw;
 
   // Layer array address
-  layer_stack_ = LayerStack();
+  layer_stack_ = LayerStack(need_retire_fence_);
   layer_stack_.layers = reinterpret_cast<Layer *>(current_address);
   layer_stack_.layer_count = static_cast<uint32_t>(num_hw_layers);
   current_address += num_hw_layers * sizeof(Layer);
diff --git a/displayengine/libs/hwc/hwc_display.h b/displayengine/libs/hwc/hwc_display.h
index 2ad1987..7f90430 100644
--- a/displayengine/libs/hwc/hwc_display.h
+++ b/displayengine/libs/hwc/hwc_display.h
@@ -69,7 +69,8 @@
     LayerStackCache() : layer_count(0) { }
   };
 
-  HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id);
+  HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id,
+             bool need_retire_fence);
   virtual ~HWCDisplay() { }
 
   // DisplayEventHandler methods
@@ -88,14 +89,15 @@
   inline void SetBlending(const int32_t &source, LayerBlending *target);
   inline int SetFormat(const int32_t &source, LayerBufferFormat *target);
 
-  LayerStackMemory layer_stack_memory_;
-  LayerStack layer_stack_;
-  LayerStackCache layer_stack_cache_;
   CoreInterface *core_intf_;
   hwc_procs_t const **hwc_procs_;
   DisplayType type_;
   int id_;
   DisplayInterface *display_intf_;
+  LayerStackMemory layer_stack_memory_;
+  LayerStack layer_stack_;
+  bool need_retire_fence_;
+  LayerStackCache layer_stack_cache_;
 };
 
 }  // namespace sde
diff --git a/displayengine/libs/hwc/hwc_display_external.cpp b/displayengine/libs/hwc/hwc_display_external.cpp
index 894374c..442e241 100644
--- a/displayengine/libs/hwc/hwc_display_external.cpp
+++ b/displayengine/libs/hwc/hwc_display_external.cpp
@@ -32,7 +32,7 @@
 namespace sde {
 
 HWCDisplayExternal::HWCDisplayExternal(CoreInterface *core_intf, hwc_procs_t const **hwc_procs)
-  : HWCDisplay(core_intf, hwc_procs, kHDMI, HWC_DISPLAY_EXTERNAL) {
+  : HWCDisplay(core_intf, hwc_procs, kHDMI, HWC_DISPLAY_EXTERNAL, true) {
 }
 
 int HWCDisplayExternal::Prepare(hwc_display_contents_1_t *content_list) {
@@ -43,8 +43,6 @@
     return status;
   }
 
-  layer_stack_.retire_fence_fd = -1;
-
   status = PrepareLayerStack(content_list);
   if (status) {
     return status;
diff --git a/displayengine/libs/hwc/hwc_display_primary.cpp b/displayengine/libs/hwc/hwc_display_primary.cpp
index 41e657e..dc98913 100644
--- a/displayengine/libs/hwc/hwc_display_primary.cpp
+++ b/displayengine/libs/hwc/hwc_display_primary.cpp
@@ -32,7 +32,7 @@
 namespace sde {
 
 HWCDisplayPrimary::HWCDisplayPrimary(CoreInterface *core_intf, hwc_procs_t const **hwc_procs)
-  : HWCDisplay(core_intf, hwc_procs, kPrimary, HWC_DISPLAY_PRIMARY) {
+  : HWCDisplay(core_intf, hwc_procs, kPrimary, HWC_DISPLAY_PRIMARY, true) {
 }
 
 int HWCDisplayPrimary::Prepare(hwc_display_contents_1_t *content_list) {
@@ -43,8 +43,6 @@
     return status;
   }
 
-  layer_stack_.retire_fence_fd = -1;
-
   status = PrepareLayerStack(content_list);
   if (status) {
     return status;
diff --git a/displayengine/libs/hwc/hwc_display_virtual.cpp b/displayengine/libs/hwc/hwc_display_virtual.cpp
index 3ac2376..6420b5a 100755
--- a/displayengine/libs/hwc/hwc_display_virtual.cpp
+++ b/displayengine/libs/hwc/hwc_display_virtual.cpp
@@ -32,7 +32,7 @@
 namespace sde {
 
 HWCDisplayVirtual::HWCDisplayVirtual(CoreInterface *core_intf, hwc_procs_t const **hwc_procs)
-  : HWCDisplay(core_intf, hwc_procs, kVirtual, HWC_DISPLAY_VIRTUAL) {
+  : HWCDisplay(core_intf, hwc_procs, kVirtual, HWC_DISPLAY_VIRTUAL, false) {
 }
 
 int HWCDisplayVirtual::Init() {