Merge "overlay: Fix min decimation for width outside limits"
diff --git a/displayengine/include/core/display_interface.h b/displayengine/include/core/display_interface.h
index 97f7911..bdeb8a3 100755
--- a/displayengine/include/core/display_interface.h
+++ b/displayengine/include/core/display_interface.h
@@ -94,6 +94,7 @@
   float y_dpi;                //!< Dots per inch in Y-direction.
   float fps;                  //!< Frame rate per second.
   uint32_t vsync_period_ns;   //!< VSync period in nanoseconds.
+  uint32_t v_total;           //!< Total lines in Y-direction (vActive + vFP + vBP + vPulseWidth).
 
   DisplayConfigVariableInfo() : x_pixels(0), y_pixels(0), x_dpi(0.0f), y_dpi(0.0f),
                                fps(0.0f), vsync_period_ns(0) { }
diff --git a/displayengine/include/core/layer_stack.h b/displayengine/include/core/layer_stack.h
index 6cae11a..67a812d 100755
--- a/displayengine/include/core/layer_stack.h
+++ b/displayengine/include/core/layer_stack.h
@@ -95,10 +95,12 @@
 struct LayerFlags {
   uint64_t skip : 1;      //!< This flag shall be set by client to indicate that this layer will be
                           //!< handled by GPU. Display Device will not consider it for composition.
+
   uint64_t updating : 1;  //!< This flag shall be set by client to indicate that this is updating/
                           //!< non-updating. so strategy manager will mark them for SDE/GPU
                           //!< composition respectively when the layer stack qualifies for cache
                           //!< based composition.
+
   LayerFlags() : skip(0), updating(0) { }
 };
 
@@ -111,12 +113,15 @@
   uint64_t geometry_changed : 1;  //!< This flag shall be set by client to indicate that the layer
                                   //!< set passed to Prepare() has changed by more than just the
                                   //!< buffer handles and acquire fences.
+
   uint64_t skip_present : 1;      //!< This flag will be set to true, if the current layer stack
-                                  //!< contains skip layers
+                                  //!< contains skip layers.
+
   uint64_t video_present : 1;     //!< This flag will be set to true, if current layer stack
-                                  //!< contains video
+                                  //!< contains video.
+
   uint64_t secure_present : 1;    //!< This flag will be set to true, if the current layer stack
-                                  //!< contains secure layers
+                                  //!< contains secure layers.
 
   LayerStackFlags() : geometry_changed(0), skip_present(0), video_present(0), secure_present(0) { }
 };
@@ -200,30 +205,24 @@
   @sa DisplayInterface::Commit
 */
 struct LayerStack {
-  union {
-    int retire_fence_fd;          //!< File descriptor referring to a sync fence object which will
-                                  //!< be signaled when this composited frame has been replaced on
-                                  //!< screen by a subsequent frame on a physical display. The fence
-                                  //!< object is created and returned during Commit(). Client shall
-                                  //!< Client shall close the returned file descriptor.
-                                  //!< NOTE: This field applies to a physical display only.
+  Layer *layers;                //!< Array of layers.
+  uint32_t layer_count;         //!< Total number of layers.
 
-    LayerBuffer *output_buffer;   //!< Pointer to the buffer where composed buffer would be rendered
-                                  //!< for virtual displays.
-                                  //!< NOTE: This field applies to a virtual display only.
-  };
+  int retire_fence_fd;          //!< File descriptor referring to a sync fence object which will
+                                //!< be signaled when this composited frame has been replaced on
+                                //!< screen by a subsequent frame on a physical display. The fence
+                                //!< object is created and returned during Commit(). Client shall
+                                //!< Client shall close the returned file descriptor.
+                                //!< NOTE: This field applies to a physical display only.
 
-  Layer *layers;          //!< Array of layers.
-  uint32_t layer_count;   //!< Total number of layers.
-  LayerStackFlags flags;  //!< Flags associated with this layer set.
+  LayerBuffer *output_buffer;   //!< Pointer to the buffer where composed buffer would be rendered
+                                //!< for virtual displays.
+                                //!< NOTE: This field applies to a virtual display only.
 
-  explicit LayerStack(bool need_retire_fence) : layers(NULL), layer_count(0) {
-    if (need_retire_fence) {
-      retire_fence_fd = -1;
-    } else {
-      output_buffer = NULL;
-    }
-  }
+
+  LayerStackFlags flags;        //!< Flags associated with this layer set.
+
+  LayerStack() : layers(NULL), layer_count(0), retire_fence_fd(-1), output_buffer(NULL) { }
 };
 
 }  // namespace sde
