Merge "display:config: Enable HDR and RENDER_INTENTS"
diff --git a/common.mk b/common.mk
index 82d247f..bb6494a 100644
--- a/common.mk
+++ b/common.mk
@@ -1,20 +1,31 @@
 #Common headers
 display_top := $(call my-dir)
-display_config_version := $(shell \
-    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.1" ];\
-    then echo DISPLAY_CONFIG_1_1; fi)
-display_config_version := $(shell \
-    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.2" ];\
-    then echo DISPLAY_CONFIG_1_2; fi)
-display_config_version := $(shell \
-    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.3" ];\
-    then echo DISPLAY_CONFIG_1_3; fi)
-display_config_version := $(shell \
-    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.4" ];\
-    then echo DISPLAY_CONFIG_1_4; fi)
+
+#Get the highest display config version available
 display_config_version := $(shell \
     if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.5" ];\
     then echo DISPLAY_CONFIG_1_5; fi)
+ifeq ($(display_config_version),)
+display_config_version := $(shell \
+    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.4" ];\
+    then echo DISPLAY_CONFIG_1_4; fi)
+endif
+ifeq ($(display_config_version),)
+display_config_version := $(shell \
+    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.3" ];\
+    then echo DISPLAY_CONFIG_1_3; fi)
+endif
+ifeq ($(display_config_version),)
+display_config_version := $(shell \
+    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.2" ];\
+    then echo DISPLAY_CONFIG_1_2; fi)
+endif
+ifeq ($(display_config_version),)
+display_config_version := $(shell \
+    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.1" ];\
+    then echo DISPLAY_CONFIG_1_1; fi)
+endif
+
 #Common C flags
 common_flags := -Wno-missing-field-initializers
 common_flags += -Wconversion -Wall -Werror -std=c++14
diff --git a/config/trinket.mk b/config/trinket.mk
new file mode 100644
index 0000000..8dfc945
--- /dev/null
+++ b/config/trinket.mk
@@ -0,0 +1,60 @@
+#Display related packages and configuration
+
+PRODUCT_PACKAGES += \
+    android.hardware.graphics.composer@2.2-impl \
+    android.hardware.graphics.composer@2.2-service \
+    android.hardware.graphics.mapper@2.0-impl-qti-display \
+    vendor.qti.hardware.display.allocator@1.0-service \
+    android.hardware.memtrack@1.0-impl \
+    android.hardware.memtrack@1.0-service \
+    android.hardware.light@2.0-impl \
+    android.hardware.light@2.0-service \
+    gralloc.trinket \
+    lights.trinket \
+    hwcomposer.trinket \
+    memtrack.trinket \
+    libqdutils \
+    libqdMetaData \
+    libqdMetaData.system \
+    modetest
+
+#QDCM calibration xml file
+PRODUCT_COPY_FILES += hardware/qcom/display/config/qdcm_calib_data_nt35597_cmd_mode_dsi_truly_panel_with_DSC.xml:$(TARGET_COPY_OUT_VENDOR)/etc/qdcm_calib_data_hx83112a_video_mode_dsi_truly_panel.xml
+
+#Enable Charging Icon
+TARGET_RECOVERY_PIXEL_FORMAT := RGBX_8888
+
+TARGET_USES_GRALLOC1 := true
+TARGET_USES_DRM_PP := true
+TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS := true
+MAX_VIRTUAL_DISPLAY_DIMENSION := 4096
+NUM_FRAMEBUFFER_SURFACE_BUFFERS := 3
+TARGET_USES_HWC2 := true
+TARGET_USES_QCOM_DISPLAY_BSP := true
+TARGET_USES_COLOR_METADATA := true
+TARGET_HAS_WIDE_COLOR_DISPLAY := true
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    persist.demo.hdmirotationlock=false \
+    debug.sf.hw=0 \
+    debug.egl.hw=0 \
+    debug.sf.latch_unsignaled=1 \
+    debug.mdpcomp.logs=0 \
+    debug.sf.enable_hwc_vds=1 \
+    ro.vendor.display.cabl=2 \
+    vendor.gralloc.disable_ubwc=0 \
+    vendor.display.disable_scaler=0 \
+    vendor.display.disable_inline_rotator=1 \
+    vendor.display.disable_decimation=1 \
+    vendor.display.enable_null_display=0 \
+    vendor.display.disable_excl_rect=0 \
+    vendor.display.comp_mask=0 \
+    vendor.display.disable_hw_recovery=1 \
+    vendor.display.enable_default_color_mode=1
+
+# This matrix should be in column major order, per SurfaceFlinger requirement
+#  1.16868   -0.16868    0.00000
+# -0.03155    1.03155    0.00000
+# -0.01473   -0.05899    1.07372
+PRODUCT_PROPERTY_OVERRIDES += \
+    vendor.display.dataspace_saturation_matrix=1.16868,-0.03155,-0.01473,-0.16868,1.03155,-0.05899,0.00000,0.00000,1.07372
diff --git a/libdebug/Android.mk b/libdebug/Android.mk
index e975a22..14e5de0 100644
--- a/libdebug/Android.mk
+++ b/libdebug/Android.mk
@@ -8,7 +8,5 @@
 LOCAL_CFLAGS                  := -DLOG_TAG=\"SDM\" -Wall -std=c++11 -Werror -fno-operator-names
 LOCAL_CLANG                   := true
 LOCAL_SRC_FILES               := debug_handler.cpp
-LOCAL_COPY_HEADERS_TO         := qcom/display
-LOCAL_COPY_HEADERS            := debug_handler.h
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/libdrmutils/drm_interface.h b/libdrmutils/drm_interface.h
index 0fe0d2c..8cb300a 100644
--- a/libdrmutils/drm_interface.h
+++ b/libdrmutils/drm_interface.h
@@ -389,6 +389,12 @@
    *     uint32_t - qsync mode
    */
   CONNECTOR_SET_QSYNC_MODE,
+  /*
+   * Op: Sets topology control on this connector
+   * Arg: uint32_t - Connector ID
+   *      uint32_t - Topology control bit-mask
+   */
+  CONNECTOR_SET_TOPOLOGY_CONTROL,
 };
 
 enum struct DRMRotation {
@@ -603,6 +609,7 @@
   // Connection status of this connector
   bool is_connected;
   bool is_wb_ubwc_supported;
+  uint32_t topology_control;
 };
 
 // All DRM Connectors as map<Connector_id , connector_info>
@@ -765,6 +772,14 @@
   CONTINUOUS,
 };
 
+enum struct DRMTopologyControl {
+  NONE          = 0,
+  RESERVE_LOCK  = 1 << 0,
+  RESERVE_CLEAR = 1 << 1,
+  DSPP          = 1 << 2,
+  DEST_SCALER   = 1 << 3,
+};
+
 struct DRMSolidfillStage {
   DRMRect bounding_rect {};
   bool is_exclusion_rect = false;
diff --git a/sdm/include/private/color_params.h b/sdm/include/private/color_params.h
index 7c2846f..2527d9d 100644
--- a/sdm/include/private/color_params.h
+++ b/sdm/include/private/color_params.h
@@ -194,6 +194,7 @@
   bool own_payload = false;  // to indicate if *payload is owned by this or just a reference.
   uint32_t size = 0;
   uint8_t *payload = NULL;
+  int fd = -1;
 
   PPDisplayAPIPayload() = default;
   PPDisplayAPIPayload(uint32_t size, uint8_t *param)
diff --git a/sdm/libs/core/color_manager.cpp b/sdm/libs/core/color_manager.cpp
index d895bf7..abe64ad 100644
--- a/sdm/libs/core/color_manager.cpp
+++ b/sdm/libs/core/color_manager.cpp
@@ -185,12 +185,6 @@
 }
 
 DisplayError ColorManagerProxy::Commit() {
-  static bool first_cycle = true;
-  if (first_cycle) {
-    first_cycle = false;
-    return kErrorNone;
-  }
-
   Locker &locker(pp_features_.GetLocker());
   SCOPE_LOCK(locker);
 
diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp
index 3fd121a..4715848 100644
--- a/sdm/libs/core/drm/hw_device_drm.cpp
+++ b/sdm/libs/core/drm/hw_device_drm.cpp
@@ -1128,6 +1128,8 @@
   }
 
   if (first_cycle_) {
+    drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_TOPOLOGY_CONTROL, token_.conn_id,
+                              topology_control_);
     drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1);
     drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_CRTC, token_.conn_id, token_.crtc_id);
     drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::ON);
diff --git a/sdm/libs/core/drm/hw_device_drm.h b/sdm/libs/core/drm/hw_device_drm.h
index aa7f281..054ff31 100644
--- a/sdm/libs/core/drm/hw_device_drm.h
+++ b/sdm/libs/core/drm/hw_device_drm.h
@@ -215,6 +215,7 @@
   bool secure_display_active_ = false;
   uint64_t debug_dump_count_ = 0;
   bool synchronous_commit_ = false;
+  uint32_t topology_control_ = 0;
 
  private:
   std::string interface_str_ = "DSI";
diff --git a/sdm/libs/core/drm/hw_peripheral_drm.cpp b/sdm/libs/core/drm/hw_peripheral_drm.cpp
index 84c311d..7ad6a71 100644
--- a/sdm/libs/core/drm/hw_peripheral_drm.cpp
+++ b/sdm/libs/core/drm/hw_peripheral_drm.cpp
@@ -63,6 +63,10 @@
   scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count);
   dest_scalar_cache_.resize(hw_resource_.hw_dest_scalar_info.count);
 
+  topology_control_ = UINT32(sde_drm::DRMTopologyControl::DSPP);
+  if (hw_panel_info_.is_primary_panel) {
+    topology_control_ |= UINT32(sde_drm::DRMTopologyControl::DEST_SCALER);
+  }
   return kErrorNone;
 }
 
diff --git a/sdm/libs/hwc2/Android.mk b/sdm/libs/hwc2/Android.mk
index 837c5d1..314504c 100644
--- a/sdm/libs/hwc2/Android.mk
+++ b/sdm/libs/hwc2/Android.mk
@@ -27,6 +27,7 @@
                                  android.hardware.graphics.allocator@2.0 \
                                  android.hardware.graphics.composer@2.2 \
 
+$(info IDisplayConfig version: $(display_config_version))
 ifeq ($(display_config_version), DISPLAY_CONFIG_1_1)
 LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.1
 endif
diff --git a/sdm/libs/hwc2/hwc_color_manager.cpp b/sdm/libs/hwc2/hwc_color_manager.cpp
index 0355cc2..8288439 100644
--- a/sdm/libs/hwc2/hwc_color_manager.cpp
+++ b/sdm/libs/hwc2/hwc_color_manager.cpp
@@ -82,6 +82,14 @@
 
 void HWCColorManager::MarshallStructIntoParcel(const PPDisplayAPIPayload &data,
                                                android::Parcel *out_parcel) {
+  if (data.fd > 0) {
+    int err = out_parcel->writeDupFileDescriptor(data.fd);
+    if (err) {
+      DLOGE("writeDupFileDescriptor status = %d", err);
+    }
+    close(data.fd);
+  }
+
   out_parcel->writeInt32(INT32(data.size));
   if (data.payload)
     out_parcel->write(data.payload, data.size);
diff --git a/sdm/libs/hwc2/hwc_display.cpp b/sdm/libs/hwc2/hwc_display.cpp
index c3f1416..46523b9 100644
--- a/sdm/libs/hwc2/hwc_display.cpp
+++ b/sdm/libs/hwc2/hwc_display.cpp
@@ -1476,8 +1476,8 @@
   }
 
   DLOGI("dump_frame_count %d dump_input_layers %d", dump_frame_count_, dump_input_layers_);
-  snprintf(dir_path, sizeof(dir_path), "%s/frame_dump_%s", HWCDebugHandler::DumpDir(),
-           GetDisplayString());
+  snprintf(dir_path, sizeof(dir_path), "%s/frame_dump_disp_id_%02u_%s", HWCDebugHandler::DumpDir(),
+           UINT32(id_), GetDisplayString());
 
   status = mkdir(dir_path, 777);
   if ((status != 0) && errno != EEXIST) {
@@ -1549,8 +1549,8 @@
   char dir_path[PATH_MAX];
   int  status;
 
-  snprintf(dir_path, sizeof(dir_path), "%s/frame_dump_%s", HWCDebugHandler::DumpDir(),
-           GetDisplayString());
+  snprintf(dir_path, sizeof(dir_path), "%s/frame_dump_disp_id_%02u_%s", HWCDebugHandler::DumpDir(),
+           UINT32(id_), GetDisplayString());
 
   status = mkdir(dir_path, 777);
   if ((status != 0) && errno != EEXIST) {
@@ -1593,10 +1593,10 @@
 
 const char *HWCDisplay::GetDisplayString() {
   switch (type_) {
-    case kPrimary:
-      return "primary";
-    case kHDMI:
-      return "hdmi";
+    case kBuiltIn:
+      return "builtin";
+    case kPluggable:
+      return "pluggable";
     case kVirtual:
       return "virtual";
     default:
diff --git a/sdm/libs/hwc2/hwc_display_pluggable.cpp b/sdm/libs/hwc2/hwc_display_pluggable.cpp
index ef979eb..43de395 100644
--- a/sdm/libs/hwc2/hwc_display_pluggable.cpp
+++ b/sdm/libs/hwc2/hwc_display_pluggable.cpp
@@ -141,6 +141,12 @@
     return status;
   }
 
+  // Apply current Color Mode and Render Intent.
+  if (color_mode_->ApplyCurrentColorModeWithRenderIntent() != HWC2::Error::None) {
+    // Fallback to GPU Composition, if Color Mode can't be applied.
+    MarkLayersForClientComposition();
+  }
+
   // TODO(user): SetRefreshRate need to follow new interface when added.
 
   status = PrepareLayerStack(out_num_types, out_num_requests);
@@ -317,7 +323,7 @@
 }
 
 HWC2::Error HWCDisplayPluggable::SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent) {
-  auto status = color_mode_->SetColorModeWithRenderIntent(mode, intent);
+  auto status = color_mode_->CacheColorModeWithRenderIntent(mode, intent);
   if (status != HWC2::Error::None) {
     DLOGE("failed for mode = %d intent = %d", mode, intent);
     return status;
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index 08c06dd..0cfcb16 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -506,6 +506,11 @@
   if (out_num_intents == nullptr) {
     return HWC2_ERROR_BAD_PARAMETER;
   }
+
+  if (mode < ColorMode::NATIVE || mode > ColorMode::BT2100_HLG) {
+    DLOGE("Invalid ColorMode: %d", mode);
+    return HWC2_ERROR_BAD_PARAMETER;
+  }
   return HWCSession::CallDisplayFunction(device, display, &HWCDisplay::GetRenderIntents, mode,
                                          out_num_intents, out_intents);
 }
@@ -733,6 +738,11 @@
     return HWC2_ERROR_BAD_PARAMETER;
   }
   auto render_intent = static_cast<RenderIntent>(int_render_intent);
+  if ((render_intent < RenderIntent::COLORIMETRIC) ||
+      (render_intent > RenderIntent::TONE_MAP_ENHANCE)) {
+    DLOGE("Invalid RenderIntent: %d", render_intent);
+    return HWC2_ERROR_BAD_PARAMETER;
+  }
   return HWCSession::CallDisplayFunction(device, display, &HWCDisplay::SetColorModeWithRenderIntent,
                                          mode, render_intent);
 }
@@ -891,7 +901,7 @@
     hwc_session->idle_pc_ref_cnt_ = 0;
   }
 
-  hwc_session->UpdateVsyncSource(display);
+  hwc_session->UpdateVsyncSource();
 
   return HWC2_ERROR_NONE;
 }
