sdm: Support cursor without h/w cursor

Support cursor with any pipe type. Simplify design to
factor in h/w cursor presence much later in draw cycle during
resource allocation.

Change-Id: If10866516d95cb3f8f33021a25ec6237b35ac32c
CRs-fixed: 1114808
diff --git a/sdm/include/core/layer_stack.h b/sdm/include/core/layer_stack.h
index f12e5c1..b8977e2 100644
--- a/sdm/include/core/layer_stack.h
+++ b/sdm/include/core/layer_stack.h
@@ -85,8 +85,8 @@
   kCompositionSDE,          //!< This layer will be composed by SDE. It must not be composed by
                             //!< GPU or Blit.
 
-  kCompositionHWCursor,     //!< This layer will be composed by SDE using HW Cursor. It must not be
-                            //!< composed by GPU or Blit.
+  kCompositionCursor,       // This cursor layer can receive async position updates irrespective of
+                            // dedicated h/w cursor usage. It must not be composed by GPU or Blit
 
   kCompositionHybrid,       //!< This layer will be drawn by a blit engine and SDE together.
                             //!< Display device will split the layer, update the blit rectangle
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 68e953e..e12df69 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -485,10 +485,8 @@
   std::vector<LayerRect> left_frame_roi = {};   // Left ROI.
   std::vector<LayerRect> right_frame_roi = {};  // Right ROI.
   LayerRect partial_fb_roi = {};   // Damaged area in framebuffer.
-
   bool roi_split = false;          // Indicates separated left and right ROI
-
-  bool use_hw_cursor = false;      // Indicates that HWCursor pipe needs to be used for cursor layer
+  bool async_cursor_updates = false;  // Cursor layer allowed to have async updates
   DestScaleInfoMap dest_scale_info_map = {};
   HWHDRLayerInfo hdr_layer_info = {};
   Handle pvt_data = NULL;   // Private data used by sdm extension only.
diff --git a/sdm/include/private/partial_update_interface.h b/sdm/include/private/partial_update_interface.h
index b753587..a1c2382 100644
--- a/sdm/include/private/partial_update_interface.h
+++ b/sdm/include/private/partial_update_interface.h
@@ -35,8 +35,6 @@
 
 struct PUConstraints {
   bool enable = true;             //!< If this is set, PU will be enabled or it will be disabled
-  bool enable_cursor_pu = false;  //!< If this is set, PU will consider cursor layer in the layer
-                                   //!< stack for cursor partial update
 };
 
 class PartialUpdateInterface {
diff --git a/sdm/include/private/resource_interface.h b/sdm/include/private/resource_interface.h
index e7df7a5..e140c33 100644
--- a/sdm/include/private/resource_interface.h
+++ b/sdm/include/private/resource_interface.h
@@ -58,8 +58,6 @@
   virtual DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst,
                                        bool rotate90, BufferLayout layout,
                                        bool use_rotator_downscale) = 0;
-  virtual DisplayError ValidateCursorConfig(Handle display_ctx, const Layer *layer,
-                                            bool is_top) = 0;
   virtual DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers,
                                               int x, int y) = 0;
   virtual DisplayError SetMaxBandwidthMode(HWBwModes mode) = 0;
diff --git a/sdm/include/private/strategy_interface.h b/sdm/include/private/strategy_interface.h
index f903d5f..1174e7f 100644
--- a/sdm/include/private/strategy_interface.h
+++ b/sdm/include/private/strategy_interface.h
@@ -36,9 +36,6 @@
                             //!< that requires minimum number of pipe for the current frame. i.e.,
                             //!< video only composition, secure only composition or GPU composition
 
-  bool use_cursor = false;  //!< If this is set, strategy manager will configure cursor layer in the
-                            //!< layer stack as hw cursor else it will be treated as a normal layer
-
   uint32_t max_layers = kMaxSDELayers;  //!< Maximum number of layers that shall be programmed
                                         //!< on hardware for the given layer stack.
 };
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index 2b9fa92..d18b5b8 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -33,12 +33,6 @@
 
 namespace sdm {
 
-static bool NeedsScaledComposition(const DisplayConfigVariableInfo &fb_config,
-                                   const HWMixerAttributes &mixer_attributes) {
-  return ((fb_config.x_pixels != mixer_attributes.width) ||
-          (fb_config.y_pixels != mixer_attributes.height));
-}
-
 DisplayError CompManager::Init(const HWResourceInfo &hw_res_info,
                                ExtensionInterface *extension_intf,
                                BufferAllocator *buffer_allocator,
@@ -135,7 +129,6 @@
     max_sde_ext_layers_ = UINT32(Debug::GetExtMaxlayers());
   }
 
-  display_comp_ctx->scaled_composition = NeedsScaledComposition(fb_config, mixer_attributes);
   DLOGV_IF(kTagCompManager, "registered display bit mask 0x%x, configured display bit mask 0x%x, " \
            "display type %d", registered_displays_.to_ulong(), configured_displays_.to_ulong(),
            display_comp_ctx->display_type);
@@ -214,8 +207,6 @@
     }
   }
 
