diff options
author | Kaiyi Li <kaiyili@google.com> | 2024-01-18 13:09:30 -0800 |
---|---|---|
committer | Kaiyi Li <kaiyili@google.com> | 2024-03-12 12:48:38 -0700 |
commit | 32e51246d901670ec78965dded50f8b060d6ccd0 (patch) | |
tree | 74241efbb6d294982d683f4001e37c0b00fd5974 | |
parent | 96b83c5162735cff7fd3fcea05b0a989c65002d6 (diff) | |
download | goldfish-opengl-32e51246d901670ec78965dded50f8b060d6ccd0.tar.gz |
hwc3: edid: move EDID parsing to a separate file
Bug: b/328091332
Test: presubmit
Change-Id: I922fcb5cc70ebfda44fdf70632f4868a8ff25198
-rw-r--r-- | system/hwc3/Android.bp | 1 | ||||
-rw-r--r-- | system/hwc3/DrmConnector.cpp | 36 | ||||
-rw-r--r-- | system/hwc3/DrmConnector.h | 3 | ||||
-rw-r--r-- | system/hwc3/EdidInfo.cpp | 30 | ||||
-rw-r--r-- | system/hwc3/EdidInfo.h | 16 |
5 files changed, 61 insertions, 25 deletions
diff --git a/system/hwc3/Android.bp b/system/hwc3/Android.bp index ccbab191..a08a1bed 100644 --- a/system/hwc3/Android.bp +++ b/system/hwc3/Android.bp @@ -77,6 +77,7 @@ cc_binary { "DrmEventListener.cpp", "DrmMode.cpp", "DrmPlane.cpp", + "EdidInfo.cpp", "Gralloc.cpp", "GuestFrameComposer.cpp", "HostFrameComposer.cpp", diff --git a/system/hwc3/DrmConnector.cpp b/system/hwc3/DrmConnector.cpp index dac64058..c5f9e0d8 100644 --- a/system/hwc3/DrmConnector.cpp +++ b/system/hwc3/DrmConnector.cpp @@ -18,6 +18,8 @@ #include <span> +#include "EdidInfo.h" + namespace aidl::android::hardware::graphics::composer3::impl { namespace { @@ -67,9 +69,14 @@ bool DrmConnector::update(::android::base::borrowed_fd drmFd) { drmModeFreeConnector(drmConnector); if (mStatus == DRM_MODE_CONNECTED) { - if (!loadEdid(drmFd)) { + std::optional<EdidInfo> maybeEdidInfo = loadEdid(drmFd); + if (!maybeEdidInfo) { + ALOGE("%s: failed to parse EDID info for display:%" PRIu32 ".", __FUNCTION__, mId); return false; } + const EdidInfo& edidInfo = maybeEdidInfo.value(); + mWidthMillimeters = edidInfo.mWidthMillimeters; + mHeightMillimeters = edidInfo.mHeightMillimeters; } DEBUG_LOG("%s: connector:%" PRIu32 " widthMillimeters:%" PRIu32 " heightMillimeters:%" PRIu32, @@ -79,20 +86,20 @@ bool DrmConnector::update(::android::base::borrowed_fd drmFd) { return true; } -bool DrmConnector::loadEdid(::android::base::borrowed_fd drmFd) { +std::optional<EdidInfo> DrmConnector::loadEdid(::android::base::borrowed_fd drmFd) { DEBUG_LOG("%s: display:%" PRIu32, __FUNCTION__, mId); const uint64_t edidBlobId = mEdidProp.getValue(); if (edidBlobId == -1) { ALOGW("%s: display:%" PRIu32 " does not have EDID.", __FUNCTION__, mId); - return true; + return std::nullopt; } auto blob = drmModeGetPropertyBlob(drmFd.get(), static_cast<uint32_t>(edidBlobId)); if (!blob) { ALOGE("%s: display:%" PRIu32 " failed to read EDID blob (%" PRIu64 "): %s", __FUNCTION__, mId, edidBlobId, strerror(errno)); - return false; + return std::nullopt; } const uint8_t* blobStart = static_cast<uint8_t*>(blob->data); @@ -101,28 +108,9 @@ bool DrmConnector::loadEdid(::android::base::borrowed_fd drmFd) { drmModeFreePropertyBlob(blob); using byte_view = std::span<const uint8_t>; - - constexpr size_t kEdidDescriptorOffset = 54; - constexpr size_t kEdidDescriptorLength = 18; - byte_view edid(*mEdid); - edid = edid.subspan(kEdidDescriptorOffset); - byte_view descriptor(edid.data(), kEdidDescriptorLength); - if (descriptor[0] == 0 && descriptor[1] == 0) { - ALOGE("%s: display:%" PRIu32 " is missing preferred detailed timing descriptor.", - __FUNCTION__, mId); - return -1; - } - - const uint8_t w_mm_lsb = descriptor[12]; - const uint8_t h_mm_lsb = descriptor[13]; - const uint8_t w_and_h_mm_msb = descriptor[14]; - - mWidthMillimeters = w_mm_lsb | (w_and_h_mm_msb & 0xf0) << 4; - mHeightMillimeters = h_mm_lsb | (w_and_h_mm_msb & 0xf) << 8; - - return true; + return EdidInfo::parse(edid); } uint32_t DrmConnector::getWidth() const { diff --git a/system/hwc3/DrmConnector.h b/system/hwc3/DrmConnector.h index 1cc46c5c..f908631d 100644 --- a/system/hwc3/DrmConnector.h +++ b/system/hwc3/DrmConnector.h @@ -30,6 +30,7 @@ #include "Common.h" #include "DrmMode.h" #include "DrmProperty.h" +#include "EdidInfo.h" namespace aidl::android::hardware::graphics::composer3::impl { @@ -63,7 +64,7 @@ class DrmConnector { private: DrmConnector(uint32_t id) : mId(id) {} - bool loadEdid(::android::base::borrowed_fd drmFd); + std::optional<EdidInfo> loadEdid(::android::base::borrowed_fd drmFd); const uint32_t mId; diff --git a/system/hwc3/EdidInfo.cpp b/system/hwc3/EdidInfo.cpp new file mode 100644 index 00000000..e4b63fa6 --- /dev/null +++ b/system/hwc3/EdidInfo.cpp @@ -0,0 +1,30 @@ +#include "EdidInfo.h" + +#include "Common.h" + +namespace aidl::android::hardware::graphics::composer3::impl { +std::optional<EdidInfo> EdidInfo::parse(std::span<const uint8_t> blob) { + constexpr size_t kEdidDescriptorOffset = 54; + constexpr size_t kEdidDescriptorLength = 18; + + blob = blob.subspan(kEdidDescriptorOffset); + + using byte_view = std::span<const uint8_t>; + byte_view descriptor(blob.data(), kEdidDescriptorLength); + if (descriptor[0] == 0 && descriptor[1] == 0) { + ALOGE("%s: missing preferred detailed timing descriptor", __FUNCTION__); + return std::nullopt; + } + + const uint8_t w_mm_lsb = descriptor[12]; + const uint8_t h_mm_lsb = descriptor[13]; + const uint8_t w_and_h_mm_msb = descriptor[14]; + + return EdidInfo{ + .mWidthMillimeters = + static_cast<uint32_t>(w_mm_lsb) | ((static_cast<uint32_t>(w_and_h_mm_msb) & 0xf0) << 4), + .mHeightMillimeters = + static_cast<uint32_t>(h_mm_lsb) | ((static_cast<uint32_t>(w_and_h_mm_msb) & 0xf) << 8), + }; +} +} // namespace aidl::android::hardware::graphics::composer3::impl diff --git a/system/hwc3/EdidInfo.h b/system/hwc3/EdidInfo.h new file mode 100644 index 00000000..bcccebfd --- /dev/null +++ b/system/hwc3/EdidInfo.h @@ -0,0 +1,16 @@ +#pragma once + +#include <cinttypes> +#include <optional> +#include <span> + +namespace aidl::android::hardware::graphics::composer3::impl { + +struct EdidInfo { + uint32_t mWidthMillimeters = 0; + uint32_t mHeightMillimeters = 0; + + static std::optional<EdidInfo> parse(std::span<const uint8_t> blob); +}; + +} // namespace aidl::android::hardware::graphics::composer3::impl |