@@ -1573,7 +1583,10 @@
 
   android::status_t status = 0;
 
-  for (uint32_t i = 0; i < 32 && bit_mask_display_type[i]; i++) {
+  for (uint32_t i = 0; i < bit_mask_display_type.size(); i++) {
+    if (!bit_mask_display_type[i]) {
+      continue;
+    }
     int disp_idx = GetDisplayIndex(INT(i));
     if (disp_idx == -1) {
       continue;
@@ -1633,6 +1646,10 @@
     return -EINVAL;
   }
 
+  if (mode < ColorMode::NATIVE || mode > ColorMode::BT2100_HLG) {
+    DLOGE("Invalid ColorMode: %d", mode);
+    return HWC2_ERROR_BAD_PARAMETER;
+  }
   auto err = CallDisplayFunction(device, static_cast<hwc2_display_t>(disp_idx),
                                  &HWCDisplay::SetColorMode, mode);
   if (err != HWC2_ERROR_NONE)
@@ -1671,6 +1688,16 @@
   auto intent = static_cast<RenderIntent>(input_parcel->readInt32());
   auto device = static_cast<hwc2_device_t *>(this);
 
+  if (mode < ColorMode::NATIVE || mode > ColorMode::BT2100_HLG) {
+    DLOGE("Invalid ColorMode: %d", mode);
+    return HWC2_ERROR_BAD_PARAMETER;
+  }
+
+  if (intent < RenderIntent::COLORIMETRIC || intent > RenderIntent::TONE_MAP_ENHANCE) {
+    DLOGE("Invalid RenderIntent: %d", intent);
+    return HWC2_ERROR_BAD_PARAMETER;
+  }
+
   auto err =
       CallDisplayFunction(device, display, &HWCDisplay::SetColorModeWithRenderIntent, mode, intent);
   if (err != HWC2_ERROR_NONE)
@@ -2298,6 +2325,7 @@
   for (auto client_id : pending_hotplugs) {
     DLOGI("Notify hotplug display connected: client id = %d", client_id);
     callbacks_.Hotplug(client_id, HWC2::Connection::Connected);
+    UpdateVsyncSource();
   }
 
   return 0;
@@ -2369,6 +2397,7 @@
     }
     hwc_display = nullptr;
     map_info->Reset();
+    UpdateVsyncSource();
   }
 
   if (notify_hotplug) {
@@ -2631,46 +2660,49 @@
   return CallDisplayFunction(device, HWC_DISPLAY_PRIMARY, &HWCDisplay::SetQSyncMode, qsync_mode);
 }
 
