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>
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 @@
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 @@
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