sdm: drm: Add support for default non-atomic mode
Add support for booting up with default non-atomic mode
Add libdrmutils that currently has:
DRMMaster:
Creates a master DRM session
Converts ION handles to DRM FB_ID
DRMResMgr:
Enables a default display path by providing APIs for
connector id, crtc id, mode etc
Change-Id: I1dc697d2cc5e3fa744c99e2c9ddd57bf06e78c4f
CRs-fixed: 1114808
diff --git a/libdrmutils/Android.mk b/libdrmutils/Android.mk
new file mode 100644
index 0000000..2f7ae4a
--- /dev/null
+++ b/libdrmutils/Android.mk
@@ -0,0 +1,15 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libdrmutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include \
+ external/libdrm
+LOCAL_SHARED_LIBRARIES := libdrm
+LOCAL_CFLAGS := -DLOG_TAG=\"DRMUTILS\" -Wall -std=c++11 -Werror
+LOCAL_CLANG := true
+LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+LOCAL_SRC_FILES := drm_master.cpp drm_res_mgr.cpp
+LOCAL_COPY_HEADERS_TO := qcom/display
+LOCAL_COPY_HEADERS := drm_master.h drm_res_mgr.h
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libdrmutils/drm_logger.h b/libdrmutils/drm_logger.h
new file mode 100644
index 0000000..b332ea0
--- /dev/null
+++ b/libdrmutils/drm_logger.h
@@ -0,0 +1,75 @@
+/*
+* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_LOGGER_H__
+#define __DRM_LOGGER_H__
+
+#include <utility>
+
+namespace drm_utils {
+
+class DRMLogger {
+ public:
+ virtual ~DRMLogger() {}
+ virtual void Error(const char *format, ...) = 0;
+ virtual void Info(const char *format, ...) = 0;
+ virtual void Debug(const char *format, ...) = 0;
+
+ static void Set(DRMLogger *logger) { s_instance = logger; }
+ static DRMLogger *Get() { return s_instance; }
+
+ private:
+ static DRMLogger *s_instance;
+};
+
+template <typename... T>
+void DRM_LOGE(const char *format, T&&... args) {
+ if (DRMLogger::Get()) {
+ DRMLogger::Get()->Error(format, std::forward<T>(args)...);
+ }
+}
+
+template <typename... T>
+void DRM_LOGI(const char *format, T&&... args) {
+ if (DRMLogger::Get()) {
+ DRMLogger::Get()->Info(format, std::forward<T>(args)...);
+ }
+}
+
+template <typename... T>
+void DRM_LOGD_IF(bool pred, const char *format, T&&... args) {
+ if (pred && DRMLogger::Get()) {
+ DRMLogger::Get()->Debug(format, std::forward<T>(args)...);
+ }
+}
+
+} // namespace drm_utils
+
+#endif // __DRM_LOGGER_H__
+
diff --git a/libdrmutils/drm_master.cpp b/libdrmutils/drm_master.cpp
new file mode 100644
index 0000000..f6a2e41
--- /dev/null
+++ b/libdrmutils/drm_master.cpp
@@ -0,0 +1,137 @@
+/*
+* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <drm/drm_fourcc.h>
+
+#include <algorithm>
+#include <iterator>
+
+#include "drm_master.h"
+
+#define __CLASS__ "DRMMaster"
+
+using std::mutex;
+using std::lock_guard;
+using std::begin;
+using std::copy;
+using std::end;
+using std::fill;
+
+namespace drm_utils {
+
+DRMLogger *DRMLogger::s_instance = nullptr;
+DRMMaster *DRMMaster::s_instance = nullptr;
+mutex DRMMaster::s_lock;
+
+int DRMMaster::GetInstance(DRMMaster **master) {
+ lock_guard<mutex> obj(s_lock);
+
+ if (!s_instance) {
+ s_instance = new DRMMaster();
+ if (s_instance->Init() < 0) {
+ delete s_instance;
+ s_instance = nullptr;
+ return -ENODEV;
+ }
+ }
+
+ *master = s_instance;
+ return 0;
+}
+
+int DRMMaster::Init() {
+ dev_fd_ = drmOpen("msm_drm", nullptr);
+ if (dev_fd_ < 0) {
+ DRM_LOGE("%s::%s: drmOpen failed with error %d", __CLASS__, __FUNCTION__, dev_fd_);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+DRMMaster::~DRMMaster() {
+ drmClose(dev_fd_);
+ dev_fd_ = -1;
+}
+
+int DRMMaster::CreateFbId(const DRMBuffer &drm_buffer, uint32_t *gem_handle, uint32_t *fb_id) {
+ int ret = drmPrimeFDToHandle(dev_fd_, drm_buffer.fd, gem_handle);
+ if (ret) {
+ DRM_LOGE("%s::%s: drmPrimeFDToHandle failed with error %d", __CLASS__, __FUNCTION__, ret);
+ return ret;
+ }
+
+ uint32_t gem_handles[4] = {0};
+ uint32_t pitches[4] = {0};
+ uint32_t offsets[4] = {0};
+ uint64_t modifier[4] = {0};
+
+ fill(begin(gem_handles), begin(gem_handles) + drm_buffer.num_planes, *gem_handle);
+ copy(begin(drm_buffer.stride), end(drm_buffer.stride), begin(pitches));
+ copy(begin(drm_buffer.offset), end(drm_buffer.offset), begin(offsets));
+ fill(begin(modifier), begin(modifier) + drm_buffer.num_planes, drm_buffer.drm_format_modifier);
+
+ ret = drmModeAddFB3(dev_fd_, drm_buffer.width, drm_buffer.height, drm_buffer.drm_format,
+ gem_handles, pitches, offsets, modifier, fb_id, DRM_MODE_FB_MODIFIERS);
+ if (ret) {
+ DRM_LOGE("%s::%s: drmModeAddFB3 failed with error %d", __CLASS__, __FUNCTION__, ret);
+ struct drm_gem_close gem_close = {};
+ gem_close.handle = *gem_handle;
+ int ret1 = drmIoctl(dev_fd_, DRM_IOCTL_GEM_CLOSE, &gem_close);
+ if (ret1) {
+ DRM_LOGE("drmIoctl::DRM_IOCTL_GEM_CLOSE failed with error %d", ret1);
+ }
+ }
+
+ return ret;
+}
+
+int DRMMaster::RemoveFbId(uint32_t gem_handle, uint32_t fb_id) {
+ int ret = drmModeRmFB(dev_fd_, fb_id);
+ if (ret) {
+ DRM_LOGE("%s::%s: drmModeRmFB failed with error %d", __CLASS__, __FUNCTION__, ret);
+ }
+
+ struct drm_gem_close gem_close = {};
+ gem_close.handle = gem_handle;
+ ret = drmIoctl(dev_fd_, DRM_IOCTL_GEM_CLOSE, &gem_close);
+ if (ret) {
+ DRM_LOGE("drmIoctl::DRM_IOCTL_GEM_CLOSE failed with error %d", ret);
+ }
+
+ return ret;
+}
+
+} // namespace drm_utils
diff --git a/libdrmutils/drm_master.h b/libdrmutils/drm_master.h
new file mode 100644
index 0000000..8c32a1b
--- /dev/null
+++ b/libdrmutils/drm_master.h
@@ -0,0 +1,94 @@
+/*
+* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_MASTER_H__
+#define __DRM_MASTER_H__
+
+#include <mutex>
+
+#include "drm_logger.h"
+
+namespace drm_utils {
+
+struct DRMBuffer {
+ int fd = -1;
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t drm_format = 0;
+ uint64_t drm_format_modifier = 0;
+ uint32_t stride[4] = {};
+ uint32_t offset[4] = {};
+ uint32_t num_planes = 1;
+};
+
+class DRMMaster {
+ public:
+ ~DRMMaster();
+ /* Converts from ION fd --> Prime Handle --> FB_ID.
+ * Input:
+ * drm_buffer: A DRMBuffer obj that packages description of buffer
+ * Output:
+ * fb_id: Pointer to store DRM framebuffer id into
+ * Returns:
+ * ioctl error code
+ */
+ int CreateFbId(const DRMBuffer &drm_buffer, uint32_t *gem_handle, uint32_t *fb_id);
+ /* Removes the fb_id from DRM
+ * Input:
+ * fb_id: DRM FB to be removed
+ * Returns:
+ * ioctl error code
+ */
+ int RemoveFbId(uint32_t gem_handle, uint32_t fb_id);
+ /* Poplulates master DRM fd
+ * Input:
+ * fd: Pointer to store master fd into
+ */
+ void GetHandle(int *fd) { *fd = dev_fd_; }
+
+ /* Creates an instance of DRMMaster if it doesn't exist and initializes it. Threadsafe.
+ * Input:
+ * master: Pointer to store a pointer to the instance
+ * Returns:
+ * -ENODEV if device cannot be opened or initilization fails
+ */
+ static int GetInstance(DRMMaster **master);
+
+ private:
+ DRMMaster() {}
+ int Init();
+
+ int dev_fd_ = -1; // Master fd for DRM
+ static DRMMaster *s_instance; // Singleton instance
+ static std::mutex s_lock;
+};
+
+} // namespace drm_utils
+
+#endif // __DRM_MASTER_H__
diff --git a/libdrmutils/drm_res_mgr.cpp b/libdrmutils/drm_res_mgr.cpp
new file mode 100644
index 0000000..61d25c4
--- /dev/null
+++ b/libdrmutils/drm_res_mgr.cpp
@@ -0,0 +1,149 @@
+/*
+* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <errno.h>
+
+#include "drm_master.h"
+#include "drm_res_mgr.h"
+
+#define DEBUG 0
+#define __CLASS__ "DRMResMgr"
+
+using std::mutex;
+using std::lock_guard;
+
+namespace drm_utils {
+
+DRMResMgr *DRMResMgr::s_instance = nullptr;
+mutex DRMResMgr::s_lock;
+
+static bool GetConnector(int dev_fd, drmModeRes *res, drmModeConnector **connector) {
+ for (auto i = 0; i < res->count_connectors; i++) {
+ drmModeConnector *conn = drmModeGetConnector(dev_fd, res->connectors[i]);
+ if (conn && conn->connector_type == DRM_MODE_CONNECTOR_DSI && conn->count_modes &&
+ conn->connection == DRM_MODE_CONNECTED) {
+ *connector = conn;
+ DRM_LOGI("drm_utils::%s found connector %d", __FUNCTION__, conn->connector_id);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool GetEncoder(int dev_fd, drmModeConnector *conn, drmModeEncoder **encoder) {
+ for (auto i = 0; i < conn->count_encoders; i++) {
+ drmModeEncoder *enc = drmModeGetEncoder(dev_fd, conn->encoders[i]);
+ if (enc && enc->encoder_type == DRM_MODE_ENCODER_DSI) {
+ *encoder = enc;
+ DRM_LOGI("drm_utils::%s found encoder %d", __FUNCTION__, enc->encoder_id);
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool GetCrtc(int dev_fd, drmModeRes *res, drmModeEncoder *enc, drmModeCrtc **crtc) {
+ for (auto i = 0; i < res->count_crtcs; i++) {
+ if (enc->possible_crtcs & (1 << i)) {
+ drmModeCrtc *c = drmModeGetCrtc(dev_fd, res->crtcs[i]);
+ if (c) {
+ *crtc = c;
+ DRM_LOGI("drm_utils::%s found crtc %d", __FUNCTION__, c->crtc_id);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+int DRMResMgr::GetInstance(DRMResMgr **res_mgr) {
+ lock_guard<mutex> obj(s_lock);
+
+ if (!s_instance) {
+ s_instance = new DRMResMgr();
+ if (s_instance->Init() < 0) {
+ delete s_instance;
+ s_instance = nullptr;
+ return -ENODEV;
+ }
+ }
+
+ *res_mgr = s_instance;
+ return 0;
+}
+
+int DRMResMgr::Init() {
+ DRMMaster *master = nullptr;
+ int dev_fd = -1;
+
+ int ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ return ret;
+ }
+
+ master->GetHandle(&dev_fd);
+ drmModeRes *res = drmModeGetResources(dev_fd);
+ if (res == nullptr) {
+ DRM_LOGE("%s::%s: drmModeGetResources failed", __CLASS__, __FUNCTION__);
+ return -ENODEV;
+ }
+
+ drmModeConnector *conn = nullptr;
+ if (!GetConnector(dev_fd, res, &conn)) {
+ DRM_LOGE("%s::%s: Failed to find a connector", __CLASS__, __FUNCTION__);
+ return -ENODEV;
+ }
+
+ drmModeEncoder *enc = nullptr;
+ if (!GetEncoder(dev_fd, conn, &enc)) {
+ DRM_LOGE("%s::%s: Failed to find an encoder", __CLASS__, __FUNCTION__);
+ drmModeFreeConnector(conn);
+ return -ENODEV;
+ }
+
+ drmModeCrtc *crtc = nullptr;
+ if (!GetCrtc(dev_fd, res, enc, &crtc)) {
+ DRM_LOGE("%s::%s: Failed to find a crtc", __CLASS__, __FUNCTION__);
+ drmModeFreeEncoder(enc);
+ drmModeFreeConnector(conn);
+ drmModeFreeResources(res);
+ return -ENODEV;
+ }
+
+ res_ = res;
+ conn_ = conn;
+ enc_ = enc;
+ crtc_ = crtc;
+
+ return 0;
+}
+
+} // namespace drm_utils
diff --git a/libdrmutils/drm_res_mgr.h b/libdrmutils/drm_res_mgr.h
new file mode 100644
index 0000000..3a8378c
--- /dev/null
+++ b/libdrmutils/drm_res_mgr.h
@@ -0,0 +1,72 @@
+/*
+* Copyright (c) 2017, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_RES_MGR_H__
+#define __DRM_RES_MGR_H__
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include <mutex>
+
+namespace drm_utils {
+
+class DRMResMgr {
+ public:
+ /* Returns the default connector id for primary panel */
+ void GetConnectorId(uint32_t *id) { *id = conn_->connector_id; }
+ /* Returns the default crtc id for primary pipeline */
+ void GetCrtcId(uint32_t *id) { *id = crtc_->crtc_id; }
+ /* Returns the default mode currently used by the connector */
+ void GetMode(drmModeModeInfo *mode) { *mode = conn_->modes[0]; }
+ /* Returns the panel dimensions in mm */
+ void GetDisplayDimInMM(uint32_t *w, uint32_t *h) {
+ *w = conn_->mmWidth;
+ *h = conn_->mmHeight;
+ }
+
+ /* Creates and initializes an instance of DRMResMgr. On success, returns a pointer to it, on
+ * failure returns -ENODEV */
+ static int GetInstance(DRMResMgr **res_mgr);
+
+ private:
+ int Init();
+
+ drmModeRes *res_ = nullptr;
+ drmModeConnector *conn_ = nullptr;
+ drmModeEncoder *enc_ = nullptr;
+ drmModeCrtc *crtc_ = nullptr;
+
+ static DRMResMgr *s_instance;
+ static std::mutex s_lock;
+};
+
+} // namespace drm_utils
+
+#endif // __DRM_RES_MGR_H__