diff options
| author | 2016-04-14 12:31:01 -0700 | |
|---|---|---|
| committer | 2016-04-14 12:37:41 -0700 | |
| commit | 09e7a27fabde3da99ba6dfd2fd20be7d1425a9ad (patch) | |
| tree | 9d5af5b35fb55826239986aee36917a9b0a61de8 | |
| parent | 6979bb988915d22b3463aacdf4d86c5c8ab3b2ac (diff) | |
HWC2: Check SidebandStream capability on load
Checks whether the HWC2 device has the SidebandStream capability
before attempting to load the corresponding function pointer
Bug: 28161394
Change-Id: I6407d61a1b23138781e57213bcb868be46609018
| -rw-r--r-- | services/surfaceflinger/DisplayHardware/HWC2.cpp | 18 | ||||
| -rw-r--r-- | services/surfaceflinger/DisplayHardware/HWC2.h | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp index 5c78c68ef2..f7678e405c 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.cpp +++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp @@ -30,6 +30,7 @@ #include <android/configuration.h> +#include <algorithm> #include <inttypes.h> extern "C" { @@ -303,6 +304,12 @@ void Device::loadCapabilities() mHwcDevice->getCapabilities(mHwcDevice, &numCapabilities, asInt); } +bool Device::hasCapability(HWC2::Capability capability) const +{ + return std::find(mCapabilities.cbegin(), mCapabilities.cend(), + capability) != mCapabilities.cend(); +} + void Device::loadFunctionPointers() { // For all of these early returns, we log an error message inside @@ -378,8 +385,10 @@ void Device::loadFunctionPointers() mSetLayerDisplayFrame)) return; if (!loadFunctionPointer(FunctionDescriptor::SetLayerPlaneAlpha, mSetLayerPlaneAlpha)) return; - if (!loadFunctionPointer(FunctionDescriptor::SetLayerSidebandStream, - mSetLayerSidebandStream)) return; + if (hasCapability(Capability::SidebandStream)) { + if (!loadFunctionPointer(FunctionDescriptor::SetLayerSidebandStream, + mSetLayerSidebandStream)) return; + } if (!loadFunctionPointer(FunctionDescriptor::SetLayerSourceCrop, mSetLayerSourceCrop)) return; if (!loadFunctionPointer(FunctionDescriptor::SetLayerTransform, @@ -973,6 +982,11 @@ Error Layer::setPlaneAlpha(float alpha) Error Layer::setSidebandStream(const native_handle_t* stream) { + if (!mDevice.hasCapability(Capability::SidebandStream)) { + ALOGE("Attempted to call setSidebandStream without checking that the " + "device supports sideband streams"); + return Error::Unsupported; + } int32_t intError = mDevice.mSetLayerSidebandStream(mDevice.mHwcDevice, mDisplayId, mId, stream); return static_cast<Error>(intError); diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index 7d33a0a4d4..967add01f2 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -89,6 +89,8 @@ public: // as connected std::shared_ptr<Display> getDisplayById(hwc2_display_t id); + bool hasCapability(HWC2::Capability capability) const; + private: // Initialization methods |