OSDN Git Service

drm_hwcomposer: Move ValidatePlane method into DrmPlane
authorMatvii Zorin <matvii.zorin@globallogic.com>
Sun, 31 Jan 2021 12:45:05 +0000 (14:45 +0200)
committerMatvii Zorin <matvii.zorin@globallogic.com>
Tue, 6 Apr 2021 09:46:22 +0000 (12:46 +0300)
It is more common to validate the layer for the proper object.

Signed-off-by: Matvii Zorin <matvii.zorin@globallogic.com>
compositor/Planner.cpp
compositor/Planner.h
drm/DrmPlane.cpp
drm/DrmPlane.h

index d87e79f..42259d1 100644 (file)
@@ -44,57 +44,6 @@ std::vector<DrmPlane *> Planner::GetUsablePlanes(
   return usable_planes;
 }
 
-int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) {
-  int ret = 0;
-  uint64_t blend = UINT64_MAX;
-
-  if ((plane->rotation_property().id() == 0) &&
-      layer->transform != DrmHwcTransform::kIdentity) {
-    ALOGE("Rotation is not supported on plane %d", plane->id());
-    return -EINVAL;
-  }
-
-  if (plane->alpha_property().id() == 0 && layer->alpha != 0xffff) {
-    ALOGE("Alpha is not supported on plane %d", plane->id());
-    return -EINVAL;
-  }
-
-  if (plane->blend_property().id() == 0) {
-    if ((layer->blending != DrmHwcBlending::kNone) &&
-        (layer->blending != DrmHwcBlending::kPreMult)) {
-      ALOGE("Blending is not supported on plane %d", plane->id());
-      return -EINVAL;
-    }
-  } else {
-    switch (layer->blending) {
-      case DrmHwcBlending::kPreMult:
-        std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
-            "Pre-multiplied");
-        break;
-      case DrmHwcBlending::kCoverage:
-        std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
-            "Coverage");
-        break;
-      case DrmHwcBlending::kNone:
-      default:
-        std::tie(blend,
-                 ret) = plane->blend_property().GetEnumValueWithName("None");
-        break;
-    }
-    if (ret)
-      ALOGE("Expected a valid blend mode on plane %d", plane->id());
-  }
-
-  uint32_t format = layer->buffer->format;
-  if (!plane->IsFormatSupported(format)) {
-    ALOGE("Plane %d does not supports %c%c%c%c format", plane->id(), format,
-          format >> 8, format >> 16, format >> 24);
-    return -EINVAL;
-  }
-
-  return ret;
-}
-
 std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
     std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
     std::vector<DrmPlane *> *primary_planes,
index 7c1fe80..3390acb 100644 (file)
@@ -52,8 +52,6 @@ class Planner {
       return plane;
     }
 
-    static int ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer);
-
     // Inserts the given layer:plane in the composition at the back
     static int Emplace(std::vector<DrmCompositionPlane> *composition,
                        std::vector<DrmPlane *> *planes,
@@ -63,7 +61,7 @@ class Planner {
       std::vector<DrmPlane *> unused_planes;
       int ret = -ENOENT;
       while (plane) {
-        ret = ValidatePlane(plane, layer.second);
+        ret = plane->IsValidForLayer(layer.second) ? 0 : -EINVAL;
         if (!ret)
           break;
         if (!plane->zpos_property().is_immutable())
index 2967a7a..b841189 100644 (file)
@@ -164,6 +164,57 @@ bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
   return ((1 << crtc.pipe()) & possible_crtc_mask_) != 0;
 }
 
+bool DrmPlane::IsValidForLayer(DrmHwcLayer *layer) {
+  if ((rotation_property_.id() == 0) &&
+      layer->transform != DrmHwcTransform::kIdentity) {
+    ALOGV("Rotation is not supported on plane %d", id_);
+    return false;
+  }
+
+  if (alpha_property_.id() == 0 && layer->alpha != 0xffff) {
+    ALOGV("Alpha is not supported on plane %d", id_);
+    return false;
+  }
+
+  if (blend_property_.id() == 0) {
+    if ((layer->blending != DrmHwcBlending::kNone) &&
+        (layer->blending != DrmHwcBlending::kPreMult)) {
+      ALOGV("Blending is not supported on plane %d", id_);
+      return false;
+    }
+  } else {
+    int ret = 0;
+    uint64_t blend = 0;
+
+    switch (layer->blending) {
+      case DrmHwcBlending::kPreMult:
+        std::tie(blend,
+                 ret) = blend_property_.GetEnumValueWithName("Pre-multiplied");
+        break;
+      case DrmHwcBlending::kCoverage:
+        std::tie(blend, ret) = blend_property_.GetEnumValueWithName("Coverage");
+        break;
+      case DrmHwcBlending::kNone:
+      default:
+        std::tie(blend, ret) = blend_property_.GetEnumValueWithName("None");
+        break;
+    }
+    if (ret) {
+      ALOGV("Expected a valid blend mode on plane %d", id_);
+      return false;
+    }
+  }
+
+  uint32_t format = layer->buffer->format;
+  if (!IsFormatSupported(format)) {
+    ALOGV("Plane %d does not supports %c%c%c%c format", id_, format,
+          format >> 8, format >> 16, format >> 24);
+    return false;
+  }
+
+  return true;
+}
+
 uint32_t DrmPlane::type() const {
   return type_;
 }
index 2e2c121..862a0f3 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "DrmCrtc.h"
 #include "DrmProperty.h"
+#include "drmhwcomposer.h"
 
 namespace android {
 
@@ -40,6 +41,7 @@ class DrmPlane {
   uint32_t id() const;
 
   bool GetCrtcSupported(const DrmCrtc &crtc) const;
+  bool IsValidForLayer(DrmHwcLayer *layer);
 
   uint32_t type() const;