drm_hwcomposer: Only validate layer brightness

Layer brightness is not supported, but an error is returned when a bad
value is set for layer brightness regardless.

Move the related code around to make this clearer and consistent with
other layer commands.

Change-Id: Iad59dcefb4ff0187d1c3f2c1ff368a58661b0ae0
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc3/ComposerClient.cpp b/hwc3/ComposerClient.cpp
index 1becdb1..2aed2bc 100644
--- a/hwc3/ComposerClient.cpp
+++ b/hwc3/ComposerClient.cpp
@@ -154,6 +154,14 @@
   }
 }
 
+bool ValidateLayerBrightness(const std::optional<LayerBrightness>& brightness) {
+  if (!brightness) {
+    return true;
+  }
+  return !(std::signbit(brightness->brightness) ||
+           std::isnan(brightness->brightness));
+}
+
 std::optional<HWC2::Composition> AidlToCompositionType(
     const std::optional<ParcelableComposition> composition) {
   if (!composition) {
@@ -512,6 +520,13 @@
     return;
   }
 
+  // For some invalid parameters, the HWC should return an error and not process
+  // any further commands.
+  if (!ValidateLayerBrightness(command.brightness)) {
+    cmd_result_writer_->AddError(hwc3::Error::kBadParameter);
+    return;
+  }
+
   HwcLayerWrapper layer_wrapper{command.layer, layer};
   if (command.buffer) {
     ExecuteSetLayerBuffer(display_id, layer_wrapper, *command.buffer);
@@ -530,10 +545,6 @@
 
   layer->SetLayerProperties(properties);
 
-  if (command.brightness) {
-    ExecuteSetLayerBrightness(display_id, layer_wrapper, *command.brightness);
-  }
-
   // Some unsupported functionality returns kUnsupported, and others
   // are just a no-op.
   // TODO: Audit whether some of these should actually return kUnsupported
@@ -1224,15 +1235,6 @@
   }
 }
 
-void ComposerClient::ExecuteSetLayerBrightness(
-    int64_t /*display_id*/, HwcLayerWrapper& /*layer*/,
-    const LayerBrightness& brightness) {
-  if (std::signbit(brightness.brightness) ||
-      std::isnan(brightness.brightness)) {
-    cmd_result_writer_->AddError(hwc3::Error::kBadParameter);
-  }
-}
-
 void ComposerClient::ExecuteSetDisplayBrightness(
     uint64_t display_id, const DisplayBrightness& command) {
   auto* display = GetDisplay(display_id);