OSDN Git Service

drm_hwcomposer: HWC2: Handle bad display_handle
authorVincent Donnefort <vincent.donnefort@arm.com>
Wed, 9 Oct 2019 13:23:42 +0000 (14:23 +0100)
committerVincent Donnefort <vincent.donnefort@arm.com>
Tue, 22 Oct 2019 12:49:37 +0000 (13:49 +0100)
HWC2 can issue a command with an incorrect display handle. Making sure a such
error is caught with the right HWC2 error code BadDisplay.

This can be verified with the VTS tests:

  * GraphicsComposerHidlTest.DestroyLayerBadDisplay
  * GraphicsComposerHidlTest.CreateLayerBadDisplay
  * GraphicsComposerHidlTest.GetActiveConfigBadDisplay

Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com>
include/drmhwctwo.h

index a71d7cc..1fdf401 100644 (file)
@@ -243,20 +243,32 @@ class DrmHwcTwo : public hwc2_device_t {
     return static_cast<T>(((*hwc).*func)(std::forward<Args>(args)...));
   }
 
+  static HwcDisplay *GetDisplay(DrmHwcTwo *hwc, hwc2_display_t display_handle) {
+    auto it = hwc->displays_.find(display_handle);
+    if (it == hwc->displays_.end())
+      return nullptr;
+
+    return &it->second;
+  }
+
   template <typename HookType, HookType func, typename... Args>
   static int32_t DisplayHook(hwc2_device_t *dev, hwc2_display_t display_handle,
                              Args... args) {
-    DrmHwcTwo *hwc = toDrmHwcTwo(dev);
-    HwcDisplay &display = hwc->displays_.at(display_handle);
-    return static_cast<int32_t>((display.*func)(std::forward<Args>(args)...));
+    HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
+    if (!display)
+      return static_cast<int32_t>(HWC2::Error::BadDisplay);
+
+    return static_cast<int32_t>((display->*func)(std::forward<Args>(args)...));
   }
 
   template <typename HookType, HookType func, typename... Args>
   static int32_t LayerHook(hwc2_device_t *dev, hwc2_display_t display_handle,
                            hwc2_layer_t layer_handle, Args... args) {
-    DrmHwcTwo *hwc = toDrmHwcTwo(dev);
-    HwcDisplay &display = hwc->displays_.at(display_handle);
-    HwcLayer &layer = display.get_layer(layer_handle);
+    HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
+    if (!display)
+      return static_cast<int32_t>(HWC2::Error::BadDisplay);
+
+    HwcLayer &layer = display->get_layer(layer_handle);
     return static_cast<int32_t>((layer.*func)(std::forward<Args>(args)...));
   }