2010-06-11 16:56:24 +00:00
|
|
|
/*
|
Change remaining GPLv2 headers to MIT
The files in question are copyright Benjamin Franzke (who agrees),
Intel Corporation, Red Hat and myself. On behalf of Red Hat,
Richard Fontana says:
"Therefore, to the extent that Red Hat, Inc. has any copyright
interest in the files you cited as of this date (compositor-drm.c,
compositor.c, compositor.h, screenshooter.c in
http://cgit.freedesktop.org/wayland/wayland-demos/tree/compositor),
Red Hat hereby elects to apply the CC0 1.0 Universal Public Domain
Dedication to such copyrighted material. See:
http://creativecommons.org/publicdomain/zero/1.0/legalcode .
Thanks,
Richard E. Fontana
Open Source Licensing and Patent Counsel
Red Hat, Inc."
2011-09-15 19:43:14 +00:00
|
|
|
* Copyright © 2008-2011 Kristian Høgsberg
|
|
|
|
* Copyright © 2011 Intel Corporation
|
2010-06-11 16:56:24 +00:00
|
|
|
*
|
2015-06-11 22:35:43 +00:00
|
|
|
* 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:
|
2010-06-11 16:56:24 +00:00
|
|
|
*
|
2015-06-11 22:35:43 +00:00
|
|
|
* 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.
|
2010-06-11 16:56:24 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-22 15:03:19 +00:00
|
|
|
#include "config.h"
|
2011-04-12 15:34:32 +00:00
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
#include <errno.h>
|
2016-07-19 11:16:27 +00:00
|
|
|
#include <stdint.h>
|
2010-06-11 16:56:24 +00:00
|
|
|
#include <stdlib.h>
|
2013-04-24 13:58:02 +00:00
|
|
|
#include <ctype.h>
|
2010-06-11 16:56:24 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2012-04-10 04:11:50 +00:00
|
|
|
#include <linux/input.h>
|
2013-09-19 06:00:17 +00:00
|
|
|
#include <linux/vt.h>
|
2012-06-26 14:09:14 +00:00
|
|
|
#include <assert.h>
|
2013-01-25 13:13:04 +00:00
|
|
|
#include <sys/mman.h>
|
2013-10-14 12:57:11 +00:00
|
|
|
#include <dlfcn.h>
|
2013-05-07 11:16:59 +00:00
|
|
|
#include <time.h>
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2011-03-02 10:56:04 +00:00
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
2012-02-23 14:45:49 +00:00
|
|
|
#include <drm_fourcc.h>
|
2011-03-02 10:56:04 +00:00
|
|
|
|
2011-04-30 07:32:11 +00:00
|
|
|
#include <gbm.h>
|
2012-08-03 17:30:30 +00:00
|
|
|
#include <libudev.h>
|
2011-04-30 07:32:11 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
#include "compositor.h"
|
|
|
|
#include "compositor-drm.h"
|
2015-06-15 22:37:08 +00:00
|
|
|
#include "shared/helpers.h"
|
compositor-drm: Allow instant start of repaint loop. (v4)
drm_output_start_repaint_loop() incurred a delay of
one refresh cycle by using a no-op page-flip to get
an accurate vblank timestamp as reference. This causes
unwanted lag whenever Weston exited its repaint loop, e.g.,
whenever an application wants to repaint with less than
full video refresh rate but still minimum lag.
Try to use the drmWaitVblank ioctl to get a proper
timestamp instantaneously without lag. If that does
not work, fall back to the old method of idle page-flip.
This optimization will work on any drm/kms driver
which supports high precision vblank timestamping.
As of Linux 4.0 these would be intel, radeon and
nouveau on all their supported gpu's.
On kms drivers without instant high precision timestamping
support, the kernel is supposed to return a timestamp
of zero when calling drmWaitVblank() to query the current
vblank count and time iff vblank irqs are currently
disabled, because the only way to get a valid timestamp
on such kms drivers is to enable vblank interrupts and
then wait a bit for the next vblank irq to take a new valid
timestamp. The caller is supposed to poll until at next
vblank irq it gets a valid non-zero timestamp if it needs
a timestamp.
This zero-timestamp signalling works up to Linux 3.17, but
got broken due to a regression in Linux 3.18 and later. On
Linux 3.18+ with kms drivers that don't have high precision
timestamping, the kernel erroneously returns a stale timestamp
from an earlier vblank, ie. the vblank count and timestamp are
mismatched. A patch is under way to fix this, but to deal with
broken kernels, we also check non-zero timestamps if they are
more than one refresh duration in the past, as this indicates
a stale/invalid timestamp, so we need to take the page-flip
fallback for restarting the repaint loop.
v2: Implement review suggestions by Pekka Paalanen, especially
extend the commit message to describe when and why the
instant restart won't work due to missing Linux kernel
functionality or a Linux kernel regression.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
v3: Fix timespec_to_nsec() which was computing picoseconds,
use the new timespec-util.h helpers.
v4: Rebased to master, split long lines.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-21 19:25:14 +00:00
|
|
|
#include "shared/timespec-util.h"
|
2012-11-13 18:10:28 +00:00
|
|
|
#include "gl-renderer.h"
|
2013-01-25 13:13:05 +00:00
|
|
|
#include "pixman-renderer.h"
|
2016-04-29 22:40:34 +00:00
|
|
|
#include "libbacklight.h"
|
2014-11-25 21:06:31 +00:00
|
|
|
#include "libinput-seat.h"
|
2012-01-30 13:04:04 +00:00
|
|
|
#include "launcher-util.h"
|
2013-08-23 14:15:48 +00:00
|
|
|
#include "vaapi-recorder.h"
|
2016-02-18 14:53:27 +00:00
|
|
|
#include "presentation-time-server-protocol.h"
|
2014-06-12 12:12:48 +00:00
|
|
|
#include "linux-dmabuf.h"
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2013-05-07 11:16:59 +00:00
|
|
|
#ifndef DRM_CAP_TIMESTAMP_MONOTONIC
|
|
|
|
#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
|
|
|
|
#endif
|
|
|
|
|
2014-07-28 21:30:17 +00:00
|
|
|
#ifndef DRM_CAP_CURSOR_WIDTH
|
|
|
|
#define DRM_CAP_CURSOR_WIDTH 0x8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DRM_CAP_CURSOR_HEIGHT
|
|
|
|
#define DRM_CAP_CURSOR_HEIGHT 0x9
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GBM_BO_USE_CURSOR
|
|
|
|
#define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64
|
|
|
|
#endif
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend {
|
|
|
|
struct weston_backend base;
|
|
|
|
struct weston_compositor *compositor;
|
2010-06-14 15:54:00 +00:00
|
|
|
|
|
|
|
struct udev *udev;
|
|
|
|
struct wl_event_source *drm_source;
|
|
|
|
|
2011-03-15 14:08:41 +00:00
|
|
|
struct udev_monitor *udev_monitor;
|
|
|
|
struct wl_event_source *udev_drm_source;
|
|
|
|
|
2011-03-02 10:14:59 +00:00
|
|
|
struct {
|
2012-03-11 19:05:21 +00:00
|
|
|
int id;
|
2011-03-02 10:14:59 +00:00
|
|
|
int fd;
|
2013-08-23 14:15:48 +00:00
|
|
|
char *filename;
|
2011-03-02 10:14:59 +00:00
|
|
|
} drm;
|
2011-04-30 07:32:11 +00:00
|
|
|
struct gbm_device *gbm;
|
2012-02-23 14:45:49 +00:00
|
|
|
uint32_t *crtcs;
|
|
|
|
int num_crtcs;
|
2011-02-10 00:01:42 +00:00
|
|
|
uint32_t crtc_allocator;
|
2011-03-15 14:08:41 +00:00
|
|
|
uint32_t connector_allocator;
|
2013-09-17 23:02:57 +00:00
|
|
|
struct wl_listener session_listener;
|
2016-03-21 16:41:03 +00:00
|
|
|
uint32_t gbm_format;
|
2011-12-02 11:07:27 +00:00
|
|
|
|
2012-08-09 19:18:28 +00:00
|
|
|
/* we need these parameters in order to not fail drmModeAddFB2()
|
|
|
|
* due to out of bounds dimensions, and then mistakenly set
|
|
|
|
* sprites_are_broken:
|
|
|
|
*/
|
2012-11-09 12:19:05 +00:00
|
|
|
uint32_t min_width, max_width;
|
|
|
|
uint32_t min_height, max_height;
|
|
|
|
int no_addfb2;
|
2012-08-09 19:18:28 +00:00
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
struct wl_list sprite_list;
|
2012-03-06 00:57:35 +00:00
|
|
|
int sprites_are_broken;
|
2012-10-31 15:55:46 +00:00
|
|
|
int sprites_hidden;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2012-08-09 18:24:45 +00:00
|
|
|
int cursors_are_broken;
|
|
|
|
|
2013-01-25 13:13:05 +00:00
|
|
|
int use_pixman;
|
|
|
|
|
2011-12-02 11:07:27 +00:00
|
|
|
uint32_t prev_state;
|
2013-05-07 11:16:59 +00:00
|
|
|
|
2013-05-31 17:09:55 +00:00
|
|
|
struct udev_input input;
|
2014-07-28 21:30:17 +00:00
|
|
|
|
2015-06-16 17:42:23 +00:00
|
|
|
int32_t cursor_width;
|
|
|
|
int32_t cursor_height;
|
2016-04-29 22:40:34 +00:00
|
|
|
|
|
|
|
/** Callback used to configure the outputs.
|
|
|
|
*
|
|
|
|
* This function will be called by the backend when a new DRM
|
|
|
|
* output needs to be configured.
|
|
|
|
*/
|
|
|
|
enum weston_drm_backend_output_mode
|
|
|
|
(*configure_output)(struct weston_compositor *compositor,
|
|
|
|
bool use_current_mode,
|
|
|
|
const char *name,
|
|
|
|
struct weston_drm_backend_output_config *output_config);
|
|
|
|
bool use_current_mode;
|
2010-06-14 15:54:00 +00:00
|
|
|
};
|
|
|
|
|
2011-06-21 15:16:58 +00:00
|
|
|
struct drm_mode {
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
struct weston_mode base;
|
2011-06-21 15:16:58 +00:00
|
|
|
drmModeModeInfo mode_info;
|
|
|
|
};
|
|
|
|
|
2012-05-02 13:42:21 +00:00
|
|
|
struct drm_fb {
|
2013-01-25 13:13:04 +00:00
|
|
|
uint32_t fb_id, stride, handle, size;
|
|
|
|
int fd;
|
2012-05-02 13:42:21 +00:00
|
|
|
int is_client_buffer;
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 13:58:12 +00:00
|
|
|
struct weston_buffer_reference buffer_ref;
|
2013-01-25 13:13:04 +00:00
|
|
|
|
|
|
|
/* Used by gbm fbs */
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
|
|
|
|
/* Used by dumb fbs */
|
|
|
|
void *map;
|
2012-05-02 13:42:21 +00:00
|
|
|
};
|
|
|
|
|
2013-04-24 13:58:02 +00:00
|
|
|
struct drm_edid {
|
|
|
|
char eisa_id[13];
|
|
|
|
char monitor_name[13];
|
|
|
|
char pnp_id[5];
|
|
|
|
char serial_number[13];
|
|
|
|
};
|
|
|
|
|
2010-06-14 15:54:00 +00:00
|
|
|
struct drm_output {
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
struct weston_output base;
|
2010-06-14 15:54:00 +00:00
|
|
|
|
|
|
|
uint32_t crtc_id;
|
2012-08-09 01:27:37 +00:00
|
|
|
int pipe;
|
2010-06-14 15:54:00 +00:00
|
|
|
uint32_t connector_id;
|
2011-08-29 20:52:23 +00:00
|
|
|
drmModeCrtcPtr original_crtc;
|
2013-04-24 13:58:02 +00:00
|
|
|
struct drm_edid edid;
|
2013-06-04 13:24:04 +00:00
|
|
|
drmModePropertyPtr dpms_prop;
|
2016-03-21 16:41:03 +00:00
|
|
|
uint32_t gbm_format;
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2015-06-18 06:49:02 +00:00
|
|
|
enum dpms_enum dpms;
|
|
|
|
|
2012-06-26 14:09:13 +00:00
|
|
|
int vblank_pending;
|
|
|
|
int page_flip_pending;
|
2013-10-11 06:43:07 +00:00
|
|
|
int destroy_pending;
|
2012-06-26 14:09:13 +00:00
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
struct gbm_surface *gbm_surface;
|
|
|
|
struct gbm_bo *gbm_cursor_bo[2];
|
2012-08-03 15:30:18 +00:00
|
|
|
struct weston_plane cursor_plane;
|
|
|
|
struct weston_plane fb_plane;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *cursor_view;
|
2012-08-03 15:50:05 +00:00
|
|
|
int current_cursor;
|
2012-05-02 13:42:21 +00:00
|
|
|
struct drm_fb *current, *next;
|
2012-02-29 17:53:50 +00:00
|
|
|
struct backlight *backlight;
|
2013-01-25 13:13:05 +00:00
|
|
|
|
|
|
|
struct drm_fb *dumb[2];
|
|
|
|
pixman_image_t *image[2];
|
|
|
|
int current_image;
|
|
|
|
pixman_region32_t previous_damage;
|
2013-08-23 14:15:48 +00:00
|
|
|
|
|
|
|
struct vaapi_recorder *recorder;
|
|
|
|
struct wl_listener recorder_frame_listener;
|
2010-06-14 15:54:00 +00:00
|
|
|
};
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
/*
|
|
|
|
* An output has a primary display plane plus zero or more sprites for
|
|
|
|
* blending display contents.
|
|
|
|
*/
|
|
|
|
struct drm_sprite {
|
|
|
|
struct wl_list link;
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
struct weston_plane plane;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2012-11-09 12:19:05 +00:00
|
|
|
struct drm_fb *current, *next;
|
2012-06-26 14:09:13 +00:00
|
|
|
struct drm_output *output;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *backend;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
|
|
|
uint32_t possible_crtcs;
|
|
|
|
uint32_t plane_id;
|
|
|
|
uint32_t count_formats;
|
|
|
|
|
|
|
|
int32_t src_x, src_y;
|
|
|
|
uint32_t src_w, src_h;
|
|
|
|
uint32_t dest_x, dest_y;
|
|
|
|
uint32_t dest_w, dest_h;
|
|
|
|
|
|
|
|
uint32_t formats[];
|
|
|
|
};
|
|
|
|
|
2013-10-14 12:57:11 +00:00
|
|
|
static struct gl_renderer_interface *gl_renderer;
|
|
|
|
|
2013-02-18 21:15:53 +00:00
|
|
|
static const char default_seat[] = "seat0";
|
2012-08-03 17:30:30 +00:00
|
|
|
|
2012-08-03 15:50:05 +00:00
|
|
|
static void
|
|
|
|
drm_output_set_cursor(struct drm_output *output);
|
|
|
|
|
compositor-drm: Allow instant start of repaint loop. (v4)
drm_output_start_repaint_loop() incurred a delay of
one refresh cycle by using a no-op page-flip to get
an accurate vblank timestamp as reference. This causes
unwanted lag whenever Weston exited its repaint loop, e.g.,
whenever an application wants to repaint with less than
full video refresh rate but still minimum lag.
Try to use the drmWaitVblank ioctl to get a proper
timestamp instantaneously without lag. If that does
not work, fall back to the old method of idle page-flip.
This optimization will work on any drm/kms driver
which supports high precision vblank timestamping.
As of Linux 4.0 these would be intel, radeon and
nouveau on all their supported gpu's.
On kms drivers without instant high precision timestamping
support, the kernel is supposed to return a timestamp
of zero when calling drmWaitVblank() to query the current
vblank count and time iff vblank irqs are currently
disabled, because the only way to get a valid timestamp
on such kms drivers is to enable vblank interrupts and
then wait a bit for the next vblank irq to take a new valid
timestamp. The caller is supposed to poll until at next
vblank irq it gets a valid non-zero timestamp if it needs
a timestamp.
This zero-timestamp signalling works up to Linux 3.17, but
got broken due to a regression in Linux 3.18 and later. On
Linux 3.18+ with kms drivers that don't have high precision
timestamping, the kernel erroneously returns a stale timestamp
from an earlier vblank, ie. the vblank count and timestamp are
mismatched. A patch is under way to fix this, but to deal with
broken kernels, we also check non-zero timestamps if they are
more than one refresh duration in the past, as this indicates
a stale/invalid timestamp, so we need to take the page-flip
fallback for restarting the repaint loop.
v2: Implement review suggestions by Pekka Paalanen, especially
extend the commit message to describe when and why the
instant restart won't work due to missing Linux kernel
functionality or a Linux kernel regression.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
v3: Fix timespec_to_nsec() which was computing picoseconds,
use the new timespec-util.h helpers.
v4: Rebased to master, split long lines.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-21 19:25:14 +00:00
|
|
|
static void
|
|
|
|
drm_output_update_msc(struct drm_output *output, unsigned int seq);
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
static int
|
2014-12-17 14:20:38 +00:00
|
|
|
drm_sprite_crtc_supported(struct drm_output *output, uint32_t supported)
|
2012-02-23 14:45:49 +00:00
|
|
|
{
|
2014-12-17 14:20:38 +00:00
|
|
|
struct weston_compositor *ec = output->base.compositor;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =(struct drm_backend *)ec->backend;
|
2012-02-23 14:45:49 +00:00
|
|
|
int crtc;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
for (crtc = 0; crtc < b->num_crtcs; crtc++) {
|
|
|
|
if (b->crtcs[crtc] != output->crtc_id)
|
2012-02-23 14:45:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (supported & (1 << crtc))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-02 13:42:21 +00:00
|
|
|
static void
|
|
|
|
drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
|
|
|
|
{
|
|
|
|
struct drm_fb *fb = data;
|
|
|
|
struct gbm_device *gbm = gbm_bo_get_device(bo);
|
|
|
|
|
|
|
|
if (fb->fb_id)
|
|
|
|
drmModeRmFB(gbm_device_get_fd(gbm), fb->fb_id);
|
|
|
|
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 13:58:12 +00:00
|
|
|
weston_buffer_reference(&fb->buffer_ref, NULL);
|
2012-05-02 13:42:21 +00:00
|
|
|
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:04 +00:00
|
|
|
static struct drm_fb *
|
2016-06-20 11:18:45 +00:00
|
|
|
drm_fb_create_dumb(struct drm_backend *b, unsigned width, unsigned height,
|
|
|
|
uint32_t format)
|
2013-01-25 13:13:04 +00:00
|
|
|
{
|
|
|
|
struct drm_fb *fb;
|
|
|
|
int ret;
|
2016-06-20 11:18:45 +00:00
|
|
|
uint32_t bpp, depth;
|
2013-01-25 13:13:04 +00:00
|
|
|
|
|
|
|
struct drm_mode_create_dumb create_arg;
|
|
|
|
struct drm_mode_destroy_dumb destroy_arg;
|
|
|
|
struct drm_mode_map_dumb map_arg;
|
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
fb = zalloc(sizeof *fb);
|
2013-01-25 13:13:04 +00:00
|
|
|
if (!fb)
|
|
|
|
return NULL;
|
|
|
|
|
2016-06-20 11:18:45 +00:00
|
|
|
switch (format) {
|
|
|
|
case GBM_FORMAT_XRGB8888:
|
|
|
|
bpp = 32;
|
|
|
|
depth = 24;
|
|
|
|
break;
|
|
|
|
case GBM_FORMAT_RGB565:
|
|
|
|
bpp = depth = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-22 05:14:14 +00:00
|
|
|
memset(&create_arg, 0, sizeof create_arg);
|
2016-06-20 11:18:45 +00:00
|
|
|
create_arg.bpp = bpp;
|
2013-01-25 13:13:04 +00:00
|
|
|
create_arg.width = width;
|
|
|
|
create_arg.height = height;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmIoctl(b->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg);
|
2013-01-25 13:13:04 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_fb;
|
|
|
|
|
|
|
|
fb->handle = create_arg.handle;
|
|
|
|
fb->stride = create_arg.pitch;
|
|
|
|
fb->size = create_arg.size;
|
2014-10-11 15:27:30 +00:00
|
|
|
fb->fd = b->drm.fd;
|
2013-01-25 13:13:04 +00:00
|
|
|
|
2016-06-20 11:18:45 +00:00
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
if (!b->no_addfb2) {
|
|
|
|
uint32_t handles[4], pitches[4], offsets[4];
|
|
|
|
|
|
|
|
handles[0] = fb->handle;
|
|
|
|
pitches[0] = fb->stride;
|
|
|
|
offsets[0] = 0;
|
|
|
|
|
|
|
|
ret = drmModeAddFB2(b->drm.fd, width, height,
|
|
|
|
format, handles, pitches, offsets,
|
|
|
|
&fb->fb_id, 0);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("addfb2 failed: %m\n");
|
|
|
|
b->no_addfb2 = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
ret = drmModeAddFB(b->drm.fd, width, height, depth, bpp,
|
|
|
|
fb->stride, fb->handle, &fb->fb_id);
|
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:04 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_bo;
|
|
|
|
|
2013-08-22 05:14:14 +00:00
|
|
|
memset(&map_arg, 0, sizeof map_arg);
|
2013-01-25 13:13:04 +00:00
|
|
|
map_arg.handle = fb->handle;
|
2013-05-02 01:26:02 +00:00
|
|
|
ret = drmIoctl(fb->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
|
2013-01-25 13:13:04 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_add_fb;
|
|
|
|
|
2015-11-10 15:40:37 +00:00
|
|
|
fb->map = mmap(NULL, fb->size, PROT_WRITE,
|
2014-10-11 15:27:30 +00:00
|
|
|
MAP_SHARED, b->drm.fd, map_arg.offset);
|
2013-01-25 13:13:04 +00:00
|
|
|
if (fb->map == MAP_FAILED)
|
|
|
|
goto err_add_fb;
|
|
|
|
|
|
|
|
return fb;
|
|
|
|
|
|
|
|
err_add_fb:
|
2014-10-11 15:27:30 +00:00
|
|
|
drmModeRmFB(b->drm.fd, fb->fb_id);
|
2013-01-25 13:13:04 +00:00
|
|
|
err_bo:
|
|
|
|
memset(&destroy_arg, 0, sizeof(destroy_arg));
|
|
|
|
destroy_arg.handle = create_arg.handle;
|
2014-10-11 15:27:30 +00:00
|
|
|
drmIoctl(b->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
|
2013-01-25 13:13:04 +00:00
|
|
|
err_fb:
|
|
|
|
free(fb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_fb_destroy_dumb(struct drm_fb *fb)
|
|
|
|
{
|
|
|
|
struct drm_mode_destroy_dumb destroy_arg;
|
|
|
|
|
|
|
|
if (!fb->map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fb->fb_id)
|
|
|
|
drmModeRmFB(fb->fd, fb->fb_id);
|
|
|
|
|
|
|
|
weston_buffer_reference(&fb->buffer_ref, NULL);
|
|
|
|
|
|
|
|
munmap(fb->map, fb->size);
|
|
|
|
|
|
|
|
memset(&destroy_arg, 0, sizeof(destroy_arg));
|
|
|
|
destroy_arg.handle = fb->handle;
|
|
|
|
drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
|
|
|
|
|
|
|
|
free(fb);
|
|
|
|
}
|
|
|
|
|
2012-05-02 13:42:21 +00:00
|
|
|
static struct drm_fb *
|
2012-12-07 17:37:58 +00:00
|
|
|
drm_fb_get_from_bo(struct gbm_bo *bo,
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *backend, uint32_t format)
|
2012-05-02 13:42:21 +00:00
|
|
|
{
|
|
|
|
struct drm_fb *fb = gbm_bo_get_user_data(bo);
|
2013-01-25 13:13:04 +00:00
|
|
|
uint32_t width, height;
|
2012-11-09 12:19:05 +00:00
|
|
|
uint32_t handles[4], pitches[4], offsets[4];
|
2012-05-02 13:42:21 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (fb)
|
|
|
|
return fb;
|
|
|
|
|
2014-11-21 06:21:57 +00:00
|
|
|
fb = zalloc(sizeof *fb);
|
|
|
|
if (fb == NULL)
|
2013-01-25 13:13:04 +00:00
|
|
|
return NULL;
|
2012-05-02 13:42:21 +00:00
|
|
|
|
|
|
|
fb->bo = bo;
|
|
|
|
|
|
|
|
width = gbm_bo_get_width(bo);
|
|
|
|
height = gbm_bo_get_height(bo);
|
2013-01-25 13:13:04 +00:00
|
|
|
fb->stride = gbm_bo_get_stride(bo);
|
|
|
|
fb->handle = gbm_bo_get_handle(bo).u32;
|
|
|
|
fb->size = fb->stride * height;
|
2014-10-11 15:27:30 +00:00
|
|
|
fb->fd = backend->drm.fd;
|
2012-05-02 13:42:21 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (backend->min_width > width || width > backend->max_width ||
|
|
|
|
backend->min_height > height ||
|
|
|
|
height > backend->max_height) {
|
2012-11-09 12:19:05 +00:00
|
|
|
weston_log("bo geometry out of bounds\n");
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (format && !backend->no_addfb2) {
|
2013-01-25 13:13:04 +00:00
|
|
|
handles[0] = fb->handle;
|
|
|
|
pitches[0] = fb->stride;
|
2012-11-09 12:19:05 +00:00
|
|
|
offsets[0] = 0;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmModeAddFB2(backend->drm.fd, width, height,
|
2012-11-09 12:19:05 +00:00
|
|
|
format, handles, pitches, offsets,
|
|
|
|
&fb->fb_id, 0);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("addfb2 failed: %m\n");
|
2014-10-11 15:27:30 +00:00
|
|
|
backend->no_addfb2 = 1;
|
|
|
|
backend->sprites_are_broken = 1;
|
2012-11-09 12:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmModeAddFB(backend->drm.fd, width, height, 24, 32,
|
2013-01-25 13:13:04 +00:00
|
|
|
fb->stride, fb->handle, &fb->fb_id);
|
2012-11-09 12:19:05 +00:00
|
|
|
|
2012-05-02 13:42:21 +00:00
|
|
|
if (ret) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to create kms fb: %m\n");
|
2012-11-09 12:19:05 +00:00
|
|
|
goto err_free;
|
2012-05-02 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback);
|
|
|
|
|
|
|
|
return fb;
|
2012-11-09 12:19:05 +00:00
|
|
|
|
|
|
|
err_free:
|
|
|
|
free(fb);
|
|
|
|
return NULL;
|
2012-05-02 13:42:21 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 12:19:05 +00:00
|
|
|
static void
|
2013-06-21 01:38:23 +00:00
|
|
|
drm_fb_set_buffer(struct drm_fb *fb, struct weston_buffer *buffer)
|
2012-11-09 12:19:05 +00:00
|
|
|
{
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 13:58:12 +00:00
|
|
|
assert(fb->buffer_ref.buffer == NULL);
|
2012-11-09 12:19:05 +00:00
|
|
|
|
|
|
|
fb->is_client_buffer = 1;
|
|
|
|
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 13:58:12 +00:00
|
|
|
weston_buffer_reference(&fb->buffer_ref, buffer);
|
2012-11-09 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:03 +00:00
|
|
|
static void
|
|
|
|
drm_output_release_fb(struct drm_output *output, struct drm_fb *fb)
|
|
|
|
{
|
|
|
|
if (!fb)
|
|
|
|
return;
|
|
|
|
|
2013-01-25 13:13:05 +00:00
|
|
|
if (fb->map &&
|
|
|
|
(fb != output->dumb[0] && fb != output->dumb[1])) {
|
2013-01-25 13:13:04 +00:00
|
|
|
drm_fb_destroy_dumb(fb);
|
|
|
|
} else if (fb->bo) {
|
2013-01-25 13:13:03 +00:00
|
|
|
if (fb->is_client_buffer)
|
|
|
|
gbm_bo_destroy(fb->bo);
|
|
|
|
else
|
2016-03-21 16:41:03 +00:00
|
|
|
gbm_surface_release_buffer(output->gbm_surface,
|
2013-11-15 02:52:35 +00:00
|
|
|
fb->bo);
|
2013-01-25 13:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-07 17:37:58 +00:00
|
|
|
static uint32_t
|
2012-11-30 15:34:22 +00:00
|
|
|
drm_output_check_scanout_format(struct drm_output *output,
|
|
|
|
struct weston_surface *es, struct gbm_bo *bo)
|
|
|
|
{
|
|
|
|
uint32_t format;
|
|
|
|
pixman_region32_t r;
|
|
|
|
|
|
|
|
format = gbm_bo_get_format(bo);
|
|
|
|
|
2013-10-16 23:08:57 +00:00
|
|
|
if (format == GBM_FORMAT_ARGB8888) {
|
|
|
|
/* We can scanout an ARGB buffer if the surface's
|
|
|
|
* opaque region covers the whole output, but we have
|
|
|
|
* to use XRGB as the KMS format code. */
|
2014-01-17 22:22:41 +00:00
|
|
|
pixman_region32_init_rect(&r, 0, 0,
|
|
|
|
output->base.width,
|
|
|
|
output->base.height);
|
|
|
|
pixman_region32_subtract(&r, &r, &es->opaque);
|
2012-11-30 15:34:22 +00:00
|
|
|
|
|
|
|
if (!pixman_region32_not_empty(&r))
|
2012-12-07 17:37:58 +00:00
|
|
|
format = GBM_FORMAT_XRGB8888;
|
2012-11-30 15:34:22 +00:00
|
|
|
|
|
|
|
pixman_region32_fini(&r);
|
2013-10-16 23:08:57 +00:00
|
|
|
}
|
2012-11-30 15:34:22 +00:00
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
if (output->gbm_format == format)
|
2012-12-07 17:37:58 +00:00
|
|
|
return format;
|
2013-10-16 23:08:57 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-11-30 15:34:22 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
static struct weston_plane *
|
2014-12-17 14:20:38 +00:00
|
|
|
drm_output_prepare_scanout_view(struct drm_output *output,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *ev)
|
2012-01-26 04:59:42 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *)output->base.compositor->backend;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
|
2014-03-14 12:38:15 +00:00
|
|
|
struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
|
2012-05-02 13:42:21 +00:00
|
|
|
struct gbm_bo *bo;
|
2012-12-07 17:37:58 +00:00
|
|
|
uint32_t format;
|
2012-01-26 04:59:42 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (ev->geometry.x != output->base.x ||
|
|
|
|
ev->geometry.y != output->base.y ||
|
2014-10-11 15:27:30 +00:00
|
|
|
buffer == NULL || b->gbm == NULL ||
|
2013-09-18 21:56:35 +00:00
|
|
|
buffer->width != output->base.current_mode->width ||
|
|
|
|
buffer->height != output->base.current_mode->height ||
|
2014-03-14 12:38:15 +00:00
|
|
|
output->base.transform != viewport->buffer.transform ||
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
ev->transform.enabled)
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-01-26 04:59:42 +00:00
|
|
|
|
2015-02-17 14:33:18 +00:00
|
|
|
if (ev->geometry.scissor_enabled)
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
|
2013-09-04 05:27:08 +00:00
|
|
|
buffer->resource, GBM_BO_USE_SCANOUT);
|
2012-05-02 13:42:21 +00:00
|
|
|
|
2012-09-14 22:25:41 +00:00
|
|
|
/* Unable to use the buffer for scanout */
|
|
|
|
if (!bo)
|
|
|
|
return NULL;
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
format = drm_output_check_scanout_format(output, ev->surface, bo);
|
2012-12-07 17:37:58 +00:00
|
|
|
if (format == 0) {
|
2012-05-02 13:42:22 +00:00
|
|
|
gbm_bo_destroy(bo);
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-05-02 13:42:22 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
output->next = drm_fb_get_from_bo(bo, b, format);
|
2012-05-02 13:42:21 +00:00
|
|
|
if (!output->next) {
|
|
|
|
gbm_bo_destroy(bo);
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-05-02 13:42:21 +00:00
|
|
|
}
|
2012-01-26 04:59:42 +00:00
|
|
|
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 13:58:12 +00:00
|
|
|
drm_fb_set_buffer(output->next, buffer);
|
2012-01-26 04:59:42 +00:00
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
return &output->fb_plane;
|
2012-01-26 04:59:42 +00:00
|
|
|
}
|
|
|
|
|
2012-03-11 22:27:41 +00:00
|
|
|
static void
|
2013-01-25 13:13:05 +00:00
|
|
|
drm_output_render_gl(struct drm_output *output, pixman_region32_t *damage)
|
2012-03-11 22:27:41 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *)output->base.compositor->backend;
|
2012-05-02 13:42:21 +00:00
|
|
|
struct gbm_bo *bo;
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
output->base.compositor->renderer->repaint_output(&output->base,
|
|
|
|
damage);
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
bo = gbm_surface_lock_front_buffer(output->gbm_surface);
|
2012-05-02 13:42:21 +00:00
|
|
|
if (!bo) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to lock front buffer: %m\n");
|
2012-03-11 22:27:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-02 13:42:21 +00:00
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
output->next = drm_fb_get_from_bo(bo, b, output->gbm_format);
|
2012-05-02 13:42:21 +00:00
|
|
|
if (!output->next) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to get drm_fb for bo\n");
|
2016-03-21 16:41:03 +00:00
|
|
|
gbm_surface_release_buffer(output->gbm_surface, bo);
|
2012-05-02 13:42:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-11 22:27:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:05 +00:00
|
|
|
static void
|
|
|
|
drm_output_render_pixman(struct drm_output *output, pixman_region32_t *damage)
|
|
|
|
{
|
|
|
|
struct weston_compositor *ec = output->base.compositor;
|
|
|
|
pixman_region32_t total_damage, previous_damage;
|
|
|
|
|
|
|
|
pixman_region32_init(&total_damage);
|
|
|
|
pixman_region32_init(&previous_damage);
|
|
|
|
|
|
|
|
pixman_region32_copy(&previous_damage, damage);
|
|
|
|
|
|
|
|
pixman_region32_union(&total_damage, damage, &output->previous_damage);
|
|
|
|
pixman_region32_copy(&output->previous_damage, &previous_damage);
|
|
|
|
|
|
|
|
output->current_image ^= 1;
|
|
|
|
|
|
|
|
output->next = output->dumb[output->current_image];
|
|
|
|
pixman_renderer_output_set_buffer(&output->base,
|
|
|
|
output->image[output->current_image]);
|
|
|
|
|
|
|
|
ec->renderer->repaint_output(&output->base, &total_damage);
|
|
|
|
|
|
|
|
pixman_region32_fini(&total_damage);
|
|
|
|
pixman_region32_fini(&previous_damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_output_render(struct drm_output *output, pixman_region32_t *damage)
|
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct weston_compositor *c = output->base.compositor;
|
|
|
|
struct drm_backend *b = (struct drm_backend *)c->backend;
|
2013-01-25 13:13:05 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->use_pixman)
|
2013-01-25 13:13:05 +00:00
|
|
|
drm_output_render_pixman(output, damage);
|
|
|
|
else
|
|
|
|
drm_output_render_gl(output, damage);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
pixman_region32_subtract(&c->primary_plane.damage,
|
|
|
|
&c->primary_plane.damage, damage);
|
2013-01-25 13:13:05 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 20:52:12 +00:00
|
|
|
static void
|
|
|
|
drm_output_set_gamma(struct weston_output *output_base,
|
|
|
|
uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct drm_output *output = (struct drm_output *) output_base;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *backend =
|
|
|
|
(struct drm_backend *) output->base.compositor->backend;
|
2013-05-01 20:52:12 +00:00
|
|
|
|
|
|
|
/* check */
|
|
|
|
if (output_base->gamma_size != size)
|
|
|
|
return;
|
|
|
|
if (!output->original_crtc)
|
|
|
|
return;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
rc = drmModeCrtcSetGamma(backend->drm.fd,
|
2013-05-01 20:52:12 +00:00
|
|
|
output->crtc_id,
|
|
|
|
size, r, g, b);
|
|
|
|
if (rc)
|
|
|
|
weston_log("set gamma failed: %m\n");
|
|
|
|
}
|
|
|
|
|
2015-06-30 20:25:46 +00:00
|
|
|
/* Determine the type of vblank synchronization to use for the output.
|
2016-02-18 14:53:27 +00:00
|
|
|
*
|
2015-06-30 20:25:46 +00:00
|
|
|
* The pipe parameter indicates which CRTC is in use. Knowing this, we
|
|
|
|
* can determine which vblank sequence type to use for it. Traditional
|
|
|
|
* cards had only two CRTCs, with CRTC 0 using no special flags, and
|
|
|
|
* CRTC 1 using DRM_VBLANK_SECONDARY. The first bit of the pipe
|
|
|
|
* parameter indicates this.
|
2016-02-18 14:53:27 +00:00
|
|
|
*
|
2015-06-30 20:25:46 +00:00
|
|
|
* Bits 1-5 of the pipe parameter are 5 bit wide pipe number between
|
|
|
|
* 0-31. If this is non-zero it indicates we're dealing with a
|
|
|
|
* multi-gpu situation and we need to calculate the vblank sync
|
|
|
|
* using DRM_BLANK_HIGH_CRTC_MASK.
|
|
|
|
*/
|
2015-07-02 12:06:08 +00:00
|
|
|
static unsigned int
|
|
|
|
drm_waitvblank_pipe(struct drm_output *output)
|
2015-06-21 19:25:13 +00:00
|
|
|
{
|
|
|
|
if (output->pipe > 1)
|
|
|
|
return (output->pipe << DRM_VBLANK_HIGH_CRTC_SHIFT) &
|
|
|
|
DRM_VBLANK_HIGH_CRTC_MASK;
|
|
|
|
else if (output->pipe > 0)
|
|
|
|
return DRM_VBLANK_SECONDARY;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-22 15:11:26 +00:00
|
|
|
static int
|
2012-02-29 03:31:58 +00:00
|
|
|
drm_output_repaint(struct weston_output *output_base,
|
2012-09-06 01:54:15 +00:00
|
|
|
pixman_region32_t *damage)
|
2011-03-11 15:39:20 +00:00
|
|
|
{
|
|
|
|
struct drm_output *output = (struct drm_output *) output_base;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *backend =
|
|
|
|
(struct drm_backend *)output->base.compositor->backend;
|
2012-02-23 14:45:49 +00:00
|
|
|
struct drm_sprite *s;
|
2012-03-11 22:27:41 +00:00
|
|
|
struct drm_mode *mode;
|
2012-02-23 14:45:49 +00:00
|
|
|
int ret = 0;
|
2011-03-11 15:39:20 +00:00
|
|
|
|
2013-10-11 06:43:07 +00:00
|
|
|
if (output->destroy_pending)
|
2013-10-22 15:11:26 +00:00
|
|
|
return -1;
|
2013-10-11 06:43:07 +00:00
|
|
|
|
2012-05-02 13:42:21 +00:00
|
|
|
if (!output->next)
|
2012-09-06 01:54:15 +00:00
|
|
|
drm_output_render(output, damage);
|
2012-05-02 13:42:21 +00:00
|
|
|
if (!output->next)
|
2013-10-22 15:11:26 +00:00
|
|
|
return -1;
|
2010-06-14 15:54:00 +00:00
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
mode = container_of(output->base.current_mode, struct drm_mode, base);
|
2013-11-19 13:22:04 +00:00
|
|
|
if (!output->current ||
|
|
|
|
output->current->stride != output->next->stride) {
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmModeSetCrtc(backend->drm.fd, output->crtc_id,
|
2012-05-02 13:42:21 +00:00
|
|
|
output->next->fb_id, 0, 0,
|
2012-03-11 22:27:41 +00:00
|
|
|
&output->connector_id, 1,
|
|
|
|
&mode->mode_info);
|
|
|
|
if (ret) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("set mode failed: %m\n");
|
2013-10-22 15:11:26 +00:00
|
|
|
goto err_pageflip;
|
2012-03-11 22:27:41 +00:00
|
|
|
}
|
2013-06-04 13:24:05 +00:00
|
|
|
output_base->set_dpms(output_base, WESTON_DPMS_ON);
|
2011-04-10 14:49:52 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drmModePageFlip(backend->drm.fd, output->crtc_id,
|
2012-05-02 13:42:21 +00:00
|
|
|
output->next->fb_id,
|
2012-01-18 16:47:41 +00:00
|
|
|
DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("queueing pageflip failed: %m\n");
|
2013-10-22 15:11:26 +00:00
|
|
|
goto err_pageflip;
|
2012-01-18 16:47:41 +00:00
|
|
|
}
|
2011-03-11 15:39:20 +00:00
|
|
|
|
2012-06-26 14:09:13 +00:00
|
|
|
output->page_flip_pending = 1;
|
|
|
|
|
2012-08-03 15:50:05 +00:00
|
|
|
drm_output_set_cursor(output);
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
/*
|
|
|
|
* Now, update all the sprite surfaces
|
|
|
|
*/
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(s, &backend->sprite_list, link) {
|
2012-11-09 12:19:05 +00:00
|
|
|
uint32_t flags = 0, fb_id = 0;
|
2012-02-23 14:45:49 +00:00
|
|
|
drmVBlank vbl = {
|
|
|
|
.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT,
|
|
|
|
.request.sequence = 1,
|
|
|
|
};
|
|
|
|
|
2012-11-09 12:19:05 +00:00
|
|
|
if ((!s->current && !s->next) ||
|
2014-12-17 14:20:38 +00:00
|
|
|
!drm_sprite_crtc_supported(output, s->possible_crtcs))
|
2012-02-23 14:45:49 +00:00
|
|
|
continue;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (s->next && !backend->sprites_hidden)
|
2012-11-09 12:19:05 +00:00
|
|
|
fb_id = s->next->fb_id;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmModeSetPlane(backend->drm.fd, s->plane_id,
|
2012-11-09 12:19:05 +00:00
|
|
|
output->crtc_id, fb_id, flags,
|
2012-02-23 14:45:49 +00:00
|
|
|
s->dest_x, s->dest_y,
|
|
|
|
s->dest_w, s->dest_h,
|
|
|
|
s->src_x, s->src_y,
|
|
|
|
s->src_w, s->src_h);
|
|
|
|
if (ret)
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("setplane failed: %d: %s\n",
|
2012-02-23 14:45:49 +00:00
|
|
|
ret, strerror(errno));
|
|
|
|
|
2015-06-21 19:25:13 +00:00
|
|
|
vbl.request.type |= drm_waitvblank_pipe(output);
|
2012-08-09 01:27:37 +00:00
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
/*
|
|
|
|
* Queue a vblank signal so we know when the surface
|
|
|
|
* becomes active on the display or has been replaced.
|
|
|
|
*/
|
|
|
|
vbl.request.signal = (unsigned long)s;
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmWaitVBlank(backend->drm.fd, &vbl);
|
2012-02-23 14:45:49 +00:00
|
|
|
if (ret) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("vblank event request failed: %d: %s\n",
|
2012-02-23 14:45:49 +00:00
|
|
|
ret, strerror(errno));
|
|
|
|
}
|
2012-06-26 14:09:13 +00:00
|
|
|
|
|
|
|
s->output = output;
|
|
|
|
output->vblank_pending = 1;
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 15:11:26 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_pageflip:
|
2014-01-24 00:25:06 +00:00
|
|
|
output->cursor_view = NULL;
|
2013-10-22 15:11:26 +00:00
|
|
|
if (output->next) {
|
|
|
|
drm_output_release_fb(output, output->next);
|
|
|
|
output->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2010-06-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 21:07:11 +00:00
|
|
|
static void
|
|
|
|
drm_output_start_repaint_loop(struct weston_output *output_base)
|
|
|
|
{
|
|
|
|
struct drm_output *output = (struct drm_output *) output_base;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *backend = (struct drm_backend *)
|
|
|
|
output_base->compositor->backend;
|
2013-04-05 21:07:11 +00:00
|
|
|
uint32_t fb_id;
|
compositor-drm: Allow instant start of repaint loop. (v4)
drm_output_start_repaint_loop() incurred a delay of
one refresh cycle by using a no-op page-flip to get
an accurate vblank timestamp as reference. This causes
unwanted lag whenever Weston exited its repaint loop, e.g.,
whenever an application wants to repaint with less than
full video refresh rate but still minimum lag.
Try to use the drmWaitVblank ioctl to get a proper
timestamp instantaneously without lag. If that does
not work, fall back to the old method of idle page-flip.
This optimization will work on any drm/kms driver
which supports high precision vblank timestamping.
As of Linux 4.0 these would be intel, radeon and
nouveau on all their supported gpu's.
On kms drivers without instant high precision timestamping
support, the kernel is supposed to return a timestamp
of zero when calling drmWaitVblank() to query the current
vblank count and time iff vblank irqs are currently
disabled, because the only way to get a valid timestamp
on such kms drivers is to enable vblank interrupts and
then wait a bit for the next vblank irq to take a new valid
timestamp. The caller is supposed to poll until at next
vblank irq it gets a valid non-zero timestamp if it needs
a timestamp.
This zero-timestamp signalling works up to Linux 3.17, but
got broken due to a regression in Linux 3.18 and later. On
Linux 3.18+ with kms drivers that don't have high precision
timestamping, the kernel erroneously returns a stale timestamp
from an earlier vblank, ie. the vblank count and timestamp are
mismatched. A patch is under way to fix this, but to deal with
broken kernels, we also check non-zero timestamps if they are
more than one refresh duration in the past, as this indicates
a stale/invalid timestamp, so we need to take the page-flip
fallback for restarting the repaint loop.
v2: Implement review suggestions by Pekka Paalanen, especially
extend the commit message to describe when and why the
instant restart won't work due to missing Linux kernel
functionality or a Linux kernel regression.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
v3: Fix timespec_to_nsec() which was computing picoseconds,
use the new timespec-util.h helpers.
v4: Rebased to master, split long lines.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-21 19:25:14 +00:00
|
|
|
struct timespec ts, tnow;
|
|
|
|
struct timespec vbl2now;
|
|
|
|
int64_t refresh_nsec;
|
|
|
|
int ret;
|
|
|
|
drmVBlank vbl = {
|
|
|
|
.request.type = DRM_VBLANK_RELATIVE,
|
|
|
|
.request.sequence = 0,
|
|
|
|
.request.signal = 0,
|
|
|
|
};
|
2013-05-07 11:16:59 +00:00
|
|
|
|
2013-10-11 06:43:07 +00:00
|
|
|
if (output->destroy_pending)
|
|
|
|
return;
|
|
|
|
|
2013-05-07 11:16:59 +00:00
|
|
|
if (!output->current) {
|
|
|
|
/* We can't page flip if there's no mode set */
|
2013-10-22 15:11:25 +00:00
|
|
|
goto finish_frame;
|
2013-05-07 11:16:59 +00:00
|
|
|
}
|
|
|
|
|
compositor-drm: Allow instant start of repaint loop. (v4)
drm_output_start_repaint_loop() incurred a delay of
one refresh cycle by using a no-op page-flip to get
an accurate vblank timestamp as reference. This causes
unwanted lag whenever Weston exited its repaint loop, e.g.,
whenever an application wants to repaint with less than
full video refresh rate but still minimum lag.
Try to use the drmWaitVblank ioctl to get a proper
timestamp instantaneously without lag. If that does
not work, fall back to the old method of idle page-flip.
This optimization will work on any drm/kms driver
which supports high precision vblank timestamping.
As of Linux 4.0 these would be intel, radeon and
nouveau on all their supported gpu's.
On kms drivers without instant high precision timestamping
support, the kernel is supposed to return a timestamp
of zero when calling drmWaitVblank() to query the current
vblank count and time iff vblank irqs are currently
disabled, because the only way to get a valid timestamp
on such kms drivers is to enable vblank interrupts and
then wait a bit for the next vblank irq to take a new valid
timestamp. The caller is supposed to poll until at next
vblank irq it gets a valid non-zero timestamp if it needs
a timestamp.
This zero-timestamp signalling works up to Linux 3.17, but
got broken due to a regression in Linux 3.18 and later. On
Linux 3.18+ with kms drivers that don't have high precision
timestamping, the kernel erroneously returns a stale timestamp
from an earlier vblank, ie. the vblank count and timestamp are
mismatched. A patch is under way to fix this, but to deal with
broken kernels, we also check non-zero timestamps if they are
more than one refresh duration in the past, as this indicates
a stale/invalid timestamp, so we need to take the page-flip
fallback for restarting the repaint loop.
v2: Implement review suggestions by Pekka Paalanen, especially
extend the commit message to describe when and why the
instant restart won't work due to missing Linux kernel
functionality or a Linux kernel regression.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
v3: Fix timespec_to_nsec() which was computing picoseconds,
use the new timespec-util.h helpers.
v4: Rebased to master, split long lines.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-21 19:25:14 +00:00
|
|
|
/* Try to get current msc and timestamp via instant query */
|
|
|
|
vbl.request.type |= drm_waitvblank_pipe(output);
|
|
|
|
ret = drmWaitVBlank(backend->drm.fd, &vbl);
|
|
|
|
|
|
|
|
/* Error ret or zero timestamp means failure to get valid timestamp */
|
|
|
|
if ((ret == 0) && (vbl.reply.tval_sec > 0 || vbl.reply.tval_usec > 0)) {
|
|
|
|
ts.tv_sec = vbl.reply.tval_sec;
|
|
|
|
ts.tv_nsec = vbl.reply.tval_usec * 1000;
|
|
|
|
|
|
|
|
/* Valid timestamp for most recent vblank - not stale?
|
|
|
|
* Stale ts could happen on Linux 3.17+, so make sure it
|
|
|
|
* is not older than 1 refresh duration since now.
|
|
|
|
*/
|
|
|
|
weston_compositor_read_presentation_clock(backend->compositor,
|
|
|
|
&tnow);
|
|
|
|
timespec_sub(&vbl2now, &tnow, &ts);
|
|
|
|
refresh_nsec =
|
|
|
|
millihz_to_nsec(output->base.current_mode->refresh);
|
|
|
|
if (timespec_to_nsec(&vbl2now) < refresh_nsec) {
|
|
|
|
drm_output_update_msc(output, vbl.reply.sequence);
|
|
|
|
weston_output_finish_frame(output_base, &ts,
|
2016-02-18 14:53:27 +00:00
|
|
|
WP_PRESENTATION_FEEDBACK_INVALID);
|
compositor-drm: Allow instant start of repaint loop. (v4)
drm_output_start_repaint_loop() incurred a delay of
one refresh cycle by using a no-op page-flip to get
an accurate vblank timestamp as reference. This causes
unwanted lag whenever Weston exited its repaint loop, e.g.,
whenever an application wants to repaint with less than
full video refresh rate but still minimum lag.
Try to use the drmWaitVblank ioctl to get a proper
timestamp instantaneously without lag. If that does
not work, fall back to the old method of idle page-flip.
This optimization will work on any drm/kms driver
which supports high precision vblank timestamping.
As of Linux 4.0 these would be intel, radeon and
nouveau on all their supported gpu's.
On kms drivers without instant high precision timestamping
support, the kernel is supposed to return a timestamp
of zero when calling drmWaitVblank() to query the current
vblank count and time iff vblank irqs are currently
disabled, because the only way to get a valid timestamp
on such kms drivers is to enable vblank interrupts and
then wait a bit for the next vblank irq to take a new valid
timestamp. The caller is supposed to poll until at next
vblank irq it gets a valid non-zero timestamp if it needs
a timestamp.
This zero-timestamp signalling works up to Linux 3.17, but
got broken due to a regression in Linux 3.18 and later. On
Linux 3.18+ with kms drivers that don't have high precision
timestamping, the kernel erroneously returns a stale timestamp
from an earlier vblank, ie. the vblank count and timestamp are
mismatched. A patch is under way to fix this, but to deal with
broken kernels, we also check non-zero timestamps if they are
more than one refresh duration in the past, as this indicates
a stale/invalid timestamp, so we need to take the page-flip
fallback for restarting the repaint loop.
v2: Implement review suggestions by Pekka Paalanen, especially
extend the commit message to describe when and why the
instant restart won't work due to missing Linux kernel
functionality or a Linux kernel regression.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
v3: Fix timespec_to_nsec() which was computing picoseconds,
use the new timespec-util.h helpers.
v4: Rebased to master, split long lines.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-21 19:25:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Immediate query didn't provide valid timestamp.
|
|
|
|
* Use pageflip fallback.
|
|
|
|
*/
|
2013-05-07 11:16:59 +00:00
|
|
|
fb_id = output->current->fb_id;
|
2013-04-05 21:07:11 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drmModePageFlip(backend->drm.fd, output->crtc_id, fb_id,
|
2013-04-05 21:07:11 +00:00
|
|
|
DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
|
|
|
|
weston_log("queueing pageflip failed: %m\n");
|
2013-10-22 15:11:25 +00:00
|
|
|
goto finish_frame;
|
2013-04-05 21:07:11 +00:00
|
|
|
}
|
2013-10-22 15:11:25 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
finish_frame:
|
|
|
|
/* if we cannot page-flip, immediately finish frame */
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_compositor_read_presentation_clock(output_base->compositor, &ts);
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 14:20:40 +00:00
|
|
|
weston_output_finish_frame(output_base, &ts,
|
2016-02-18 14:53:27 +00:00
|
|
|
WP_PRESENTATION_FEEDBACK_INVALID);
|
2013-04-05 21:07:11 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:08:47 +00:00
|
|
|
static void
|
|
|
|
drm_output_update_msc(struct drm_output *output, unsigned int seq)
|
|
|
|
{
|
|
|
|
uint64_t msc_hi = output->base.msc >> 32;
|
|
|
|
|
|
|
|
if (seq < (output->base.msc & 0xffffffff))
|
|
|
|
msc_hi++;
|
|
|
|
|
|
|
|
output->base.msc = (msc_hi << 32) + seq;
|
|
|
|
}
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
static void
|
|
|
|
vblank_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct drm_sprite *s = (struct drm_sprite *)data;
|
2012-06-26 14:09:13 +00:00
|
|
|
struct drm_output *output = s->output;
|
2014-09-24 02:08:45 +00:00
|
|
|
struct timespec ts;
|
2016-02-18 14:53:27 +00:00
|
|
|
uint32_t flags = WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION |
|
|
|
|
WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK;
|
2012-06-26 14:09:13 +00:00
|
|
|
|
2014-09-24 02:08:47 +00:00
|
|
|
drm_output_update_msc(output, frame);
|
2012-06-26 14:09:13 +00:00
|
|
|
output->vblank_pending = 0;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2013-01-25 13:13:03 +00:00
|
|
|
drm_output_release_fb(output, s->current);
|
2012-11-09 12:19:05 +00:00
|
|
|
s->current = s->next;
|
|
|
|
s->next = NULL;
|
2012-06-26 14:09:13 +00:00
|
|
|
|
|
|
|
if (!output->page_flip_pending) {
|
2014-09-24 02:08:45 +00:00
|
|
|
ts.tv_sec = sec;
|
|
|
|
ts.tv_nsec = usec * 1000;
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 14:20:40 +00:00
|
|
|
weston_output_finish_frame(&output->base, &ts, flags);
|
2012-06-26 14:09:13 +00:00
|
|
|
}
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 06:43:07 +00:00
|
|
|
static void
|
|
|
|
drm_output_destroy(struct weston_output *output_base);
|
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
static void
|
|
|
|
page_flip_handler(int fd, unsigned int frame,
|
|
|
|
unsigned int sec, unsigned int usec, void *data)
|
|
|
|
{
|
2011-04-10 14:49:52 +00:00
|
|
|
struct drm_output *output = (struct drm_output *) data;
|
2014-09-24 02:08:45 +00:00
|
|
|
struct timespec ts;
|
2016-02-18 14:53:27 +00:00
|
|
|
uint32_t flags = WP_PRESENTATION_FEEDBACK_KIND_VSYNC |
|
|
|
|
WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION |
|
|
|
|
WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK;
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2014-09-24 02:08:47 +00:00
|
|
|
drm_output_update_msc(output, frame);
|
|
|
|
|
2013-04-05 21:07:11 +00:00
|
|
|
/* We don't set page_flip_pending on start_repaint_loop, in that case
|
|
|
|
* we just want to page flip to the current buffer to get an accurate
|
|
|
|
* timestamp */
|
|
|
|
if (output->page_flip_pending) {
|
|
|
|
drm_output_release_fb(output, output->current);
|
|
|
|
output->current = output->next;
|
|
|
|
output->next = NULL;
|
|
|
|
}
|
2012-06-26 14:09:13 +00:00
|
|
|
|
2013-04-05 21:07:11 +00:00
|
|
|
output->page_flip_pending = 0;
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2013-10-11 06:43:07 +00:00
|
|
|
if (output->destroy_pending)
|
|
|
|
drm_output_destroy(&output->base);
|
|
|
|
else if (!output->vblank_pending) {
|
2014-09-24 02:08:45 +00:00
|
|
|
ts.tv_sec = sec;
|
|
|
|
ts.tv_nsec = usec * 1000;
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 14:20:40 +00:00
|
|
|
weston_output_finish_frame(&output->base, &ts, flags);
|
2013-08-23 14:15:48 +00:00
|
|
|
|
|
|
|
/* We can't call this from frame_notify, because the output's
|
|
|
|
* repaint needed flag is cleared just after that */
|
|
|
|
if (output->recorder)
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
2012-06-26 14:09:13 +00:00
|
|
|
}
|
2011-04-10 14:49:52 +00:00
|
|
|
}
|
|
|
|
|
2012-12-07 17:37:58 +00:00
|
|
|
static uint32_t
|
|
|
|
drm_output_check_sprite_format(struct drm_sprite *s,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *ev, struct gbm_bo *bo)
|
2012-02-23 14:45:49 +00:00
|
|
|
{
|
2012-12-07 17:37:58 +00:00
|
|
|
uint32_t i, format;
|
|
|
|
|
|
|
|
format = gbm_bo_get_format(bo);
|
|
|
|
|
|
|
|
if (format == GBM_FORMAT_ARGB8888) {
|
|
|
|
pixman_region32_t r;
|
|
|
|
|
2013-03-01 19:29:16 +00:00
|
|
|
pixman_region32_init_rect(&r, 0, 0,
|
2013-12-03 03:01:53 +00:00
|
|
|
ev->surface->width,
|
|
|
|
ev->surface->height);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
pixman_region32_subtract(&r, &r, &ev->surface->opaque);
|
2012-12-07 17:37:58 +00:00
|
|
|
|
|
|
|
if (!pixman_region32_not_empty(&r))
|
|
|
|
format = GBM_FORMAT_XRGB8888;
|
|
|
|
|
|
|
|
pixman_region32_fini(&r);
|
|
|
|
}
|
2012-02-23 14:45:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < s->count_formats; i++)
|
|
|
|
if (s->formats[i] == format)
|
2012-12-07 17:37:58 +00:00
|
|
|
return format;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
drm_view_transform_supported(struct weston_view *ev)
|
2012-02-23 14:45:49 +00:00
|
|
|
{
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
return !ev->transform.enabled ||
|
|
|
|
(ev->transform.matrix.type < WESTON_MATRIX_TRANSFORM_ROTATE);
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
static struct weston_plane *
|
2014-12-17 14:20:38 +00:00
|
|
|
drm_output_prepare_overlay_view(struct drm_output *output,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *ev)
|
2012-02-23 14:45:49 +00:00
|
|
|
{
|
2014-12-17 14:20:38 +00:00
|
|
|
struct weston_compositor *ec = output->base.compositor;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = (struct drm_backend *)ec->backend;
|
2014-03-14 12:38:15 +00:00
|
|
|
struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
|
2014-06-12 14:12:12 +00:00
|
|
|
struct wl_resource *buffer_resource;
|
2012-02-23 14:45:49 +00:00
|
|
|
struct drm_sprite *s;
|
2014-06-12 14:12:12 +00:00
|
|
|
struct linux_dmabuf_buffer *dmabuf;
|
2012-02-23 14:45:49 +00:00
|
|
|
int found = 0;
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
pixman_region32_t dest_rect, src_rect;
|
2012-12-05 13:14:04 +00:00
|
|
|
pixman_box32_t *box, tbox;
|
2012-02-23 14:45:49 +00:00
|
|
|
uint32_t format;
|
2012-07-13 19:25:07 +00:00
|
|
|
wl_fixed_t sx1, sy1, sx2, sy2;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->gbm == NULL)
|
2013-01-25 13:13:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-12-17 14:20:38 +00:00
|
|
|
if (viewport->buffer.transform != output->base.transform)
|
2012-11-27 15:03:43 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-12-17 14:20:38 +00:00
|
|
|
if (viewport->buffer.scale != output->base.current_scale)
|
2013-05-22 12:41:39 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->sprites_are_broken)
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-03-06 00:57:35 +00:00
|
|
|
|
2014-12-17 14:20:38 +00:00
|
|
|
if (ev->output_mask != (1u << output->base.id))
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-06-26 14:09:12 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (ev->surface->buffer_ref.buffer == NULL)
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2014-06-12 14:12:12 +00:00
|
|
|
buffer_resource = ev->surface->buffer_ref.buffer->resource;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (ev->alpha != 1.0f)
|
2012-11-16 09:48:46 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-06-12 14:12:12 +00:00
|
|
|
if (wl_shm_buffer_get(buffer_resource))
|
2012-08-09 19:18:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (!drm_view_transform_supported(ev))
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(s, &b->sprite_list, link) {
|
2014-12-17 14:20:38 +00:00
|
|
|
if (!drm_sprite_crtc_supported(output, s->possible_crtcs))
|
2012-02-23 14:45:49 +00:00
|
|
|
continue;
|
|
|
|
|
2012-11-09 12:19:05 +00:00
|
|
|
if (!s->next) {
|
2012-02-23 14:45:49 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No sprites available */
|
|
|
|
if (!found)
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-06-12 14:12:12 +00:00
|
|
|
if ((dmabuf = linux_dmabuf_buffer_get(buffer_resource))) {
|
2015-08-14 19:23:13 +00:00
|
|
|
#ifdef HAVE_GBM_FD_IMPORT
|
2014-06-12 14:12:12 +00:00
|
|
|
/* XXX: TODO:
|
|
|
|
*
|
|
|
|
* Use AddFB2 directly, do not go via GBM.
|
|
|
|
* Add support for multiplanar formats.
|
|
|
|
* Both require refactoring in the DRM-backend to
|
|
|
|
* support a mix of gbm_bos and drmfbs.
|
|
|
|
*/
|
|
|
|
struct gbm_import_fd_data gbm_dmabuf = {
|
2015-11-24 19:28:24 +00:00
|
|
|
.fd = dmabuf->attributes.fd[0],
|
|
|
|
.width = dmabuf->attributes.width,
|
|
|
|
.height = dmabuf->attributes.height,
|
|
|
|
.stride = dmabuf->attributes.stride[0],
|
|
|
|
.format = dmabuf->attributes.format
|
2014-06-12 14:12:12 +00:00
|
|
|
};
|
|
|
|
|
2015-11-24 19:28:24 +00:00
|
|
|
if (dmabuf->attributes.n_planes != 1 || dmabuf->attributes.offset[0] != 0)
|
2014-06-12 14:12:12 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD, &gbm_dmabuf,
|
|
|
|
GBM_BO_USE_SCANOUT);
|
2015-08-14 19:23:13 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2014-06-12 14:12:12 +00:00
|
|
|
} else {
|
|
|
|
bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_WL_BUFFER,
|
|
|
|
buffer_resource, GBM_BO_USE_SCANOUT);
|
|
|
|
}
|
2012-07-14 02:54:43 +00:00
|
|
|
if (!bo)
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-07-14 02:54:43 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
format = drm_output_check_sprite_format(s, ev, bo);
|
2012-12-07 17:37:58 +00:00
|
|
|
if (format == 0) {
|
2012-11-09 12:19:05 +00:00
|
|
|
gbm_bo_destroy(bo);
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-11-09 12:19:05 +00:00
|
|
|
}
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
s->next = drm_fb_get_from_bo(bo, b, format);
|
2012-11-09 12:19:05 +00:00
|
|
|
if (!s->next) {
|
|
|
|
gbm_bo_destroy(bo);
|
2012-08-03 15:30:18 +00:00
|
|
|
return NULL;
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
drm_fb_set_buffer(s->next, ev->surface->buffer_ref.buffer);
|
2012-02-23 14:45:49 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
box = pixman_region32_extents(&ev->transform.boundingbox);
|
2012-08-03 15:30:18 +00:00
|
|
|
s->plane.x = box->x1;
|
|
|
|
s->plane.y = box->y1;
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
/*
|
|
|
|
* Calculate the source & dest rects properly based on actual
|
2014-09-10 20:37:33 +00:00
|
|
|
* position (note the caller has called weston_view_update_transform()
|
2012-02-23 14:45:49 +00:00
|
|
|
* for us already).
|
|
|
|
*/
|
|
|
|
pixman_region32_init(&dest_rect);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
pixman_region32_intersect(&dest_rect, &ev->transform.boundingbox,
|
2014-12-17 14:20:38 +00:00
|
|
|
&output->base.region);
|
|
|
|
pixman_region32_translate(&dest_rect, -output->base.x, -output->base.y);
|
2012-02-23 14:45:49 +00:00
|
|
|
box = pixman_region32_extents(&dest_rect);
|
2014-12-17 14:20:38 +00:00
|
|
|
tbox = weston_transformed_rect(output->base.width,
|
|
|
|
output->base.height,
|
|
|
|
output->base.transform,
|
|
|
|
output->base.current_scale,
|
2013-05-22 12:41:39 +00:00
|
|
|
*box);
|
2012-12-05 13:14:04 +00:00
|
|
|
s->dest_x = tbox.x1;
|
|
|
|
s->dest_y = tbox.y1;
|
|
|
|
s->dest_w = tbox.x2 - tbox.x1;
|
|
|
|
s->dest_h = tbox.y2 - tbox.y1;
|
2012-02-23 14:45:49 +00:00
|
|
|
pixman_region32_fini(&dest_rect);
|
|
|
|
|
|
|
|
pixman_region32_init(&src_rect);
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
pixman_region32_intersect(&src_rect, &ev->transform.boundingbox,
|
2014-12-17 14:20:38 +00:00
|
|
|
&output->base.region);
|
2012-02-23 14:45:49 +00:00
|
|
|
box = pixman_region32_extents(&src_rect);
|
2012-07-13 19:25:07 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
weston_view_from_global_fixed(ev,
|
|
|
|
wl_fixed_from_int(box->x1),
|
|
|
|
wl_fixed_from_int(box->y1),
|
|
|
|
&sx1, &sy1);
|
|
|
|
weston_view_from_global_fixed(ev,
|
|
|
|
wl_fixed_from_int(box->x2),
|
|
|
|
wl_fixed_from_int(box->y2),
|
|
|
|
&sx2, &sy2);
|
2012-07-13 19:25:07 +00:00
|
|
|
|
|
|
|
if (sx1 < 0)
|
|
|
|
sx1 = 0;
|
|
|
|
if (sy1 < 0)
|
|
|
|
sy1 = 0;
|
2013-12-03 03:01:53 +00:00
|
|
|
if (sx2 > wl_fixed_from_int(ev->surface->width))
|
|
|
|
sx2 = wl_fixed_from_int(ev->surface->width);
|
|
|
|
if (sy2 > wl_fixed_from_int(ev->surface->height))
|
|
|
|
sy2 = wl_fixed_from_int(ev->surface->height);
|
2012-07-13 19:25:07 +00:00
|
|
|
|
2012-12-05 13:14:04 +00:00
|
|
|
tbox.x1 = sx1;
|
|
|
|
tbox.y1 = sy1;
|
|
|
|
tbox.x2 = sx2;
|
|
|
|
tbox.y2 = sy2;
|
|
|
|
|
2013-12-03 03:01:53 +00:00
|
|
|
tbox = weston_transformed_rect(wl_fixed_from_int(ev->surface->width),
|
|
|
|
wl_fixed_from_int(ev->surface->height),
|
2014-03-14 12:38:15 +00:00
|
|
|
viewport->buffer.transform,
|
|
|
|
viewport->buffer.scale,
|
2013-11-26 17:19:41 +00:00
|
|
|
tbox);
|
2012-12-05 13:14:04 +00:00
|
|
|
|
|
|
|
s->src_x = tbox.x1 << 8;
|
|
|
|
s->src_y = tbox.y1 << 8;
|
|
|
|
s->src_w = (tbox.x2 - tbox.x1) << 8;
|
|
|
|
s->src_h = (tbox.y2 - tbox.y1) << 8;
|
2012-02-23 14:45:49 +00:00
|
|
|
pixman_region32_fini(&src_rect);
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
return &s->plane;
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
static struct weston_plane *
|
2014-12-17 14:20:38 +00:00
|
|
|
drm_output_prepare_cursor_view(struct drm_output *output,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *ev)
|
2012-02-24 04:03:14 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *)output->base.compositor->backend;
|
2014-05-01 17:00:41 +00:00
|
|
|
struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
|
2015-12-03 20:07:12 +00:00
|
|
|
struct wl_shm_buffer *shmbuf;
|
2012-08-03 15:50:05 +00:00
|
|
|
|
2015-11-24 17:39:38 +00:00
|
|
|
if (ev->transform.enabled &&
|
|
|
|
(ev->transform.matrix.type > WESTON_MATRIX_TRANSFORM_TRANSLATE))
|
|
|
|
return NULL;
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->gbm == NULL)
|
2013-01-25 13:13:05 +00:00
|
|
|
return NULL;
|
2012-11-27 15:03:43 +00:00
|
|
|
if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
|
|
|
|
return NULL;
|
2014-12-17 14:20:38 +00:00
|
|
|
if (viewport->buffer.scale != output->base.current_scale)
|
2014-05-01 17:00:41 +00:00
|
|
|
return NULL;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
if (output->cursor_view)
|
2012-08-03 15:50:05 +00:00
|
|
|
return NULL;
|
2014-12-17 14:20:38 +00:00
|
|
|
if (ev->output_mask != (1u << output->base.id))
|
2012-08-03 15:50:05 +00:00
|
|
|
return NULL;
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->cursors_are_broken)
|
2012-08-09 21:19:23 +00:00
|
|
|
return NULL;
|
2015-02-17 14:33:18 +00:00
|
|
|
if (ev->geometry.scissor_enabled)
|
|
|
|
return NULL;
|
2015-12-03 20:07:12 +00:00
|
|
|
if (ev->surface->buffer_ref.buffer == NULL)
|
|
|
|
return NULL;
|
|
|
|
shmbuf = wl_shm_buffer_get(ev->surface->buffer_ref.buffer->resource);
|
|
|
|
if (!shmbuf)
|
|
|
|
return NULL;
|
|
|
|
if (wl_shm_buffer_get_format(shmbuf) != WL_SHM_FORMAT_ARGB8888)
|
|
|
|
return NULL;
|
|
|
|
if (ev->surface->width > b->cursor_width ||
|
2015-06-16 17:42:23 +00:00
|
|
|
ev->surface->height > b->cursor_height)
|
2012-08-03 15:50:05 +00:00
|
|
|
return NULL;
|
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
output->cursor_view = ev;
|
2012-08-03 15:50:05 +00:00
|
|
|
|
|
|
|
return &output->cursor_plane;
|
|
|
|
}
|
|
|
|
|
2014-06-16 09:05:40 +00:00
|
|
|
/**
|
|
|
|
* Update the image for the current cursor surface
|
|
|
|
*
|
|
|
|
* @param b DRM backend structure
|
|
|
|
* @param bo GBM buffer object to write into
|
|
|
|
* @param ev View to use for cursor image
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cursor_bo_update(struct drm_backend *b, struct gbm_bo *bo,
|
|
|
|
struct weston_view *ev)
|
|
|
|
{
|
|
|
|
struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
|
|
|
|
uint32_t buf[b->cursor_width * b->cursor_height];
|
|
|
|
int32_t stride;
|
|
|
|
uint8_t *s;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(buffer && buffer->shm_buffer);
|
|
|
|
assert(buffer->shm_buffer == wl_shm_buffer_get(buffer->resource));
|
|
|
|
assert(ev->surface->width <= b->cursor_width);
|
|
|
|
assert(ev->surface->height <= b->cursor_height);
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof buf);
|
|
|
|
stride = wl_shm_buffer_get_stride(buffer->shm_buffer);
|
|
|
|
s = wl_shm_buffer_get_data(buffer->shm_buffer);
|
|
|
|
|
|
|
|
wl_shm_buffer_begin_access(buffer->shm_buffer);
|
|
|
|
for (i = 0; i < ev->surface->height; i++)
|
|
|
|
memcpy(buf + i * b->cursor_width,
|
|
|
|
s + i * stride,
|
|
|
|
ev->surface->width * 4);
|
|
|
|
wl_shm_buffer_end_access(buffer->shm_buffer);
|
|
|
|
|
|
|
|
if (gbm_bo_write(bo, buf, sizeof buf) < 0)
|
|
|
|
weston_log("failed update cursor: %m\n");
|
|
|
|
}
|
|
|
|
|
2012-08-03 15:50:05 +00:00
|
|
|
static void
|
|
|
|
drm_output_set_cursor(struct drm_output *output)
|
|
|
|
{
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *ev = output->cursor_view;
|
2013-11-13 15:44:06 +00:00
|
|
|
struct weston_buffer *buffer;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *) output->base.compositor->backend;
|
2014-06-16 09:05:40 +00:00
|
|
|
EGLint handle;
|
2012-07-14 05:06:28 +00:00
|
|
|
struct gbm_bo *bo;
|
2015-11-24 17:39:38 +00:00
|
|
|
float x, y;
|
2012-07-14 05:06:28 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
output->cursor_view = NULL;
|
|
|
|
if (ev == NULL) {
|
2014-10-11 15:27:30 +00:00
|
|
|
drmModeSetCursor(b->drm.fd, output->crtc_id, 0, 0, 0);
|
2016-02-05 21:55:20 +00:00
|
|
|
output->cursor_plane.x = INT32_MIN;
|
|
|
|
output->cursor_plane.y = INT32_MIN;
|
2012-08-03 15:50:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-02-24 04:03:14 +00:00
|
|
|
|
2013-11-13 15:44:06 +00:00
|
|
|
buffer = ev->surface->buffer_ref.buffer;
|
|
|
|
|
|
|
|
if (buffer &&
|
compositor: introduce weston_buffer_reference
The wl_buffer reference counting API has been inconsistent. You would
manually increment the refcount and register a destroy listener, as
opposed to calling weston_buffer_post_release(), which internally
decremented the refcount, and then removing a list item.
Replace both cases with a single function:
weston_buffer_reference(weston_buffer_reference *ref, wl_buffer *buffer)
Buffer is assigned to ref->buffer, while taking care of all the refcounting
and release posting. You take a reference by passing a non-NULL buffer, and
release a reference by passing NULL as buffer. The function uses an
internal wl_buffer destroy listener, so the pointer gets reset on
destruction automatically.
This is inspired by the pipe_resource_reference() of Mesa, and modified
by krh's suggestion to add struct weston_buffer_reference.
Additionally, when a surface gets destroyed, the associated wl_buffer
will send a release event. Often the buffer is already destroyed on
client side, so the event will be discarded by libwayland-client.
Compositor-drm.c is converted to use weston_buffer_reference.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-04 13:58:12 +00:00
|
|
|
pixman_region32_not_empty(&output->cursor_plane.damage)) {
|
2012-08-03 15:50:05 +00:00
|
|
|
pixman_region32_fini(&output->cursor_plane.damage);
|
|
|
|
pixman_region32_init(&output->cursor_plane.damage);
|
2012-07-18 16:09:58 +00:00
|
|
|
output->current_cursor ^= 1;
|
2016-03-21 16:41:03 +00:00
|
|
|
bo = output->gbm_cursor_bo[output->current_cursor];
|
2012-02-24 04:03:14 +00:00
|
|
|
|
2014-06-16 09:05:40 +00:00
|
|
|
cursor_bo_update(b, bo, ev);
|
2012-07-18 16:09:58 +00:00
|
|
|
handle = gbm_bo_get_handle(bo).s32;
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drmModeSetCursor(b->drm.fd, output->crtc_id, handle,
|
|
|
|
b->cursor_width, b->cursor_height)) {
|
2012-08-06 11:57:05 +00:00
|
|
|
weston_log("failed to set cursor: %m\n");
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursors_are_broken = 1;
|
2012-08-09 18:24:45 +00:00
|
|
|
}
|
2012-07-14 05:06:28 +00:00
|
|
|
}
|
2012-02-24 04:03:14 +00:00
|
|
|
|
2015-11-24 17:39:38 +00:00
|
|
|
weston_view_to_global_float(ev, 0, 0, &x, &y);
|
2015-11-27 12:20:58 +00:00
|
|
|
|
|
|
|
/* From global to output space, output transform is guaranteed to be
|
|
|
|
* NORMAL by drm_output_prepare_cursor_view().
|
|
|
|
*/
|
|
|
|
x = (x - output->base.x) * output->base.current_scale;
|
|
|
|
y = (y - output->base.y) * output->base.current_scale;
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
if (output->cursor_plane.x != x || output->cursor_plane.y != y) {
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drmModeMoveCursor(b->drm.fd, output->crtc_id, x, y)) {
|
2012-07-18 16:08:37 +00:00
|
|
|
weston_log("failed to move cursor: %m\n");
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursors_are_broken = 1;
|
2012-08-09 18:24:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
output->cursor_plane.x = x;
|
|
|
|
output->cursor_plane.y = y;
|
2012-07-14 05:06:28 +00:00
|
|
|
}
|
2012-02-24 04:03:14 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
static void
|
2014-12-17 14:20:38 +00:00
|
|
|
drm_assign_planes(struct weston_output *output_base)
|
2012-02-23 14:45:49 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *)output_base->compositor->backend;
|
2014-12-17 14:20:38 +00:00
|
|
|
struct drm_output *output = (struct drm_output *)output_base;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
struct weston_view *ev, *next;
|
2012-02-23 14:45:49 +00:00
|
|
|
pixman_region32_t overlap, surface_overlap;
|
2012-08-03 15:30:18 +00:00
|
|
|
struct weston_plane *primary, *next_plane;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a surface for each sprite in the output using some heuristics:
|
|
|
|
* 1) size
|
|
|
|
* 2) frequency of update
|
|
|
|
* 3) opacity (though some hw might support alpha blending)
|
|
|
|
* 4) clipping (this can be fixed with color keys)
|
|
|
|
*
|
|
|
|
* The idea is to save on blitting since this should save power.
|
|
|
|
* If we can get a large video surface on the sprite for example,
|
|
|
|
* the main display surface may not need to update at all, and
|
|
|
|
* the client buffer can be used directly for the sprite surface
|
|
|
|
* as we do for flipping full screen surfaces.
|
|
|
|
*/
|
|
|
|
pixman_region32_init(&overlap);
|
2014-10-11 15:27:30 +00:00
|
|
|
primary = &output_base->compositor->primary_plane;
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each_safe(ev, next, &output_base->compositor->view_list, link) {
|
2013-11-19 13:22:05 +00:00
|
|
|
struct weston_surface *es = ev->surface;
|
|
|
|
|
|
|
|
/* Test whether this buffer can ever go into a plane:
|
|
|
|
* non-shm, or small enough to be a cursor.
|
|
|
|
*
|
|
|
|
* Also, keep a reference when using the pixman renderer.
|
|
|
|
* That makes it possible to do a seamless switch to the GL
|
|
|
|
* renderer and since the pixman renderer keeps a reference
|
|
|
|
* to the buffer anyway, there is no side effects.
|
2012-12-04 13:58:14 +00:00
|
|
|
*/
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->use_pixman ||
|
2013-11-19 13:22:05 +00:00
|
|
|
(es->buffer_ref.buffer &&
|
|
|
|
(!wl_shm_buffer_get(es->buffer_ref.buffer->resource) ||
|
2015-10-15 15:24:48 +00:00
|
|
|
(ev->surface->width <= b->cursor_width &&
|
|
|
|
ev->surface->height <= b->cursor_height))))
|
2014-10-10 14:36:45 +00:00
|
|
|
es->keep_buffer = true;
|
2013-11-19 13:22:05 +00:00
|
|
|
else
|
2014-10-10 14:36:45 +00:00
|
|
|
es->keep_buffer = false;
|
2012-12-04 13:58:14 +00:00
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
pixman_region32_init(&surface_overlap);
|
|
|
|
pixman_region32_intersect(&surface_overlap, &overlap,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
&ev->transform.boundingbox);
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
next_plane = NULL;
|
2012-07-14 04:31:32 +00:00
|
|
|
if (pixman_region32_not_empty(&surface_overlap))
|
2012-08-03 15:30:18 +00:00
|
|
|
next_plane = primary;
|
|
|
|
if (next_plane == NULL)
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
next_plane = drm_output_prepare_cursor_view(output, ev);
|
2012-08-03 15:30:18 +00:00
|
|
|
if (next_plane == NULL)
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
next_plane = drm_output_prepare_scanout_view(output, ev);
|
2012-08-03 15:30:18 +00:00
|
|
|
if (next_plane == NULL)
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
next_plane = drm_output_prepare_overlay_view(output, ev);
|
2012-08-03 15:30:18 +00:00
|
|
|
if (next_plane == NULL)
|
|
|
|
next_plane = primary;
|
2014-12-17 14:20:41 +00:00
|
|
|
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
weston_view_move_to_plane(ev, next_plane);
|
2014-12-17 14:20:41 +00:00
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
if (next_plane == primary)
|
2012-02-23 14:45:49 +00:00
|
|
|
pixman_region32_union(&overlap, &overlap,
|
Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-10-13 03:38:11 +00:00
|
|
|
&ev->transform.boundingbox);
|
2012-07-14 04:31:32 +00:00
|
|
|
|
2014-12-17 14:20:41 +00:00
|
|
|
if (next_plane == primary ||
|
|
|
|
next_plane == &output->cursor_plane) {
|
|
|
|
/* cursor plane involves a copy */
|
|
|
|
ev->psf_flags = 0;
|
|
|
|
} else {
|
|
|
|
/* All other planes are a direct scanout of a
|
|
|
|
* single client buffer.
|
|
|
|
*/
|
2016-02-18 14:53:27 +00:00
|
|
|
ev->psf_flags = WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY;
|
2014-12-17 14:20:41 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
pixman_region32_fini(&surface_overlap);
|
|
|
|
}
|
|
|
|
pixman_region32_fini(&overlap);
|
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:05 +00:00
|
|
|
static void
|
|
|
|
drm_output_fini_pixman(struct drm_output *output);
|
|
|
|
|
2011-08-29 20:52:23 +00:00
|
|
|
static void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
drm_output_destroy(struct weston_output *output_base)
|
2011-08-29 20:52:23 +00:00
|
|
|
{
|
|
|
|
struct drm_output *output = (struct drm_output *) output_base;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *)output->base.compositor->backend;
|
2011-08-29 20:52:23 +00:00
|
|
|
drmModeCrtcPtr origcrtc = output->original_crtc;
|
|
|
|
|
2013-10-11 06:43:07 +00:00
|
|
|
if (output->page_flip_pending) {
|
|
|
|
output->destroy_pending = 1;
|
|
|
|
weston_log("destroy output while page flip pending\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-29 17:53:50 +00:00
|
|
|
if (output->backlight)
|
|
|
|
backlight_destroy(output->backlight);
|
|
|
|
|
2013-06-04 13:24:04 +00:00
|
|
|
drmModeFreeProperty(output->dpms_prop);
|
|
|
|
|
2011-08-29 20:52:23 +00:00
|
|
|
/* Turn off hardware cursor */
|
2014-10-11 15:27:30 +00:00
|
|
|
drmModeSetCursor(b->drm.fd, output->crtc_id, 0, 0, 0);
|
2011-08-29 20:52:23 +00:00
|
|
|
|
|
|
|
/* Restore original CRTC state */
|
2014-10-11 15:27:30 +00:00
|
|
|
drmModeSetCrtc(b->drm.fd, origcrtc->crtc_id, origcrtc->buffer_id,
|
2011-08-30 09:38:26 +00:00
|
|
|
origcrtc->x, origcrtc->y,
|
|
|
|
&output->connector_id, 1, &origcrtc->mode);
|
2011-08-29 20:52:23 +00:00
|
|
|
drmModeFreeCrtc(origcrtc);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->crtc_allocator &= ~(1 << output->crtc_id);
|
|
|
|
b->connector_allocator &= ~(1 << output->connector_id);
|
2011-08-30 09:44:56 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->use_pixman) {
|
2013-01-25 13:13:05 +00:00
|
|
|
drm_output_fini_pixman(output);
|
|
|
|
} else {
|
2013-10-14 12:57:11 +00:00
|
|
|
gl_renderer->output_destroy(output_base);
|
2016-03-21 16:41:03 +00:00
|
|
|
gbm_surface_destroy(output->gbm_surface);
|
2013-01-25 13:13:05 +00:00
|
|
|
}
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2012-08-03 15:30:18 +00:00
|
|
|
weston_plane_release(&output->fb_plane);
|
|
|
|
weston_plane_release(&output->cursor_plane);
|
|
|
|
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
weston_output_destroy(&output->base);
|
2011-08-30 09:44:56 +00:00
|
|
|
|
2011-08-29 20:52:23 +00:00
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
|
2014-06-04 11:00:53 +00:00
|
|
|
/**
|
|
|
|
* Find the closest-matching mode for a given target
|
|
|
|
*
|
|
|
|
* Given a target mode, find the most suitable mode amongst the output's
|
|
|
|
* current mode list to use, preferring the current mode if possible, to
|
|
|
|
* avoid an expensive mode switch.
|
|
|
|
*
|
|
|
|
* @param output DRM output
|
|
|
|
* @param target_mode Mode to attempt to match
|
|
|
|
* @returns Pointer to a mode from the output's mode list
|
|
|
|
*/
|
2012-04-17 09:20:48 +00:00
|
|
|
static struct drm_mode *
|
|
|
|
choose_mode (struct drm_output *output, struct weston_mode *target_mode)
|
|
|
|
{
|
|
|
|
struct drm_mode *tmp_mode = NULL, *mode;
|
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
if (output->base.current_mode->width == target_mode->width &&
|
|
|
|
output->base.current_mode->height == target_mode->height &&
|
|
|
|
(output->base.current_mode->refresh == target_mode->refresh ||
|
2012-04-17 09:20:48 +00:00
|
|
|
target_mode->refresh == 0))
|
2013-09-18 21:56:35 +00:00
|
|
|
return (struct drm_mode *)output->base.current_mode;
|
2012-04-17 09:20:48 +00:00
|
|
|
|
|
|
|
wl_list_for_each(mode, &output->base.mode_list, base.link) {
|
|
|
|
if (mode->mode_info.hdisplay == target_mode->width &&
|
|
|
|
mode->mode_info.vdisplay == target_mode->height) {
|
2015-06-21 19:25:09 +00:00
|
|
|
if (mode->base.refresh == target_mode->refresh ||
|
|
|
|
target_mode->refresh == 0) {
|
2012-04-17 09:20:48 +00:00
|
|
|
return mode;
|
2015-05-21 07:28:58 +00:00
|
|
|
} else if (!tmp_mode)
|
2012-04-17 09:20:48 +00:00
|
|
|
tmp_mode = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp_mode;
|
|
|
|
}
|
|
|
|
|
2012-12-14 15:37:30 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
drm_output_init_egl(struct drm_output *output, struct drm_backend *b);
|
2013-01-25 13:13:05 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
drm_output_init_pixman(struct drm_output *output, struct drm_backend *b);
|
2012-12-14 15:37:30 +00:00
|
|
|
|
2012-04-17 09:20:48 +00:00
|
|
|
static int
|
|
|
|
drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
|
|
|
struct drm_mode *drm_mode;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b;
|
2012-04-17 09:20:48 +00:00
|
|
|
|
|
|
|
if (output_base == NULL) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("output is NULL.\n");
|
2012-04-17 09:20:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == NULL) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("mode is NULL.\n");
|
2012-04-17 09:20:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b = (struct drm_backend *)output_base->compositor->backend;
|
2012-04-17 09:20:48 +00:00
|
|
|
output = (struct drm_output *)output_base;
|
|
|
|
drm_mode = choose_mode (output, mode);
|
|
|
|
|
|
|
|
if (!drm_mode) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("%s, invalid resolution:%dx%d\n", __func__, mode->width, mode->height);
|
2012-04-17 09:20:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
if (&drm_mode->base == output->base.current_mode)
|
2012-12-14 15:37:30 +00:00
|
|
|
return 0;
|
2012-04-17 09:20:48 +00:00
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
output->base.current_mode->flags = 0;
|
2012-04-17 09:20:48 +00:00
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
output->base.current_mode = &drm_mode->base;
|
|
|
|
output->base.current_mode->flags =
|
2012-12-14 15:37:30 +00:00
|
|
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
2012-04-17 09:20:48 +00:00
|
|
|
|
|
|
|
/* reset rendering stuff. */
|
2013-01-25 13:13:03 +00:00
|
|
|
drm_output_release_fb(output, output->current);
|
|
|
|
drm_output_release_fb(output, output->next);
|
|
|
|
output->current = output->next = NULL;
|
2012-04-17 09:20:48 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->use_pixman) {
|
2013-01-25 13:13:05 +00:00
|
|
|
drm_output_fini_pixman(output);
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drm_output_init_pixman(output, b) < 0) {
|
2013-01-25 13:13:05 +00:00
|
|
|
weston_log("failed to init output pixman state with "
|
|
|
|
"new mode\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2013-10-14 12:57:11 +00:00
|
|
|
gl_renderer->output_destroy(&output->base);
|
2016-03-21 16:41:03 +00:00
|
|
|
gbm_surface_destroy(output->gbm_surface);
|
2012-04-17 09:20:48 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drm_output_init_egl(output, b) < 0) {
|
2013-01-25 13:13:05 +00:00
|
|
|
weston_log("failed to init output egl state with "
|
|
|
|
"new mode");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-12-14 15:37:30 +00:00
|
|
|
}
|
2012-04-17 09:20:48 +00:00
|
|
|
|
2012-12-14 15:37:30 +00:00
|
|
|
return 0;
|
2012-04-17 09:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 16:27:57 +00:00
|
|
|
static int
|
2010-06-11 16:56:24 +00:00
|
|
|
on_drm_input(int fd, uint32_t mask, void *data)
|
|
|
|
{
|
|
|
|
drmEventContext evctx;
|
|
|
|
|
|
|
|
memset(&evctx, 0, sizeof evctx);
|
|
|
|
evctx.version = DRM_EVENT_CONTEXT_VERSION;
|
|
|
|
evctx.page_flip_handler = page_flip_handler;
|
2012-02-23 14:45:49 +00:00
|
|
|
evctx.vblank_handler = vblank_handler;
|
2010-06-11 16:56:24 +00:00
|
|
|
drmHandleEvent(fd, &evctx);
|
2011-04-22 16:27:57 +00:00
|
|
|
|
|
|
|
return 1;
|
2010-06-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
init_drm(struct drm_backend *b, struct udev_device *device)
|
2010-06-11 16:56:24 +00:00
|
|
|
{
|
2012-03-29 02:53:49 +00:00
|
|
|
const char *filename, *sysnum;
|
2013-05-07 11:16:59 +00:00
|
|
|
uint64_t cap;
|
|
|
|
int fd, ret;
|
2014-09-24 02:08:45 +00:00
|
|
|
clockid_t clk_id;
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2012-05-10 16:28:35 +00:00
|
|
|
sysnum = udev_device_get_sysnum(device);
|
|
|
|
if (sysnum)
|
2014-10-11 15:27:30 +00:00
|
|
|
b->drm.id = atoi(sysnum);
|
|
|
|
if (!sysnum || b->drm.id < 0) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("cannot get device sysnum\n");
|
2012-05-10 16:28:35 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-09 18:43:33 +00:00
|
|
|
filename = udev_device_get_devnode(device);
|
2014-10-11 15:27:30 +00:00
|
|
|
fd = weston_launcher_open(b->compositor->launcher, filename, O_RDWR);
|
2010-08-09 18:43:33 +00:00
|
|
|
if (fd < 0) {
|
2010-06-11 16:56:24 +00:00
|
|
|
/* Probably permissions error */
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("couldn't open %s, skipping\n",
|
2010-06-11 16:56:24 +00:00
|
|
|
udev_device_get_devnode(device));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-08 20:45:33 +00:00
|
|
|
weston_log("using %s\n", filename);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->drm.fd = fd;
|
|
|
|
b->drm.filename = strdup(filename);
|
2013-01-25 13:13:02 +00:00
|
|
|
|
2013-05-07 11:16:59 +00:00
|
|
|
ret = drmGetCap(fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
|
|
|
|
if (ret == 0 && cap == 1)
|
2014-09-24 02:08:45 +00:00
|
|
|
clk_id = CLOCK_MONOTONIC;
|
2013-05-07 11:16:59 +00:00
|
|
|
else
|
2014-09-24 02:08:45 +00:00
|
|
|
clk_id = CLOCK_REALTIME;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (weston_compositor_set_presentation_clock(b->compositor, clk_id) < 0) {
|
2014-09-24 02:08:45 +00:00
|
|
|
weston_log("Error: failed to set presentation clock %d.\n",
|
|
|
|
clk_id);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-01-25 13:13:04 +00:00
|
|
|
|
2014-07-28 21:30:17 +00:00
|
|
|
ret = drmGetCap(fd, DRM_CAP_CURSOR_WIDTH, &cap);
|
|
|
|
if (ret == 0)
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursor_width = cap;
|
2014-07-28 21:30:17 +00:00
|
|
|
else
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursor_width = 64;
|
2014-07-28 21:30:17 +00:00
|
|
|
|
|
|
|
ret = drmGetCap(fd, DRM_CAP_CURSOR_HEIGHT, &cap);
|
|
|
|
if (ret == 0)
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursor_height = cap;
|
2014-07-28 21:30:17 +00:00
|
|
|
else
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursor_height = 64;
|
2014-07-28 21:30:17 +00:00
|
|
|
|
2013-01-25 13:13:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-19 13:22:04 +00:00
|
|
|
static struct gbm_device *
|
|
|
|
create_gbm_device(int fd)
|
2013-01-25 13:13:02 +00:00
|
|
|
{
|
2013-11-19 13:22:04 +00:00
|
|
|
struct gbm_device *gbm;
|
2013-10-02 16:51:05 +00:00
|
|
|
|
2013-10-14 12:57:11 +00:00
|
|
|
gl_renderer = weston_load_module("gl-renderer.so",
|
|
|
|
"gl_renderer_interface");
|
|
|
|
if (!gl_renderer)
|
2013-11-19 13:22:04 +00:00
|
|
|
return NULL;
|
2013-10-14 12:57:11 +00:00
|
|
|
|
|
|
|
/* GBM will load a dri driver, but even though they need symbols from
|
|
|
|
* libglapi, in some version of Mesa they are not linked to it. Since
|
|
|
|
* only the gl-renderer module links to it, the call above won't make
|
|
|
|
* these symbols globally available, and loading the DRI driver fails.
|
|
|
|
* Workaround this by dlopen()'ing libglapi with RTLD_GLOBAL. */
|
|
|
|
dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL);
|
|
|
|
|
2013-11-19 13:22:04 +00:00
|
|
|
gbm = gbm_create_device(fd);
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2013-11-19 13:22:04 +00:00
|
|
|
return gbm;
|
|
|
|
}
|
|
|
|
|
2015-05-19 22:25:18 +00:00
|
|
|
/* When initializing EGL, if the preferred buffer format isn't available
|
2016-04-16 03:28:26 +00:00
|
|
|
* we may be able to substitute an ARGB format for an XRGB one.
|
2015-05-15 17:12:40 +00:00
|
|
|
*
|
|
|
|
* This returns 0 if substitution isn't possible, but 0 might be a
|
|
|
|
* legitimate format for other EGL platforms, so the caller is
|
|
|
|
* responsible for checking for 0 before calling gl_renderer->create().
|
|
|
|
*
|
|
|
|
* This works around https://bugs.freedesktop.org/show_bug.cgi?id=89689
|
|
|
|
* but it's entirely possible we'll see this again on other implementations.
|
|
|
|
*/
|
2013-11-19 13:22:04 +00:00
|
|
|
static int
|
2015-05-15 17:12:40 +00:00
|
|
|
fallback_format_for(uint32_t format)
|
2013-11-19 13:22:04 +00:00
|
|
|
{
|
2015-05-15 17:12:40 +00:00
|
|
|
switch (format) {
|
|
|
|
case GBM_FORMAT_XRGB8888:
|
|
|
|
return GBM_FORMAT_ARGB8888;
|
|
|
|
case GBM_FORMAT_XRGB2101010:
|
|
|
|
return GBM_FORMAT_ARGB2101010;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2013-03-02 11:27:39 +00:00
|
|
|
|
2015-05-15 17:12:40 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
drm_backend_create_gl_renderer(struct drm_backend *b)
|
2015-05-15 17:12:40 +00:00
|
|
|
{
|
2015-11-04 20:47:33 +00:00
|
|
|
EGLint format[3] = {
|
2016-03-21 16:41:03 +00:00
|
|
|
b->gbm_format,
|
|
|
|
fallback_format_for(b->gbm_format),
|
2015-11-04 20:47:33 +00:00
|
|
|
0,
|
2015-05-15 17:12:40 +00:00
|
|
|
};
|
2015-11-04 20:47:33 +00:00
|
|
|
int n_formats = 2;
|
2015-05-15 17:12:40 +00:00
|
|
|
|
|
|
|
if (format[1])
|
2015-11-04 20:47:33 +00:00
|
|
|
n_formats = 3;
|
2014-10-11 15:27:30 +00:00
|
|
|
if (gl_renderer->create(b->compositor,
|
2015-05-15 17:12:40 +00:00
|
|
|
EGL_PLATFORM_GBM_KHR,
|
2014-10-11 15:27:30 +00:00
|
|
|
(void *)b->gbm,
|
2015-05-15 17:12:40 +00:00
|
|
|
gl_renderer->opaque_attribs,
|
|
|
|
format,
|
|
|
|
n_formats) < 0) {
|
2013-11-19 13:22:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
init_egl(struct drm_backend *b)
|
2013-11-19 13:22:04 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
b->gbm = create_gbm_device(b->drm.fd);
|
2013-11-19 13:22:04 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (!b->gbm)
|
2013-11-19 13:22:04 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drm_backend_create_gl_renderer(b) < 0) {
|
|
|
|
gbm_device_destroy(b->gbm);
|
2012-03-11 22:27:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:05 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
init_pixman(struct drm_backend *b)
|
2013-01-25 13:13:05 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
return pixman_renderer_init(b->compositor);
|
2013-01-25 13:13:05 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 11:00:53 +00:00
|
|
|
/**
|
|
|
|
* Add a mode to output's mode list
|
|
|
|
*
|
|
|
|
* Copy the supplied DRM mode into a Weston mode structure, and add it to the
|
|
|
|
* output's mode list.
|
|
|
|
*
|
|
|
|
* @param output DRM output to add mode to
|
|
|
|
* @param info DRM mode structure to add
|
|
|
|
* @returns Newly-allocated Weston/DRM mode structure
|
|
|
|
*/
|
2012-08-09 13:45:00 +00:00
|
|
|
static struct drm_mode *
|
2014-06-04 11:00:53 +00:00
|
|
|
drm_output_add_mode(struct drm_output *output, const drmModeModeInfo *info)
|
2011-06-21 15:16:58 +00:00
|
|
|
{
|
|
|
|
struct drm_mode *mode;
|
2012-05-10 16:23:53 +00:00
|
|
|
uint64_t refresh;
|
2011-06-21 15:16:58 +00:00
|
|
|
|
|
|
|
mode = malloc(sizeof *mode);
|
|
|
|
if (mode == NULL)
|
2012-08-09 13:45:00 +00:00
|
|
|
return NULL;
|
2011-06-21 15:16:58 +00:00
|
|
|
|
|
|
|
mode->base.flags = 0;
|
2013-05-28 14:23:36 +00:00
|
|
|
mode->base.width = info->hdisplay;
|
|
|
|
mode->base.height = info->vdisplay;
|
2012-05-10 16:23:53 +00:00
|
|
|
|
|
|
|
/* Calculate higher precision (mHz) refresh rate */
|
|
|
|
refresh = (info->clock * 1000000LL / info->htotal +
|
|
|
|
info->vtotal / 2) / info->vtotal;
|
|
|
|
|
|
|
|
if (info->flags & DRM_MODE_FLAG_INTERLACE)
|
|
|
|
refresh *= 2;
|
|
|
|
if (info->flags & DRM_MODE_FLAG_DBLSCAN)
|
|
|
|
refresh /= 2;
|
|
|
|
if (info->vscan > 1)
|
|
|
|
refresh /= info->vscan;
|
|
|
|
|
|
|
|
mode->base.refresh = refresh;
|
2011-06-21 15:16:58 +00:00
|
|
|
mode->mode_info = *info;
|
2012-06-28 15:28:15 +00:00
|
|
|
|
|
|
|
if (info->type & DRM_MODE_TYPE_PREFERRED)
|
|
|
|
mode->base.flags |= WL_OUTPUT_MODE_PREFERRED;
|
|
|
|
|
2011-06-21 15:16:58 +00:00
|
|
|
wl_list_insert(output->base.mode_list.prev, &mode->base.link);
|
|
|
|
|
2012-08-09 13:45:00 +00:00
|
|
|
return mode;
|
2011-06-21 15:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
drm_subpixel_to_wayland(int drm_value)
|
|
|
|
{
|
|
|
|
switch (drm_value) {
|
|
|
|
default:
|
|
|
|
case DRM_MODE_SUBPIXEL_UNKNOWN:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_UNKNOWN;
|
|
|
|
case DRM_MODE_SUBPIXEL_NONE:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_NONE;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
|
|
|
|
return WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 22:40:09 +00:00
|
|
|
/* returns a value between 0-255 range, where higher is brighter */
|
2012-02-29 17:53:50 +00:00
|
|
|
static uint32_t
|
|
|
|
drm_get_backlight(struct drm_output *output)
|
|
|
|
{
|
|
|
|
long brightness, max_brightness, norm;
|
|
|
|
|
|
|
|
brightness = backlight_get_brightness(output->backlight);
|
|
|
|
max_brightness = backlight_get_max_brightness(output->backlight);
|
|
|
|
|
2012-03-12 22:40:09 +00:00
|
|
|
/* convert it on a scale of 0 to 255 */
|
|
|
|
norm = (brightness * 255)/(max_brightness);
|
2012-02-29 17:53:50 +00:00
|
|
|
|
|
|
|
return (uint32_t) norm;
|
|
|
|
}
|
|
|
|
|
2012-03-12 22:40:09 +00:00
|
|
|
/* values accepted are between 0-255 range */
|
2012-02-29 17:53:50 +00:00
|
|
|
static void
|
|
|
|
drm_set_backlight(struct weston_output *output_base, uint32_t value)
|
|
|
|
{
|
|
|
|
struct drm_output *output = (struct drm_output *) output_base;
|
|
|
|
long max_brightness, new_brightness;
|
|
|
|
|
|
|
|
if (!output->backlight)
|
|
|
|
return;
|
|
|
|
|
2012-03-30 15:52:39 +00:00
|
|
|
if (value > 255)
|
2012-02-29 17:53:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
max_brightness = backlight_get_max_brightness(output->backlight);
|
|
|
|
|
|
|
|
/* get denormalized value */
|
2012-03-12 22:40:09 +00:00
|
|
|
new_brightness = (value * max_brightness) / 255;
|
2012-02-29 17:53:50 +00:00
|
|
|
|
|
|
|
backlight_set_brightness(output->backlight, new_brightness);
|
|
|
|
}
|
|
|
|
|
|
|
|
static drmModePropertyPtr
|
|
|
|
drm_get_prop(int fd, drmModeConnectorPtr connector, const char *name)
|
|
|
|
{
|
|
|
|
drmModePropertyPtr props;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < connector->count_props; i++) {
|
|
|
|
props = drmModeGetProperty(fd, connector->props[i]);
|
|
|
|
if (!props)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!strcmp(props->name, name))
|
|
|
|
return props;
|
|
|
|
|
|
|
|
drmModeFreeProperty(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)
|
|
|
|
{
|
|
|
|
struct drm_output *output = (struct drm_output *) output_base;
|
|
|
|
struct weston_compositor *ec = output_base->compositor;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = (struct drm_backend *)ec->backend;
|
2015-06-18 06:49:02 +00:00
|
|
|
int ret;
|
2012-02-29 17:53:50 +00:00
|
|
|
|
2013-06-04 13:24:04 +00:00
|
|
|
if (!output->dpms_prop)
|
2012-02-29 17:53:50 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-18 06:49:02 +00:00
|
|
|
ret = drmModeConnectorSetProperty(b->drm.fd, output->connector_id,
|
|
|
|
output->dpms_prop->prop_id, level);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("DRM: DPMS: failed property set for %s\n",
|
|
|
|
output->base.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->dpms = level;
|
2012-02-29 17:53:50 +00:00
|
|
|
}
|
|
|
|
|
2014-06-04 13:29:49 +00:00
|
|
|
static const char * const connector_type_names[] = {
|
2015-08-19 12:25:57 +00:00
|
|
|
[DRM_MODE_CONNECTOR_Unknown] = "Unknown",
|
|
|
|
[DRM_MODE_CONNECTOR_VGA] = "VGA",
|
|
|
|
[DRM_MODE_CONNECTOR_DVII] = "DVI-I",
|
|
|
|
[DRM_MODE_CONNECTOR_DVID] = "DVI-D",
|
|
|
|
[DRM_MODE_CONNECTOR_DVIA] = "DVI-A",
|
|
|
|
[DRM_MODE_CONNECTOR_Composite] = "Composite",
|
|
|
|
[DRM_MODE_CONNECTOR_SVIDEO] = "SVIDEO",
|
|
|
|
[DRM_MODE_CONNECTOR_LVDS] = "LVDS",
|
|
|
|
[DRM_MODE_CONNECTOR_Component] = "Component",
|
|
|
|
[DRM_MODE_CONNECTOR_9PinDIN] = "DIN",
|
|
|
|
[DRM_MODE_CONNECTOR_DisplayPort] = "DP",
|
|
|
|
[DRM_MODE_CONNECTOR_HDMIA] = "HDMI-A",
|
|
|
|
[DRM_MODE_CONNECTOR_HDMIB] = "HDMI-B",
|
|
|
|
[DRM_MODE_CONNECTOR_TV] = "TV",
|
|
|
|
[DRM_MODE_CONNECTOR_eDP] = "eDP",
|
2015-08-24 11:27:07 +00:00
|
|
|
#ifdef DRM_MODE_CONNECTOR_DSI
|
2015-08-19 12:25:57 +00:00
|
|
|
[DRM_MODE_CONNECTOR_VIRTUAL] = "Virtual",
|
|
|
|
[DRM_MODE_CONNECTOR_DSI] = "DSI",
|
2015-08-24 11:27:07 +00:00
|
|
|
#endif
|
2012-07-26 21:57:15 +00:00
|
|
|
};
|
|
|
|
|
2014-06-04 13:29:49 +00:00
|
|
|
static char *
|
|
|
|
make_connector_name(const drmModeConnector *con)
|
|
|
|
{
|
|
|
|
char name[32];
|
2015-08-19 12:25:57 +00:00
|
|
|
const char *type_name = NULL;
|
2014-06-04 13:29:49 +00:00
|
|
|
|
|
|
|
if (con->connector_type < ARRAY_LENGTH(connector_type_names))
|
|
|
|
type_name = connector_type_names[con->connector_type];
|
2015-08-19 12:25:57 +00:00
|
|
|
|
|
|
|
if (!type_name)
|
|
|
|
type_name = "UNNAMED";
|
|
|
|
|
|
|
|
snprintf(name, sizeof name, "%s-%d", type_name, con->connector_type_id);
|
2014-06-04 13:29:49 +00:00
|
|
|
|
|
|
|
return strdup(name);
|
|
|
|
}
|
|
|
|
|
2012-07-27 02:44:55 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
find_crtc_for_connector(struct drm_backend *b,
|
2012-07-27 02:44:55 +00:00
|
|
|
drmModeRes *resources, drmModeConnector *connector)
|
|
|
|
{
|
|
|
|
drmModeEncoder *encoder;
|
|
|
|
uint32_t possible_crtcs;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (j = 0; j < connector->count_encoders; j++) {
|
2014-10-11 15:27:30 +00:00
|
|
|
encoder = drmModeGetEncoder(b->drm.fd, connector->encoders[j]);
|
2012-07-27 02:44:55 +00:00
|
|
|
if (encoder == NULL) {
|
|
|
|
weston_log("Failed to get encoder.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
possible_crtcs = encoder->possible_crtcs;
|
|
|
|
drmModeFreeEncoder(encoder);
|
|
|
|
|
|
|
|
for (i = 0; i < resources->count_crtcs; i++) {
|
|
|
|
if (possible_crtcs & (1 << i) &&
|
2014-10-11 15:27:30 +00:00
|
|
|
!(b->crtc_allocator & (1 << resources->crtcs[i])))
|
2012-07-27 02:44:55 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-12-14 15:37:29 +00:00
|
|
|
/* Init output state that depends on gl or gbm */
|
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
|
2012-12-14 15:37:29 +00:00
|
|
|
{
|
2015-05-15 17:12:40 +00:00
|
|
|
EGLint format[2] = {
|
2016-03-21 16:41:03 +00:00
|
|
|
output->gbm_format,
|
|
|
|
fallback_format_for(output->gbm_format),
|
2015-05-15 17:12:40 +00:00
|
|
|
};
|
|
|
|
int i, flags, n_formats = 1;
|
2012-12-14 15:37:30 +00:00
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
output->gbm_surface = gbm_surface_create(b->gbm,
|
2013-09-18 21:56:35 +00:00
|
|
|
output->base.current_mode->width,
|
|
|
|
output->base.current_mode->height,
|
2015-05-15 17:12:40 +00:00
|
|
|
format[0],
|
2012-12-14 15:37:29 +00:00
|
|
|
GBM_BO_USE_SCANOUT |
|
|
|
|
GBM_BO_USE_RENDERING);
|
2016-03-21 16:41:03 +00:00
|
|
|
if (!output->gbm_surface) {
|
2012-12-14 15:37:29 +00:00
|
|
|
weston_log("failed to create gbm surface\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-15 17:12:40 +00:00
|
|
|
if (format[1])
|
|
|
|
n_formats = 2;
|
2015-03-20 14:26:52 +00:00
|
|
|
if (gl_renderer->output_create(&output->base,
|
2016-03-21 16:41:03 +00:00
|
|
|
(EGLNativeWindowType)output->gbm_surface,
|
|
|
|
output->gbm_surface,
|
2014-03-07 18:05:50 +00:00
|
|
|
gl_renderer->opaque_attribs,
|
2015-05-15 17:12:40 +00:00
|
|
|
format,
|
|
|
|
n_formats) < 0) {
|
2012-12-14 15:37:30 +00:00
|
|
|
weston_log("failed to create gl renderer output state\n");
|
2016-03-21 16:41:03 +00:00
|
|
|
gbm_surface_destroy(output->gbm_surface);
|
2012-12-14 15:37:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-07-28 21:30:17 +00:00
|
|
|
flags = GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE;
|
2012-12-14 15:37:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
2016-03-21 16:41:03 +00:00
|
|
|
if (output->gbm_cursor_bo[i])
|
2012-12-14 15:37:30 +00:00
|
|
|
continue;
|
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
output->gbm_cursor_bo[i] =
|
2014-10-11 15:27:30 +00:00
|
|
|
gbm_bo_create(b->gbm, b->cursor_width, b->cursor_height,
|
2014-07-28 21:30:17 +00:00
|
|
|
GBM_FORMAT_ARGB8888, flags);
|
2012-12-14 15:37:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 16:41:03 +00:00
|
|
|
if (output->gbm_cursor_bo[0] == NULL || output->gbm_cursor_bo[1] == NULL) {
|
2012-12-14 15:37:29 +00:00
|
|
|
weston_log("cursor buffers unavailable, using gl cursors\n");
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursors_are_broken = 1;
|
2012-12-14 15:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-25 13:13:05 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
drm_output_init_pixman(struct drm_output *output, struct drm_backend *b)
|
2013-01-25 13:13:05 +00:00
|
|
|
{
|
2013-09-18 21:56:35 +00:00
|
|
|
int w = output->base.current_mode->width;
|
|
|
|
int h = output->base.current_mode->height;
|
2016-06-20 11:18:45 +00:00
|
|
|
uint32_t format = output->gbm_format;
|
|
|
|
uint32_t pixman_format;
|
2013-01-25 13:13:05 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2016-06-20 11:18:45 +00:00
|
|
|
switch (format) {
|
|
|
|
case GBM_FORMAT_XRGB8888:
|
|
|
|
pixman_format = PIXMAN_x8r8g8b8;
|
|
|
|
break;
|
|
|
|
case GBM_FORMAT_RGB565:
|
|
|
|
pixman_format = PIXMAN_r5g6b5;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
weston_log("Unsupported pixman format 0x%x\n", format);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-01-25 13:13:05 +00:00
|
|
|
|
2016-06-20 11:18:45 +00:00
|
|
|
/* FIXME error checking */
|
2013-01-25 13:13:05 +00:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
|
2016-06-20 11:18:45 +00:00
|
|
|
output->dumb[i] = drm_fb_create_dumb(b, w, h, format);
|
2013-01-25 13:13:05 +00:00
|
|
|
if (!output->dumb[i])
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
output->image[i] =
|
2016-06-20 11:18:45 +00:00
|
|
|
pixman_image_create_bits(pixman_format, w, h,
|
2013-01-25 13:13:05 +00:00
|
|
|
output->dumb[i]->map,
|
|
|
|
output->dumb[i]->stride);
|
|
|
|
if (!output->image[i])
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixman_renderer_output_create(&output->base) < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
pixman_region32_init_rect(&output->previous_damage,
|
2013-05-28 14:23:36 +00:00
|
|
|
output->base.x, output->base.y, output->base.width, output->base.height);
|
2013-01-25 13:13:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
|
|
|
|
if (output->dumb[i])
|
|
|
|
drm_fb_destroy_dumb(output->dumb[i]);
|
|
|
|
if (output->image[i])
|
|
|
|
pixman_image_unref(output->image[i]);
|
|
|
|
|
|
|
|
output->dumb[i] = NULL;
|
|
|
|
output->image[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_output_fini_pixman(struct drm_output *output)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
pixman_renderer_output_destroy(&output->base);
|
|
|
|
pixman_region32_fini(&output->previous_damage);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
|
|
|
|
drm_fb_destroy_dumb(output->dumb[i]);
|
|
|
|
pixman_image_unref(output->image[i]);
|
|
|
|
output->dumb[i] = NULL;
|
|
|
|
output->image[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:58:02 +00:00
|
|
|
static void
|
|
|
|
edid_parse_string(const uint8_t *data, char text[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int replaced = 0;
|
|
|
|
|
|
|
|
/* this is always 12 bytes, but we can't guarantee it's null
|
|
|
|
* terminated or not junk. */
|
|
|
|
strncpy(text, (const char *) data, 12);
|
|
|
|
|
2015-08-28 20:04:26 +00:00
|
|
|
/* guarantee our new string is null-terminated */
|
|
|
|
text[12] = '\0';
|
|
|
|
|
2013-04-24 13:58:02 +00:00
|
|
|
/* remove insane chars */
|
|
|
|
for (i = 0; text[i] != '\0'; i++) {
|
|
|
|
if (text[i] == '\n' ||
|
|
|
|
text[i] == '\r') {
|
|
|
|
text[i] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure string is printable */
|
|
|
|
for (i = 0; text[i] != '\0'; i++) {
|
|
|
|
if (!isprint(text[i])) {
|
|
|
|
text[i] = '-';
|
|
|
|
replaced++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if the string is random junk, ignore the string */
|
|
|
|
if (replaced > 4)
|
|
|
|
text[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING 0xfe
|
|
|
|
#define EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME 0xfc
|
|
|
|
#define EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER 0xff
|
|
|
|
#define EDID_OFFSET_DATA_BLOCKS 0x36
|
|
|
|
#define EDID_OFFSET_LAST_BLOCK 0x6c
|
|
|
|
#define EDID_OFFSET_PNPID 0x08
|
|
|
|
#define EDID_OFFSET_SERIAL 0x0c
|
|
|
|
|
|
|
|
static int
|
|
|
|
edid_parse(struct drm_edid *edid, const uint8_t *data, size_t length)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint32_t serial_number;
|
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (length < 128)
|
|
|
|
return -1;
|
|
|
|
if (data[0] != 0x00 || data[1] != 0xff)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* decode the PNP ID from three 5 bit words packed into 2 bytes
|
|
|
|
* /--08--\/--09--\
|
|
|
|
* 7654321076543210
|
|
|
|
* |\---/\---/\---/
|
|
|
|
* R C1 C2 C3 */
|
|
|
|
edid->pnp_id[0] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x7c) / 4) - 1;
|
|
|
|
edid->pnp_id[1] = 'A' + ((data[EDID_OFFSET_PNPID + 0] & 0x3) * 8) + ((data[EDID_OFFSET_PNPID + 1] & 0xe0) / 32) - 1;
|
|
|
|
edid->pnp_id[2] = 'A' + (data[EDID_OFFSET_PNPID + 1] & 0x1f) - 1;
|
|
|
|
edid->pnp_id[3] = '\0';
|
|
|
|
|
|
|
|
/* maybe there isn't a ASCII serial number descriptor, so use this instead */
|
|
|
|
serial_number = (uint32_t) data[EDID_OFFSET_SERIAL + 0];
|
|
|
|
serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 1] * 0x100;
|
|
|
|
serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 2] * 0x10000;
|
|
|
|
serial_number += (uint32_t) data[EDID_OFFSET_SERIAL + 3] * 0x1000000;
|
|
|
|
if (serial_number > 0)
|
|
|
|
sprintf(edid->serial_number, "%lu", (unsigned long) serial_number);
|
|
|
|
|
|
|
|
/* parse EDID data */
|
|
|
|
for (i = EDID_OFFSET_DATA_BLOCKS;
|
|
|
|
i <= EDID_OFFSET_LAST_BLOCK;
|
|
|
|
i += 18) {
|
|
|
|
/* ignore pixel clock data */
|
|
|
|
if (data[i] != 0)
|
|
|
|
continue;
|
|
|
|
if (data[i+2] != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* any useful blocks? */
|
|
|
|
if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_NAME) {
|
|
|
|
edid_parse_string(&data[i+5],
|
|
|
|
edid->monitor_name);
|
|
|
|
} else if (data[i+3] == EDID_DESCRIPTOR_DISPLAY_PRODUCT_SERIAL_NUMBER) {
|
|
|
|
edid_parse_string(&data[i+5],
|
|
|
|
edid->serial_number);
|
|
|
|
} else if (data[i+3] == EDID_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) {
|
|
|
|
edid_parse_string(&data[i+5],
|
|
|
|
edid->eisa_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
find_and_parse_output_edid(struct drm_backend *b,
|
2013-04-24 13:58:02 +00:00
|
|
|
struct drm_output *output,
|
|
|
|
drmModeConnector *connector)
|
|
|
|
{
|
|
|
|
drmModePropertyBlobPtr edid_blob = NULL;
|
|
|
|
drmModePropertyPtr property;
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for (i = 0; i < connector->count_props && !edid_blob; i++) {
|
2014-10-11 15:27:30 +00:00
|
|
|
property = drmModeGetProperty(b->drm.fd, connector->props[i]);
|
2013-04-24 13:58:02 +00:00
|
|
|
if (!property)
|
|
|
|
continue;
|
|
|
|
if ((property->flags & DRM_MODE_PROP_BLOB) &&
|
|
|
|
!strcmp(property->name, "EDID")) {
|
2014-10-11 15:27:30 +00:00
|
|
|
edid_blob = drmModeGetPropertyBlob(b->drm.fd,
|
2013-04-24 13:58:02 +00:00
|
|
|
connector->prop_values[i]);
|
|
|
|
}
|
|
|
|
drmModeFreeProperty(property);
|
|
|
|
}
|
|
|
|
if (!edid_blob)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rc = edid_parse(&output->edid,
|
|
|
|
edid_blob->data,
|
|
|
|
edid_blob->length);
|
|
|
|
if (!rc) {
|
|
|
|
weston_log("EDID data '%s', '%s', '%s'\n",
|
|
|
|
output->edid.pnp_id,
|
|
|
|
output->edid.monitor_name,
|
|
|
|
output->edid.serial_number);
|
|
|
|
if (output->edid.pnp_id[0] != '\0')
|
|
|
|
output->base.make = output->edid.pnp_id;
|
|
|
|
if (output->edid.monitor_name[0] != '\0')
|
|
|
|
output->base.model = output->edid.monitor_name;
|
|
|
|
if (output->edid.serial_number[0] != '\0')
|
|
|
|
output->base.serial_number = output->edid.serial_number;
|
|
|
|
}
|
|
|
|
drmModeFreePropertyBlob(edid_blob);
|
|
|
|
}
|
|
|
|
|
2013-05-23 21:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_modeline(const char *s, drmModeModeInfo *mode)
|
|
|
|
{
|
|
|
|
char hsync[16];
|
|
|
|
char vsync[16];
|
|
|
|
float fclock;
|
|
|
|
|
|
|
|
mode->type = DRM_MODE_TYPE_USERDEF;
|
|
|
|
mode->hskew = 0;
|
|
|
|
mode->vscan = 0;
|
|
|
|
mode->vrefresh = 0;
|
|
|
|
mode->flags = 0;
|
|
|
|
|
2013-07-26 15:29:40 +00:00
|
|
|
if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s",
|
2013-05-23 21:23:15 +00:00
|
|
|
&fclock,
|
|
|
|
&mode->hdisplay,
|
|
|
|
&mode->hsync_start,
|
|
|
|
&mode->hsync_end,
|
|
|
|
&mode->htotal,
|
|
|
|
&mode->vdisplay,
|
|
|
|
&mode->vsync_start,
|
|
|
|
&mode->vsync_end,
|
|
|
|
&mode->vtotal, hsync, vsync) != 11)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
mode->clock = fclock * 1000;
|
|
|
|
if (strcmp(hsync, "+hsync") == 0)
|
|
|
|
mode->flags |= DRM_MODE_FLAG_PHSYNC;
|
|
|
|
else if (strcmp(hsync, "-hsync") == 0)
|
|
|
|
mode->flags |= DRM_MODE_FLAG_NHSYNC;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (strcmp(vsync, "+vsync") == 0)
|
|
|
|
mode->flags |= DRM_MODE_FLAG_PVSYNC;
|
|
|
|
else if (strcmp(vsync, "-vsync") == 0)
|
|
|
|
mode->flags |= DRM_MODE_FLAG_NVSYNC;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
2016-05-02 21:40:11 +00:00
|
|
|
snprintf(mode->name, sizeof mode->name, "%dx%d@%.3f",
|
|
|
|
mode->hdisplay, mode->vdisplay, fclock);
|
|
|
|
|
2013-05-23 21:23:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-25 17:56:42 +00:00
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
setup_output_seat_constraint(struct drm_backend *b,
|
2013-06-25 17:56:42 +00:00
|
|
|
struct weston_output *output,
|
|
|
|
const char *s)
|
|
|
|
{
|
|
|
|
if (strcmp(s, "") != 0) {
|
2015-07-31 21:55:32 +00:00
|
|
|
struct weston_pointer *pointer;
|
2013-06-25 17:56:42 +00:00
|
|
|
struct udev_seat *seat;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
seat = udev_seat_get_named(&b->input, s);
|
2015-07-15 18:00:35 +00:00
|
|
|
if (!seat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
seat->base.output = output;
|
2013-06-25 17:56:42 +00:00
|
|
|
|
2015-07-31 21:55:32 +00:00
|
|
|
pointer = weston_seat_get_pointer(&seat->base);
|
|
|
|
if (pointer)
|
|
|
|
weston_pointer_clamp(pointer,
|
|
|
|
&pointer->x,
|
|
|
|
&pointer->y);
|
2013-06-25 17:56:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-07 18:05:50 +00:00
|
|
|
static int
|
2016-04-29 22:40:34 +00:00
|
|
|
parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format)
|
2014-03-07 18:05:50 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (s == NULL)
|
2016-04-29 22:40:34 +00:00
|
|
|
*gbm_format = default_value;
|
2014-03-07 18:05:50 +00:00
|
|
|
else if (strcmp(s, "xrgb8888") == 0)
|
2016-04-29 22:40:34 +00:00
|
|
|
*gbm_format = GBM_FORMAT_XRGB8888;
|
2014-03-07 18:05:50 +00:00
|
|
|
else if (strcmp(s, "rgb565") == 0)
|
2016-04-29 22:40:34 +00:00
|
|
|
*gbm_format = GBM_FORMAT_RGB565;
|
2014-03-07 18:05:50 +00:00
|
|
|
else if (strcmp(s, "xrgb2101010") == 0)
|
2016-04-29 22:40:34 +00:00
|
|
|
*gbm_format = GBM_FORMAT_XRGB2101010;
|
2014-03-07 18:05:50 +00:00
|
|
|
else {
|
|
|
|
weston_log("fatal: unrecognized pixel format: %s\n", s);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-04 11:00:53 +00:00
|
|
|
/**
|
|
|
|
* Choose suitable mode for an output
|
|
|
|
*
|
|
|
|
* Find the most suitable mode to use for initial setup (or reconfiguration on
|
|
|
|
* hotplug etc) for a DRM output.
|
|
|
|
*
|
|
|
|
* @param output DRM output to choose mode for
|
|
|
|
* @param kind Strategy and preference to use when choosing mode
|
|
|
|
* @param width Desired width for this output
|
|
|
|
* @param height Desired height for this output
|
|
|
|
* @param current_mode Mode currently being displayed on this output
|
|
|
|
* @param modeline Manually-entered mode (may be NULL)
|
|
|
|
* @returns A mode from the output's mode list, or NULL if none available
|
|
|
|
*/
|
|
|
|
static struct drm_mode *
|
2016-04-29 22:40:34 +00:00
|
|
|
drm_output_choose_initial_mode(struct drm_backend *backend,
|
|
|
|
struct drm_output *output,
|
|
|
|
enum weston_drm_backend_output_mode mode,
|
|
|
|
struct weston_drm_backend_output_config *config,
|
|
|
|
const drmModeModeInfo *current_mode)
|
2014-06-04 11:00:53 +00:00
|
|
|
{
|
|
|
|
struct drm_mode *preferred = NULL;
|
|
|
|
struct drm_mode *current = NULL;
|
|
|
|
struct drm_mode *configured = NULL;
|
|
|
|
struct drm_mode *best = NULL;
|
|
|
|
struct drm_mode *drm_mode;
|
2016-04-29 22:40:34 +00:00
|
|
|
drmModeModeInfo modeline;
|
|
|
|
int32_t width = 0;
|
|
|
|
int32_t height = 0;
|
|
|
|
|
|
|
|
if (mode == WESTON_DRM_BACKEND_OUTPUT_PREFERRED && config->modeline) {
|
|
|
|
if (sscanf(config->modeline, "%dx%d", &width, &height) != 2) {
|
|
|
|
width = -1;
|
|
|
|
|
|
|
|
if (parse_modeline(config->modeline, &modeline) == 0) {
|
|
|
|
configured = drm_output_add_mode(output, &modeline);
|
|
|
|
if (!configured)
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
weston_log("Invalid modeline \"%s\" for output %s\n",
|
|
|
|
config->modeline, output->base.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 11:00:53 +00:00
|
|
|
|
|
|
|
wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
|
2016-04-29 22:40:34 +00:00
|
|
|
if (width == drm_mode->base.width &&
|
2014-06-04 11:00:53 +00:00
|
|
|
height == drm_mode->base.height)
|
|
|
|
configured = drm_mode;
|
|
|
|
|
2016-03-17 12:29:27 +00:00
|
|
|
if (memcmp(current_mode, &drm_mode->mode_info,
|
2014-06-04 11:00:53 +00:00
|
|
|
sizeof *current_mode) == 0)
|
|
|
|
current = drm_mode;
|
|
|
|
|
|
|
|
if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED)
|
|
|
|
preferred = drm_mode;
|
|
|
|
|
|
|
|
best = drm_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current == NULL && current_mode->clock != 0) {
|
|
|
|
current = drm_output_add_mode(output, current_mode);
|
|
|
|
if (!current)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
if (mode == WESTON_DRM_BACKEND_OUTPUT_CURRENT)
|
2014-06-04 11:00:53 +00:00
|
|
|
configured = current;
|
|
|
|
|
|
|
|
if (configured)
|
|
|
|
return configured;
|
|
|
|
|
|
|
|
if (preferred)
|
|
|
|
return preferred;
|
|
|
|
|
|
|
|
if (current)
|
|
|
|
return current;
|
|
|
|
|
|
|
|
if (best)
|
|
|
|
return best;
|
|
|
|
|
|
|
|
weston_log("no available modes for %s\n", output->base.name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-04 13:43:06 +00:00
|
|
|
static int
|
|
|
|
connector_get_current_mode(drmModeConnector *connector, int drm_fd,
|
|
|
|
drmModeModeInfo *mode)
|
|
|
|
{
|
|
|
|
drmModeEncoder *encoder;
|
|
|
|
drmModeCrtc *crtc;
|
|
|
|
|
|
|
|
/* Get the current mode on the crtc that's currently driving
|
|
|
|
* this connector. */
|
|
|
|
encoder = drmModeGetEncoder(drm_fd, connector->encoder_id);
|
|
|
|
memset(mode, 0, sizeof *mode);
|
|
|
|
if (encoder != NULL) {
|
|
|
|
crtc = drmModeGetCrtc(drm_fd, encoder->crtc_id);
|
|
|
|
drmModeFreeEncoder(encoder);
|
|
|
|
if (crtc == NULL)
|
|
|
|
return -1;
|
|
|
|
if (crtc->mode_valid)
|
|
|
|
*mode = crtc->mode;
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-04 11:00:53 +00:00
|
|
|
/**
|
|
|
|
* Create and configure a Weston output structure
|
|
|
|
*
|
|
|
|
* Given a DRM connector, create a matching drm_output structure and add it
|
|
|
|
* to Weston's output list.
|
|
|
|
*
|
2014-06-04 13:43:06 +00:00
|
|
|
* @param b Weston backend structure structure
|
2014-06-04 11:00:53 +00:00
|
|
|
* @param resources DRM resources for this device
|
|
|
|
* @param connector DRM connector to use for this new output
|
|
|
|
* @param x Horizontal offset to use into global co-ordinate space
|
|
|
|
* @param y Vertical offset to use into global co-ordinate space
|
|
|
|
* @param drm_device udev device pointer
|
|
|
|
* @returns 0 on success, or -1 on failure
|
|
|
|
*/
|
2010-06-11 16:56:24 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
create_output_for_connector(struct drm_backend *b,
|
2010-06-11 16:56:24 +00:00
|
|
|
drmModeRes *resources,
|
2011-03-11 15:39:20 +00:00
|
|
|
drmModeConnector *connector,
|
2012-02-29 17:53:50 +00:00
|
|
|
int x, int y, struct udev_device *drm_device)
|
2010-06-11 16:56:24 +00:00
|
|
|
{
|
2010-06-14 15:54:00 +00:00
|
|
|
struct drm_output *output;
|
2014-06-04 11:00:53 +00:00
|
|
|
struct drm_mode *drm_mode, *next, *current;
|
2012-08-09 13:45:00 +00:00
|
|
|
struct weston_mode *m;
|
2016-04-29 22:40:34 +00:00
|
|
|
|
|
|
|
drmModeModeInfo crtc_mode;
|
|
|
|
int i;
|
|
|
|
enum weston_drm_backend_output_mode mode;
|
|
|
|
struct weston_drm_backend_output_config config = {{ 0 }};
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
i = find_crtc_for_connector(b, resources, connector);
|
2012-07-27 02:44:55 +00:00
|
|
|
if (i < 0) {
|
|
|
|
weston_log("No usable crtc/encoder pair for connector.\n");
|
2010-06-11 16:56:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
output = zalloc(sizeof *output);
|
2012-07-27 02:44:55 +00:00
|
|
|
if (output == NULL)
|
2011-06-21 15:16:58 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);
|
2014-06-04 13:29:49 +00:00
|
|
|
output->base.name = make_connector_name(connector);
|
2011-06-21 15:16:58 +00:00
|
|
|
output->base.make = "unknown";
|
|
|
|
output->base.model = "unknown";
|
2013-04-24 13:58:02 +00:00
|
|
|
output->base.serial_number = "unknown";
|
2011-06-21 15:16:58 +00:00
|
|
|
wl_list_init(&output->base.mode_list);
|
2010-06-14 15:54:00 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
mode = b->configure_output(b->compositor, b->use_current_mode,
|
|
|
|
output->base.name, &config);
|
|
|
|
if (parse_gbm_format(config.gbm_format, b->gbm_format, &output->gbm_format) == -1)
|
2016-03-21 16:41:03 +00:00
|
|
|
output->gbm_format = b->gbm_format;
|
2014-03-07 18:05:50 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
setup_output_seat_constraint(b, &output->base,
|
|
|
|
config.seat ? config.seat : "");
|
|
|
|
free(config.seat);
|
2013-06-25 17:56:42 +00:00
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
output->crtc_id = resources->crtcs[i];
|
2012-08-09 01:27:37 +00:00
|
|
|
output->pipe = i;
|
2014-10-11 15:27:30 +00:00
|
|
|
b->crtc_allocator |= (1 << output->crtc_id);
|
2010-06-11 16:56:24 +00:00
|
|
|
output->connector_id = connector->connector_id;
|
2014-10-11 15:27:30 +00:00
|
|
|
b->connector_allocator |= (1 << output->connector_id);
|
2011-06-21 15:16:58 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
output->original_crtc = drmModeGetCrtc(b->drm.fd, output->crtc_id);
|
|
|
|
output->dpms_prop = drm_get_prop(b->drm.fd, connector, "DPMS");
|
2011-12-08 16:05:45 +00:00
|
|
|
|
2014-06-04 13:43:06 +00:00
|
|
|
if (connector_get_current_mode(connector, b->drm.fd, &crtc_mode) < 0)
|
|
|
|
goto err_free;
|
2012-06-28 15:28:15 +00:00
|
|
|
|
2011-12-08 16:05:45 +00:00
|
|
|
for (i = 0; i < connector->count_modes; i++) {
|
2013-05-28 14:23:36 +00:00
|
|
|
drm_mode = drm_output_add_mode(output, &connector->modes[i]);
|
2012-08-09 13:45:00 +00:00
|
|
|
if (!drm_mode)
|
2011-12-08 16:05:45 +00:00
|
|
|
goto err_free;
|
|
|
|
}
|
2011-08-29 20:52:23 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
if (mode == WESTON_DRM_BACKEND_OUTPUT_OFF) {
|
2013-05-23 21:23:15 +00:00
|
|
|
weston_log("Disabling output %s\n", output->base.name);
|
2014-10-11 15:27:30 +00:00
|
|
|
drmModeSetCrtc(b->drm.fd, output->crtc_id,
|
2013-05-23 21:23:15 +00:00
|
|
|
0, 0, 0, 0, 0, NULL);
|
2012-07-31 01:51:08 +00:00
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
current = drm_output_choose_initial_mode(b, output, mode, &config,
|
|
|
|
&crtc_mode);
|
2014-06-04 11:00:53 +00:00
|
|
|
if (!current)
|
2012-07-30 22:09:46 +00:00
|
|
|
goto err_free;
|
2014-06-04 11:00:53 +00:00
|
|
|
output->base.current_mode = ¤t->base;
|
2013-09-18 21:56:35 +00:00
|
|
|
output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
|
2012-07-30 22:09:46 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_output_init(&output->base, b->compositor, x, y,
|
2012-11-13 18:10:18 +00:00
|
|
|
connector->mmWidth, connector->mmHeight,
|
2016-04-29 22:40:34 +00:00
|
|
|
config.base.transform, config.base.scale);
|
2012-11-13 18:10:18 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->use_pixman) {
|
|
|
|
if (drm_output_init_pixman(output, b) < 0) {
|
2013-01-25 13:13:05 +00:00
|
|
|
weston_log("Failed to init output pixman state\n");
|
|
|
|
goto err_output;
|
|
|
|
}
|
2014-10-11 15:27:30 +00:00
|
|
|
} else if (drm_output_init_egl(output, b) < 0) {
|
2012-12-14 15:37:29 +00:00
|
|
|
weston_log("Failed to init output gl state\n");
|
2012-11-13 18:10:18 +00:00
|
|
|
goto err_output;
|
2012-10-21 17:29:26 +00:00
|
|
|
}
|
2012-05-03 15:39:35 +00:00
|
|
|
|
2012-02-29 17:53:50 +00:00
|
|
|
output->backlight = backlight_init(drm_device,
|
|
|
|
connector->connector_type);
|
|
|
|
if (output->backlight) {
|
2013-05-24 00:29:40 +00:00
|
|
|
weston_log("Initialized backlight, device %s\n",
|
|
|
|
output->backlight->path);
|
2012-02-29 17:53:50 +00:00
|
|
|
output->base.set_backlight = drm_set_backlight;
|
|
|
|
output->base.backlight_current = drm_get_backlight(output);
|
2013-05-24 00:29:40 +00:00
|
|
|
} else {
|
|
|
|
weston_log("Failed to initialize backlight\n");
|
2012-02-29 17:53:50 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_compositor_add_output(b->compositor, &output->base);
|
2011-10-24 17:26:32 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
find_and_parse_output_edid(b, output, connector);
|
2013-05-09 19:31:09 +00:00
|
|
|
if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
|
|
|
|
output->base.connection_internal = 1;
|
2013-04-24 13:58:02 +00:00
|
|
|
|
2013-04-05 21:07:11 +00:00
|
|
|
output->base.start_repaint_loop = drm_output_start_repaint_loop;
|
2012-01-26 04:32:28 +00:00
|
|
|
output->base.repaint = drm_output_repaint;
|
2011-08-29 20:52:23 +00:00
|
|
|
output->base.destroy = drm_output_destroy;
|
2012-02-23 14:45:49 +00:00
|
|
|
output->base.assign_planes = drm_assign_planes;
|
2012-02-29 17:53:50 +00:00
|
|
|
output->base.set_dpms = drm_set_dpms;
|
2012-04-17 09:20:48 +00:00
|
|
|
output->base.switch_mode = drm_output_switch_mode;
|
2011-03-11 15:39:20 +00:00
|
|
|
|
2013-05-01 20:52:12 +00:00
|
|
|
output->base.gamma_size = output->original_crtc->gamma_size;
|
|
|
|
output->base.set_gamma = drm_output_set_gamma;
|
|
|
|
|
2016-02-05 21:55:20 +00:00
|
|
|
weston_plane_init(&output->cursor_plane, b->compositor,
|
|
|
|
INT32_MIN, INT32_MIN);
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_plane_init(&output->fb_plane, b->compositor, 0, 0);
|
2012-08-03 15:30:18 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_compositor_stack_plane(b->compositor, &output->cursor_plane, NULL);
|
|
|
|
weston_compositor_stack_plane(b->compositor, &output->fb_plane,
|
|
|
|
&b->compositor->primary_plane);
|
2013-03-05 15:30:27 +00:00
|
|
|
|
2012-07-26 21:57:15 +00:00
|
|
|
weston_log("Output %s, (connector %d, crtc %d)\n",
|
2013-05-02 09:10:04 +00:00
|
|
|
output->base.name, output->connector_id, output->crtc_id);
|
2012-06-28 15:28:15 +00:00
|
|
|
wl_list_for_each(m, &output->base.mode_list, link)
|
2014-01-10 18:15:17 +00:00
|
|
|
weston_log_continue(STAMP_SPACE "mode %dx%d@%.1f%s%s%s\n",
|
2012-06-28 15:28:15 +00:00
|
|
|
m->width, m->height, m->refresh / 1000.0,
|
|
|
|
m->flags & WL_OUTPUT_MODE_PREFERRED ?
|
|
|
|
", preferred" : "",
|
|
|
|
m->flags & WL_OUTPUT_MODE_CURRENT ?
|
|
|
|
", current" : "",
|
|
|
|
connector->count_modes == 0 ?
|
|
|
|
", built-in" : "");
|
2012-06-08 20:45:33 +00:00
|
|
|
|
2015-06-21 19:25:11 +00:00
|
|
|
/* Set native_ fields, so weston_output_mode_switch_to_native() works */
|
|
|
|
output->base.native_mode = output->base.current_mode;
|
|
|
|
output->base.native_scale = output->base.current_scale;
|
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
return 0;
|
2011-12-08 16:05:45 +00:00
|
|
|
|
2012-11-13 18:10:18 +00:00
|
|
|
err_output:
|
|
|
|
weston_output_destroy(&output->base);
|
2011-12-08 16:05:45 +00:00
|
|
|
err_free:
|
|
|
|
wl_list_for_each_safe(drm_mode, next, &output->base.mode_list,
|
|
|
|
base.link) {
|
|
|
|
wl_list_remove(&drm_mode->base.link);
|
|
|
|
free(drm_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
drmModeFreeCrtc(output->original_crtc);
|
2014-10-11 15:27:30 +00:00
|
|
|
b->crtc_allocator &= ~(1 << output->crtc_id);
|
|
|
|
b->connector_allocator &= ~(1 << output->connector_id);
|
2011-12-08 16:05:45 +00:00
|
|
|
free(output);
|
2016-04-29 22:40:34 +00:00
|
|
|
free(config.modeline);
|
2012-03-11 22:27:41 +00:00
|
|
|
|
2011-12-08 16:05:45 +00:00
|
|
|
return -1;
|
2010-06-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 14:45:49 +00:00
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
create_sprites(struct drm_backend *b)
|
2012-02-23 14:45:49 +00:00
|
|
|
{
|
|
|
|
struct drm_sprite *sprite;
|
|
|
|
drmModePlaneRes *plane_res;
|
|
|
|
drmModePlane *plane;
|
2012-03-30 15:52:39 +00:00
|
|
|
uint32_t i;
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
plane_res = drmModeGetPlaneResources(b->drm.fd);
|
2012-02-23 14:45:49 +00:00
|
|
|
if (!plane_res) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to get plane resources: %s\n",
|
2012-02-23 14:45:49 +00:00
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < plane_res->count_planes; i++) {
|
2014-10-11 15:27:30 +00:00
|
|
|
plane = drmModeGetPlane(b->drm.fd, plane_res->planes[i]);
|
2012-02-23 14:45:49 +00:00
|
|
|
if (!plane)
|
|
|
|
continue;
|
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
sprite = zalloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
|
2012-02-23 14:45:49 +00:00
|
|
|
plane->count_formats));
|
|
|
|
if (!sprite) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("%s: out of memory\n",
|
2012-02-23 14:45:49 +00:00
|
|
|
__func__);
|
2014-01-02 11:39:40 +00:00
|
|
|
drmModeFreePlane(plane);
|
2012-02-23 14:45:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite->possible_crtcs = plane->possible_crtcs;
|
|
|
|
sprite->plane_id = plane->plane_id;
|
2012-11-09 12:19:05 +00:00
|
|
|
sprite->current = NULL;
|
|
|
|
sprite->next = NULL;
|
2014-10-11 15:27:30 +00:00
|
|
|
sprite->backend = b;
|
2012-02-23 14:45:49 +00:00
|
|
|
sprite->count_formats = plane->count_formats;
|
|
|
|
memcpy(sprite->formats, plane->formats,
|
2012-03-12 00:48:44 +00:00
|
|
|
plane->count_formats * sizeof(plane->formats[0]));
|
2012-02-23 14:45:49 +00:00
|
|
|
drmModeFreePlane(plane);
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_plane_init(&sprite->plane, b->compositor, 0, 0);
|
|
|
|
weston_compositor_stack_plane(b->compositor, &sprite->plane,
|
|
|
|
&b->compositor->primary_plane);
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_insert(&b->sprite_list, &sprite->link);
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 08:03:33 +00:00
|
|
|
drmModeFreePlaneResources(plane_res);
|
2012-02-23 14:45:49 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 02:45:32 +00:00
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
destroy_sprites(struct drm_backend *backend)
|
2012-02-24 02:45:32 +00:00
|
|
|
{
|
|
|
|
struct drm_sprite *sprite, *next;
|
|
|
|
struct drm_output *output;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
output = container_of(backend->compositor->output_list.next,
|
2012-02-24 02:45:32 +00:00
|
|
|
struct drm_output, base.link);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each_safe(sprite, next, &backend->sprite_list, link) {
|
|
|
|
drmModeSetPlane(backend->drm.fd,
|
2012-02-24 02:45:32 +00:00
|
|
|
sprite->plane_id,
|
|
|
|
output->crtc_id, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0);
|
2013-01-25 13:13:03 +00:00
|
|
|
drm_output_release_fb(output, sprite->current);
|
|
|
|
drm_output_release_fb(output, sprite->next);
|
2012-08-03 15:30:18 +00:00
|
|
|
weston_plane_release(&sprite->plane);
|
2012-02-24 02:45:32 +00:00
|
|
|
free(sprite);
|
|
|
|
}
|
|
|
|
}
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
create_outputs(struct drm_backend *b, uint32_t option_connector,
|
2012-02-29 17:53:50 +00:00
|
|
|
struct udev_device *drm_device)
|
2010-06-11 16:56:24 +00:00
|
|
|
{
|
|
|
|
drmModeConnector *connector;
|
|
|
|
drmModeRes *resources;
|
|
|
|
int i;
|
2011-03-11 15:39:20 +00:00
|
|
|
int x = 0, y = 0;
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
resources = drmModeGetResources(b->drm.fd);
|
2010-06-11 16:56:24 +00:00
|
|
|
if (!resources) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("drmModeGetResources failed\n");
|
2010-06-11 16:56:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->crtcs = calloc(resources->count_crtcs, sizeof(uint32_t));
|
|
|
|
if (!b->crtcs) {
|
2012-03-07 19:55:21 +00:00
|
|
|
drmModeFreeResources(resources);
|
2012-02-23 14:45:49 +00:00
|
|
|
return -1;
|
2012-03-07 19:55:21 +00:00
|
|
|
}
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->min_width = resources->min_width;
|
|
|
|
b->max_width = resources->max_width;
|
|
|
|
b->min_height = resources->min_height;
|
|
|
|
b->max_height = resources->max_height;
|
2012-08-09 19:18:28 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->num_crtcs = resources->count_crtcs;
|
|
|
|
memcpy(b->crtcs, resources->crtcs, sizeof(uint32_t) * b->num_crtcs);
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
for (i = 0; i < resources->count_connectors; i++) {
|
2014-10-11 15:27:30 +00:00
|
|
|
connector = drmModeGetConnector(b->drm.fd,
|
2011-08-30 09:38:26 +00:00
|
|
|
resources->connectors[i]);
|
2010-06-11 16:56:24 +00:00
|
|
|
if (connector == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (connector->connection == DRM_MODE_CONNECTED &&
|
|
|
|
(option_connector == 0 ||
|
2011-08-02 11:03:54 +00:00
|
|
|
connector->connector_id == option_connector)) {
|
2014-10-11 15:27:30 +00:00
|
|
|
if (create_output_for_connector(b, resources,
|
2012-02-29 17:53:50 +00:00
|
|
|
connector, x, y,
|
|
|
|
drm_device) < 0) {
|
2011-10-07 06:20:53 +00:00
|
|
|
drmModeFreeConnector(connector);
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
x += container_of(b->compositor->output_list.prev,
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
struct weston_output,
|
2012-08-18 07:04:05 +00:00
|
|
|
link)->width;
|
2011-08-02 11:03:54 +00:00
|
|
|
}
|
2011-03-11 15:39:20 +00:00
|
|
|
|
2010-06-11 16:56:24 +00:00
|
|
|
drmModeFreeConnector(connector);
|
|
|
|
}
|
|
|
|
|
2016-07-29 11:26:22 +00:00
|
|
|
if (wl_list_empty(&b->compositor->output_list))
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("No currently active connector found.\n");
|
2010-06-11 16:56:24 +00:00
|
|
|
|
|
|
|
drmModeFreeResources(resources);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-15 14:08:41 +00:00
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
update_outputs(struct drm_backend *b, struct udev_device *drm_device)
|
2011-03-15 14:08:41 +00:00
|
|
|
{
|
|
|
|
drmModeConnector *connector;
|
|
|
|
drmModeRes *resources;
|
|
|
|
struct drm_output *output, *next;
|
|
|
|
int x = 0, y = 0;
|
|
|
|
uint32_t connected = 0, disconnects = 0;
|
|
|
|
int i;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
resources = drmModeGetResources(b->drm.fd);
|
2011-03-15 14:08:41 +00:00
|
|
|
if (!resources) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("drmModeGetResources failed\n");
|
2011-03-15 14:08:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* collect new connects */
|
|
|
|
for (i = 0; i < resources->count_connectors; i++) {
|
2011-08-30 09:38:26 +00:00
|
|
|
int connector_id = resources->connectors[i];
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
connector = drmModeGetConnector(b->drm.fd, connector_id);
|
2011-12-08 16:05:43 +00:00
|
|
|
if (connector == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (connector->connection != DRM_MODE_CONNECTED) {
|
|
|
|
drmModeFreeConnector(connector);
|
2011-03-15 14:08:41 +00:00
|
|
|
continue;
|
2011-12-08 16:05:43 +00:00
|
|
|
}
|
2011-03-15 14:08:41 +00:00
|
|
|
|
2011-08-30 09:38:26 +00:00
|
|
|
connected |= (1 << connector_id);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (!(b->connector_allocator & (1 << connector_id))) {
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
struct weston_output *last =
|
2014-10-11 15:27:30 +00:00
|
|
|
container_of(b->compositor->output_list.prev,
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
struct weston_output, link);
|
2011-03-15 14:08:41 +00:00
|
|
|
|
|
|
|
/* XXX: not yet needed, we die with 0 outputs */
|
2014-10-11 15:27:30 +00:00
|
|
|
if (!wl_list_empty(&b->compositor->output_list))
|
2012-08-18 07:04:05 +00:00
|
|
|
x = last->x + last->width;
|
2011-03-15 14:08:41 +00:00
|
|
|
else
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2014-10-11 15:27:30 +00:00
|
|
|
create_output_for_connector(b, resources,
|
2012-02-29 17:53:50 +00:00
|
|
|
connector, x, y,
|
|
|
|
drm_device);
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("connector %d connected\n", connector_id);
|
2011-08-30 09:38:26 +00:00
|
|
|
|
2011-03-15 14:08:41 +00:00
|
|
|
}
|
|
|
|
drmModeFreeConnector(connector);
|
|
|
|
}
|
|
|
|
drmModeFreeResources(resources);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
disconnects = b->connector_allocator & ~connected;
|
2011-03-15 14:08:41 +00:00
|
|
|
if (disconnects) {
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each_safe(output, next, &b->compositor->output_list,
|
2011-03-15 14:08:41 +00:00
|
|
|
base.link) {
|
|
|
|
if (disconnects & (1 << output->connector_id)) {
|
|
|
|
disconnects &= ~(1 << output->connector_id);
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("connector %d disconnected\n",
|
2011-03-15 14:08:41 +00:00
|
|
|
output->connector_id);
|
2011-08-30 09:44:56 +00:00
|
|
|
drm_output_destroy(&output->base);
|
2011-03-15 14:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_event_is_hotplug(struct drm_backend *b, struct udev_device *device)
|
2011-03-15 14:08:41 +00:00
|
|
|
{
|
2012-03-11 19:05:21 +00:00
|
|
|
const char *sysnum;
|
2012-03-11 19:05:22 +00:00
|
|
|
const char *val;
|
2012-03-11 19:05:21 +00:00
|
|
|
|
|
|
|
sysnum = udev_device_get_sysnum(device);
|
2014-10-11 15:27:30 +00:00
|
|
|
if (!sysnum || atoi(sysnum) != b->drm.id)
|
2012-03-11 19:05:21 +00:00
|
|
|
return 0;
|
2011-08-30 09:38:26 +00:00
|
|
|
|
2012-03-11 19:05:22 +00:00
|
|
|
val = udev_device_get_property_value(device, "HOTPLUG");
|
|
|
|
if (!val)
|
2011-03-15 14:08:41 +00:00
|
|
|
return 0;
|
|
|
|
|
2012-03-11 19:05:22 +00:00
|
|
|
return strcmp(val, "1") == 0;
|
2011-03-15 14:08:41 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 16:27:57 +00:00
|
|
|
static int
|
2011-03-15 14:08:41 +00:00
|
|
|
udev_drm_event(int fd, uint32_t mask, void *data)
|
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = data;
|
2011-03-15 14:08:41 +00:00
|
|
|
struct udev_device *event;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
event = udev_monitor_receive_device(b->udev_monitor);
|
2011-08-30 09:38:26 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (udev_event_is_hotplug(b, event))
|
|
|
|
update_outputs(b, event);
|
2011-03-15 14:08:41 +00:00
|
|
|
|
|
|
|
udev_device_unref(event);
|
2011-04-22 16:27:57 +00:00
|
|
|
|
|
|
|
return 1;
|
2011-03-15 14:08:41 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 18:32:01 +00:00
|
|
|
static void
|
|
|
|
drm_restore(struct weston_compositor *ec)
|
|
|
|
{
|
2013-09-19 06:00:17 +00:00
|
|
|
weston_launcher_restore(ec->launcher);
|
2012-07-31 18:32:01 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 21:52:15 +00:00
|
|
|
static void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
drm_destroy(struct weston_compositor *ec)
|
2010-12-01 21:52:15 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = (struct drm_backend *) ec->backend;
|
2010-12-01 21:52:15 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_input_destroy(&b->input);
|
2012-03-28 20:36:09 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_event_source_remove(b->udev_drm_source);
|
|
|
|
wl_event_source_remove(b->drm_source);
|
2012-03-28 20:36:09 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
destroy_sprites(b);
|
2013-05-10 16:36:04 +00:00
|
|
|
|
2013-10-25 13:26:32 +00:00
|
|
|
weston_compositor_shutdown(ec);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->gbm)
|
|
|
|
gbm_device_destroy(b->gbm);
|
2013-01-25 13:13:05 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_launcher_destroy(ec->launcher);
|
2010-12-01 21:52:15 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
close(b->drm.fd);
|
|
|
|
free(b);
|
2010-12-01 21:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 16:48:46 +00:00
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
drm_backend_set_modes(struct drm_backend *backend)
|
2012-01-18 16:48:46 +00:00
|
|
|
{
|
|
|
|
struct drm_output *output;
|
|
|
|
struct drm_mode *drm_mode;
|
|
|
|
int ret;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(output, &backend->compositor->output_list, base.link) {
|
2013-02-26 11:44:58 +00:00
|
|
|
if (!output->current) {
|
|
|
|
/* If something that would cause the output to
|
|
|
|
* switch mode happened while in another vt, we
|
|
|
|
* might not have a current drm_fb. In that case,
|
|
|
|
* schedule a repaint and let drm_output_repaint
|
|
|
|
* handle setting the mode. */
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
drm_mode = (struct drm_mode *) output->base.current_mode;
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmModeSetCrtc(backend->drm.fd, output->crtc_id,
|
2012-05-02 13:42:21 +00:00
|
|
|
output->current->fb_id, 0, 0,
|
2012-01-18 16:48:46 +00:00
|
|
|
&output->connector_id, 1,
|
|
|
|
&drm_mode->mode_info);
|
|
|
|
if (ret < 0) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log(
|
2012-03-11 22:27:41 +00:00
|
|
|
"failed to set mode %dx%d for output at %d,%d: %m\n",
|
2015-05-21 07:28:58 +00:00
|
|
|
drm_mode->base.width, drm_mode->base.height,
|
2012-01-18 16:48:46 +00:00
|
|
|
output->base.x, output->base.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 19:15:37 +00:00
|
|
|
static void
|
2013-09-17 23:02:57 +00:00
|
|
|
session_notify(struct wl_listener *listener, void *data)
|
2011-05-06 19:15:37 +00:00
|
|
|
{
|
2013-09-17 23:02:57 +00:00
|
|
|
struct weston_compositor *compositor = data;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = (struct drm_backend *)compositor->backend;
|
2012-02-24 02:45:32 +00:00
|
|
|
struct drm_sprite *sprite;
|
2012-07-14 05:06:28 +00:00
|
|
|
struct drm_output *output;
|
2011-05-06 19:15:37 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (compositor->session_active) {
|
2013-09-17 23:02:57 +00:00
|
|
|
weston_log("activating session\n");
|
2014-10-11 15:27:30 +00:00
|
|
|
compositor->state = b->prev_state;
|
|
|
|
drm_backend_set_modes(b);
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 15:29:47 +00:00
|
|
|
weston_compositor_damage_all(compositor);
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_input_enable(&b->input);
|
2013-09-17 23:02:57 +00:00
|
|
|
} else {
|
|
|
|
weston_log("deactivating session\n");
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_input_disable(&b->input);
|
2012-04-10 04:08:45 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->prev_state = compositor->state;
|
2013-03-29 12:01:56 +00:00
|
|
|
weston_compositor_offscreen(compositor);
|
2011-05-06 19:38:28 +00:00
|
|
|
|
2012-01-18 16:50:31 +00:00
|
|
|
/* If we have a repaint scheduled (either from a
|
|
|
|
* pending pageflip or the idle handler), make sure we
|
|
|
|
* cancel that so we don't try to pageflip when we're
|
2013-03-29 12:01:56 +00:00
|
|
|
* vt switched away. The OFFSCREEN state will prevent
|
2012-01-18 16:50:31 +00:00
|
|
|
* further attemps at repainting. When we switch
|
|
|
|
* back, we schedule a repaint, which will process
|
|
|
|
* pending frame callbacks. */
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(output, &compositor->output_list, base.link) {
|
2012-07-14 05:06:28 +00:00
|
|
|
output->base.repaint_needed = 0;
|
2014-10-11 15:27:30 +00:00
|
|
|
drmModeSetCursor(b->drm.fd, output->crtc_id, 0, 0, 0);
|
2012-01-18 16:50:31 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
output = container_of(compositor->output_list.next,
|
2012-07-14 05:06:28 +00:00
|
|
|
struct drm_output, base.link);
|
2012-02-24 02:45:32 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(sprite, &b->sprite_list, link)
|
|
|
|
drmModeSetPlane(b->drm.fd,
|
2012-02-24 02:45:32 +00:00
|
|
|
sprite->plane_id,
|
2012-07-14 05:06:28 +00:00
|
|
|
output->crtc_id, 0, 0,
|
2012-02-24 02:45:32 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0);
|
2011-05-06 19:15:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-10-29 18:21:16 +00:00
|
|
|
/*
|
|
|
|
* Find primary GPU
|
|
|
|
* Some systems may have multiple DRM devices attached to a single seat. This
|
|
|
|
* function loops over all devices and tries to find a PCI device with the
|
|
|
|
* boot_vga sysfs attribute set to 1.
|
|
|
|
* If no such device is found, the first DRM device reported by udev is used.
|
|
|
|
*/
|
|
|
|
static struct udev_device*
|
2014-10-11 15:27:30 +00:00
|
|
|
find_primary_gpu(struct drm_backend *b, const char *seat)
|
2012-10-29 18:21:16 +00:00
|
|
|
{
|
|
|
|
struct udev_enumerate *e;
|
|
|
|
struct udev_list_entry *entry;
|
|
|
|
const char *path, *device_seat, *id;
|
|
|
|
struct udev_device *device, *drm_device, *pci;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
e = udev_enumerate_new(b->udev);
|
2012-10-29 18:21:16 +00:00
|
|
|
udev_enumerate_add_match_subsystem(e, "drm");
|
|
|
|
udev_enumerate_add_match_sysname(e, "card[0-9]*");
|
|
|
|
|
|
|
|
udev_enumerate_scan_devices(e);
|
|
|
|
drm_device = NULL;
|
|
|
|
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
|
|
|
|
path = udev_list_entry_get_name(entry);
|
2014-10-11 15:27:30 +00:00
|
|
|
device = udev_device_new_from_syspath(b->udev, path);
|
2012-10-29 18:21:16 +00:00
|
|
|
if (!device)
|
|
|
|
continue;
|
|
|
|
device_seat = udev_device_get_property_value(device, "ID_SEAT");
|
|
|
|
if (!device_seat)
|
|
|
|
device_seat = default_seat;
|
|
|
|
if (strcmp(device_seat, seat)) {
|
|
|
|
udev_device_unref(device);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci = udev_device_get_parent_with_subsystem_devtype(device,
|
|
|
|
"pci", NULL);
|
|
|
|
if (pci) {
|
|
|
|
id = udev_device_get_sysattr_value(pci, "boot_vga");
|
|
|
|
if (id && !strcmp(id, "1")) {
|
|
|
|
if (drm_device)
|
|
|
|
udev_device_unref(drm_device);
|
|
|
|
drm_device = device;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!drm_device)
|
|
|
|
drm_device = device;
|
|
|
|
else
|
|
|
|
udev_device_unref(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_enumerate_unref(e);
|
|
|
|
return drm_device;
|
|
|
|
}
|
|
|
|
|
2012-10-31 15:55:46 +00:00
|
|
|
static void
|
2015-07-15 18:00:36 +00:00
|
|
|
planes_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
|
|
|
void *data)
|
2012-10-31 15:55:46 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = data;
|
2012-10-31 15:55:46 +00:00
|
|
|
|
2012-11-22 13:56:59 +00:00
|
|
|
switch (key) {
|
|
|
|
case KEY_C:
|
2014-10-11 15:27:30 +00:00
|
|
|
b->cursors_are_broken ^= 1;
|
2012-11-22 13:56:59 +00:00
|
|
|
break;
|
|
|
|
case KEY_V:
|
2014-10-11 15:27:30 +00:00
|
|
|
b->sprites_are_broken ^= 1;
|
2012-11-22 13:56:59 +00:00
|
|
|
break;
|
|
|
|
case KEY_O:
|
2014-10-11 15:27:30 +00:00
|
|
|
b->sprites_hidden ^= 1;
|
2012-11-22 13:56:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-21 13:11:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 21:28:22 +00:00
|
|
|
#ifdef BUILD_VAAPI_RECORDER
|
2014-05-09 12:57:38 +00:00
|
|
|
static void
|
|
|
|
recorder_destroy(struct drm_output *output)
|
|
|
|
{
|
|
|
|
vaapi_recorder_destroy(output->recorder);
|
|
|
|
output->recorder = NULL;
|
|
|
|
|
|
|
|
output->base.disable_planes--;
|
|
|
|
|
|
|
|
wl_list_remove(&output->recorder_frame_listener.link);
|
|
|
|
weston_log("[libva recorder] done\n");
|
|
|
|
}
|
|
|
|
|
2013-08-23 14:15:48 +00:00
|
|
|
static void
|
|
|
|
recorder_frame_notify(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b;
|
2013-08-23 14:15:48 +00:00
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
output = container_of(listener, struct drm_output,
|
|
|
|
recorder_frame_listener);
|
2014-10-11 15:27:30 +00:00
|
|
|
b = (struct drm_backend *)output->base.compositor->backend;
|
2013-08-23 14:15:48 +00:00
|
|
|
|
|
|
|
if (!output->recorder)
|
|
|
|
return;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
ret = drmPrimeHandleToFD(b->drm.fd, output->current->handle,
|
2013-08-23 14:15:48 +00:00
|
|
|
DRM_CLOEXEC, &fd);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("[libva recorder] "
|
|
|
|
"failed to create prime fd for front buffer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-09 12:57:38 +00:00
|
|
|
ret = vaapi_recorder_frame(output->recorder, fd,
|
|
|
|
output->current->stride);
|
|
|
|
if (ret < 0) {
|
|
|
|
weston_log("[libva recorder] aborted: %m\n");
|
|
|
|
recorder_destroy(output);
|
|
|
|
}
|
2013-08-23 14:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2014-10-11 15:27:30 +00:00
|
|
|
create_recorder(struct drm_backend *b, int width, int height,
|
2013-08-23 14:15:48 +00:00
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
drm_magic_t magic;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
fd = open(b->drm.filename, O_RDWR | O_CLOEXEC);
|
2013-08-23 14:15:48 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
drmGetMagic(fd, &magic);
|
2014-10-11 15:27:30 +00:00
|
|
|
drmAuthMagic(b->drm.fd, magic);
|
2013-08-23 14:15:48 +00:00
|
|
|
|
|
|
|
return vaapi_recorder_create(fd, width, height, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-07-15 18:00:36 +00:00
|
|
|
recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
2013-08-23 14:15:48 +00:00
|
|
|
void *data)
|
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b = data;
|
2013-08-23 14:15:48 +00:00
|
|
|
struct drm_output *output;
|
|
|
|
int width, height;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
output = container_of(b->compositor->output_list.next,
|
2013-08-23 14:15:48 +00:00
|
|
|
struct drm_output, base.link);
|
|
|
|
|
|
|
|
if (!output->recorder) {
|
2016-03-21 16:41:03 +00:00
|
|
|
if (output->gbm_format != GBM_FORMAT_XRGB8888) {
|
2014-05-06 13:49:06 +00:00
|
|
|
weston_log("failed to start vaapi recorder: "
|
|
|
|
"output format not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-18 21:56:35 +00:00
|
|
|
width = output->base.current_mode->width;
|
|
|
|
height = output->base.current_mode->height;
|
2013-08-23 14:15:48 +00:00
|
|
|
|
|
|
|
output->recorder =
|
2014-10-11 15:27:30 +00:00
|
|
|
create_recorder(b, width, height, "capture.h264");
|
2013-08-23 14:15:48 +00:00
|
|
|
if (!output->recorder) {
|
|
|
|
weston_log("failed to create vaapi recorder\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->base.disable_planes++;
|
|
|
|
|
|
|
|
output->recorder_frame_listener.notify = recorder_frame_notify;
|
|
|
|
wl_signal_add(&output->base.frame_signal,
|
|
|
|
&output->recorder_frame_listener);
|
|
|
|
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
|
|
|
|
weston_log("[libva recorder] initialized\n");
|
|
|
|
} else {
|
2014-05-09 12:57:38 +00:00
|
|
|
recorder_destroy(output);
|
2013-08-23 14:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void
|
2015-07-17 02:12:26 +00:00
|
|
|
recorder_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t key,
|
2013-08-23 14:15:48 +00:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
weston_log("Compiled without libva support\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-19 13:22:04 +00:00
|
|
|
static void
|
2014-10-11 15:27:30 +00:00
|
|
|
switch_to_gl_renderer(struct drm_backend *b)
|
2013-11-19 13:22:04 +00:00
|
|
|
{
|
|
|
|
struct drm_output *output;
|
2014-06-12 12:12:48 +00:00
|
|
|
bool dmabuf_support_inited;
|
2013-11-19 13:22:04 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (!b->use_pixman)
|
2013-11-19 13:22:04 +00:00
|
|
|
return;
|
|
|
|
|
2014-06-12 12:12:48 +00:00
|
|
|
dmabuf_support_inited = !!b->compositor->renderer->import_dmabuf;
|
|
|
|
|
2013-11-19 13:22:04 +00:00
|
|
|
weston_log("Switching to GL renderer\n");
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->gbm = create_gbm_device(b->drm.fd);
|
|
|
|
if (!b->gbm) {
|
2013-11-19 13:22:04 +00:00
|
|
|
weston_log("Failed to create gbm device. "
|
|
|
|
"Aborting renderer switch\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(output, &b->compositor->output_list, base.link)
|
2013-11-19 13:22:04 +00:00
|
|
|
pixman_renderer_output_destroy(&output->base);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->compositor->renderer->destroy(b->compositor);
|
2013-11-19 13:22:04 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (drm_backend_create_gl_renderer(b) < 0) {
|
|
|
|
gbm_device_destroy(b->gbm);
|
2013-11-19 13:22:04 +00:00
|
|
|
weston_log("Failed to create GL renderer. Quitting.\n");
|
|
|
|
/* FIXME: we need a function to shutdown cleanly */
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_for_each(output, &b->compositor->output_list, base.link)
|
|
|
|
drm_output_init_egl(output, b);
|
2013-11-19 13:22:04 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->use_pixman = 0;
|
2014-06-12 12:12:48 +00:00
|
|
|
|
|
|
|
if (!dmabuf_support_inited && b->compositor->renderer->import_dmabuf) {
|
|
|
|
if (linux_dmabuf_setup(b->compositor) < 0)
|
|
|
|
weston_log("Error: initializing dmabuf "
|
|
|
|
"support failed.\n");
|
|
|
|
}
|
2013-11-19 13:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-07-15 18:00:36 +00:00
|
|
|
renderer_switch_binding(struct weston_keyboard *keyboard, uint32_t time,
|
|
|
|
uint32_t key, void *data)
|
2013-11-19 13:22:04 +00:00
|
|
|
{
|
2015-07-15 18:00:36 +00:00
|
|
|
struct drm_backend *b =
|
|
|
|
(struct drm_backend *) keyboard->seat->compositor;
|
2013-11-19 13:22:04 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
switch_to_gl_renderer(b);
|
2013-11-19 13:22:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
static struct drm_backend *
|
|
|
|
drm_backend_create(struct weston_compositor *compositor,
|
2016-04-29 22:40:34 +00:00
|
|
|
struct weston_drm_backend_config *config)
|
2010-06-11 16:56:24 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b;
|
2012-10-29 18:21:16 +00:00
|
|
|
struct udev_device *drm_device;
|
2010-06-11 16:56:24 +00:00
|
|
|
struct wl_event_loop *loop;
|
2012-10-29 18:21:16 +00:00
|
|
|
const char *path;
|
2016-04-29 22:40:34 +00:00
|
|
|
const char *seat_id = default_seat;
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2012-06-08 20:45:33 +00:00
|
|
|
weston_log("initializing drm backend\n");
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b = zalloc(sizeof *b);
|
|
|
|
if (b == NULL)
|
2010-06-14 15:54:00 +00:00
|
|
|
return NULL;
|
2012-06-22 13:04:36 +00:00
|
|
|
|
2015-05-19 06:53:16 +00:00
|
|
|
/*
|
|
|
|
* KMS support for hardware planes cannot properly synchronize
|
|
|
|
* without nuclear page flip. Without nuclear/atomic, hw plane
|
|
|
|
* and cursor plane updates would either tear or cause extra
|
|
|
|
* waits for vblanks which means dropping the compositor framerate
|
2015-09-07 12:38:43 +00:00
|
|
|
* to a fraction. For cursors, it's not so bad, so they are
|
|
|
|
* enabled.
|
2015-05-19 06:53:16 +00:00
|
|
|
*
|
|
|
|
* These can be enabled again when nuclear/atomic support lands.
|
|
|
|
*/
|
2014-10-11 15:27:30 +00:00
|
|
|
b->sprites_are_broken = 1;
|
|
|
|
b->compositor = compositor;
|
2016-04-29 22:40:34 +00:00
|
|
|
b->use_pixman = config->use_pixman;
|
|
|
|
b->configure_output = config->configure_output;
|
|
|
|
b->use_current_mode = config->use_current_mode;
|
2013-10-16 23:31:42 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
if (parse_gbm_format(config->gbm_format, GBM_FORMAT_XRGB8888, &b->gbm_format) < 0)
|
|
|
|
goto err_compositor;
|
2013-10-16 23:31:42 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
if (config->seat_id)
|
|
|
|
seat_id = config->seat_id;
|
2013-01-25 13:13:05 +00:00
|
|
|
|
2013-03-27 17:39:28 +00:00
|
|
|
/* Check if we run drm-backend using weston-launch */
|
2016-04-29 22:40:34 +00:00
|
|
|
compositor->launcher = weston_launcher_connect(compositor, config->tty,
|
|
|
|
seat_id, true);
|
2014-10-11 15:27:30 +00:00
|
|
|
if (compositor->launcher == NULL) {
|
2013-03-27 17:39:28 +00:00
|
|
|
weston_log("fatal: drm backend should be run "
|
2013-04-05 01:36:20 +00:00
|
|
|
"using weston-launch binary or as root\n");
|
2013-03-27 17:39:28 +00:00
|
|
|
goto err_compositor;
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->udev = udev_new();
|
|
|
|
if (b->udev == NULL) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to initialize udev context\n");
|
2013-09-19 06:00:17 +00:00
|
|
|
goto err_launcher;
|
2010-06-11 16:56:24 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->session_listener.notify = session_notify;
|
|
|
|
wl_signal_add(&compositor->session_signal, &b->session_listener);
|
2012-01-15 19:29:09 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
drm_device = find_primary_gpu(b, seat_id);
|
2011-07-16 01:28:38 +00:00
|
|
|
if (drm_device == NULL) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("no drm device found\n");
|
2013-09-19 06:00:17 +00:00
|
|
|
goto err_udev;
|
2010-06-14 15:54:00 +00:00
|
|
|
}
|
2012-10-29 18:21:16 +00:00
|
|
|
path = udev_device_get_syspath(drm_device);
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (init_drm(b, drm_device) < 0) {
|
2013-01-25 13:13:02 +00:00
|
|
|
weston_log("failed to initialize kms\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b->use_pixman) {
|
|
|
|
if (init_pixman(b) < 0) {
|
2013-01-25 13:13:05 +00:00
|
|
|
weston_log("failed to initialize pixman renderer\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
|
|
|
} else {
|
2014-10-11 15:27:30 +00:00
|
|
|
if (init_egl(b) < 0) {
|
2013-01-25 13:13:05 +00:00
|
|
|
weston_log("failed to initialize egl\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
2010-06-11 16:56:24 +00:00
|
|
|
}
|
2011-01-14 21:20:21 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->base.destroy = drm_destroy;
|
|
|
|
b->base.restore = drm_restore;
|
2011-04-20 09:02:58 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->prev_state = WESTON_COMPOSITOR_ACTIVE;
|
2011-12-02 11:07:27 +00:00
|
|
|
|
2016-01-12 10:21:47 +00:00
|
|
|
weston_setup_vt_switch_bindings(compositor);
|
2012-04-10 04:11:50 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_list_init(&b->sprite_list);
|
|
|
|
create_sprites(b);
|
2012-02-23 14:45:49 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (udev_input_init(&b->input,
|
2016-06-02 18:48:12 +00:00
|
|
|
compositor, b->udev, seat_id,
|
|
|
|
config->configure_device) < 0) {
|
2014-04-17 10:08:45 +00:00
|
|
|
weston_log("failed to create input devices\n");
|
|
|
|
goto err_sprite;
|
|
|
|
}
|
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
if (create_outputs(b, config->connector, drm_device) < 0) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to create output for %s\n", path);
|
2014-04-17 10:08:45 +00:00
|
|
|
goto err_udev_input;
|
2010-06-14 15:54:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 00:53:46 +00:00
|
|
|
/* A this point we have some idea of whether or not we have a working
|
|
|
|
* cursor plane. */
|
2014-10-11 15:27:30 +00:00
|
|
|
if (!b->cursors_are_broken)
|
|
|
|
compositor->capabilities |= WESTON_CAP_CURSOR_PLANE;
|
2014-04-03 00:53:46 +00:00
|
|
|
|
2011-10-07 06:27:26 +00:00
|
|
|
path = NULL;
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
|
|
|
b->drm_source =
|
|
|
|
wl_event_loop_add_fd(loop, b->drm.fd,
|
|
|
|
WL_EVENT_READABLE, on_drm_input, b);
|
2010-06-11 16:56:24 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
b->udev_monitor = udev_monitor_new_from_netlink(b->udev, "udev");
|
|
|
|
if (b->udev_monitor == NULL) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to intialize udev monitor\n");
|
2012-06-22 13:04:37 +00:00
|
|
|
goto err_drm_source;
|
2011-03-15 14:08:41 +00:00
|
|
|
}
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(b->udev_monitor,
|
2011-03-15 14:08:41 +00:00
|
|
|
"drm", NULL);
|
2014-10-11 15:27:30 +00:00
|
|
|
b->udev_drm_source =
|
2011-08-30 09:38:26 +00:00
|
|
|
wl_event_loop_add_fd(loop,
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_monitor_get_fd(b->udev_monitor),
|
|
|
|
WL_EVENT_READABLE, udev_drm_event, b);
|
2011-03-15 14:08:41 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
if (udev_monitor_enable_receiving(b->udev_monitor) < 0) {
|
2012-06-07 16:01:59 +00:00
|
|
|
weston_log("failed to enable udev-monitor receiving\n");
|
2012-06-22 13:04:37 +00:00
|
|
|
goto err_udev_monitor;
|
2011-03-15 14:08:41 +00:00
|
|
|
}
|
|
|
|
|
2012-06-22 13:04:37 +00:00
|
|
|
udev_device_unref(drm_device);
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_O,
|
|
|
|
planes_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_C,
|
|
|
|
planes_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_V,
|
|
|
|
planes_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_Q,
|
|
|
|
recorder_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_W,
|
|
|
|
renderer_switch_binding, b);
|
2012-10-31 15:55:46 +00:00
|
|
|
|
2014-06-12 12:12:48 +00:00
|
|
|
if (compositor->renderer->import_dmabuf) {
|
|
|
|
if (linux_dmabuf_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing dmabuf "
|
|
|
|
"support failed.\n");
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
compositor->backend = &b->base;
|
2014-06-12 12:12:48 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
return b;
|
2012-06-22 13:04:37 +00:00
|
|
|
|
|
|
|
err_udev_monitor:
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_event_source_remove(b->udev_drm_source);
|
|
|
|
udev_monitor_unref(b->udev_monitor);
|
2012-06-22 13:04:37 +00:00
|
|
|
err_drm_source:
|
2014-10-11 15:27:30 +00:00
|
|
|
wl_event_source_remove(b->drm_source);
|
2014-04-17 10:08:45 +00:00
|
|
|
err_udev_input:
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_input_destroy(&b->input);
|
2012-09-07 00:51:00 +00:00
|
|
|
err_sprite:
|
2016-05-02 21:40:13 +00:00
|
|
|
if (b->gbm)
|
|
|
|
gbm_device_destroy(b->gbm);
|
2014-10-11 15:27:30 +00:00
|
|
|
destroy_sprites(b);
|
2012-06-22 13:04:37 +00:00
|
|
|
err_udev_dev:
|
|
|
|
udev_device_unref(drm_device);
|
2013-09-19 06:00:17 +00:00
|
|
|
err_launcher:
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_launcher_destroy(compositor->launcher);
|
2012-06-22 13:04:37 +00:00
|
|
|
err_udev:
|
2014-10-11 15:27:30 +00:00
|
|
|
udev_unref(b->udev);
|
2012-06-22 13:04:37 +00:00
|
|
|
err_compositor:
|
2014-10-11 15:27:30 +00:00
|
|
|
weston_compositor_shutdown(compositor);
|
|
|
|
free(b);
|
2012-06-22 13:04:37 +00:00
|
|
|
return NULL;
|
2010-06-11 16:56:24 +00:00
|
|
|
}
|
2011-05-03 02:09:20 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
static void
|
|
|
|
config_init_to_defaults(struct weston_drm_backend_config *config)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
WL_EXPORT int
|
2016-04-29 22:40:34 +00:00
|
|
|
backend_init(struct weston_compositor *compositor,
|
2015-10-17 16:24:14 +00:00
|
|
|
struct weston_backend_config *config_base)
|
2011-05-03 02:09:20 +00:00
|
|
|
{
|
2014-10-11 15:27:30 +00:00
|
|
|
struct drm_backend *b;
|
2016-04-29 22:40:34 +00:00
|
|
|
struct weston_drm_backend_config config = {{ 0, }};
|
2012-03-12 01:05:57 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
if (config_base == NULL ||
|
|
|
|
config_base->struct_version != WESTON_DRM_BACKEND_CONFIG_VERSION ||
|
|
|
|
config_base->struct_size > sizeof(struct weston_drm_backend_config)) {
|
|
|
|
weston_log("drm backend config structure is invalid\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-16 23:15:11 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
config_init_to_defaults(&config);
|
|
|
|
memcpy(&config, config_base, config_base->struct_size);
|
2011-05-03 02:09:20 +00:00
|
|
|
|
2016-04-29 22:40:34 +00:00
|
|
|
b = drm_backend_create(compositor, &config);
|
2014-10-11 15:27:30 +00:00
|
|
|
if (b == NULL)
|
|
|
|
return -1;
|
2016-04-29 22:40:34 +00:00
|
|
|
|
2014-10-11 15:27:30 +00:00
|
|
|
return 0;
|
2011-05-03 02:09:20 +00:00
|
|
|
}
|