-  display_comp_ctx->scaled_composition = NeedsScaledComposition(fb_config, mixer_attributes);
-
   return error;
 }
 
@@ -225,7 +216,6 @@
   StrategyConstraints *constraints = &display_comp_ctx->constraints;
 
   constraints->safe_mode = safe_mode_;
-  constraints->use_cursor = false;
   constraints->max_layers = max_layers_;
 
   // Limit 2 layer SDE Comp if its not a Primary Display.
@@ -242,9 +232,6 @@
     constraints->safe_mode = true;
   }
 
-  // Set use_cursor constraint to Strategy
-  constraints->use_cursor = display_comp_ctx->valid_cursor;
-
   // TODO(user): App layer count will change for hybrid composition
   uint32_t app_layer_count = UINT32(hw_layers->info.stack->layers.size()) - 1;
   if (display_comp_ctx->idle_fallback || display_comp_ctx->thermal_fallback_) {
@@ -262,11 +249,6 @@
   SCOPE_LOCK(locker_);
   DisplayCompositionContext *display_comp_ctx =
                              reinterpret_cast<DisplayCompositionContext *>(display_ctx);
-  display_comp_ctx->valid_cursor = SupportLayerAsCursor(display_comp_ctx, hw_layers);
-
-  // pu constraints
-  display_comp_ctx->pu_constraints.enable_cursor_pu = display_comp_ctx->valid_cursor;
-
   display_comp_ctx->strategy->Start(&hw_layers->info, &display_comp_ctx->max_strategies,
                                     display_comp_ctx->pu_constraints);
   display_comp_ctx->remaining_strategies = display_comp_ctx->max_strategies;
@@ -486,39 +468,6 @@
   return resource_intf_->ValidateCursorPosition(display_resource_ctx, hw_layers, x, y);
 }
 
-bool CompManager::SupportLayerAsCursor(Handle comp_handle, HWLayers *hw_layers) {
-  DisplayCompositionContext *display_comp_ctx =
-                             reinterpret_cast<DisplayCompositionContext *>(comp_handle);
-  Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx;
-  LayerStack *layer_stack = hw_layers->info.stack;
-  bool supported = false;
-  int32_t gpu_index = -1;
-
-  // HW Cursor cannot be used, if Display configuration needs scaled composition.
-  if (display_comp_ctx->scaled_composition || !layer_stack->flags.cursor_present) {
-    return supported;
-  }
-
-  for (int32_t i = INT32(layer_stack->layers.size() - 1); i >= 0; i--) {
-    Layer *layer = layer_stack->layers.at(UINT32(i));
-    if (layer->composition == kCompositionGPUTarget) {
-      gpu_index = i;
-      break;
-    }
-  }
-  if (gpu_index <= 0) {
-    return supported;
-  }
-  Layer *cursor_layer = layer_stack->layers.at(UINT32(gpu_index) - 1);
-  if (cursor_layer->flags.cursor && !cursor_layer->flags.skip &&
-      resource_intf_->ValidateCursorConfig(display_resource_ctx,
-                                           cursor_layer, true) == kErrorNone) {
-    supported = true;
-  }
-
-  return supported;
-}
-
 DisplayError CompManager::SetMaxBandwidthMode(HWBwModes mode) {
   if ((hw_res_info_.has_dyn_bw_support == false) || (mode >= kBwModeMax)) {
     return kErrorNotSupported;
diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h
index c8646fe..c6b8972 100644
--- a/sdm/libs/core/comp_manager.h
+++ b/sdm/libs/core/comp_manager.h
@@ -67,7 +67,6 @@
   void ControlPartialUpdate(Handle display_ctx, bool enable);
   DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, bool rotate90);
   DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y);
-  bool SupportLayerAsCursor(Handle display_ctx, HWLayers *hw_layers);
   bool SetDisplayState(Handle display_ctx, DisplayState state, DisplayType display_type);
   DisplayError SetMaxBandwidthMode(HWBwModes mode);
   DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info);
@@ -97,9 +96,7 @@
     // Using primary panel flag of hw panel to configure Constraints. We do not need other hw
     // panel parameters for now.
     bool is_primary_panel = false;
-    bool valid_cursor = false;
     PUConstraints pu_constraints = {};
