backend-drm: move into new subdir
Move the DRM-backend into a new sub-directory to make it stand out from libweston core. This facilitates splitting drm.c into more files later. vaapi-recorder is used only by DRM-backend, move that too. libbacklight is used only by DRM-backend and a manual test program, and is moved as well. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
committed by
Daniel Stone
parent
644eb64a5d
commit
f0f37bcaa1
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* libbacklight - userspace interface to Linux backlight control
|
||||
*
|
||||
* Copyright © 2012 Intel Corporation
|
||||
* Copyright 2010 Red Hat <mjg@redhat.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Matthew Garrett <mjg@redhat.com>
|
||||
* Tiago Vignatti <vignatti@freedesktop.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libbacklight.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/types.h>
|
||||
#include <dirent.h>
|
||||
#include <drm.h>
|
||||
#include <fcntl.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "shared/string-helpers.h"
|
||||
|
||||
static long backlight_get(struct backlight *backlight, char *node)
|
||||
{
|
||||
char buffer[100];
|
||||
char *path;
|
||||
int fd, value;
|
||||
long ret;
|
||||
|
||||
if (asprintf(&path, "%s/%s", backlight->path, node) < 0)
|
||||
return -ENOMEM;
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = read(fd, &buffer, sizeof(buffer));
|
||||
if (ret < 1) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!safe_strtoint(buffer, &value)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = value;
|
||||
|
||||
out:
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
free(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long backlight_get_brightness(struct backlight *backlight)
|
||||
{
|
||||
return backlight_get(backlight, "brightness");
|
||||
}
|
||||
|
||||
long backlight_get_max_brightness(struct backlight *backlight)
|
||||
{
|
||||
return backlight_get(backlight, "max_brightness");
|
||||
}
|
||||
|
||||
long backlight_get_actual_brightness(struct backlight *backlight)
|
||||
{
|
||||
return backlight_get(backlight, "actual_brightness");
|
||||
}
|
||||
|
||||
long backlight_set_brightness(struct backlight *backlight, long brightness)
|
||||
{
|
||||
char *path;
|
||||
char *buffer = NULL;
|
||||
int fd;
|
||||
long ret;
|
||||
|
||||
if (asprintf(&path, "%s/%s", backlight->path, "brightness") < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
fd = open(path, O_RDWR);
|
||||
if (fd < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = read(fd, &buffer, sizeof(buffer));
|
||||
if (ret < 1) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (asprintf(&buffer, "%ld", brightness) < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = write(fd, buffer, strlen(buffer));
|
||||
if (ret < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = backlight_get_brightness(backlight);
|
||||
backlight->brightness = ret;
|
||||
out:
|
||||
free(buffer);
|
||||
free(path);
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void backlight_destroy(struct backlight *backlight)
|
||||
{
|
||||
if (!backlight)
|
||||
return;
|
||||
|
||||
if (backlight->path)
|
||||
free(backlight->path);
|
||||
|
||||
free(backlight);
|
||||
}
|
||||
|
||||
struct backlight *backlight_init(struct udev_device *drm_device,
|
||||
uint32_t connector_type)
|
||||
{
|
||||
const char *syspath = NULL;
|
||||
char *pci_name = NULL;
|
||||
char *chosen_path = NULL;
|
||||
char *path = NULL;
|
||||
DIR *backlights = NULL;
|
||||
struct dirent *entry;
|
||||
enum backlight_type type = 0;
|
||||
char buffer[100];
|
||||
struct backlight *backlight = NULL;
|
||||
int ret;
|
||||
|
||||
if (!drm_device)
|
||||
return NULL;
|
||||
|
||||
syspath = udev_device_get_syspath(drm_device);
|
||||
if (!syspath)
|
||||
return NULL;
|
||||
|
||||
if (asprintf(&path, "%s/%s", syspath, "device") < 0)
|
||||
return NULL;
|
||||
|
||||
ret = readlink(path, buffer, sizeof(buffer) - 1);
|
||||
free(path);
|
||||
if (ret < 0)
|
||||
return NULL;
|
||||
|
||||
buffer[ret] = '\0';
|
||||
pci_name = basename(buffer);
|
||||
|
||||
if (connector_type <= 0)
|
||||
return NULL;
|
||||
|
||||
backlights = opendir("/sys/class/backlight");
|
||||
if (!backlights)
|
||||
return NULL;
|
||||
|
||||
/* Find the "best" backlight for the device. Firmware
|
||||
interfaces are preferred over platform interfaces are
|
||||
preferred over raw interfaces. For raw interfaces we'll
|
||||
check if the device ID in the form of pci match, while
|
||||
for firmware interfaces we require the pci ID to
|
||||
match. It's assumed that platform interfaces always match,
|
||||
since we can't actually associate them with IDs.
|
||||
|
||||
A further awkwardness is that, while it's theoretically
|
||||
possible for an ACPI interface to include support for
|
||||
changing the backlight of external devices, it's unlikely
|
||||
to ever be done. It's effectively impossible for a platform
|
||||
interface to do so. So if we get asked about anything that
|
||||
isn't LVDS or eDP, we pretty much have to require that the
|
||||
control be supplied via a raw interface */
|
||||
|
||||
while ((entry = readdir(backlights))) {
|
||||
char *backlight_path;
|
||||
char *parent;
|
||||
enum backlight_type entry_type;
|
||||
int fd;
|
||||
|
||||
if (entry->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
if (asprintf(&backlight_path, "%s/%s", "/sys/class/backlight",
|
||||
entry->d_name) < 0)
|
||||
goto err;
|
||||
|
||||
if (asprintf(&path, "%s/%s", backlight_path, "type") < 0) {
|
||||
free(backlight_path);
|
||||
goto err;
|
||||
}
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
|
||||
if (fd < 0)
|
||||
goto out;
|
||||
|
||||
ret = read (fd, &buffer, sizeof(buffer));
|
||||
close (fd);
|
||||
|
||||
if (ret < 1)
|
||||
goto out;
|
||||
|
||||
buffer[ret] = '\0';
|
||||
|
||||
if (!strncmp(buffer, "raw\n", sizeof(buffer)))
|
||||
entry_type = BACKLIGHT_RAW;
|
||||
else if (!strncmp(buffer, "platform\n", sizeof(buffer)))
|
||||
entry_type = BACKLIGHT_PLATFORM;
|
||||
else if (!strncmp(buffer, "firmware\n", sizeof(buffer)))
|
||||
entry_type = BACKLIGHT_FIRMWARE;
|
||||
else
|
||||
goto out;
|
||||
|
||||
if (connector_type != DRM_MODE_CONNECTOR_LVDS &&
|
||||
connector_type != DRM_MODE_CONNECTOR_eDP) {
|
||||
/* External displays are assumed to require
|
||||
gpu control at the moment */
|
||||
if (entry_type != BACKLIGHT_RAW)
|
||||
goto out;
|
||||
}
|
||||
|
||||
free (path);
|
||||
|
||||
if (asprintf(&path, "%s/%s", backlight_path, "device") < 0)
|
||||
goto err;
|
||||
|
||||
ret = readlink(path, buffer, sizeof(buffer) - 1);
|
||||
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
buffer[ret] = '\0';
|
||||
|
||||
parent = basename(buffer);
|
||||
|
||||
/* Perform matching for raw and firmware backlights -
|
||||
platform backlights have to be assumed to match */
|
||||
if (entry_type == BACKLIGHT_RAW ||
|
||||
entry_type == BACKLIGHT_FIRMWARE) {
|
||||
if (!(pci_name && !strcmp(pci_name, parent)))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (entry_type < type)
|
||||
goto out;
|
||||
|
||||
type = entry_type;
|
||||
|
||||
if (chosen_path)
|
||||
free(chosen_path);
|
||||
chosen_path = strdup(backlight_path);
|
||||
|
||||
out:
|
||||
free(backlight_path);
|
||||
free(path);
|
||||
}
|
||||
|
||||
if (!chosen_path)
|
||||
goto err;
|
||||
|
||||
backlight = malloc(sizeof(struct backlight));
|
||||
|
||||
if (!backlight)
|
||||
goto err;
|
||||
|
||||
backlight->path = chosen_path;
|
||||
backlight->type = type;
|
||||
|
||||
backlight->max_brightness = backlight_get_max_brightness(backlight);
|
||||
if (backlight->max_brightness < 0)
|
||||
goto err;
|
||||
|
||||
backlight->brightness = backlight_get_actual_brightness(backlight);
|
||||
if (backlight->brightness < 0)
|
||||
goto err;
|
||||
|
||||
closedir(backlights);
|
||||
return backlight;
|
||||
err:
|
||||
closedir(backlights);
|
||||
free (chosen_path);
|
||||
free (backlight);
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* libbacklight - userspace interface to Linux backlight control
|
||||
*
|
||||
* Copyright © 2012 Intel Corporation
|
||||
* Copyright 2010 Red Hat <mjg@redhat.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Matthew Garrett <mjg@redhat.com>
|
||||
* Tiago Vignatti <vignatti@freedesktop.org>
|
||||
*/
|
||||
#ifndef LIBBACKLIGHT_H
|
||||
#define LIBBACKLIGHT_H
|
||||
#include <libudev.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum backlight_type {
|
||||
BACKLIGHT_RAW,
|
||||
BACKLIGHT_PLATFORM,
|
||||
BACKLIGHT_FIRMWARE
|
||||
};
|
||||
|
||||
struct backlight {
|
||||
char *path;
|
||||
int max_brightness;
|
||||
int brightness;
|
||||
enum backlight_type type;
|
||||
};
|
||||
|
||||
/*
|
||||
* Find and set up a backlight for a valid udev connector device, i.e. one
|
||||
* matching drm subsystem and with status of connected.
|
||||
*/
|
||||
struct backlight *backlight_init(struct udev_device *drm_device,
|
||||
uint32_t connector_type);
|
||||
|
||||
/* Free backlight resources */
|
||||
void backlight_destroy(struct backlight *backlight);
|
||||
|
||||
/* Provide the maximum backlight value */
|
||||
long backlight_get_max_brightness(struct backlight *backlight);
|
||||
|
||||
/* Provide the cached backlight value */
|
||||
long backlight_get_brightness(struct backlight *backlight);
|
||||
|
||||
/* Provide the hardware backlight value */
|
||||
long backlight_get_actual_brightness(struct backlight *backlight);
|
||||
|
||||
/* Set the backlight to a value between 0 and max */
|
||||
long backlight_set_brightness(struct backlight *backlight, long brightness);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LIBBACKLIGHT_H */
|
||||
@@ -0,0 +1,90 @@
|
||||
if not get_option('backend-drm')
|
||||
subdir_done()
|
||||
endif
|
||||
|
||||
lib_backlight = static_library(
|
||||
'backlight',
|
||||
'libbacklight.c',
|
||||
dependencies: [
|
||||
dep_libdrm_headers,
|
||||
dependency('libudev')
|
||||
],
|
||||
include_directories: include_directories('../..'),
|
||||
install: false
|
||||
)
|
||||
dep_backlight = declare_dependency(
|
||||
link_with: lib_backlight,
|
||||
include_directories: include_directories('.')
|
||||
)
|
||||
|
||||
config_h.set('BUILD_DRM_COMPOSITOR', '1')
|
||||
|
||||
srcs_drm = [
|
||||
'drm.c',
|
||||
linux_dmabuf_unstable_v1_protocol_c,
|
||||
linux_dmabuf_unstable_v1_server_protocol_h,
|
||||
presentation_time_server_protocol_h,
|
||||
]
|
||||
|
||||
deps_drm = [
|
||||
dep_libweston,
|
||||
dep_session_helper,
|
||||
dep_libdrm,
|
||||
dep_libinput_backend,
|
||||
dependency('libudev', version: '>= 136'),
|
||||
dep_backlight
|
||||
]
|
||||
|
||||
# XXX: Actually let DRM-backend build without GBM, it really should
|
||||
if true # get_option('renderer-gl')
|
||||
dep_gbm = dependency('gbm', required: false)
|
||||
if not dep_gbm.found()
|
||||
error('drm-backend requires gbm which was not found. Or, you can use \'-Dbackend-drm=false\'.')
|
||||
endif
|
||||
if dep_gbm.version().version_compare('>= 17.1')
|
||||
config_h.set('HAVE_GBM_MODIFIERS', '1')
|
||||
endif
|
||||
if dep_gbm.version().version_compare('>= 17.2')
|
||||
config_h.set('HAVE_GBM_FD_IMPORT', '1')
|
||||
endif
|
||||
deps_drm += dep_gbm
|
||||
endif
|
||||
|
||||
if get_option('backend-drm-screencast-vaapi')
|
||||
foreach name : [ 'libva', 'libva-drm' ]
|
||||
d = dependency(name, version: '>= 0.34.0', required: false)
|
||||
if not d.found()
|
||||
error('VA-API recorder requires @0@ >= 0.34.0 which was not found. Or, you can use \'-Dbackend-drm-screencast-vaapi=false\'.'.format(name))
|
||||
endif
|
||||
deps_drm += d
|
||||
endforeach
|
||||
|
||||
srcs_drm += 'vaapi-recorder.c'
|
||||
deps_drm += dependency('threads')
|
||||
config_h.set('BUILD_VAAPI_RECORDER', '1')
|
||||
endif
|
||||
|
||||
if dep_libdrm.version().version_compare('>= 2.4.71')
|
||||
config_h.set('HAVE_DRM_ADDFB2_MODIFIERS', '1')
|
||||
endif
|
||||
|
||||
if dep_libdrm.version().version_compare('>= 2.4.78')
|
||||
config_h.set('HAVE_DRM_ATOMIC', '1')
|
||||
endif
|
||||
|
||||
if dep_libdrm.version().version_compare('>= 2.4.83')
|
||||
config_h.set('HAVE_DRM_FORMATS_BLOB', '1')
|
||||
endif
|
||||
|
||||
plugin_drm = shared_library(
|
||||
'drm-backend',
|
||||
srcs_drm,
|
||||
include_directories: include_directories('../..', '../../shared'),
|
||||
dependencies: deps_drm,
|
||||
name_prefix: '',
|
||||
install: true,
|
||||
install_dir: dir_module_libweston
|
||||
)
|
||||
env_modmap += 'drm-backend.so=@0@;'.format(plugin_drm.full_path())
|
||||
|
||||
install_headers(backend_drm_h, subdir: dir_include_libweston_install)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright © 2013 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial
|
||||
* portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _VAAPI_RECORDER_H_
|
||||
#define _VAAPI_RECORDER_H_
|
||||
|
||||
struct vaapi_recorder;
|
||||
|
||||
struct vaapi_recorder *
|
||||
vaapi_recorder_create(int drm_fd, int width, int height, const char *filename);
|
||||
void
|
||||
vaapi_recorder_destroy(struct vaapi_recorder *r);
|
||||
int
|
||||
vaapi_recorder_frame(struct vaapi_recorder *r, int fd, int stride);
|
||||
|
||||
#endif /* _VAAPI_RECORDER_H_ */
|
||||
Reference in New Issue
Block a user