From 1e0e2ca0a50665f5f762d26d21edb2d6035ac2ae Mon Sep 17 00:00:00 2001 From: Andrew Wolfers Date: Tue, 11 Nov 2025 17:01:04 +0000 Subject: [PATCH] Move implementations out of headers This change moves some non-trivial implementations out of header files in drm/. This will enable some includes to be converted to forward declarations in future changes. Change-Id: I7b1248657e0fa27e3c0c0157abe4f6b918e13a29 --- drm/DrmConnector.cpp | 18 ++++++++++++++++++ drm/DrmConnector.h | 19 ++++--------------- drm/DrmDevice.cpp | 22 ++++++++++++++++++++++ drm/DrmDevice.h | 22 +++------------------- drm/DrmEncoder.cpp | 8 ++++++++ drm/DrmEncoder.h | 8 ++------ drm/DrmFbImporter.cpp | 3 +++ drm/DrmFbImporter.h | 2 +- 8 files changed, 61 insertions(+), 41 deletions(-) diff --git a/drm/DrmConnector.cpp b/drm/DrmConnector.cpp index d9e1a95..1692505 100644 --- a/drm/DrmConnector.cpp +++ b/drm/DrmConnector.cpp @@ -81,6 +81,13 @@ auto DrmConnector::CreateInstance(DrmDevice &dev, uint32_t connector_id, return c; } +DrmConnector::~DrmConnector() = default; + +DrmConnector::DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, + uint32_t index) + : connector_(std::move(connector)), drm_(drm), index_in_res_array_(index) { +} + auto DrmConnector::Init()-> bool { if (!GetConnectorProperty("DPMS", &dpms_property_) || !GetConnectorProperty("CRTC_ID", &crtc_id_property_)) { @@ -195,6 +202,17 @@ auto DrmConnector::GetEdidBlob() -> DrmModePropertyBlobUnique { return MakeDrmModePropertyBlobUnique(*drm_->GetFd(), *blob_id); } +bool DrmConnector::SupportsEncoder(DrmEncoder &enc) const { + for (int i = 0; i < connector_->count_encoders; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + if (connector_->encoders[i] == enc.GetId()) { + return true; + } + } + + return false; +} + bool DrmConnector::IsInternal() const { auto type = connector_->connector_type; return type == DRM_MODE_CONNECTOR_Unknown || diff --git a/drm/DrmConnector.h b/drm/DrmConnector.h index d9e6baf..6f2d857 100644 --- a/drm/DrmConnector.h +++ b/drm/DrmConnector.h @@ -42,7 +42,7 @@ class DrmConnector : public PipelineBindable { DrmConnector(const DrmProperty &) = delete; DrmConnector &operator=(const DrmProperty &) = delete; - virtual ~DrmConnector() = default; + virtual ~DrmConnector(); int UpdateEdidProperty(); auto GetEdidBlob() -> DrmModePropertyBlobUnique; @@ -63,16 +63,7 @@ class DrmConnector : public PipelineBindable { return connector_->encoder_id; } - auto SupportsEncoder(DrmEncoder &enc) const { - for (int i = 0; i < connector_->count_encoders; i++) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (connector_->encoders[i] == enc.GetId()) { - return true; - } - } - - return false; - } + bool SupportsEncoder(DrmEncoder &enc) const; bool IsInternal() const; bool IsExternal() const; @@ -158,10 +149,8 @@ class DrmConnector : public PipelineBindable { auto GetPanelOrientation() -> std::optional; private: - DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, uint32_t index) - : connector_(std::move(connector)), - drm_(drm), - index_in_res_array_(index) {}; + DrmConnector(DrmModeConnectorUnique connector, DrmDevice *drm, + uint32_t index); DrmModeConnectorUnique connector_; DrmDevice *const drm_; diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp index 7c50945..533603a 100644 --- a/drm/DrmDevice.cpp +++ b/drm/DrmDevice.cpp @@ -36,6 +36,8 @@ namespace android::drm_hwcomposer { +DrmDevice::~DrmDevice() = default; + auto DrmDevice::CreateInstance(std::string const &path, ResourceManager *res_man, uint32_t index) -> std::unique_ptr { @@ -194,6 +196,26 @@ auto DrmDevice::RegisterUserPropertyBlob(void *data, size_t length) const }); } +DrmCrtc *DrmDevice::FindCrtcById(uint32_t id) const { + for (const auto &crtc : crtcs_) { + if (crtc->GetId() == id) { + return crtc.get(); + } + }; + + return nullptr; +} + +DrmEncoder *DrmDevice::FindEncoderById(uint32_t id) const { + for (const auto &enc : encoders_) { + if (enc->GetId() == id) { + return enc.get(); + } + }; + + return nullptr; +} + int DrmDevice::GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, DrmProperty *property) const { drmModeObjectPropertiesPtr props = nullptr; diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h index 994c966..6526964 100644 --- a/drm/DrmDevice.h +++ b/drm/DrmDevice.h @@ -37,7 +37,7 @@ class DrmDevice { friend class FakeDrmDevice; public: - ~DrmDevice() = default; + ~DrmDevice(); static auto CreateInstance(std::string const &path, ResourceManager *res_man, uint32_t index) -> std::unique_ptr; @@ -88,25 +88,9 @@ class DrmDevice { return *drm_fb_importer_; } - auto FindCrtcById(uint32_t id) const -> DrmCrtc * { - for (const auto &crtc : crtcs_) { - if (crtc->GetId() == id) { - return crtc.get(); - } - }; + DrmCrtc *FindCrtcById(uint32_t id) const; - return nullptr; - } - - auto FindEncoderById(uint32_t id) const -> DrmEncoder * { - for (const auto &enc : encoders_) { - if (enc->GetId() == id) { - return enc.get(); - } - }; - - return nullptr; - } + DrmEncoder *FindEncoderById(uint32_t id) const; int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, DrmProperty *property) const; diff --git a/drm/DrmEncoder.cpp b/drm/DrmEncoder.cpp index a4ecab3..cc4dac8 100644 --- a/drm/DrmEncoder.cpp +++ b/drm/DrmEncoder.cpp @@ -38,4 +38,12 @@ auto DrmEncoder::CreateInstance(DrmDevice &dev, uint32_t encoder_id, return std::unique_ptr(new DrmEncoder(std::move(e), index)); } +bool DrmEncoder::CanClone(DrmEncoder &encoder) { + return (enc_->possible_clones & (1 << encoder.GetIndexInResArray())) != 0; +} + +bool DrmEncoder::SupportsCrtc(DrmCrtc &crtc) { + return (enc_->possible_crtcs & (1 << crtc.GetIndexInResArray())) != 0; +} + } // namespace android::drm_hwcomposer diff --git a/drm/DrmEncoder.h b/drm/DrmEncoder.h index ee0c454..85cfd2a 100644 --- a/drm/DrmEncoder.h +++ b/drm/DrmEncoder.h @@ -47,13 +47,9 @@ class DrmEncoder : public PipelineBindable { return index_in_res_array_; } - auto CanClone(DrmEncoder &encoder) { - return (enc_->possible_clones & (1 << encoder.GetIndexInResArray())) != 0; - } + bool CanClone(DrmEncoder &encoder); - auto SupportsCrtc(DrmCrtc &crtc) { - return (enc_->possible_crtcs & (1 << crtc.GetIndexInResArray())) != 0; - } + bool SupportsCrtc(DrmCrtc &crtc); virtual uint32_t GetCurrentCrtcId() const { return enc_->crtc_id; diff --git a/drm/DrmFbImporter.cpp b/drm/DrmFbImporter.cpp index 53d3614..2188310 100644 --- a/drm/DrmFbImporter.cpp +++ b/drm/DrmFbImporter.cpp @@ -125,6 +125,9 @@ DrmFbIdHandle::~DrmFbIdHandle() { } } +DrmFbIdHandle::DrmFbIdHandle(DrmDevice &drm) : drm_fd_(drm.GetFd()) { +} + auto DrmFbImporter::GetOrCreateFbId(BufferInfo *bo) -> std::shared_ptr { /* TODO: Clean up DrmDevices and DrmFbImporter inter-dependency. diff --git a/drm/DrmFbImporter.h b/drm/DrmFbImporter.h index fd2f44b..a8b9dcf 100644 --- a/drm/DrmFbImporter.h +++ b/drm/DrmFbImporter.h @@ -50,7 +50,7 @@ class DrmFbIdHandle { } private: - explicit DrmFbIdHandle(DrmDevice &drm) : drm_fd_(drm.GetFd()) {}; + explicit DrmFbIdHandle(DrmDevice &drm); SharedFd drm_fd_;