-    bool scaled_composition = false;
   };
 
   Locker locker_;
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 3953ce2..bf370e9 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -664,7 +664,7 @@
   switch (composition) {
   case kCompositionGPU:         return "GPU";
   case kCompositionSDE:         return "SDE";
-  case kCompositionHWCursor:    return "CURSOR";
+  case kCompositionCursor:      return "CURSOR";
   case kCompositionHybrid:      return "HYBRID";
   case kCompositionBlit:        return "BLIT";
   case kCompositionGPUTarget:   return "GPU_TARGET";
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index 95ac9b0..773845b 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -208,7 +208,6 @@
     HWPipeInfo *right_pipe = &hw_layers->config[i].right_pipe;
     HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session;
     bool is_rotator_used = (hw_rotator_session->hw_block_count != 0);
-    bool is_cursor_pipe_used = (hw_layer_info.use_hw_cursor & layer.flags.cursor);
 
     for (uint32_t count = 0; count < 2; count++) {
       HWPipeInfo *pipe_info = (count == 0) ? left_pipe : right_pipe;
@@ -247,7 +246,7 @@
 #endif
         SetRect(pipe_info->src_roi, &mdp_layer.src_rect);
         SetRect(pipe_info->dst_roi, &mdp_layer.dst_rect);
-        SetMDPFlags(&layer, is_rotator_used, is_cursor_pipe_used, &mdp_layer.flags);
+        SetMDPFlags(&layer, is_rotator_used, hw_layer_info.async_cursor_updates, &mdp_layer.flags);
         SetCSC(layer.input_buffer.color_metadata, &mdp_layer.color_space);
         if (pipe_info->flags & kIGC) {
           SetIGC(&layer.input_buffer, mdp_layer_count);
@@ -710,7 +709,7 @@
 }
 
 void HWDevice::SetMDPFlags(const Layer *layer, const bool &is_rotator_used,
-                           bool is_cursor_pipe_used, uint32_t *mdp_flags) {
+                           bool async_cursor_updates, uint32_t *mdp_flags) {
   const LayerBuffer &input_buffer = layer->input_buffer;
 
   // Flips will be taken care by rotator, if layer uses rotator for downscale/rotation. So ignore
@@ -743,7 +742,7 @@
     *mdp_flags |= MDP_LAYER_SOLID_FILL;
   }
 
-  if (hw_panel_info_.mode != kModeCommand && layer->flags.cursor && is_cursor_pipe_used) {
+  if (layer->flags.cursor && async_cursor_updates) {
     // command mode panels does not support async position update
     *mdp_flags |= MDP_LAYER_ASYNC;
   }
diff --git a/sdm/libs/core/fb/hw_device.h b/sdm/libs/core/fb/hw_device.h
index 374df56..2eea87b 100644
--- a/sdm/libs/core/fb/hw_device.h
+++ b/sdm/libs/core/fb/hw_device.h
@@ -116,7 +116,7 @@
   void SetBlending(const LayerBlending &source, mdss_mdp_blend_op *target);
   void SetRect(const LayerRect &source, mdp_rect *target);
   void SetMDPFlags(const Layer *layer, const bool &is_rotator_used,
-                   bool is_cursor_pipe_used, uint32_t *mdp_flags);
+                   bool async_cursor_updates, uint32_t *mdp_flags);
   // Retrieves HW FrameBuffer Node Index
   int GetFBNodeIndex(HWDeviceType device_type);
   // Populates HWPanelInfo based on node index
diff --git a/sdm/libs/core/resource_default.cpp b/sdm/libs/core/resource_default.cpp
index 31d8704..2d74941 100644
--- a/sdm/libs/core/resource_default.cpp
+++ b/sdm/libs/core/resource_default.cpp
@@ -923,11 +923,6 @@
   return kErrorNone;
 }
 
-DisplayError ResourceDefault::ValidateCursorConfig(Handle display_ctx, const Layer *layer,
-                                                   bool is_top) {
-  return kErrorNotSupported;
-}
-
 DisplayError ResourceDefault::ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers,
                                                      int x, int y) {
   return kErrorNotSupported;
diff --git a/sdm/libs/hwc/hwc_display.cpp b/sdm/libs/hwc/hwc_display.cpp
index 6cba7f0..07ec2ce 100644
--- a/sdm/libs/hwc/hwc_display.cpp
+++ b/sdm/libs/hwc/hwc_display.cpp
@@ -953,7 +953,7 @@
   case kCompositionGPUTarget:   *target = HWC_FRAMEBUFFER_TARGET; break;
   case kCompositionGPU:         *target = HWC_FRAMEBUFFER;        break;
   case kCompositionGPUS3D:      *target = HWC_FRAMEBUFFER;        break;
-  case kCompositionHWCursor:    *target = HWC_CURSOR_OVERLAY;     break;
+  case kCompositionCursor:      *target = HWC_CURSOR_OVERLAY;     break;
   default:                      *target = HWC_OVERLAY;            break;
   }
 }
diff --git a/sdm/libs/hwc2/hwc_layers.cpp b/sdm/libs/hwc2/hwc_layers.cpp
index da8a1d8..51a8687 100644
--- a/sdm/libs/hwc2/hwc_layers.cpp
+++ b/sdm/libs/hwc2/hwc_layers.cpp
@@ -690,7 +690,7 @@
     case kCompositionGPU:
       hwc_composition = HWC2::Composition::Client;
       break;
-    case kCompositionHWCursor:
+    case kCompositionCursor:
       hwc_composition = HWC2::Composition::Cursor;
       break;
     default: