aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drmhwctwo.cpp10
-rw-r--r--include/drmhwctwo.h36
2 files changed, 35 insertions, 11 deletions
diff --git a/drmhwctwo.cpp b/drmhwctwo.cpp
index 9268cdc..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;
}
@@ -732,7 +735,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetColorMode(int32_t mode) {
supported(__func__);
if (mode != HAL_COLOR_MODE_NATIVE)
- return HWC2::Error::Unsupported;
+ return HWC2::Error::BadParameter;
color_mode_ = mode;
return HWC2::Error::None;
@@ -763,9 +766,12 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetPowerMode(int32_t mode_in) {
case HWC2::PowerMode::On:
dpms_value = DRM_MODE_DPMS_ON;
break;
+ case HWC2::PowerMode::Doze:
+ case HWC2::PowerMode::DozeSuspend:
+ return HWC2::Error::Unsupported;
default:
ALOGI("Power mode %d is unsupported\n", mode);
- return HWC2::Error::Unsupported;
+ return HWC2::Error::BadParameter;
};
std::unique_ptr<DrmDisplayComposition> composition = compositor_
diff --git a/include/drmhwctwo.h b/include/drmhwctwo.h
index a71d7cc..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:
@@ -243,21 +246,36 @@ 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);
- return static_cast<int32_t>((layer.*func)(std::forward<Args>(args)...));
+ HwcDisplay *display = GetDisplay(toDrmHwcTwo(dev), display_handle);
+ if (!display)
+ return static_cast<int32_t>(HWC2::Error::BadDisplay);
+
+ 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