diff options
author | Vincent Donnefort <vincent.donnefort@arm.com> | 2019-10-09 15:43:43 +0100 |
---|---|---|
committer | Vincent Donnefort <vincent.donnefort@arm.com> | 2019-10-22 13:49:59 +0100 |
commit | 9abec035e84bd38b1ff03c8077f6bb40c9fc75b8 (patch) | |
tree | ce37cf558e34ebd9b9ef5dd00a97396bd2697c3c | |
parent | 315444c821887bc0722ca0cd182bc3bd72edb785 (diff) |
drm_hwcomposer: HWC2: Handle bad layer_handle
HWC2 can issue a command with an incorrect layer handle. Making sure a such
error is caught with the expected HWC2 error code BadLayer
This can be verified with the VTS test:
* GraphicsComposerHidlTest.DestroyLayerBadLayerError
Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com>
-rw-r--r-- | drmhwctwo.cpp | 3 | ||||
-rw-r--r-- | include/drmhwctwo.h | 14 |
2 files changed, 13 insertions, 4 deletions
diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp index 95c93de..814d8f7 100644 --- a/drmhwctwo.cpp +++ b/drmhwctwo.cpp @@ -273,6 +273,9 @@ HWC2::Error DrmHwcTwo::HwcDisplay::CreateLayer(hwc2_layer_t *layer) { HWC2::Error DrmHwcTwo::HwcDisplay::DestroyLayer(hwc2_layer_t layer) { supported(__func__); + if (!get_layer(layer)) + return HWC2::Error::BadLayer; + layers_.erase(layer); return HWC2::Error::None; } diff --git a/include/drmhwctwo.h b/include/drmhwctwo.h index 1fdf401..8c75fc0 100644 --- a/include/drmhwctwo.h +++ b/include/drmhwctwo.h @@ -183,8 +183,11 @@ class DrmHwcTwo : public hwc2_device_t { HWC2::Error SetPowerMode(int32_t mode); HWC2::Error SetVsyncEnabled(int32_t enabled); HWC2::Error ValidateDisplay(uint32_t *num_types, uint32_t *num_requests); - HwcLayer &get_layer(hwc2_layer_t layer) { - return layers_.at(layer); + HwcLayer *get_layer(hwc2_layer_t layer) { + auto it = layers_.find(layer); + if (it == layers_.end()) + return nullptr; + return &it->second; } private: @@ -268,8 +271,11 @@ class DrmHwcTwo : public hwc2_device_t { 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)...)); + HwcLayer *layer = display->get_layer(layer_handle); + if (!layer) + return static_cast<int32_t>(HWC2::Error::BadLayer); + + return static_cast<int32_t>((layer->*func)(std::forward<Args>(args)...)); } // hwc2_device_t hooks |