summaryrefslogtreecommitdiff
path: root/libweston/backend-tdm/tdm-internal.h
blob: 6fb8818d74f3ef43d1cc3eac11cad84f6b61f5f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * Copyright © 2008-2011 Kristian Høgsberg
 * Copyright © 2011 Intel Corporation
 * Copyright © 2017, 2018 Collabora, Ltd.
 * Copyright © 2017, 2018 General Electric Company
 * Copyright (c) 2018 DisplayLink (UK) Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "config.h"

#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/vt.h>
#include <assert.h>
#include <sys/mman.h>
#include <time.h>

#include <libudev.h>

#include <libweston/libweston.h>
#include <libweston/backend-drm.h>
#include <libweston/weston-log.h>
#include <tdm.h>
#include <tbm_bufmgr.h>
#include <tbm_surface_internal.h>
#include <tbm_dummy_display.h>
#include "shared/helpers.h"
#include "libinput-seat.h"
#include "backend.h"
#include "libweston-internal.h"

#define tdm_debug(b, ...) \
	weston_log_scope_printf((b)->debug, __VA_ARGS__)

/**
 * Possible values for the WTDM_PLANE_TYPE property.
 */
enum wtdm_backend_plane_type {
	WTDM_PLANE_TYPE_PRIMARY = 0,
	WTDM_PLANE_TYPE_OVERLAY,
};

struct tdm_backend {
	struct weston_backend base;
	struct weston_compositor *compositor;

	struct udev *udev;
	struct wl_event_source *tdm_source;

	struct wl_listener session_listener;
	uint32_t gbm_format;

	struct udev_input input;

	bool use_pixman;
	bool use_pixman_shadow;

	uint32_t pageflip_timeout;

	struct weston_log_scope *debug;

	tbm_bufmgr tbufmgr;
	tbm_dummy_display *tbm_display;
	tdm_display *tdisplay;

	int tdm_fd;

	struct wl_list plane_list;
};

struct tdm_backend_mode {
	struct weston_mode base;

	struct wl_list head_link;
	const tdm_output_mode *tmode;
};

struct tdm_backend_plane {
	struct weston_plane base;
	struct tdm_backend *backend;
	enum wtdm_backend_plane_type type;
	struct wl_list link;
};

struct tdm_backend_hwc {
	struct tdm_backend *backend;

	tdm_hwc            *thwc;
	tbm_surface_queue_h target_buffer_queue;

	tbm_surface_h       commit_fb;
	tbm_surface_h       display_fb;
};

struct tdm_backend_head {
	struct weston_head base;
	struct tdm_backend *backend;

	int index;
	unsigned int pipe;

	tdm_output *toutput;
	tdm_output_type toutput_type;
	struct tdm_backend_hwc *hwc;

	struct wl_list mode_list;

	tdm_output_dpms dpms;
	tdm_output_conn_status conn_status;
};

struct tdm_backend_output {
	struct weston_output base;
	struct tdm_backend *backend;

	tbm_surface_h pending_fb;
	tbm_surface_h current_fb;

	tbm_surface_h pixman_tsurfaces[2];
	pixman_image_t *image[2];
	int current_image;
	pixman_region32_t previous_damage;
};

struct tdm_pending_state {
	struct tdm_backend *backend;
	struct wl_list output_list;
};

static inline struct tdm_backend_head *
to_tdm_head(struct weston_head *base)
{
	return container_of(base, struct tdm_backend_head, base);
}

static inline struct tdm_backend_output *
to_tdm_output(struct weston_output *base)
{
	return container_of(base, struct tdm_backend_output, base);
}

static inline struct tdm_backend *
to_tdm_backend(struct weston_compositor *base)
{
	return container_of(base->backend, struct tdm_backend, base);
}

static inline struct tdm_backend_mode *
to_tdm_mode(struct weston_mode *base)
{
	return container_of(base, struct tdm_backend_mode, base);
}