diff options
Diffstat (limited to 'drm')
-rw-r--r-- | drm/DrmConnector.cpp | 6 | ||||
-rw-r--r-- | drm/DrmCrtc.cpp | 2 | ||||
-rw-r--r-- | drm/DrmDevice.cpp | 87 | ||||
-rw-r--r-- | drm/DrmDevice.h | 29 | ||||
-rw-r--r-- | drm/DrmEncoder.cpp | 2 | ||||
-rw-r--r-- | drm/DrmFbImporter.cpp | 19 | ||||
-rw-r--r-- | drm/DrmFbImporter.h | 13 | ||||
-rw-r--r-- | drm/DrmPlane.cpp | 2 | ||||
-rw-r--r-- | drm/VSyncWorker.cpp | 2 |
9 files changed, 82 insertions, 80 deletions
diff --git a/drm/DrmConnector.cpp b/drm/DrmConnector.cpp index 5e00dd6..4737316 100644 --- a/drm/DrmConnector.cpp +++ b/drm/DrmConnector.cpp @@ -63,7 +63,7 @@ static bool GetConnectorProperty(const DrmDevice &dev, auto DrmConnector::CreateInstance(DrmDevice &dev, uint32_t connector_id, uint32_t index) -> std::unique_ptr<DrmConnector> { - auto conn = MakeDrmModeConnectorUnique(dev.fd(), connector_id); + auto conn = MakeDrmModeConnectorUnique(dev.GetFd(), connector_id); if (!conn) { ALOGE("Failed to get connector %d", connector_id); return {}; @@ -110,7 +110,7 @@ auto DrmConnector::GetEdidBlob() -> DrmModePropertyBlobUnique { return {}; } - return MakeDrmModePropertyBlobUnique(drm_->fd(), blob_id); + return MakeDrmModePropertyBlobUnique(drm_->GetFd(), blob_id); } bool DrmConnector::IsInternal() const { @@ -159,7 +159,7 @@ std::string DrmConnector::GetName() const { } int DrmConnector::UpdateModes() { - auto conn = MakeDrmModeConnectorUnique(drm_->fd(), GetId()); + auto conn = MakeDrmModeConnectorUnique(drm_->GetFd(), GetId()); if (!conn) { ALOGE("Failed to get connector %d", GetId()); return -ENODEV; diff --git a/drm/DrmCrtc.cpp b/drm/DrmCrtc.cpp index bc19141..b54f14b 100644 --- a/drm/DrmCrtc.cpp +++ b/drm/DrmCrtc.cpp @@ -35,7 +35,7 @@ static int GetCrtcProperty(const DrmDevice &dev, const DrmCrtc &crtc, auto DrmCrtc::CreateInstance(DrmDevice &dev, uint32_t crtc_id, uint32_t index) -> std::unique_ptr<DrmCrtc> { - auto crtc = MakeDrmModeCrtcUnique(dev.fd(), crtc_id); + auto crtc = MakeDrmModeCrtcUnique(dev.GetFd(), crtc_id); if (!crtc) { ALOGE("Failed to get CRTC %d", crtc_id); return {}; diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp index a6d2289..29dd95f 100644 --- a/drm/DrmDevice.cpp +++ b/drm/DrmDevice.cpp @@ -37,54 +37,53 @@ namespace android { DrmDevice::DrmDevice() { - self.reset(this); - mDrmFbImporter = std::make_unique<DrmFbImporter>(self); + drm_fb_importer_ = std::make_unique<DrmFbImporter>(*this); } // NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) { /* TODO: Use drmOpenControl here instead */ fd_ = UniqueFd(open(path, O_RDWR | O_CLOEXEC)); - if (fd() < 0) { + if (!fd_) { // NOLINTNEXTLINE(concurrency-mt-unsafe): Fixme ALOGE("Failed to open dri %s: %s", path, strerror(errno)); return std::make_tuple(-ENODEV, 0); } - int ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); - if (ret) { + int ret = drmSetClientCap(GetFd(), DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); + if (ret != 0) { ALOGE("Failed to set universal plane cap %d", ret); return std::make_tuple(ret, 0); } - ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_ATOMIC, 1); - if (ret) { + ret = drmSetClientCap(GetFd(), DRM_CLIENT_CAP_ATOMIC, 1); + if (ret != 0) { ALOGE("Failed to set atomic cap %d", ret); return std::make_tuple(ret, 0); } #ifdef DRM_CLIENT_CAP_WRITEBACK_CONNECTORS - ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1); - if (ret) { + ret = drmSetClientCap(GetFd(), DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1); + if (ret != 0) { ALOGI("Failed to set writeback cap %d", ret); ret = 0; } #endif uint64_t cap_value = 0; - if (drmGetCap(fd(), DRM_CAP_ADDFB2_MODIFIERS, &cap_value)) { + if (drmGetCap(GetFd(), DRM_CAP_ADDFB2_MODIFIERS, &cap_value) != 0) { ALOGW("drmGetCap failed. Fallback to no modifier support."); cap_value = 0; } HasAddFb2ModifiersSupport_ = cap_value != 0; - drmSetMaster(fd()); - if (!drmIsMaster(fd())) { + drmSetMaster(GetFd()); + if (drmIsMaster(GetFd()) == 0) { ALOGE("DRM/KMS master access required"); return std::make_tuple(-EACCES, 0); } - auto res = MakeDrmModeResUnique(fd()); + auto res = MakeDrmModeResUnique(GetFd()); if (!res) { ALOGE("Failed to get DrmDevice resources"); return std::make_tuple(-ENODEV, 0); @@ -147,10 +146,10 @@ std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) { add_displays(/*internal = */ false, /*connected = */ false); // Catch-all for the above loops - if (ret) + if (ret != 0) return std::make_tuple(ret, 0); - auto plane_res = MakeDrmModePlaneResUnique(fd()); + auto plane_res = MakeDrmModePlaneResUnique(GetFd()); if (!plane_res) { ALOGE("Failed to get plane resources"); return std::make_tuple(-ENOENT, 0); @@ -167,7 +166,7 @@ std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) { for (auto &conn : connectors_) { ret = CreateDisplayPipe(conn.get()); - if (ret) { + if (ret != 0) { ALOGE("Failed CreateDisplayPipe %d with %d", conn->GetId(), ret); return std::make_tuple(ret, 0); } @@ -187,18 +186,10 @@ DrmCrtc *DrmDevice::GetCrtcForDisplay(int display) const { return bound_crtcs_.at(display); } -const std::vector<std::unique_ptr<DrmCrtc>> &DrmDevice::crtcs() const { - return crtcs_; -} - -uint32_t DrmDevice::next_mode_id() { - return ++mode_id_; -} - int DrmDevice::TryEncoderForDisplay(int display, DrmEncoder *enc) { /* First try to use the currently-bound crtc */ auto *crtc = FindCrtcById(enc->GetCurrentCrtcId()); - if (crtc && bound_crtcs_.count(display) == 0) { + if (crtc != nullptr && bound_crtcs_.count(display) == 0) { bound_crtcs_[display] = crtc; bound_encoders_[crtc] = enc; return 0; @@ -228,7 +219,7 @@ int DrmDevice::CreateDisplayPipe(DrmConnector *connector) { auto *enc0 = FindEncoderById(connector->GetCurrentEncoderId()); if (enc0 != nullptr && encoders_to_display_id_.count(enc0) == 0) { int ret = TryEncoderForDisplay(display, enc0); - if (!ret) { + if (ret == 0) { encoders_to_display_id_[enc0] = display; return 0; } @@ -246,7 +237,7 @@ int DrmDevice::CreateDisplayPipe(DrmConnector *connector) { } int ret = TryEncoderForDisplay(display, enc.get()); - if (!ret) { + if (ret == 0) { encoders_to_display_id_[enc.get()] = display; return 0; } @@ -264,10 +255,11 @@ auto DrmDevice::RegisterUserPropertyBlob(void *data, size_t length) const -> DrmModeUserPropertyBlobUnique { struct drm_mode_create_blob create_blob {}; create_blob.length = length; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) create_blob.data = (__u64)data; - int ret = drmIoctl(fd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob); - if (ret) { + int ret = drmIoctl(GetFd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob); + if (ret != 0) { ALOGE("Failed to create mode property blob %d", ret); return {}; } @@ -276,7 +268,8 @@ auto DrmDevice::RegisterUserPropertyBlob(void *data, size_t length) const new uint32_t(create_blob.blob_id), [this](const uint32_t *it) { struct drm_mode_destroy_blob destroy_blob {}; destroy_blob.blob_id = (__u32)*it; - int err = drmIoctl(fd(), DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy_blob); + int err = drmIoctl(GetFd(), DRM_IOCTL_MODE_DESTROYPROPBLOB, + &destroy_blob); if (err != 0) { ALOGE("Failed to destroy mode property blob %" PRIu32 "/%d", *it, err); @@ -290,16 +283,18 @@ int DrmDevice::GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, DrmProperty *property) const { drmModeObjectPropertiesPtr props = nullptr; - props = drmModeObjectGetProperties(fd(), obj_id, obj_type); - if (!props) { + props = drmModeObjectGetProperties(GetFd(), obj_id, obj_type); + if (props == nullptr) { ALOGE("Failed to get properties for %d/%x", obj_id, obj_type); return -ENODEV; } bool found = false; for (int i = 0; !found && (size_t)i < props->count_props; ++i) { - drmModePropertyPtr p = drmModeGetProperty(fd(), props->props[i]); - if (!strcmp(p->name, prop_name)) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + drmModePropertyPtr p = drmModeGetProperty(GetFd(), props->props[i]); + if (strcmp(p->name, prop_name) == 0) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) property->Init(obj_id, p, props->prop_values[i]); found = true; } @@ -311,9 +306,9 @@ int DrmDevice::GetProperty(uint32_t obj_id, uint32_t obj_type, } std::string DrmDevice::GetName() const { - auto *ver = drmGetVersion(fd()); - if (!ver) { - ALOGW("Failed to get drm version for fd=%d", fd()); + auto *ver = drmGetVersion(GetFd()); + if (ver == nullptr) { + ALOGW("Failed to get drm version for fd=%d", GetFd()); return "generic"; } @@ -339,4 +334,22 @@ auto DrmDevice::IsKMSDev(const char *path) -> bool { return is_kms; } +auto DrmDevice::GetConnectors() + -> const std::vector<std::unique_ptr<DrmConnector>> & { + return connectors_; +} + +auto DrmDevice::GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> & { + return planes_; +} + +auto DrmDevice::GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> & { + return crtcs_; +} + +auto DrmDevice::GetEncoders() + -> const std::vector<std::unique_ptr<DrmEncoder>> & { + return encoders_; +} + } // namespace android diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h index cd87127..6d792c2 100644 --- a/drm/DrmDevice.h +++ b/drm/DrmDevice.h @@ -39,23 +39,20 @@ class DrmDevice { std::tuple<int, int> Init(const char *path, int num_displays); - int fd() const { + auto GetFd() const { return fd_.Get(); } - const std::vector<std::unique_ptr<DrmConnector>> &connectors() const { - return connectors_; - } - - const std::vector<std::unique_ptr<DrmPlane>> &planes() const { - return planes_; - } + auto GetConnectors() -> const std::vector<std::unique_ptr<DrmConnector>> &; + auto GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> &; + auto GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> &; + auto GetEncoders() -> const std::vector<std::unique_ptr<DrmEncoder>> &; - std::pair<uint32_t, uint32_t> min_resolution() const { + auto GetMinResolution() const { return min_resolution_; } - std::pair<uint32_t, uint32_t> max_resolution() const { + auto GetMaxResolution() const { return max_resolution_; } @@ -64,9 +61,6 @@ class DrmDevice { std::string GetName() const; - const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const; - uint32_t next_mode_id(); - auto RegisterUserPropertyBlob(void *data, size_t length) const -> DrmModeUserPropertyBlobUnique; @@ -76,8 +70,8 @@ class DrmDevice { return HasAddFb2ModifiersSupport_; } - DrmFbImporter &GetDrmFbImporter() { - return *mDrmFbImporter; + auto &GetDrmFbImporter() { + return *drm_fb_importer_; } static auto IsKMSDev(const char *path) -> bool; @@ -115,7 +109,6 @@ class DrmDevice { int CreateDisplayPipe(DrmConnector *connector); UniqueFd fd_; - uint32_t mode_id_ = 0; std::vector<std::unique_ptr<DrmConnector>> connectors_; std::vector<std::unique_ptr<DrmConnector>> writeback_connectors_; @@ -134,9 +127,7 @@ class DrmDevice { bool HasAddFb2ModifiersSupport_{}; - std::shared_ptr<DrmDevice> self; - - std::unique_ptr<DrmFbImporter> mDrmFbImporter; + std::unique_ptr<DrmFbImporter> drm_fb_importer_; }; } // namespace android diff --git a/drm/DrmEncoder.cpp b/drm/DrmEncoder.cpp index 8049a5c..eed5b5f 100644 --- a/drm/DrmEncoder.cpp +++ b/drm/DrmEncoder.cpp @@ -29,7 +29,7 @@ namespace android { auto DrmEncoder::CreateInstance(DrmDevice &dev, uint32_t encoder_id, uint32_t index) -> std::unique_ptr<DrmEncoder> { - auto e = MakeDrmModeEncoderUnique(dev.fd(), encoder_id); + auto e = MakeDrmModeEncoderUnique(dev.GetFd(), encoder_id); if (!e) { ALOGE("Failed to get encoder %d", encoder_id); return {}; diff --git a/drm/DrmFbImporter.cpp b/drm/DrmFbImporter.cpp index 6f2abe8..eeab076 100644 --- a/drm/DrmFbImporter.cpp +++ b/drm/DrmFbImporter.cpp @@ -32,7 +32,7 @@ namespace android { auto DrmFbIdHandle::CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle, - const std::shared_ptr<DrmDevice> &drm) + DrmDevice &drm) -> std::shared_ptr<DrmFbIdHandle> { // NOLINTNEXTLINE(cppcoreguidelines-owning-memory): priv. constructor usage std::shared_ptr<DrmFbIdHandle> local(new DrmFbIdHandle(drm)); @@ -44,7 +44,7 @@ auto DrmFbIdHandle::CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle, for (size_t i = 1; i < local->gem_handles_.size(); i++) { if (bo->prime_fds[i] > 0) { if (bo->prime_fds[i] != bo->prime_fds[0]) { - err = drmPrimeFDToHandle(drm->fd(), bo->prime_fds[i], + err = drmPrimeFDToHandle(drm.GetFd(), bo->prime_fds[i], &local->gem_handles_.at(i)); if (err != 0) { ALOGE("failed to import prime fd %d errno=%d", bo->prime_fds[i], @@ -59,7 +59,7 @@ auto DrmFbIdHandle::CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle, bool has_modifiers = bo->modifiers[0] != DRM_FORMAT_MOD_NONE && bo->modifiers[0] != DRM_FORMAT_MOD_INVALID; - if (!drm->HasAddFb2ModifiersSupport() && has_modifiers) { + if (!drm.HasAddFb2ModifiersSupport() && has_modifiers) { ALOGE("No ADDFB2 with modifier support. Can't import modifier %" PRIu64, bo->modifiers[0]); local.reset(); @@ -68,11 +68,11 @@ auto DrmFbIdHandle::CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle, /* Create framebuffer object */ if (!has_modifiers) { - err = drmModeAddFB2(drm->fd(), bo->width, bo->height, bo->format, + err = drmModeAddFB2(drm.GetFd(), bo->width, bo->height, bo->format, &local->gem_handles_[0], &bo->pitches[0], &bo->offsets[0], &local->fb_id_, 0); } else { - err = drmModeAddFB2WithModifiers(drm->fd(), bo->width, bo->height, + err = drmModeAddFB2WithModifiers(drm.GetFd(), bo->width, bo->height, bo->format, &local->gem_handles_[0], &bo->pitches[0], &bo->offsets[0], &bo->modifiers[0], &local->fb_id_, @@ -88,7 +88,7 @@ auto DrmFbIdHandle::CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle, DrmFbIdHandle::~DrmFbIdHandle() { /* Destroy framebuffer object */ - if (drmModeRmFB(drm_->fd(), fb_id_) != 0) { + if (drmModeRmFB(drm_->GetFd(), fb_id_) != 0) { ALOGE("Failed to rm fb"); } @@ -109,7 +109,7 @@ DrmFbIdHandle::~DrmFbIdHandle() { continue; } gem_close.handle = gem_handles_[i]; - int32_t err = drmIoctl(drm_->fd(), DRM_IOCTL_GEM_CLOSE, &gem_close); + int32_t err = drmIoctl(drm_->GetFd(), DRM_IOCTL_GEM_CLOSE, &gem_close); if (err != 0) { ALOGE("Failed to close gem handle %d, errno: %d", gem_handles_[i], errno); } @@ -120,7 +120,8 @@ auto DrmFbImporter::GetOrCreateFbId(hwc_drm_bo_t *bo) -> std::shared_ptr<DrmFbIdHandle> { /* Lookup DrmFbIdHandle in cache first. First handle serves as a cache key. */ GemHandle first_handle = 0; - int32_t err = drmPrimeFDToHandle(drm_->fd(), bo->prime_fds[0], &first_handle); + int32_t err = drmPrimeFDToHandle(drm_->GetFd(), bo->prime_fds[0], + &first_handle); if (err != 0) { ALOGE("Failed to import prime fd %d ret=%d", bo->prime_fds[0], err); @@ -143,7 +144,7 @@ auto DrmFbImporter::GetOrCreateFbId(hwc_drm_bo_t *bo) } /* No DrmFbIdHandle found in cache, create framebuffer object */ - auto fb_id_handle = DrmFbIdHandle::CreateInstance(bo, first_handle, drm_); + auto fb_id_handle = DrmFbIdHandle::CreateInstance(bo, first_handle, *drm_); if (fb_id_handle) { drm_fb_id_handle_cache_[first_handle] = fb_id_handle; } diff --git a/drm/DrmFbImporter.h b/drm/DrmFbImporter.h index efeb457..7f17bbe 100644 --- a/drm/DrmFbImporter.h +++ b/drm/DrmFbImporter.h @@ -37,8 +37,7 @@ namespace android { class DrmFbIdHandle { public: static auto CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle, - const std::shared_ptr<DrmDevice> &drm) - -> std::shared_ptr<DrmFbIdHandle>; + DrmDevice &drm) -> std::shared_ptr<DrmFbIdHandle>; ~DrmFbIdHandle(); DrmFbIdHandle(DrmFbIdHandle &&) = delete; @@ -51,10 +50,9 @@ class DrmFbIdHandle { } private: - explicit DrmFbIdHandle(std::shared_ptr<DrmDevice> drm) - : drm_(std::move(drm)){}; + explicit DrmFbIdHandle(DrmDevice &drm) : drm_(&drm){}; - const std::shared_ptr<DrmDevice> drm_; + DrmDevice *const drm_; uint32_t fb_id_{}; std::array<GemHandle, kHwcDrmBoMaxPlanes> gem_handles_{}; @@ -62,8 +60,7 @@ class DrmFbIdHandle { class DrmFbImporter { public: - explicit DrmFbImporter(std::shared_ptr<DrmDevice> drm) - : drm_(std::move(drm)){}; + explicit DrmFbImporter(DrmDevice &drm) : drm_(&drm){}; ~DrmFbImporter() = default; DrmFbImporter(const DrmFbImporter &) = delete; DrmFbImporter(DrmFbImporter &&) = delete; @@ -84,7 +81,7 @@ class DrmFbImporter { } } - const std::shared_ptr<DrmDevice> drm_; + DrmDevice *const drm_; std::map<GemHandle, std::weak_ptr<DrmFbIdHandle>> drm_fb_id_handle_cache_; }; diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp index 6b5cec1..28f48f3 100644 --- a/drm/DrmPlane.cpp +++ b/drm/DrmPlane.cpp @@ -31,7 +31,7 @@ namespace android { auto DrmPlane::CreateInstance(DrmDevice &dev, uint32_t plane_id) -> std::unique_ptr<DrmPlane> { - auto p = MakeDrmModePlaneUnique(dev.fd(), plane_id); + auto p = MakeDrmModePlaneUnique(dev.GetFd(), plane_id); if (!p) { ALOGE("Failed to get plane %d", plane_id); return {}; diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp index 3bcb4d0..64af85b 100644 --- a/drm/VSyncWorker.cpp +++ b/drm/VSyncWorker.cpp @@ -140,7 +140,7 @@ void VSyncWorker::Routine() { vblank.request.sequence = 1; int64_t timestamp = 0; - ret = drmWaitVBlank(drm_->fd(), &vblank); + ret = drmWaitVBlank(drm_->GetFd(), &vblank); if (ret == -EINTR) return; |