diff --git a/displayengine/include/private/strategy_interface.h b/displayengine/include/private/strategy_interface.h
index ee9763e..b56789e 100755
--- a/displayengine/include/private/strategy_interface.h
+++ b/displayengine/include/private/strategy_interface.h
@@ -35,31 +35,31 @@
 
 /*! @brief Strategy library name
 
-    @details This macro defines name for the composition strategy library. This macro shall be used
-    to load library using dlopen().
+  @details This macro defines name for the composition strategy library. This macro shall be used
+  to load library using dlopen().
 
-    @sa CreateStrategyInterface
-    @sa DestoryStrategyInterface
+  @sa CreateStrategyInterface
+  @sa DestoryStrategyInterface
 */
 #define STRATEGY_LIBRARY_NAME "libsdestrategy.so"
 
 /*! @brief Function name to create composer strategy interface
 
-    @details This macro defines function name for CreateStrategyInterface() which is implemented
-    in the composition strategy library. This macro shall be used to specify name of the function
-    in dlsym().
+  @details This macro defines function name for CreateStrategyInterface() which is implemented in
+  the composition strategy library. This macro shall be used to specify name of the function in
+  dlsym().
 
-    @sa CreateStrategyInterface
+  @sa CreateStrategyInterface
 */
 #define CREATE_STRATEGY_INTERFACE_NAME "CreateStrategyInterface"
 
 /*! @brief Function name to destroy composer strategy interface
 
-    @details This macro defines function name for DestroyStrategyInterface() which is implemented
-    in the composition strategy library. This macro shall be used to specify name of the function
-    in dlsym().
+  @details This macro defines function name for DestroyStrategyInterface() which is implemented in
+  the composition strategy library. This macro shall be used to specify name of the function in
+  dlsym().
 
-    @sa DestroyStrategyInterface
+  @sa DestroyStrategyInterface
 */
 #define DESTROY_STRATEGY_INTERFACE_NAME "DestroyStrategyInterface"
 
@@ -82,23 +82,23 @@
 
 /*! @brief Function to create composer strategy interface.
 
-    @details This function is used to create StrategyInterface object which resides in the composer
-    strategy library loaded at runtime.
+  @details This function is used to create StrategyInterface object which resides in the composer
+  strategy library loaded at runtime.
 
-    @param[out] version \link STRATEGY_VERSION_TAG \endlink
-    @param[out] interface \link StrategyInterface \endlink
+  @param[out] version \link STRATEGY_VERSION_TAG \endlink
+  @param[out] interface \link StrategyInterface \endlink
 
-    @return \link DisplayError \endlink
+  @return \link DisplayError \endlink
 */
 typedef DisplayError (*CreateStrategyInterface)(uint16_t version, StrategyInterface **interface);
 
 /*! @brief Function to destroy composer strategy interface.
 
-    @details This function is used to destroy StrategyInterface object.
+  @details This function is used to destroy StrategyInterface object.
 
-    @param[in] interface \link StrategyInterface \endlink
+  @param[in] interface \link StrategyInterface \endlink
 
-    @return \link DisplayError \endlink
+  @return \link DisplayError \endlink
 */
 typedef DisplayError (*DestroyStrategyInterface)(StrategyInterface *interface);
 
@@ -107,9 +107,9 @@
 const int kMaxSDELayers = 16;
 
 /*! @brief This structure defines constraints and display properties that shall be considered for
-    deciding a composition strategy.
+  deciding a composition strategy.
 
-    @sa GetNextStrategy
+  @sa GetNextStrategy
 */
 struct StrategyConstraints {
   bool safe_mode;         //!< In this mode, strategy manager chooses the composition strategy
@@ -123,9 +123,9 @@
 };
 
 /*! @brief This structure encapsulates information about the input layer stack and the layers which
-    shall be programmed on hardware.
+  shall be programmed on hardware.
 
-    @sa GetNextStrategy
+  @sa Start
 */
 struct HWLayersInfo {
   LayerStack *stack;        //!< Input layer stack. Set by the caller.
@@ -136,34 +136,45 @@
 
   uint32_t count;           //!< Total number of layers which need to be set on hardware.
 
-  uint32_t flags;           //!< Strategy flags. Caller must reset it to 0 for a new layer stack.
-                            //!< A non-zero flag value indicates that a strategy has been selected
-                            //!< previously for the current layer stack. This flag must be
-                            //!< preserved between multiple GetNextStrategy() calls.
-
-  HWLayersInfo() {
-    Reset();
-  }
-
-  void Reset() {
-    stack = NULL;
-    count = 0;
-    flags = 0;
-  }
+  HWLayersInfo() : stack(NULL), count(0) { }
 };
 
