From 5610b6440617246972105a93ca6a35c9ed045db4 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 8 Dec 2016 01:11:44 +0200 Subject: Remove libdrm_omap dependency The library is just a wrapper around ioctls. It doesn't provide much value, and its API is marked as experimental and should thus not be expected to be stable. As third party library dependencies are always painful for distributors and packagers, use the ioctls directly for now. Signed-off-by: Laurent Pinchart --- CMakeLists.txt | 9 +++--- config.h.in | 1 + kms++/CMakeLists.txt | 7 ++--- kms++/inc/kms++/omap/omapframebuffer.h | 5 ---- kms++/src/omap/omapcard.cpp | 6 ---- kms++/src/omap/omapframebuffer.cpp | 54 ++++++++++++++++++---------------- py/pykms/CMakeLists.txt | 3 +- py/pykms/pykms.cpp | 6 ++-- 8 files changed, 42 insertions(+), 49 deletions(-) create mode 100644 config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 57088bc..73b610e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) include(CheckCXXCompilerFlag) +include(CheckSymbolExists) IF(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting build type to 'Release' as none was specified.") @@ -66,10 +67,7 @@ endif() find_package(PkgConfig REQUIRED) pkg_check_modules(LIBDRM libdrm>=2.4.64 REQUIRED) -pkg_check_modules(LIBDRM_OMAP libdrm_omap) -if(LIBDRM_OMAP_FOUND) - add_definitions(-DHAS_LIBDRM_OMAP) -endif() +check_symbol_exists(DRM_IOCTL_OMAP_GEM_NEW "stdint.h;drm/omap_drm.h" HAVE_OMAP_DRM) enable_testing() @@ -86,3 +84,6 @@ if(KMSXX_ENABLE_PYTHON) endif() add_custom_target(docs SOURCES "README.md") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..641d4bb --- /dev/null +++ b/config.h.in @@ -0,0 +1 @@ +#cmakedefine HAVE_OMAP_DRM 1 diff --git a/kms++/CMakeLists.txt b/kms++/CMakeLists.txt index 10352a2..66b4286 100644 --- a/kms++/CMakeLists.txt +++ b/kms++/CMakeLists.txt @@ -1,13 +1,10 @@ include_directories(${LIBDRM_INCLUDE_DIRS}) link_directories(${LIBDRM_LIBRARY_DIRS}) -include_directories(${LIBDRM_OMAP_INCLUDE_DIRS}) -link_directories(${LIBDRM_OMAP_LIBRARY_DIRS}) - file(GLOB SRCS "src/*.cpp" "src/*.h") file(GLOB PUB_HDRS "inc/kms++/*.h") -if(LIBDRM_OMAP_FOUND) +if(HAVE_OMAP_DRM) file(GLOB OMAP_SRCS "src/omap/*.cpp" "src/omap/*.h") file(GLOB OMAP_PUB_HDRS "inc/kms++/omap/*.h") @@ -22,7 +19,7 @@ target_include_directories(kms++ PUBLIC $ PRIVATE src) -target_link_libraries(kms++ ${LIBDRM_LIBRARIES} ${LIBDRM_OMAP_LIBRARIES}) +target_link_libraries(kms++ ${LIBDRM_LIBRARIES}) set_target_properties(kms++ PROPERTIES PUBLIC_HEADER "${PUB_HDRS}") diff --git a/kms++/inc/kms++/omap/omapframebuffer.h b/kms++/inc/kms++/omap/omapframebuffer.h index 16d6cf8..9b628f4 100644 --- a/kms++/inc/kms++/omap/omapframebuffer.h +++ b/kms++/inc/kms++/omap/omapframebuffer.h @@ -3,8 +3,6 @@ #include #include -struct omap_bo; - namespace kms { class OmapCard; @@ -30,10 +28,7 @@ public: int prime_fd(unsigned plane); private: - OmapCard& m_omap_card; - struct FramebufferPlane { - struct omap_bo* omap_bo; uint32_t handle; int prime_fd; uint32_t size; diff --git a/kms++/src/omap/omapcard.cpp b/kms++/src/omap/omapcard.cpp index e811b6d..7b78cde 100644 --- a/kms++/src/omap/omapcard.cpp +++ b/kms++/src/omap/omapcard.cpp @@ -1,10 +1,6 @@ #include -extern "C" { -#include -} - using namespace std; namespace kms @@ -18,12 +14,10 @@ OmapCard::OmapCard() OmapCard::OmapCard(const string& device) : Card(device) { - m_omap_dev = omap_device_new(fd()); } OmapCard::~OmapCard() { - omap_device_del(m_omap_dev); } } diff --git a/kms++/src/omap/omapframebuffer.cpp b/kms++/src/omap/omapframebuffer.cpp index e1e2234..312552c 100644 --- a/kms++/src/omap/omapframebuffer.cpp +++ b/kms++/src/omap/omapframebuffer.cpp @@ -9,14 +9,11 @@ #include #include #include +#include #include #include -extern "C" { -#include -} - using namespace std; namespace kms @@ -28,7 +25,7 @@ OmapFramebuffer::OmapFramebuffer(OmapCard& card, uint32_t width, uint32_t height } OmapFramebuffer::OmapFramebuffer(OmapCard& card, uint32_t width, uint32_t height, PixelFormat format) - : MappedFramebuffer(card, width, height), m_omap_card(card), m_format(format) + : MappedFramebuffer(card, width, height), m_format(format) { Create(); } @@ -48,20 +45,19 @@ void OmapFramebuffer::Create() const PixelFormatPlaneInfo& pi = format_info.planes[i]; FramebufferPlane& plane = m_planes[i]; - uint32_t flags = OMAP_BO_SCANOUT | OMAP_BO_WC; - - uint32_t size = width() * height() * pi.bitspp / 8; - - struct omap_bo* bo = omap_bo_new(m_omap_card.dev(), size, flags); - if (!bo) - throw invalid_argument(string("omap_bo_new failed: ") + strerror(errno)); - - uint32_t stride = width() * pi.bitspp / 8; - - plane.omap_bo = bo; - plane.handle = omap_bo_handle(bo); + uint32_t stride = (width() * pi.bitspp + 7) / 8; + uint32_t size = stride * height(); + struct drm_omap_gem_new creq = { + .size = { .bytes = size }, + .flags = OMAP_BO_SCANOUT | OMAP_BO_WC, + }; + int r = drmIoctl(card().fd(), DRM_IOCTL_OMAP_GEM_NEW, &creq); + if (r) + throw invalid_argument(string("DRM_IOCTL_OMAP_GEM_NEW failed: ") + strerror(errno)); + + plane.handle = creq.handle; plane.stride = stride; - plane.size = omap_bo_size(bo); + plane.size = size; plane.offset = 0; plane.map = 0; plane.prime_fd = -1; @@ -91,7 +87,8 @@ void OmapFramebuffer::Destroy() if (plane.map) munmap(plane.map, plane.size); - omap_bo_del(plane.omap_bo); + struct drm_gem_close dreq = { .handle = plane.handle }; + drmIoctl(card().fd(), DRM_IOCTL_GEM_CLOSE, &dreq); if (plane.prime_fd >= 0) ::close(plane.prime_fd); @@ -105,7 +102,13 @@ uint8_t* OmapFramebuffer::map(unsigned plane) if (p.map) return p.map; - p.map = (uint8_t*)omap_bo_map(p.omap_bo); + struct drm_omap_gem_info mreq = { .handle = p.handle }; + int r = drmIoctl(card().fd(), DRM_IOCTL_OMAP_GEM_INFO, &mreq); + if (r) + throw invalid_argument(string("DRM_IOCTL_OMAP_GEM_INFO failed: ") + strerror(errno)); + + p.map = (uint8_t *)mmap(0, p.size, PROT_READ | PROT_WRITE, MAP_SHARED, + card().fd(), mreq.offset); if (p.map == MAP_FAILED) throw invalid_argument(string("mmap failed: ") + strerror(errno)); @@ -119,13 +122,12 @@ int OmapFramebuffer::prime_fd(unsigned int plane) if (p.prime_fd >= 0) return p.prime_fd; - int fd = omap_bo_dmabuf(p.omap_bo); - if (fd < 0) - throw std::runtime_error("omap_bo_dmabuf failed\n"); - - p.prime_fd = fd; + int r = drmPrimeHandleToFD(card().fd(), p.handle, DRM_CLOEXEC | O_RDWR, + &p.prime_fd); + if (r) + throw std::runtime_error("drmPrimeHandleToFD failed"); - return fd; + return p.prime_fd; } } diff --git a/py/pykms/CMakeLists.txt b/py/pykms/CMakeLists.txt index 505c0c3..56a9c35 100644 --- a/py/pykms/CMakeLists.txt +++ b/py/pykms/CMakeLists.txt @@ -1,3 +1,4 @@ +include_directories(${PROJECT_BINARY_DIR}) # for config.h include_directories(${LIBDRM_INCLUDE_DIRS}) link_directories(${LIBDRM_LIBRARY_DIRS}) @@ -12,7 +13,7 @@ include_directories(${PROJECT_SOURCE_DIR}/ext/pybind11/include) set(SRCS pykms.cpp pykmsbase.cpp pykmsutil.cpp pyvid.cpp) -if(LIBDRM_OMAP_FOUND) +if(HAVE_OMAP_DRM) set(SRCS ${SRCS} pykmsomap.cpp) endif() diff --git a/py/pykms/pykms.cpp b/py/pykms/pykms.cpp index 7752f19..819093e 100644 --- a/py/pykms/pykms.cpp +++ b/py/pykms/pykms.cpp @@ -2,6 +2,8 @@ #include #include +#include "config.h" + namespace py = pybind11; using namespace kms; @@ -11,7 +13,7 @@ void init_pykmstest(py::module &m); void init_pykmsbase(py::module &m); void init_pyvid(py::module &m); -#if HAS_LIBDRM_OMAP +#if HAVE_OMAP_DRM void init_pykmsomap(py::module &m); #endif @@ -29,7 +31,7 @@ PYBIND11_PLUGIN(pykms) { init_pyvid(m); -#if HAS_LIBDRM_OMAP +#if HAVE_OMAP_DRM init_pykmsomap(m); #endif return m.ptr(); -- cgit v1.2.3