summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Donnefort <vincent.donnefort@arm.com>2019-10-09 14:23:42 +0100
committerVincent Donnefort <vincent.donnefort@arm.com>2019-10-22 13:49:37 +0100
commit315444c821887bc0722ca0cd182bc3bd72edb785 (patch)
tree520044280017de5bd1781a3a79cc0cadf1a17cdd
parent7834a89950e97473ba3a2c7d7f27c8e236ed5e52 (diff)
drm_hwcomposer: HWC2: Handle bad display_handle
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>
-rw-r--r--include/drmhwctwo.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/include/drmhwctwo.h b/include/drmhwctwo.h
index a71d7cc..1fdf401 100644
--- a/include/drmhwctwo.h
+++ b/include/drmhwctwo.h
@@ -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)...));
}