sdm: Fix hw layer stack corruption

Strategy might create multiple layers from input stack.
This can result in corruption if predefined arrays cannot handle
required size. To mitgate this use vectors.

CRs-Fixed: 2125010
Change-Id: Ib6a681332480a5fdf42ac1df97a64f8d758218a8
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 173dc4f..9f6a5d6 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -524,9 +524,9 @@
 
   std::vector<Layer> hw_layers = {};  // Layers which need to be programmed on the HW
 
-  uint32_t index[kMaxSDELayers] = {};   // Indexes of the layers from the layer stack which need to
-                                        // be programmed on hardware.
-  uint32_t roi_index[kMaxSDELayers] = {0};  // Stores the ROI index where the layers are visible.
+  std::vector<uint32_t> index;   // Indexes of the layers from the layer stack which need to
+                                 // be programmed on hardware.
+  std::vector<uint32_t> roi_index;  // Stores the ROI index where the layers are visible.
 
   int sync_handle = -1;         // Release fence id for current draw cycle.
   int set_idle_time_ms = -1;    // Set idle time to the new specified value.
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index ee2fe44..043f304 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -598,7 +598,7 @@
   DumpImpl::AppendString(buffer, length, newline);
 
   for (uint32_t i = 0; i < num_hw_layers; i++) {
-    uint32_t layer_index = hw_layers_.info.index[i];
+    uint32_t layer_index = hw_layers_.info.index.at(i);
     // sdm-layer from client layer stack
     Layer *sdm_layer = hw_layers_.info.stack->layers.at(layer_index);
     // hw-layer from hw layers info
@@ -1318,7 +1318,7 @@
   uint32_t hw_layers_count = UINT32(hw_layers_.info.hw_layers.size());
 
   for (uint32_t i = 0; i < hw_layers_count; i++) {
-    Layer *sdm_layer = layer_stack->layers.at(hw_layers_.info.index[i]);
+    Layer *sdm_layer = layer_stack->layers.at(hw_layers_.info.index.at(i));
     Layer &hw_layer = hw_layers_.info.hw_layers.at(i);
 
     hw_layer.input_buffer.planes[0].fd = sdm_layer->input_buffer.planes[0].fd;
@@ -1338,7 +1338,7 @@
   std::vector<uint32_t> fence_dup_flag;
 
   for (uint32_t i = 0; i < hw_layers_count; i++) {
-    uint32_t sdm_layer_index = hw_layers_.info.index[i];
+    uint32_t sdm_layer_index = hw_layers_.info.index.at(i);
     Layer *sdm_layer = layer_stack->layers.at(sdm_layer_index);
     Layer &hw_layer = hw_layers_.info.hw_layers.at(i);
 
diff --git a/sdm/libs/core/strategy.cpp b/sdm/libs/core/strategy.cpp
index 85c648e..d682070 100644
--- a/sdm/libs/core/strategy.cpp
+++ b/sdm/libs/core/strategy.cpp
@@ -144,9 +144,9 @@
   LayerRect dst_domain = (LayerRect){0.0f, 0.0f, layer_mixer_width, layer_mixer_height};
 
   Layer layer = *gpu_target_layer;
-  hw_layers_info_->index[0] = hw_layers_info_->gpu_target_index;
+  hw_layers_info_->index.push_back(hw_layers_info_->gpu_target_index);
+  hw_layers_info_->roi_index.push_back(0);
   MapRect(src_domain, dst_domain, layer.dst_rect, &layer.dst_rect);
-  hw_layers_info_->hw_layers.clear();
   hw_layers_info_->hw_layers.push_back(layer);
 
   return kErrorNone;