-void HWCSession::UpdateVsyncSource(hwc2_display_t display) {
-  // Nothing to do if this display is not source for vysnc currently and it is non-primary.
+void HWCSession::UpdateVsyncSource() {
   hwc2_display_t active_source = callbacks_.GetVsyncSource();
-  if (display != active_source && display != HWC_DISPLAY_PRIMARY) {
-    DLOGI("Display = %d is not source for vsync and non-primary", display);
+  hwc2_display_t next_vsync_source = GetNextVsyncSource();
+  if (active_source == next_vsync_source) {
     return;
   }
 
-  HWC2::Vsync vsync_mode = hwc_display_[active_source]->GetLastVsyncMode();
-  HWC2::PowerMode power_mode = hwc_display_[display]->GetLastPowerMode();
+  callbacks_.SetSwapVsync(next_vsync_source, HWC_DISPLAY_PRIMARY);
+  HWC2::PowerMode power_mode = hwc_display_[next_vsync_source]->GetLastPowerMode();
 
+  // Skip enabling vsync if display is Off, happens only for default source ie; primary.
+  if (power_mode == HWC2::PowerMode::Off) {
+    return;
+  }
+
+  HWC2::Vsync vsync_mode = hwc_display_[active_source] ?
+                           hwc_display_[active_source]->GetLastVsyncMode() : HWC2::Vsync::Enable;
+  hwc_display_[next_vsync_source]->SetVsyncEnabled(vsync_mode);
+  DLOGI("active_source %d next_vsync_source %d", active_source, next_vsync_source);
+}
+
+hwc2_display_t HWCSession::GetNextVsyncSource() {
   // If primary display is powered off, change vsync source to next builtin display.
   // If primary display is powerd on, change vsync source back to primary display.
-  if (power_mode == HWC2::PowerMode::Off) {
-    hwc2_display_t next_vsync_source = HWC_DISPLAY_PRIMARY;
-    for (auto &info : map_info_builtin_) {
-      auto &hwc_display = hwc_display_[info.client_id];
-      if (!hwc_display) {
-        continue;
-      }
+  // First check for active builtins. If not found switch to pluggable displays.
 
-      if (hwc_display->GetLastPowerMode() != HWC2::PowerMode::Off) {
-        next_vsync_source = info.client_id;
-        DLOGI("Swap vsync source to display = %d", next_vsync_source);
-        break;
-      }
+  std::vector<DisplayMapInfo> map_info = {map_info_primary_};
+  std::copy(map_info_builtin_.begin(), map_info_builtin_.end(), std::back_inserter(map_info));
+  std::copy(map_info_pluggable_.begin(), map_info_pluggable_.end(), std::back_inserter(map_info));
+
+  for (auto &info : map_info) {
+    auto &hwc_display = hwc_display_[info.client_id];
+    if (!hwc_display) {
+      continue;
     }
 
-    // No other active builtin display is present.
-    if (next_vsync_source == HWC_DISPLAY_PRIMARY) {
-      DLOGI("No other active builtin display, nothing to do.");
-      return;
+    if (hwc_display->GetLastPowerMode() != HWC2::PowerMode::Off) {
+      return info.client_id;
     }
-
-    callbacks_.SetSwapVsync(next_vsync_source, HWC_DISPLAY_PRIMARY);
-    hwc_display_[next_vsync_source]->SetVsyncEnabled(vsync_mode);
-  } else if (display == HWC_DISPLAY_PRIMARY) {
-    callbacks_.SetSwapVsync(HWC_DISPLAY_PRIMARY, HWC_DISPLAY_PRIMARY);
-    hwc_display_[HWC_DISPLAY_PRIMARY]->SetVsyncEnabled(vsync_mode);
   }
+
+  // No Vsync source found. Default to main display.
+  return HWC_DISPLAY_PRIMARY;
 }
 
 android::status_t HWCSession::SetIdlePC(const android::Parcel *input_parcel) {
diff --git a/sdm/libs/hwc2/hwc_session.h b/sdm/libs/hwc2/hwc_session.h
index b2a4100..31110a6 100644
--- a/sdm/libs/hwc2/hwc_session.h
+++ b/sdm/libs/hwc2/hwc_session.h
@@ -347,8 +347,9 @@
   void HandleSecureSession(hwc2_display_t display);
   void HandlePowerOnPending(hwc2_display_t display, int retire_fence);
   void HandleHotplugPending(hwc2_display_t disp_id, int retire_fence);
-  void UpdateVsyncSource(hwc2_display_t display);
+  void UpdateVsyncSource();
   hwc2_display_t GetNextBuiltinIndex();
+  hwc2_display_t GetNextVsyncSource();
 
   CoreInterface *core_intf_ = nullptr;
   HWCDisplay *hwc_display_[kNumDisplays] = {nullptr};
diff --git a/sdm/libs/hwc2/hwc_session_services.cpp b/sdm/libs/hwc2/hwc_session_services.cpp
index ff71e82..c00fc58 100644
--- a/sdm/libs/hwc2/hwc_session_services.cpp
+++ b/sdm/libs/hwc2/hwc_session_services.cpp
@@ -602,8 +602,8 @@
       if (!idle_pc_ref_cnt_) {
         HWC2::Error err =
             hwc_display_[HWC_DISPLAY_PRIMARY]->ControlIdlePowerCollapse(enable, synchronous);
-        if (err == HWC2::Error::Unsupported) {
-          return 0;
+        if (err != HWC2::Error::None) {
+          return (err == HWC2::Error::Unsupported) ? 0 : -EINVAL;
         }
         Refresh(HWC_DISPLAY_PRIMARY);
         int32_t error = locker_[HWC_DISPLAY_PRIMARY].WaitFinite(kCommitDoneTimeoutMs);
@@ -618,8 +618,8 @@
       if (!(idle_pc_ref_cnt_ - 1)) {
         HWC2::Error err =
             hwc_display_[HWC_DISPLAY_PRIMARY]->ControlIdlePowerCollapse(enable, synchronous);
-        if (err == HWC2::Error::Unsupported) {
-          return 0;
+        if (err != HWC2::Error::None) {
+          return (err == HWC2::Error::Unsupported) ? 0 : -EINVAL;
         }
         DLOGI("Idle PC enabled!!");
       }