Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

DRM backend + Session interface + EGL #2

Merged
merged 21 commits into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CMake/FindGBM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#.rst:
# FindGBM
# -------
#
# Find GBM library
#
# Try to find GBM library on UNIX systems. The following values are defined
#
# ::
#
# GBM_FOUND - True if gbm is available
# GBM_INCLUDE_DIRS - Include directories for gbm
# GBM_LIBRARIES - List of libraries for gbm
# GBM_DEFINITIONS - List of definitions for gbm
#
#=============================================================================
# Copyright (c) 2015 Jari Vetoniemi
#
# Distributed under the OSI-approved BSD License (the "License");
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

set_package_properties(GBM PROPERTIES
URL "http://www.mesa3d.org/"
DESCRIPTION "Generic buffer manager")

find_package(PkgConfig)
pkg_check_modules(PC_GBM QUIET gbm)
find_library(GBM_LIBRARIES NAMES gbm HINTS ${PC_GBM_LIBRARY_DIRS})
find_path(GBM_INCLUDE_DIRS gbm.h HINTS ${PC_GBM_INCLUDE_DIRS})

set(GBM_DEFINITIONS ${PC_GBM_CFLAGS_OTHER})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GBM DEFAULT_MSG GBM_INCLUDE_DIRS GBM_LIBRARIES)
mark_as_advanced(GBM_INCLUDE_DIRS GBM_LIBRARIES GBM_DEFINITIONS)
40 changes: 40 additions & 0 deletions CMake/FindSystemd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#.rst:
# FindSystemd
# -------
#
# Find Systemd library
#
# Try to find Systemd library on UNIX systems. The following values are defined
#
# ::
#
# SYSTEMD_FOUND - True if Systemd is available
# SYSTEMD_INCLUDE_DIRS - Include directories for Systemd
# SYSTEMD_LIBRARIES - List of libraries for Systemd
# SYSTEMD_DEFINITIONS - List of definitions for Systemd
#
#=============================================================================
# Copyright (c) 2015 Jari Vetoniemi
#
# Distributed under the OSI-approved BSD License (the "License");
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

include(FeatureSummary)
set_package_properties(Systemd PROPERTIES
URL "http://freedesktop.org/wiki/Software/systemd/"
DESCRIPTION "System and Service Manager")

find_package(PkgConfig)
pkg_check_modules(PC_SYSTEMD QUIET libsystemd)
find_library(SYSTEMD_LIBRARIES NAMES systemd ${PC_SYSTEMD_LIBRARY_DIRS})
find_path(SYSTEMD_INCLUDE_DIRS systemd/sd-login.h HINTS ${PC_SYSTEMD_INCLUDE_DIRS})

set(SYSTEMD_DEFINITIONS ${PC_SYSTEMD_CFLAGS_OTHER})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SYSTEMD DEFAULT_MSG SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
mark_as_advanced(SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES SYSTEMD_DEFINITIONS)
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ find_package(WaylandProtocols REQUIRED)
find_package(EGL REQUIRED)
find_package(GLESv2 REQUIRED)
find_package(DRM REQUIRED)
find_package(GBM REQUIRED)
find_package(LibInput REQUIRED)
find_package(Udev)
find_package(Udev REQUIRED)
find_package(Dbus)
find_package(Systemd REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be easy to make optional with the approach I described.


include(Wayland)
include(Manpage)
Expand Down
12 changes: 12 additions & 0 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
include_directories(
${PROTOCOLS_INCLUDE_DIRS}
${WAYLAND_INCLUDE_DIR}
${DRM_INCLUDE_DIRS}
)

add_library(wlr-backend
wayland/backend.c
wayland/registry.c
wayland/wl_seat.c
wayland/wl_output.c
drm/backend.c
drm/drm.c
drm/session.c
drm/udev.c
)

target_link_libraries(wlr-backend
wlr-common
wlr-wayland
${WAYLAND_LIBRARIES}
${DRM_LIBRARIES}
${GBM_LIBRARIES}
${GLESv2_LIBRARIES}
${EGL_LIBRARIES}
${SYSTEMD_LIBRARIES}
${UDEV_LIBRARIES}
${GBM_LIBRARIES}
)
118 changes: 118 additions & 0 deletions backend/drm/backend.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include <wlr/common/list.h>

#include "backend/drm/backend.h"
#include "backend/drm/drm.h"
#include "backend/drm/session.h"
#include "backend/drm/udev.h"
#include "common/log.h"

struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
struct wl_listener *rem,
struct wl_listener *render)
{
struct wlr_drm_backend *backend = calloc(1, sizeof *backend);
if (!backend) {
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
return NULL;
}

backend->displays = list_create();
if (!backend->displays) {
wlr_log(L_ERROR, "Failed to allocate list");
goto error_backend;
}

backend->event_loop = wl_event_loop_create();
if (!backend->event_loop) {
wlr_log(L_ERROR, "Failed to create event loop");
goto error_list;
}

if (!wlr_session_start(&backend->session)) {
wlr_log(L_ERROR, "Failed to start session");
goto error_loop;
}

if (!wlr_udev_init(backend)) {
wlr_log(L_ERROR, "Failed to start udev");
goto error_session;
}

backend->fd = wlr_udev_find_gpu(&backend->udev, &backend->session);
if (backend->fd == -1) {
wlr_log(L_ERROR, "Failed to open DRM device");
goto error_udev;
}

if (!wlr_drm_renderer_init(&backend->renderer, backend, backend->fd)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point I would like to detach this somewhat from the backend as well, but for now it's fine.

wlr_log(L_ERROR, "Failed to initialize renderer");
goto error_fd;
}

wl_signal_init(&backend->signals.display_add);
wl_signal_init(&backend->signals.display_rem);
wl_signal_init(&backend->signals.display_render);

if (add)
wl_signal_add(&backend->signals.display_add, add);
if (rem)
wl_signal_add(&backend->signals.display_rem, rem);
if (render)
wl_signal_add(&backend->signals.display_render, render);

wlr_drm_scan_connectors(backend);

return backend;

error_fd:
wlr_session_release_device(&backend->session, backend->fd);
error_udev:
wlr_udev_free(&backend->udev);
error_session:
wlr_session_end(&backend->session);
error_loop:
wl_event_loop_destroy(backend->event_loop);
error_list:
list_free(backend->displays);
error_backend:
free(backend);
return NULL;
}

static void free_display(void *item)
{
struct wlr_drm_display *disp = item;
wlr_drm_display_free(disp, true);
free(disp);
}

void wlr_drm_backend_free(struct wlr_drm_backend *backend)
{
if (!backend)
return;

list_foreach(backend->displays, free_display);

wlr_drm_renderer_free(&backend->renderer);
wlr_udev_free(&backend->udev);
wlr_session_release_device(&backend->session, backend->fd);
wlr_session_end(&backend->session);

wl_event_source_remove(backend->event_src.drm);
wl_event_source_remove(backend->event_src.udev);
wl_event_loop_destroy(backend->event_loop);

list_free(backend->displays);
free(backend);
}

struct wl_event_loop *wlr_drm_backend_get_event_loop(struct wlr_drm_backend *backend)
{
return backend->event_loop;
}
Loading