+/*! @brief Strategy interface.
+
+  @details This class defines Strategy interface. It contains methods which client shall use to
+  determine which strategy to be used for layer composition. This interface is created during
+  display device creation and remains valid until destroyed.
+*/
+
 class StrategyInterface {
  public:
+  /*! @brief Method to indicate start of a new strategy selection iteration for a layer stack.
+
+    @details Client shall call this method at beginning of each draw cycle before iterating
+    through strategy selection. Strategy interface implementation uses this method to do
+    preprocessing for a given layer stack.
+
+    @param[in] layers_info \link HWLayersInfo \endlink
+
+    @return \link DisplayError \endlink
+  */
+  virtual DisplayError Start(HWLayersInfo *hw_layers_info) = 0;
+
+
   /*! @brief Method to get strategy for a layer stack. Caller can loop through this method to try
     get all applicable strategies.
 
     @param[in] constraints \link StrategyConstraints \endlink
-    @param[inout] layers_info \link HWLayersInfo \endlink
 
     @return \link DisplayError \endlink
   */
-  virtual DisplayError GetNextStrategy(StrategyConstraints *constraints,
-                                       HWLayersInfo *hw_layers_info) = 0;
+  virtual DisplayError GetNextStrategy(StrategyConstraints *constraints) = 0;
+
+  /*! @brief Method to indicate end of a strategy selection cycle.
+
+    @return \link DisplayError \endlink
+  */
+  virtual DisplayError Stop() = 0;
 
  protected:
   virtual ~StrategyInterface() { }
diff --git a/displayengine/libs/core/comp_manager.cpp b/displayengine/libs/core/comp_manager.cpp
index e7c52fc..6a9f006 100644
--- a/displayengine/libs/core/comp_manager.cpp
+++ b/displayengine/libs/core/comp_manager.cpp
@@ -27,13 +27,15 @@
 #include <utils/debug.h>
 
 #include "comp_manager.h"
+#include "strategy_default.h"
 
 #define __CLASS__ "CompManager"
 
 namespace sde {
 
-CompManager::CompManager() : strategy_lib_(NULL), strategy_intf_(NULL), registered_displays_(0),
-                             configured_displays_(0), safe_mode_(false) {
+CompManager::CompManager()
+  : strategy_lib_(NULL), create_strategy_intf_(NULL), destroy_strategy_intf_(NULL),
+    registered_displays_(0), configured_displays_(0), safe_mode_(false) {
 }
 
 DisplayError CompManager::Init(const HWResourceInfo &hw_res_info) {
@@ -49,43 +51,40 @@
   // Try to load strategy library & get handle to its interface.
   // Default to GPU only composition on failure.
   strategy_lib_ = ::dlopen(STRATEGY_LIBRARY_NAME, RTLD_NOW);
-  if (!strategy_lib_) {
-    DLOGW("Unable to load = %s", STRATEGY_LIBRARY_NAME);
-  } else {
-    CreateStrategyInterface create_strategy_intf = NULL;
-    void **sym = reinterpret_cast<void **>(&create_strategy_intf);
-    *sym = ::dlsym(strategy_lib_, CREATE_STRATEGY_INTERFACE_NAME);
-    if (!create_strategy_intf) {
-      DLOGW("Unable to find symbol for %s", CREATE_STRATEGY_INTERFACE_NAME);
-    } else if (create_strategy_intf(STRATEGY_VERSION_TAG, &strategy_intf_) != kErrorNone) {
-      DLOGW("Unable to create strategy interface");
-    }
-  }
+  if (strategy_lib_) {
+    void **create_sym = reinterpret_cast<void **>(&create_strategy_intf_);
+    void **destroy_sym = reinterpret_cast<void **>(&destroy_strategy_intf_);
 
-  if (!strategy_intf_) {
-    DLOGI("Using GPU only composition");
-    if (strategy_lib_) {
+    *create_sym = ::dlsym(strategy_lib_, CREATE_STRATEGY_INTERFACE_NAME);
+    *destroy_sym = ::dlsym(strategy_lib_, DESTROY_STRATEGY_INTERFACE_NAME);
+
+    if (!create_strategy_intf_) {
+      DLOGE("Unable to find symbol for %s", CREATE_STRATEGY_INTERFACE_NAME);
+      error = kErrorUndefined;
+    }
+
+    if (!destroy_strategy_intf_) {
+      DLOGE("Unable to find symbol for %s", DESTROY_STRATEGY_INTERFACE_NAME);
+      error = kErrorUndefined;
+    }
+
+    if (error != kErrorNone) {
       ::dlclose(strategy_lib_);
-      strategy_lib_ = NULL;
+      res_mgr_.Deinit();
     }
-    strategy_intf_ = &strategy_default_;
+  } else {
+    DLOGW("Unable to load = %s, using GPU only (default) composition", STRATEGY_LIBRARY_NAME);
+    create_strategy_intf_ = StrategyDefault::CreateStrategyInterface;
+    destroy_strategy_intf_ = StrategyDefault::DestroyStrategyInterface;
   }
 
-  return kErrorNone;
+  return error;
 }
 
 DisplayError CompManager::Deinit() {
   SCOPE_LOCK(locker_);
 
   if (strategy_lib_) {
-    DestroyStrategyInterface destroy_strategy_intf = NULL;
-    void **sym = reinterpret_cast<void **>(&destroy_strategy_intf);
-    *sym = ::dlsym(strategy_lib_, DESTROY_STRATEGY_INTERFACE_NAME);
-    if (!destroy_strategy_intf) {
-      DLOGW("Unable to find symbol for %s", DESTROY_STRATEGY_INTERFACE_NAME);
-    } else if (destroy_strategy_intf(strategy_intf_) != kErrorNone) {
-      DLOGW("Unable to destroy strategy interface");
-    }
     ::dlclose(strategy_lib_);
   }
 
@@ -105,11 +104,19 @@
     return kErrorMemory;
   }
 
+  if (create_strategy_intf_(STRATEGY_VERSION_TAG, &display_comp_ctx->strategy_intf) != kErrorNone) {
+    DLOGW("Unable to create strategy interface");
+    delete display_comp_ctx;
+    return kErrorUndefined;
+  }
+
   error = res_mgr_.RegisterDisplay(type, attributes, &display_comp_ctx->display_resource_ctx);
   if (error != kErrorNone) {
+    destroy_strategy_intf_(display_comp_ctx->strategy_intf);
     delete display_comp_ctx;
     return error;
   }
+
   SET_BIT(registered_displays_, type);
   display_comp_ctx->display_type = type;
   *display_ctx = display_comp_ctx;
@@ -127,8 +134,11 @@
                              reinterpret_cast<DisplayCompositionContext *>(comp_handle);
 
   res_mgr_.UnregisterDisplay(display_comp_ctx->display_resource_ctx);
+  destroy_strategy_intf_(display_comp_ctx->strategy_intf);
+
   CLEAR_BIT(registered_displays_, display_comp_ctx->display_type);
   CLEAR_BIT(configured_displays_, display_comp_ctx->display_type);
+
   delete display_comp_ctx;
 
   return kErrorNone;
@@ -147,12 +157,20 @@
   }
   // If validation for the best available composition strategy with driver has failed, just
   // fallback to safe mode composition e.g. GPU or video only.
-  if (UNLIKELY(hw_layers->info.flags)) {
+  if (display_comp_ctx->strategy_selected) {
     constraints->safe_mode = true;
     return;
   }
 }
 
+void CompManager::PrePrepare(Handle display_ctx, HWLayers *hw_layers) {
+  SCOPE_LOCK(locker_);
+  DisplayCompositionContext *display_comp_ctx =
+                             reinterpret_cast<DisplayCompositionContext *>(display_ctx);
+  display_comp_ctx->strategy_intf->Start(&hw_layers->info);
+  display_comp_ctx->strategy_selected = false;
+}
+
 DisplayError CompManager::Prepare(Handle display_ctx, HWLayers *hw_layers) {
   SCOPE_LOCK(locker_);
 
@@ -167,7 +185,7 @@
   // Select a composition strategy, and try to allocate resources for it.
   res_mgr_.Start(display_resource_ctx);
   while (true) {
-    error = strategy_intf_->GetNextStrategy(&display_comp_ctx->constraints, &hw_layers->info);
+    error = display_comp_ctx->strategy_intf->GetNextStrategy(&display_comp_ctx->constraints);
     if (UNLIKELY(error != kErrorNone)) {
       // Composition strategies exhausted. Resource Manager could not allocate resources even for
       // GPU composition. This will never happen.
@@ -184,6 +202,7 @@
       break;
     }
   }
+  display_comp_ctx->strategy_selected = true;
   res_mgr_.Stop(display_resource_ctx);
 
   return error;
@@ -191,6 +210,9 @@
 
 void CompManager::PostPrepare(Handle display_ctx, HWLayers *hw_layers) {
   SCOPE_LOCK(locker_);
+  DisplayCompositionContext *display_comp_ctx =
+                             reinterpret_cast<DisplayCompositionContext *>(display_ctx);
+  display_comp_ctx->strategy_intf->Stop();
 }
 
 void CompManager::PostCommit(Handle display_ctx, HWLayers *hw_layers) {
diff --git a/displayengine/libs/core/comp_manager.h b/displayengine/libs/core/comp_manager.h
index 13452b8..1c22618 100644
--- a/displayengine/libs/core/comp_manager.h
+++ b/displayengine/libs/core/comp_manager.h
@@ -28,7 +28,6 @@
 #include <core/display_interface.h>
 
 #include "hw_interface.h"
-#include "strategy_default.h"
 #include "res_manager.h"
 #include "dump_impl.h"
 
@@ -42,6 +41,7 @@
   DisplayError RegisterDisplay(DisplayType type, const HWDisplayAttributes &attributes,
                                Handle *res_mgr_hnd);
   DisplayError UnregisterDisplay(Handle res_mgr_hnd);
+  void PrePrepare(Handle display_ctx, HWLayers *hw_layers);
   DisplayError Prepare(Handle display_ctx, HWLayers *hw_layers);
   void PostPrepare(Handle display_ctx, HWLayers *hw_layers);
   void PostCommit(Handle display_ctx, HWLayers *hw_layers);
@@ -54,15 +54,17 @@
   void PrepareStrategyConstraints(Handle display_ctx, HWLayers *hw_layers);
 
   struct DisplayCompositionContext {
+    StrategyInterface *strategy_intf;
     StrategyConstraints constraints;
     Handle display_resource_ctx;
     DisplayType display_type;
+    bool strategy_selected;
   };
 
   Locker locker_;
   void *strategy_lib_;
-  StrategyInterface *strategy_intf_;
-  StrategyDefault strategy_default_;
+  CreateStrategyInterface create_strategy_intf_;
+  DestroyStrategyInterface destroy_strategy_intf_;
   ResManager res_mgr_;
   uint64_t registered_displays_;        // Stores the bit mask of registered displays
   uint64_t configured_displays_;        // Stores the bit mask of sucessfully configured displays
diff --git a/displayengine/libs/core/display_base.cpp b/displayengine/libs/core/display_base.cpp
index aaa7990..7cd88e7 100644
--- a/displayengine/libs/core/display_base.cpp
+++ b/displayengine/libs/core/display_base.cpp
@@ -117,9 +117,10 @@
 
   if ((state_ == kStateOn)) {
     // Clean hw layers for reuse.
-    hw_layers_.info.Reset();
+    hw_layers_.info = HWLayersInfo();
     hw_layers_.info.stack = layer_stack;
 
+    comp_manager_->PrePrepare(display_comp_ctx_, &hw_layers_);
     while (true) {
       error = comp_manager_->Prepare(display_comp_ctx_, &hw_layers_);
       if (error != kErrorNone) {
@@ -129,11 +130,11 @@
       error = hw_intf_->Validate(hw_device_, &hw_layers_);
       if (error == kErrorNone) {
         // Strategy is successful now, wait for Commit().
-        comp_manager_->PostPrepare(display_comp_ctx_, &hw_layers_);
         pending_commit_ = true;
         break;
       }
     }
+    comp_manager_->PostPrepare(display_comp_ctx_, &hw_layers_);
   }
 
   return error;
diff --git a/displayengine/libs/core/hw_framebuffer.cpp b/displayengine/libs/core/hw_framebuffer.cpp
index 36b86b6..3a0f2d0 100644
--- a/displayengine/libs/core/hw_framebuffer.cpp
+++ b/displayengine/libs/core/hw_framebuffer.cpp
@@ -313,12 +313,14 @@
 
       display_attributes->x_pixels = var_screeninfo.xres;
       display_attributes->y_pixels = var_screeninfo.yres;
+      display_attributes->v_total = var_screeninfo.yres + var_screeninfo.lower_margin +
+          var_screeninfo.upper_margin + var_screeninfo.vsync_len;
       display_attributes->x_dpi =
           (FLOAT(var_screeninfo.xres) * 25.4f) / FLOAT(var_screeninfo.width);
       display_attributes->y_dpi =
           (FLOAT(var_screeninfo.yres) * 25.4f) / FLOAT(var_screeninfo.height);
-      display_attributes->vsync_period_ns =
-          UINT32(1000000000L / FLOAT(meta_data.data.panel_frame_rate));
+      display_attributes->fps = FLOAT(meta_data.data.panel_frame_rate);
+      display_attributes->vsync_period_ns = UINT32(1000000000L / display_attributes->fps);
       display_attributes->is_device_split = (hw_resource_.split_info.left_split ||
           (var_screeninfo.xres > hw_resource_.max_mixer_width)) ? true : false;
       display_attributes->split_left = hw_resource_.split_info.left_split ?
@@ -339,10 +341,12 @@
       }
       display_attributes->x_pixels = timing_mode->active_h;
       display_attributes->y_pixels = timing_mode->active_v;
+      display_attributes->v_total = timing_mode->active_v + timing_mode->front_porch_v +
+          timing_mode->back_porch_v + timing_mode->pulse_width_v;
       display_attributes->x_dpi = 0;
       display_attributes->y_dpi = 0;
-      display_attributes->vsync_period_ns =
-          UINT32(1000000000L / FLOAT(timing_mode->refresh_rate));
+      display_attributes->fps = FLOAT(timing_mode->refresh_rate);
+      display_attributes->vsync_period_ns = UINT32(1000000000L / display_attributes->fps);
       display_attributes->split_left = display_attributes->x_pixels;
       if (display_attributes->x_pixels > hw_resource_.max_mixer_width) {
         display_attributes->is_device_split = true;
@@ -830,6 +834,12 @@
         hw_resource_.max_bandwidth_high = atol(tokens[1]);
       } else if (!strncmp(tokens[0], "max_mixer_width", strlen("max_mixer_width"))) {
         hw_resource_.max_mixer_width = atoi(tokens[1]);
+      } else if (!strncmp(tokens[0], "max_pipe_bw", strlen("max_pipe_bw"))) {
+        hw_resource_.max_pipe_bw = atoi(tokens[1]);
+      } else if (!strncmp(tokens[0], "max_mdp_clk", strlen("max_mdp_clk"))) {
+        hw_resource_.max_sde_clk = atoi(tokens[1]);
+      } else if (!strncmp(tokens[0], "clk_fudge_factor", strlen("clk_fudge_factor"))) {
+        hw_resource_.clk_fudge_factor = FLOAT(atoi(tokens[1])) / FLOAT(atoi(tokens[2]));
       } else if (!strncmp(tokens[0], "features", strlen("features"))) {
         for (uint32_t i = 0; i < token_count; i++) {
           if (!strncmp(tokens[i], "bwc", strlen("bwc"))) {
@@ -896,6 +906,8 @@
   DLOGI("SourceSplit = %d, Always = %d", hw_resource_.is_src_split, hw_resource_.always_src_split);
   DLOGI("MaxLowBw = %"PRIu64", MaxHighBw = %"PRIu64"", hw_resource_.max_bandwidth_low,
         hw_resource_.max_bandwidth_high);
+  DLOGI("MaxPipeBw = %"PRIu64" KBps, MaxSDEClock = %"PRIu64" Hz, ClockFudgeFactor = %f",
+        hw_resource_.max_pipe_bw, hw_resource_.max_sde_clk, hw_resource_.clk_fudge_factor);
 
   return error;
 }
diff --git a/displayengine/libs/core/hw_interface.h b/displayengine/libs/core/hw_interface.h
index 3e620ce..84870b8 100644
--- a/displayengine/libs/core/hw_interface.h
+++ b/displayengine/libs/core/hw_interface.h
@@ -66,6 +66,9 @@
   uint64_t max_bandwidth_low;
   uint64_t max_bandwidth_high;
   uint32_t max_mixer_width;
+  uint32_t max_pipe_bw;
+  uint32_t max_sde_clk;
+  float clk_fudge_factor;
   struct SplitInfo {
     uint32_t left_split;
     uint32_t right_split;
@@ -84,7 +87,8 @@
       num_cursor_pipe(0), num_blending_stages(0), num_rotator(0), num_control(0),
       num_mixer_to_disp(0), smp_total(0), smp_size(0), num_smp_per_pipe(0), max_scale_up(0),
       max_scale_down(0), max_bandwidth_low(0), max_bandwidth_high(0), max_mixer_width(2048),
-      has_bwc(false), has_decimation(false), has_macrotile(false), has_rotator_downscale(false),
+      max_pipe_bw(0), max_sde_clk(0), clk_fudge_factor(1.0f), has_bwc(false),
+      has_decimation(false), has_macrotile(false), has_rotator_downscale(false),
       has_non_scalar_rgb(false), is_src_split(false), always_src_split(false) { }
 };
 
diff --git a/displayengine/libs/core/res_manager.cpp b/displayengine/libs/core/res_manager.cpp
index 9edca48..1ccb410 100755
--- a/displayengine/libs/core/res_manager.cpp
+++ b/displayengine/libs/core/res_manager.cpp
@@ -280,13 +280,12 @@
 }
 
 bool ResManager::CheckBandwidth(DisplayResourceContext *display_ctx, HWLayers *hw_layers) {
-  float max_pipe_bw = 1.8f;  // From MDP to hw_res_info_ (in GBps)
-  float max_sde_clk = 400.0f;  // From MDP to hw_res_info_ (in MHz)
-  float clk_fudge_factor = 1.0f;  // From MDP to hw_res_info_
+  float max_pipe_bw = FLOAT(hw_res_info_.max_pipe_bw) / 1000000;  // KBps to GBps
+  float max_sde_clk = FLOAT(hw_res_info_.max_sde_clk) / 1000000;  // Hz to MHz
   const struct HWLayersInfo &layer_info = hw_layers->info;
 
-  float left_pipe_bw[layer_info.count];
-  float right_pipe_bw[layer_info.count];
+  float left_pipe_bw[kMaxSDELayers] = {0};
+  float right_pipe_bw[kMaxSDELayers] = {0};
   float left_max_clk = 0;
   float right_max_clk = 0;
 
@@ -322,7 +321,7 @@
   }
 
   // If system has Video mode panel, use max_bandwidth_low, else use max_bandwidth_high
-  if ((display_bw + bw_claimed_) > hw_res_info_.max_bandwidth_low) {
+  if ((display_bw + bw_claimed_) > (hw_res_info_.max_bandwidth_low / 1000000)) {
     DLOGV_IF(kTagResources, "Overlap bandwidth exceeds limit!");
     return false;
   }
@@ -334,7 +333,7 @@
   float system_clk = MAX(display_clk, clk_claimed_);
 
   // Apply fudge factor to consider in-efficieny
-  if ((system_clk * clk_fudge_factor) > max_sde_clk) {
+  if ((system_clk * hw_res_info_.clk_fudge_factor) > max_sde_clk) {
     DLOGV_IF(kTagResources, "Clock requirement exceeds limit!");
     return false;
   }
@@ -353,9 +352,6 @@
 
 float ResManager::GetPipeBw(DisplayResourceContext *display_ctx, HWPipeInfo *pipe, float bpp) {
   HWDisplayAttributes &display_attributes = display_ctx->display_attributes;
-  float v_total = 2600.0f;  // From MDP to display_attributes (vBP + vFP + v_active)
-  float fps = 60.0f;  // display_attributes.fps;
-
   float src_w = pipe->src_roi.right - pipe->src_roi.left;
   float src_h = pipe->src_roi.bottom - pipe->src_roi.top;
   float dst_h = pipe->dst_roi.bottom - pipe->dst_roi.top;
@@ -363,11 +359,11 @@
   // Adjust src_h with pipe decimation
   src_h /= FLOAT(pipe->decimation);
 
-  float bw = src_w * src_h * bpp * fps;
+  float bw = src_w * src_h * bpp * display_attributes.fps;
 
   // Consider panel dimension
   // (v_total / v_active) * (v_active / dst_h)
-  bw *= (v_total / dst_h);
+  bw *= FLOAT(display_attributes.v_total) / dst_h;
 
   // Bandwidth in GBps
   return (bw / 1000000000.0f);
@@ -375,8 +371,8 @@
 
 float ResManager::GetClockForPipe(DisplayResourceContext *display_ctx, HWPipeInfo *pipe) {
   HWDisplayAttributes &display_attributes = display_ctx->display_attributes;
-  float v_total = 2600.0f;  // (vBP + vFP + v_active)
-  float fps = 60.0f;  // display_attributes.fps;
+  float v_total = FLOAT(display_attributes.v_total);
+  float fps = display_attributes.fps;
 
   float src_h = pipe->src_roi.bottom - pipe->src_roi.top;
   float dst_h = pipe->dst_roi.bottom - pipe->dst_roi.top;
diff --git a/displayengine/libs/core/strategy_default.cpp b/displayengine/libs/core/strategy_default.cpp
index 6963c6c..5c0c66f 100755
--- a/displayengine/libs/core/strategy_default.cpp
+++ b/displayengine/libs/core/strategy_default.cpp
@@ -31,17 +31,53 @@
 
 namespace sde {
 
-DisplayError StrategyDefault::GetNextStrategy(StrategyConstraints *constraints,
-                                              HWLayersInfo *hw_layers_info) {
-  if (hw_layers_info->flags) {
-    DLOGW("All strategies exhausted.");
-    return kErrorUndefined;
+StrategyDefault::StrategyDefault() : hw_layers_info_(NULL) {
+}
+
+DisplayError StrategyDefault::CreateStrategyInterface(uint16_t version,
+                                                      StrategyInterface **interface) {
+  StrategyDefault *strategy_default  = new StrategyDefault();
+
+  if (!strategy_default) {
+    return kErrorMemory;
   }
 
+  *interface = strategy_default;
+
+  return kErrorNone;
+}
+
+DisplayError StrategyDefault::DestroyStrategyInterface(StrategyInterface *interface) {
+  StrategyDefault *strategy_default = static_cast<StrategyDefault *>(interface);
+
+  if (!strategy_default) {
+    return kErrorParameters;
+  }
+
+  delete strategy_default;
+
+  return kErrorNone;
+}
+
+DisplayError StrategyDefault::Start(HWLayersInfo *hw_layers_info) {
+  if (!hw_layers_info) {
+    return kErrorParameters;
+  }
+
+  hw_layers_info_ = hw_layers_info;
+
+  return kErrorNone;
+}
+
+DisplayError StrategyDefault::Stop() {
+  return kErrorNone;
+}
+
+DisplayError StrategyDefault::GetNextStrategy(StrategyConstraints *constraints) {
   // Mark all layers for GPU composition. Find GPU target buffer and store its index for programming
   // the hardware.
-  LayerStack *layer_stack = hw_layers_info->stack;
-  uint32_t &hw_layer_count = hw_layers_info->count;
+  LayerStack *layer_stack = hw_layers_info_->stack;
+  uint32_t &hw_layer_count = hw_layers_info_->count;
 
   hw_layer_count = 0;
   for (uint32_t i = 0; i < layer_stack->layer_count; i++) {
@@ -49,7 +85,7 @@
     if (composition != kCompositionGPUTarget) {
       composition = kCompositionGPU;
     } else {
-      hw_layers_info->index[hw_layer_count++] = i;
+      hw_layers_info_->index[hw_layer_count++] = i;
     }
   }
 
@@ -58,8 +94,6 @@
     return kErrorParameters;
   }
 
-  hw_layers_info->flags = 1;
-
   return kErrorNone;
 }
 
diff --git a/displayengine/libs/core/strategy_default.h b/displayengine/libs/core/strategy_default.h
index c4e10f4..94db9e9 100644
--- a/displayengine/libs/core/strategy_default.h
+++ b/displayengine/libs/core/strategy_default.h
@@ -32,10 +32,17 @@
 
 class StrategyDefault : public StrategyInterface {
  public:
-  virtual DisplayError GetNextStrategy(StrategyConstraints *constraints,
-                                       HWLayersInfo *hw_layers_info);
+  StrategyDefault();
+
+  static DisplayError CreateStrategyInterface(uint16_t version, StrategyInterface **interface);
+  static DisplayError DestroyStrategyInterface(StrategyInterface *interface);
+
+  virtual DisplayError Start(HWLayersInfo *hw_layers_info);
+  virtual DisplayError GetNextStrategy(StrategyConstraints *constraints);
+  virtual DisplayError Stop();
 
  private:
+  HWLayersInfo *hw_layers_info_;
 };
 
 }  // namespace sde
diff --git a/displayengine/libs/hwc/hwc_display.cpp b/displayengine/libs/hwc/hwc_display.cpp
index 3f6e713..7827af2 100644
--- a/displayengine/libs/hwc/hwc_display.cpp
+++ b/displayengine/libs/hwc/hwc_display.cpp
@@ -34,9 +34,8 @@
 namespace sde {
 
 HWCDisplay::HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type,
-                       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 id)
+  : core_intf_(core_intf), hwc_procs_(hwc_procs), type_(type), id_(id), display_intf_(NULL) {
 }
 
 int HWCDisplay::Init() {
@@ -242,7 +241,7 @@
   uint8_t *current_address = layer_stack_memory_.raw;
 
   // Layer array address
-  layer_stack_ = LayerStack(need_retire_fence_);
+  layer_stack_ = LayerStack();
   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 3971d4d..0ba9ca7 100644
--- a/displayengine/libs/hwc/hwc_display.h
+++ b/displayengine/libs/hwc/hwc_display.h
@@ -70,8 +70,7 @@
     LayerStackCache() : layer_count(0) { }
   };
 
-  HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id,
-             bool need_retire_fence);
+  HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id);
   virtual ~HWCDisplay() { }
 
   // DisplayEventHandler methods
@@ -97,7 +96,6 @@
   DisplayInterface *display_intf_;
   LayerStackMemory layer_stack_memory_;
   LayerStack layer_stack_;
-  bool need_retire_fence_;
   LayerStackCache layer_stack_cache_;
 };
 
diff --git a/displayengine/libs/hwc/hwc_display_external.cpp b/displayengine/libs/hwc/hwc_display_external.cpp
index 6705549..468478b 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, true) {
+  : HWCDisplay(core_intf, hwc_procs, kHDMI, HWC_DISPLAY_EXTERNAL) {
 }
 
 int HWCDisplayExternal::Prepare(hwc_display_contents_1_t *content_list) {
diff --git a/displayengine/libs/hwc/hwc_display_primary.cpp b/displayengine/libs/hwc/hwc_display_primary.cpp
index 19a1016..b282ba6 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, true) {
+  : HWCDisplay(core_intf, hwc_procs, kPrimary, HWC_DISPLAY_PRIMARY) {
 }
 
 int HWCDisplayPrimary::Prepare(hwc_display_contents_1_t *content_list) {
diff --git a/displayengine/libs/hwc/hwc_display_virtual.cpp b/displayengine/libs/hwc/hwc_display_virtual.cpp
index 657aecb..88cd073 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, false) {
+  : HWCDisplay(core_intf, hwc_procs, kVirtual, HWC_DISPLAY_VIRTUAL) {
 }
 
 int HWCDisplayVirtual::Prepare(hwc_display_contents_1_t *content_list) {
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index fd81c70..596ca77 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -294,9 +294,6 @@
     data.uncached = useUncached(usage);
     data.allocType = 0;
 
-    if(usage & GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP)
-        ionFlags |= ION_HEAP(ION_SF_HEAP_ID);
-
     if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP)
         ionFlags |= ION_HEAP(ION_SYSTEM_HEAP_ID);
 
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 1fbff11..c5ecc42 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -40,8 +40,9 @@
     /* SYSTEM heap comes from kernel vmalloc,
      * can never be uncached, is not secured*/
     GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP     =       GRALLOC_USAGE_PRIVATE_0,
-    /* SF heap is used for application buffers, is not secured */
-    GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP  =       GRALLOC_USAGE_PRIVATE_1,
+
+    /* GRALLOC_USAGE_PRIVATE_1 is unused */
+
     /* IOMMU heap comes from manually allocated pages,
      * can be cached/uncached, is not secured */
     GRALLOC_USAGE_PRIVATE_IOMMU_HEAP      =       GRALLOC_USAGE_PRIVATE_2,
@@ -82,8 +83,7 @@
 #define GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE 6
 #define GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO 7
 
-#define GRALLOC_HEAP_MASK   (GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP |\
-                             GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP    |\
+#define GRALLOC_HEAP_MASK   (GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP    |\
                              GRALLOC_USAGE_PRIVATE_IOMMU_HEAP     |\
                              GRALLOC_USAGE_PRIVATE_MM_HEAP        |\
                              GRALLOC_USAGE_PRIVATE_ADSP_HEAP)