• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2008-2011 Kristian Høgsberg
3  * Copyright © 2011 Intel Corporation
4  * Copyright © 2017, 2018 Collabora, Ltd.
5  * Copyright © 2017, 2018 General Electric Company
6  * Copyright (c) 2018 DisplayLink (UK) Ltd.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial
18  * portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  */
29 
30 #include "config.h"
31 
32 #include <errno.h>
33 #include <stdint.h>
34 #include <stdlib.h>
35 #include <ctype.h>
36 #include <string.h>
37 #include <fcntl.h>
38 #include <unistd.h>
39 #include <linux/input.h>
40 #include <linux/vt.h>
41 #include <assert.h>
42 #include <sys/mman.h>
43 #include <time.h>
44 
45 
46 #include <xf86drm.h>
47 #include <xf86drmMode.h>
48 #include <drm_fourcc.h>
49 
50 #ifdef BUILD_DRM_GBM
51 #include "shared/simple_gbm.h"
52 #endif
53 #include <libudev.h>
54 
55 #include <libweston/libweston.h>
56 #include <libweston/backend-drm.h>
57 #include <libweston/weston-log.h>
58 #include "shared/helpers.h"
59 #include "libinput-seat.h"
60 #include "backend.h"
61 #include "libweston-internal.h"
62 
63 #ifndef DRM_CLIENT_CAP_ASPECT_RATIO
64 #define DRM_CLIENT_CAP_ASPECT_RATIO	4
65 #endif
66 
67 #ifndef GBM_BO_USE_CURSOR
68 #define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64
69 #endif
70 
71 #ifndef GBM_BO_USE_LINEAR
72 #define GBM_BO_USE_LINEAR (1 << 4)
73 #endif
74 
75 #ifndef DRM_PLANE_ZPOS_INVALID_PLANE
76 #define DRM_PLANE_ZPOS_INVALID_PLANE	0xffffffffffffffffULL
77 #endif
78 
79 /**
80  * A small wrapper to print information into the 'drm-backend' debug scope.
81  *
82  * The following conventions are used to print variables:
83  *
84  *  - fixed uint32_t values, including Weston object IDs such as weston_output
85  *    IDs, DRM object IDs such as CRTCs or properties, and GBM/DRM formats:
86  *      "%lu (0x%lx)" (unsigned long) value, (unsigned long) value
87  *
88  *  - fixed uint64_t values, such as DRM property values (including object IDs
89  *    when used as a value):
90  *      "%llu (0x%llx)" (unsigned long long) value, (unsigned long long) value
91  *
92  *  - non-fixed-width signed int:
93  *      "%d" value
94  *
95  *  - non-fixed-width unsigned int:
96  *      "%u (0x%x)" value, value
97  *
98  *  - non-fixed-width unsigned long:
99  *      "%lu (0x%lx)" value, value
100  *
101  * Either the integer or hexadecimal forms may be omitted if it is known that
102  * one representation is not useful (e.g. width/height in hex are rarely what
103  * you want).
104  *
105  * This is to avoid implicit widening or narrowing when we use fixed-size
106  * types: uint32_t can be resolved by either unsigned int or unsigned long
107  * on a 32-bit system but only unsigned int on a 64-bit system, with uint64_t
108  * being unsigned long long on a 32-bit system and unsigned long on a 64-bit
109  * system. To avoid confusing side effects, we explicitly cast to the widest
110  * possible type and use a matching format specifier.
111  */
112 // OHOS hilog
113 //#define drm_debug(b, ...) \
114 //	weston_log_scope_printf((b)->debug, __VA_ARGS__)
115 #define drm_debug(b, fmt, ...) (HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__))
116 
117 #define MAX_CLONED_CONNECTORS 4
118 
119 #ifndef DRM_MODE_PICTURE_ASPECT_64_27
120 #define DRM_MODE_PICTURE_ASPECT_64_27		3
121 #define  DRM_MODE_FLAG_PIC_AR_64_27 \
122 			(DRM_MODE_PICTURE_ASPECT_64_27<<19)
123 #endif
124 #ifndef DRM_MODE_PICTURE_ASPECT_256_135
125 #define DRM_MODE_PICTURE_ASPECT_256_135		4
126 #define  DRM_MODE_FLAG_PIC_AR_256_135 \
127 			(DRM_MODE_PICTURE_ASPECT_256_135<<19)
128 #endif
129 
130 
131 /**
132  * Represents the values of an enum-type KMS property
133  */
134 struct drm_property_enum_info {
135 	const char *name; /**< name as string (static, not freed) */
136 	bool valid; /**< true if value is supported; ignore if false */
137 	uint64_t value; /**< raw value */
138 };
139 
140 /**
141  * Holds information on a DRM property, including its ID and the enum
142  * values it holds.
143  *
144  * DRM properties are allocated dynamically, and maintained as DRM objects
145  * within the normal object ID space; they thus do not have a stable ID
146  * to refer to. This includes enum values, which must be referred to by
147  * integer values, but these are not stable.
148  *
149  * drm_property_info allows a cache to be maintained where Weston can use
150  * enum values internally to refer to properties, with the mapping to DRM
151  * ID values being maintained internally.
152  */
153 struct drm_property_info {
154 	const char *name; /**< name as string (static, not freed) */
155 	uint32_t prop_id; /**< KMS property object ID */
156 	uint32_t flags;
157 	unsigned int num_enum_values; /**< number of enum values */
158 	struct drm_property_enum_info *enum_values; /**< array of enum values */
159 	unsigned int num_range_values;
160 	uint64_t range_values[2];
161 };
162 
163 /**
164  * List of properties attached to DRM planes
165  */
166 enum wdrm_plane_property {
167 	WDRM_PLANE_TYPE = 0,
168 	WDRM_PLANE_SRC_X,
169 	WDRM_PLANE_SRC_Y,
170 	WDRM_PLANE_SRC_W,
171 	WDRM_PLANE_SRC_H,
172 	WDRM_PLANE_CRTC_X,
173 	WDRM_PLANE_CRTC_Y,
174 	WDRM_PLANE_CRTC_W,
175 	WDRM_PLANE_CRTC_H,
176 	WDRM_PLANE_FB_ID,
177 	WDRM_PLANE_CRTC_ID,
178 	WDRM_PLANE_IN_FORMATS,
179 	WDRM_PLANE_IN_FENCE_FD,
180 	WDRM_PLANE_FB_DAMAGE_CLIPS,
181 	WDRM_PLANE_ZPOS,
182 	WDRM_PLANE__COUNT
183 };
184 
185 /**
186  * Possible values for the WDRM_PLANE_TYPE property.
187  */
188 enum wdrm_plane_type {
189 	WDRM_PLANE_TYPE_PRIMARY = 0,
190 	WDRM_PLANE_TYPE_CURSOR,
191 	WDRM_PLANE_TYPE_OVERLAY,
192 	WDRM_PLANE_TYPE__COUNT
193 };
194 
195 /**
196  * List of properties attached to a DRM connector
197  */
198 enum wdrm_connector_property {
199 	WDRM_CONNECTOR_EDID = 0,
200 	WDRM_CONNECTOR_DPMS,
201 	WDRM_CONNECTOR_CRTC_ID,
202 	WDRM_CONNECTOR_NON_DESKTOP,
203 	WDRM_CONNECTOR_CONTENT_PROTECTION,
204 	WDRM_CONNECTOR_HDCP_CONTENT_TYPE,
205 	WDRM_CONNECTOR_PANEL_ORIENTATION,
206 	WDRM_CONNECTOR__COUNT
207 };
208 
209 enum wdrm_content_protection_state {
210 	WDRM_CONTENT_PROTECTION_UNDESIRED = 0,
211 	WDRM_CONTENT_PROTECTION_DESIRED,
212 	WDRM_CONTENT_PROTECTION_ENABLED,
213 	WDRM_CONTENT_PROTECTION__COUNT
214 };
215 
216 enum wdrm_hdcp_content_type {
217 	WDRM_HDCP_CONTENT_TYPE0 = 0,
218 	WDRM_HDCP_CONTENT_TYPE1,
219 	WDRM_HDCP_CONTENT_TYPE__COUNT
220 };
221 
222 enum wdrm_dpms_state {
223 	WDRM_DPMS_STATE_OFF = 0,
224 	WDRM_DPMS_STATE_ON,
225 	WDRM_DPMS_STATE_STANDBY, /* unused */
226 	WDRM_DPMS_STATE_SUSPEND, /* unused */
227 	WDRM_DPMS_STATE__COUNT
228 };
229 
230 enum wdrm_panel_orientation {
231 	WDRM_PANEL_ORIENTATION_NORMAL = 0,
232 	WDRM_PANEL_ORIENTATION_UPSIDE_DOWN,
233 	WDRM_PANEL_ORIENTATION_LEFT_SIDE_UP,
234 	WDRM_PANEL_ORIENTATION_RIGHT_SIDE_UP,
235 	WDRM_PANEL_ORIENTATION__COUNT
236 };
237 
238 /**
239  * List of properties attached to DRM CRTCs
240  */
241 enum wdrm_crtc_property {
242 	WDRM_CRTC_MODE_ID = 0,
243 	WDRM_CRTC_ACTIVE,
244 	WDRM_CRTC__COUNT
245 };
246 
247 struct drm_backend {
248 	struct weston_backend base;
249 	struct weston_compositor *compositor;
250 
251 	struct udev *udev;
252 	struct wl_event_source *drm_source;
253 
254 	struct udev_monitor *udev_monitor;
255 	struct wl_event_source *udev_drm_source;
256 
257 	struct {
258 		int id;
259 		int fd;
260 		char *filename;
261 		dev_t devnum;
262 	} drm;
263 	struct gbm_device *gbm;
264 	struct wl_listener session_listener;
265 	uint32_t gbm_format;
266 
267 	/* we need these parameters in order to not fail drmModeAddFB2()
268 	 * due to out of bounds dimensions, and then mistakenly set
269 	 * sprites_are_broken:
270 	 */
271 	int min_width, max_width;
272 	int min_height, max_height;
273 
274 	struct wl_list plane_list;
275 
276 	void *repaint_data;
277 
278 	bool state_invalid;
279 
280 	/* CRTC IDs not used by any enabled output. */
281 	struct wl_array unused_crtcs;
282 
283 	bool sprites_are_broken;
284 	bool cursors_are_broken;
285 
286 	bool universal_planes;
287 	bool atomic_modeset;
288 
289 	bool use_pixman;
290 	bool use_pixman_shadow;
291 
292 	struct udev_input input;
293 
294 	int32_t cursor_width;
295 	int32_t cursor_height;
296 
297 	uint32_t pageflip_timeout;
298 
299 	bool shutting_down;
300 
301 	bool aspect_ratio_supported;
302 
303 	bool fb_modifiers;
304 
305 	struct weston_log_scope *debug;
306 
307 	bool use_tde; // OHOS fix
308 	pthread_t vsync_thread; // OHOS vsync module
309 	bool vsync_thread_running; // OHOS vsync module
310 	int pipe; // OHOS vsync module
311 };
312 
313 struct drm_mode {
314 	struct weston_mode base;
315 	drmModeModeInfo mode_info;
316 	uint32_t blob_id;
317 };
318 
319 enum drm_fb_type {
320 	BUFFER_INVALID = 0, /**< never used */
321 	BUFFER_CLIENT, /**< directly sourced from client */
322 	BUFFER_DMABUF, /**< imported from linux_dmabuf client */
323 	BUFFER_PIXMAN_DUMB, /**< internal Pixman rendering */
324 	BUFFER_GBM_SURFACE, /**< internal EGL rendering */
325 	BUFFER_CURSOR, /**< internal cursor buffer */
326 };
327 
328 struct drm_fb {
329 	enum drm_fb_type type;
330 
331 	int refcnt;
332 
333 	uint32_t fb_id, size;
334 	uint32_t handles[4];
335 	uint32_t strides[4];
336 	uint32_t offsets[4];
337 	int num_planes;
338 	const struct pixel_format_info *format;
339 	uint64_t modifier;
340 	int width, height;
341 	int fd;
342 	struct weston_buffer_reference buffer_ref;
343 	struct weston_buffer_release_reference buffer_release_ref;
344 
345 	/* Used by gbm fbs */
346 	struct gbm_bo *bo;
347 	struct gbm_surface *gbm_surface;
348 
349 	/* Used by dumb fbs */
350 	void *map;
351 };
352 
353 struct drm_edid {
354 	char eisa_id[13];
355 	char monitor_name[13];
356 	char pnp_id[5];
357 	char serial_number[13];
358 };
359 
360 /**
361  * Pending state holds one or more drm_output_state structures, collected from
362  * performing repaint. This pending state is transient, and only lives between
363  * beginning a repaint group and flushing the results: after flush, each
364  * output state will complete and be retired separately.
365  */
366 struct drm_pending_state {
367 	struct drm_backend *backend;
368 	struct wl_list output_list;
369 };
370 
371 /*
372  * Output state holds the dynamic state for one Weston output, i.e. a KMS CRTC,
373  * plus >= 1 each of encoder/connector/plane. Since everything but the planes
374  * is currently statically assigned per-output, we mainly use this to track
375  * plane state.
376  *
377  * pending_state is set when the output state is owned by a pending_state,
378  * i.e. when it is being constructed and has not yet been applied. When the
379  * output state has been applied, the owning pending_state is freed.
380  */
381 struct drm_output_state {
382 	struct drm_pending_state *pending_state;
383 	struct drm_output *output;
384 	struct wl_list link;
385 	enum dpms_enum dpms;
386 	enum weston_hdcp_protection protection;
387 	struct wl_list plane_list;
388 };
389 
390 /**
391  * An instance of this class is created each time we believe we have a plane
392  * suitable to be used by a view as a direct scan-out. The list is initalized
393  * and populated locally.
394  */
395 struct drm_plane_zpos {
396 	struct drm_plane *plane;
397 	struct wl_list link;	/**< :candidate_plane_zpos_list */
398 };
399 
400 /**
401  * Plane state holds the dynamic state for a plane: where it is positioned,
402  * and which buffer it is currently displaying.
403  *
404  * The plane state is owned by an output state, except when setting an initial
405  * state. See drm_output_state for notes on state object lifetime.
406  */
407 struct drm_plane_state {
408 	struct drm_plane *plane;
409 	struct drm_output *output;
410 	struct drm_output_state *output_state;
411 
412 	struct drm_fb *fb;
413 
414 	struct weston_view *ev; /**< maintained for drm_assign_planes only */
415 
416 	int32_t src_x, src_y;
417 	uint32_t src_w, src_h;
418 	int32_t dest_x, dest_y;
419 	uint32_t dest_w, dest_h;
420 
421 	uint64_t zpos;
422 
423 	bool complete;
424 
425 	/* We don't own the fd, so we shouldn't close it */
426 	int in_fence_fd;
427 
428 	uint32_t damage_blob_id; /* damage to kernel */
429 
430 	struct wl_list link; /* drm_output_state::plane_list */
431 };
432 
433 /**
434  * A plane represents one buffer, positioned within a CRTC, and stacked
435  * relative to other planes on the same CRTC.
436  *
437  * Each CRTC has a 'primary plane', which use used to display the classic
438  * framebuffer contents, as accessed through the legacy drmModeSetCrtc
439  * call (which combines setting the CRTC's actual physical mode, and the
440  * properties of the primary plane).
441  *
442  * The cursor plane also has its own alternate legacy API.
443  *
444  * Other planes are used opportunistically to display content we do not
445  * wish to blit into the primary plane. These non-primary/cursor planes
446  * are referred to as 'sprites'.
447  */
448 struct drm_plane {
449 	struct weston_plane base;
450 
451 	struct drm_backend *backend;
452 
453 	enum wdrm_plane_type type;
454 
455 	uint32_t possible_crtcs;
456 	uint32_t plane_id;
457 	uint32_t count_formats;
458 
459 	struct drm_property_info props[WDRM_PLANE__COUNT];
460 
461 	/* The last state submitted to the kernel for this plane. */
462 	struct drm_plane_state *state_cur;
463 
464 	uint64_t zpos_min;
465 	uint64_t zpos_max;
466 
467 	struct wl_list link;
468 
469 	struct {
470 		uint32_t format;
471 		uint32_t count_modifiers;
472 		uint64_t *modifiers;
473 	} formats[];
474 };
475 
476 struct drm_head {
477 	struct weston_head base;
478 	struct drm_backend *backend;
479 
480 	drmModeConnector *connector;
481 	uint32_t connector_id;
482 	struct drm_edid edid;
483 
484 	/* Holds the properties for the connector */
485 	struct drm_property_info props_conn[WDRM_CONNECTOR__COUNT];
486 
487 	struct backlight *backlight;
488 
489 	drmModeModeInfo inherited_mode;	/**< Original mode on the connector */
490 	uint32_t inherited_crtc_id;	/**< Original CRTC assignment */
491 };
492 
493 struct drm_output {
494 	struct weston_output base;
495 	struct drm_backend *backend;
496 
497 	uint32_t crtc_id; /* object ID to pass to DRM functions */
498 	int pipe; /* index of CRTC in resource array / bitmasks */
499 
500 	/* Holds the properties for the CRTC */
501 	struct drm_property_info props_crtc[WDRM_CRTC__COUNT];
502 
503 	bool page_flip_pending;
504 	bool atomic_complete_pending;
505 	bool destroy_pending;
506 	bool disable_pending;
507 	bool dpms_off_pending;
508 
509 	uint32_t gbm_cursor_handle[2];
510 	struct drm_fb *gbm_cursor_fb[2];
511 	struct drm_plane *cursor_plane;
512 	struct weston_view *cursor_view;
513 	int current_cursor;
514 
515 	struct gbm_surface *gbm_surface;
516 	uint32_t gbm_format;
517 	uint32_t gbm_bo_flags;
518 
519 	/* Plane being displayed directly on the CRTC */
520 	struct drm_plane *scanout_plane;
521 
522 	/* The last state submitted to the kernel for this CRTC. */
523 	struct drm_output_state *state_cur;
524 	/* The previously-submitted state, where the hardware has not
525 	 * yet acknowledged completion of state_cur. */
526 	struct drm_output_state *state_last;
527 
528 	struct drm_fb *dumb[2];
529 	pixman_image_t *image[2];
530 	int current_image;
531 	pixman_region32_t previous_damage;
532 
533 	struct vaapi_recorder *recorder;
534 	struct wl_listener recorder_frame_listener;
535 
536 	struct wl_event_source *pageflip_timer;
537 
538 	bool virtual;
539 
540 	submit_frame_cb virtual_submit_frame;
541 };
542 
543 static inline struct drm_head *
to_drm_head(struct weston_head * base)544 to_drm_head(struct weston_head *base)
545 {
546 	return container_of(base, struct drm_head, base);
547 }
548 
549 static inline struct drm_output *
to_drm_output(struct weston_output * base)550 to_drm_output(struct weston_output *base)
551 {
552 	return container_of(base, struct drm_output, base);
553 }
554 
555 static inline struct drm_backend *
to_drm_backend(struct weston_compositor * base)556 to_drm_backend(struct weston_compositor *base)
557 {
558 	return container_of(base->backend, struct drm_backend, base);
559 }
560 
561 static inline struct drm_mode *
to_drm_mode(struct weston_mode * base)562 to_drm_mode(struct weston_mode *base)
563 {
564 	return container_of(base, struct drm_mode, base);
565 }
566 
567 static inline const char *
drm_output_get_plane_type_name(struct drm_plane * p)568 drm_output_get_plane_type_name(struct drm_plane *p)
569 {
570 	switch (p->type) {
571 	case WDRM_PLANE_TYPE_PRIMARY:
572 		return "primary";
573 	case WDRM_PLANE_TYPE_CURSOR:
574 		return "cursor";
575 	case WDRM_PLANE_TYPE_OVERLAY:
576 		return "overlay";
577 	default:
578 		assert(0);
579 		// OHOS build
580 		return "";
581 		break;
582 	}
583 }
584 
585 struct drm_output *
586 drm_output_find_by_crtc(struct drm_backend *b, uint32_t crtc_id);
587 
588 struct drm_head *
589 drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id);
590 
591 static inline bool
drm_view_transform_supported(struct weston_view * ev,struct weston_output * output)592 drm_view_transform_supported(struct weston_view *ev, struct weston_output *output)
593 {
594 	struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
595 
596 	/* This will incorrectly disallow cases where the combination of
597 	 * buffer and view transformations match the output transform.
598 	 * Fixing this requires a full analysis of the transformation
599 	 * chain. */
600 	if (ev->transform.enabled &&
601 	    ev->transform.matrix.type >= WESTON_MATRIX_TRANSFORM_ROTATE)
602 		return false;
603 
604 	if (viewport->buffer.transform != output->transform)
605 		return false;
606 
607 	return true;
608 }
609 
610 int
611 drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode);
612 
613 struct drm_mode *
614 drm_output_choose_mode(struct drm_output *output,
615 		       struct weston_mode *target_mode);
616 void
617 update_head_from_connector(struct drm_head *head,
618 			   drmModeObjectProperties *props);
619 
620 void
621 drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list);
622 
623 void
624 drm_output_print_modes(struct drm_output *output);
625 
626 int
627 drm_output_set_mode(struct weston_output *base,
628 		    enum weston_drm_backend_output_mode mode,
629 		    const char *modeline);
630 
631 void
632 drm_property_info_populate(struct drm_backend *b,
633 		           const struct drm_property_info *src,
634 			   struct drm_property_info *info,
635 			   unsigned int num_infos,
636 			   drmModeObjectProperties *props);
637 uint64_t
638 drm_property_get_value(struct drm_property_info *info,
639 		       const drmModeObjectProperties *props,
640 		       uint64_t def);
641 uint64_t *
642 drm_property_get_range_values(struct drm_property_info *info,
643 			      const drmModeObjectProperties *props);
644 int
645 drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane,
646 			   const drmModeObjectProperties *props,
647 			   const bool use_modifiers);
648 void
649 drm_property_info_free(struct drm_property_info *info, int num_props);
650 
651 extern struct drm_property_enum_info plane_type_enums[];
652 extern const struct drm_property_info plane_props[];
653 extern struct drm_property_enum_info dpms_state_enums[];
654 extern struct drm_property_enum_info content_protection_enums[];
655 extern struct drm_property_enum_info hdcp_content_type_enums[];
656 extern const struct drm_property_info connector_props[];
657 extern const struct drm_property_info crtc_props[];
658 
659 int
660 init_kms_caps(struct drm_backend *b);
661 
662 int
663 drm_pending_state_test(struct drm_pending_state *pending_state);
664 int
665 drm_pending_state_apply(struct drm_pending_state *pending_state);
666 int
667 drm_pending_state_apply_sync(struct drm_pending_state *pending_state);
668 
669 void
670 drm_output_set_gamma(struct weston_output *output_base,
671 		     uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
672 
673 void
674 drm_output_update_msc(struct drm_output *output, unsigned int seq);
675 void
676 drm_output_update_complete(struct drm_output *output, uint32_t flags,
677 			   unsigned int sec, unsigned int usec);
678 int
679 on_drm_input(int fd, uint32_t mask, void *data);
680 
681 struct drm_fb *
682 drm_fb_ref(struct drm_fb *fb);
683 void
684 drm_fb_unref(struct drm_fb *fb);
685 
686 struct drm_fb *
687 drm_fb_create_dumb(struct drm_backend *b, int width, int height,
688 		   uint32_t format);
689 struct drm_fb *
690 drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
691 		   bool is_opaque, enum drm_fb_type type);
692 
693 #ifdef BUILD_DRM_GBM
694 extern struct drm_fb *
695 drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev);
696 extern bool
697 drm_can_scanout_dmabuf(struct weston_compositor *ec,
698 		       struct linux_dmabuf_buffer *dmabuf);
699 #else
700 static inline struct drm_fb *
drm_fb_get_from_view(struct drm_output_state * state,struct weston_view * ev)701 drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
702 {
703 	return NULL;
704 }
705 static inline bool
drm_can_scanout_dmabuf(struct weston_compositor * ec,struct linux_dmabuf_buffer * dmabuf)706 drm_can_scanout_dmabuf(struct weston_compositor *ec,
707 		       struct linux_dmabuf_buffer *dmabuf)
708 {
709 	return false;
710 }
711 #endif
712 
713 struct drm_pending_state *
714 drm_pending_state_alloc(struct drm_backend *backend);
715 void
716 drm_pending_state_free(struct drm_pending_state *pending_state);
717 struct drm_output_state *
718 drm_pending_state_get_output(struct drm_pending_state *pending_state,
719 			     struct drm_output *output);
720 
721 
722 /**
723  * Mode for drm_output_state_duplicate.
724  */
725 enum drm_output_state_duplicate_mode {
726 	DRM_OUTPUT_STATE_CLEAR_PLANES, /**< reset all planes to off */
727 	DRM_OUTPUT_STATE_PRESERVE_PLANES, /**< preserve plane state */
728 };
729 
730 struct drm_output_state *
731 drm_output_state_alloc(struct drm_output *output,
732 		       struct drm_pending_state *pending_state);
733 struct drm_output_state *
734 drm_output_state_duplicate(struct drm_output_state *src,
735 			   struct drm_pending_state *pending_state,
736 			   enum drm_output_state_duplicate_mode plane_mode);
737 void
738 drm_output_state_free(struct drm_output_state *state);
739 struct drm_plane_state *
740 drm_output_state_get_plane(struct drm_output_state *state_output,
741 			   struct drm_plane *plane);
742 struct drm_plane_state *
743 drm_output_state_get_existing_plane(struct drm_output_state *state_output,
744 				    struct drm_plane *plane);
745 
746 
747 
748 struct drm_plane_state *
749 drm_plane_state_alloc(struct drm_output_state *state_output,
750 		      struct drm_plane *plane);
751 struct drm_plane_state *
752 drm_plane_state_duplicate(struct drm_output_state *state_output,
753 			  struct drm_plane_state *src);
754 void
755 drm_plane_state_free(struct drm_plane_state *state, bool force);
756 void
757 drm_plane_state_put_back(struct drm_plane_state *state);
758 bool
759 drm_plane_state_coords_for_view(struct drm_plane_state *state,
760 				struct weston_view *ev, uint64_t zpos);
761 void
762 drm_plane_reset_state(struct drm_plane *plane);
763 
764 void
765 drm_assign_planes(struct weston_output *output_base, void *repaint_data);
766 
767 bool
768 drm_plane_is_available(struct drm_plane *plane, struct drm_output *output);
769 
770 void
771 drm_output_render(struct drm_output_state *state, pixman_region32_t *damage);
772 
773 int
774 parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format);
775 
776 extern struct gl_renderer_interface *gl_renderer;
777 
778 #ifdef BUILD_DRM_VIRTUAL
779 extern int
780 drm_backend_init_virtual_output_api(struct weston_compositor *compositor);
781 #else
782 inline static int
drm_backend_init_virtual_output_api(struct weston_compositor * compositor)783 drm_backend_init_virtual_output_api(struct weston_compositor *compositor)
784 {
785 	return 0;
786 }
787 #endif
788 
789 #ifdef BUILD_DRM_GBM
790 int
791 init_egl(struct drm_backend *b);
792 
793 int
794 drm_output_init_egl(struct drm_output *output, struct drm_backend *b);
795 
796 void
797 drm_output_fini_egl(struct drm_output *output);
798 
799 struct drm_fb *
800 drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage);
801 
802 void
803 renderer_switch_binding(struct weston_keyboard *keyboard,
804 			const struct timespec *time, uint32_t key, void *data);
805 #else
806 inline static int
init_egl(struct drm_backend * b)807 init_egl(struct drm_backend *b)
808 {
809 	weston_log("Compiled without GBM/EGL support\n");
810 	return -1;
811 }
812 
813 inline static int
drm_output_init_egl(struct drm_output * output,struct drm_backend * b)814 drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
815 {
816 	return -1;
817 }
818 
819 inline static void
drm_output_fini_egl(struct drm_output * output)820 drm_output_fini_egl(struct drm_output *output)
821 {
822 }
823 
824 inline static struct drm_fb *
drm_output_render_gl(struct drm_output_state * state,pixman_region32_t * damage)825 drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
826 {
827 	return NULL;
828 }
829 
830 inline static void
renderer_switch_binding(struct weston_keyboard * keyboard,const struct timespec * time,uint32_t key,void * data)831 renderer_switch_binding(struct weston_keyboard *keyboard,
832 			const struct timespec *time, uint32_t key, void *data)
833 {
834 	weston_log("Compiled without GBM/EGL support\n");
835 }
836 #endif
837