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 <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 };
311
312 struct drm_mode {
313 struct weston_mode base;
314 drmModeModeInfo mode_info;
315 uint32_t blob_id;
316 };
317
318 enum drm_fb_type {
319 BUFFER_INVALID = 0, /**< never used */
320 BUFFER_CLIENT, /**< directly sourced from client */
321 BUFFER_DMABUF, /**< imported from linux_dmabuf client */
322 BUFFER_PIXMAN_DUMB, /**< internal Pixman rendering */
323 BUFFER_GBM_SURFACE, /**< internal EGL rendering */
324 BUFFER_CURSOR, /**< internal cursor buffer */
325 };
326
327 struct drm_fb {
328 enum drm_fb_type type;
329
330 int refcnt;
331
332 uint32_t fb_id, size;
333 uint32_t handles[4];
334 uint32_t strides[4];
335 uint32_t offsets[4];
336 int num_planes;
337 const struct pixel_format_info *format;
338 uint64_t modifier;
339 int width, height;
340 int fd;
341 struct weston_buffer_reference buffer_ref;
342 struct weston_buffer_release_reference buffer_release_ref;
343
344 /* Used by gbm fbs */
345 struct gbm_bo *bo;
346 struct gbm_surface *gbm_surface;
347
348 /* Used by dumb fbs */
349 void *map;
350 };
351
352 struct drm_edid {
353 char eisa_id[13];
354 char monitor_name[13];
355 char pnp_id[5];
356 char serial_number[13];
357 };
358
359 /**
360 * Pending state holds one or more drm_output_state structures, collected from
361 * performing repaint. This pending state is transient, and only lives between
362 * beginning a repaint group and flushing the results: after flush, each
363 * output state will complete and be retired separately.
364 */
365 struct drm_pending_state {
366 struct drm_backend *backend;
367 struct wl_list output_list;
368 };
369
370 /*
371 * Output state holds the dynamic state for one Weston output, i.e. a KMS CRTC,
372 * plus >= 1 each of encoder/connector/plane. Since everything but the planes
373 * is currently statically assigned per-output, we mainly use this to track
374 * plane state.
375 *
376 * pending_state is set when the output state is owned by a pending_state,
377 * i.e. when it is being constructed and has not yet been applied. When the
378 * output state has been applied, the owning pending_state is freed.
379 */
380 struct drm_output_state {
381 struct drm_pending_state *pending_state;
382 struct drm_output *output;
383 struct wl_list link;
384 enum dpms_enum dpms;
385 enum weston_hdcp_protection protection;
386 struct wl_list plane_list;
387 };
388
389 /**
390 * An instance of this class is created each time we believe we have a plane
391 * suitable to be used by a view as a direct scan-out. The list is initalized
392 * and populated locally.
393 */
394 struct drm_plane_zpos {
395 struct drm_plane *plane;
396 struct wl_list link; /**< :candidate_plane_zpos_list */
397 };
398
399 /**
400 * Plane state holds the dynamic state for a plane: where it is positioned,
401 * and which buffer it is currently displaying.
402 *
403 * The plane state is owned by an output state, except when setting an initial
404 * state. See drm_output_state for notes on state object lifetime.
405 */
406 struct drm_plane_state {
407 struct drm_plane *plane;
408 struct drm_output *output;
409 struct drm_output_state *output_state;
410
411 struct drm_fb *fb;
412
413 struct weston_view *ev; /**< maintained for drm_assign_planes only */
414
415 int32_t src_x, src_y;
416 uint32_t src_w, src_h;
417 int32_t dest_x, dest_y;
418 uint32_t dest_w, dest_h;
419
420 uint64_t zpos;
421
422 bool complete;
423
424 /* We don't own the fd, so we shouldn't close it */
425 int in_fence_fd;
426
427 uint32_t damage_blob_id; /* damage to kernel */
428
429 struct wl_list link; /* drm_output_state::plane_list */
430 };
431
432 /**
433 * A plane represents one buffer, positioned within a CRTC, and stacked
434 * relative to other planes on the same CRTC.
435 *
436 * Each CRTC has a 'primary plane', which use used to display the classic
437 * framebuffer contents, as accessed through the legacy drmModeSetCrtc
438 * call (which combines setting the CRTC's actual physical mode, and the
439 * properties of the primary plane).
440 *
441 * The cursor plane also has its own alternate legacy API.
442 *
443 * Other planes are used opportunistically to display content we do not
444 * wish to blit into the primary plane. These non-primary/cursor planes
445 * are referred to as 'sprites'.
446 */
447 struct drm_plane {
448 struct weston_plane base;
449
450 struct drm_backend *backend;
451
452 enum wdrm_plane_type type;
453
454 uint32_t possible_crtcs;
455 uint32_t plane_id;
456 uint32_t count_formats;
457
458 struct drm_property_info props[WDRM_PLANE__COUNT];
459
460 /* The last state submitted to the kernel for this plane. */
461 struct drm_plane_state *state_cur;
462
463 uint64_t zpos_min;
464 uint64_t zpos_max;
465
466 struct wl_list link;
467
468 struct {
469 uint32_t format;
470 uint32_t count_modifiers;
471 uint64_t *modifiers;
472 } formats[];
473 };
474
475 struct drm_head {
476 struct weston_head base;
477 struct drm_backend *backend;
478
479 drmModeConnector *connector;
480 uint32_t connector_id;
481 struct drm_edid edid;
482
483 /* Holds the properties for the connector */
484 struct drm_property_info props_conn[WDRM_CONNECTOR__COUNT];
485
486 struct backlight *backlight;
487
488 drmModeModeInfo inherited_mode; /**< Original mode on the connector */
489 uint32_t inherited_crtc_id; /**< Original CRTC assignment */
490 };
491
492 struct drm_output {
493 struct weston_output base;
494 struct drm_backend *backend;
495
496 uint32_t crtc_id; /* object ID to pass to DRM functions */
497 int pipe; /* index of CRTC in resource array / bitmasks */
498
499 /* Holds the properties for the CRTC */
500 struct drm_property_info props_crtc[WDRM_CRTC__COUNT];
501
502 bool page_flip_pending;
503 bool atomic_complete_pending;
504 bool destroy_pending;
505 bool disable_pending;
506 bool dpms_off_pending;
507
508 uint32_t gbm_cursor_handle[2];
509 struct drm_fb *gbm_cursor_fb[2];
510 struct drm_plane *cursor_plane;
511 struct weston_view *cursor_view;
512 int current_cursor;
513
514 struct gbm_surface *gbm_surface;
515 uint32_t gbm_format;
516 uint32_t gbm_bo_flags;
517
518 /* Plane being displayed directly on the CRTC */
519 struct drm_plane *scanout_plane;
520
521 /* The last state submitted to the kernel for this CRTC. */
522 struct drm_output_state *state_cur;
523 /* The previously-submitted state, where the hardware has not
524 * yet acknowledged completion of state_cur. */
525 struct drm_output_state *state_last;
526
527 struct drm_fb *dumb[2];
528 pixman_image_t *image[2];
529 int current_image;
530 pixman_region32_t previous_damage;
531
532 struct vaapi_recorder *recorder;
533 struct wl_listener recorder_frame_listener;
534
535 struct wl_event_source *pageflip_timer;
536
537 bool virtual;
538
539 submit_frame_cb virtual_submit_frame;
540 };
541
542 static inline struct drm_head *
to_drm_head(struct weston_head * base)543 to_drm_head(struct weston_head *base)
544 {
545 return container_of(base, struct drm_head, base);
546 }
547
548 static inline struct drm_output *
to_drm_output(struct weston_output * base)549 to_drm_output(struct weston_output *base)
550 {
551 return container_of(base, struct drm_output, base);
552 }
553
554 static inline struct drm_backend *
to_drm_backend(struct weston_compositor * base)555 to_drm_backend(struct weston_compositor *base)
556 {
557 return container_of(base->backend, struct drm_backend, base);
558 }
559
560 static inline struct drm_mode *
to_drm_mode(struct weston_mode * base)561 to_drm_mode(struct weston_mode *base)
562 {
563 return container_of(base, struct drm_mode, base);
564 }
565
566 static inline const char *
drm_output_get_plane_type_name(struct drm_plane * p)567 drm_output_get_plane_type_name(struct drm_plane *p)
568 {
569 switch (p->type) {
570 case WDRM_PLANE_TYPE_PRIMARY:
571 return "primary";
572 case WDRM_PLANE_TYPE_CURSOR:
573 return "cursor";
574 case WDRM_PLANE_TYPE_OVERLAY:
575 return "overlay";
576 default:
577 assert(0);
578 // OHOS build
579 return "";
580 break;
581 }
582 }
583
584 struct drm_output *
585 drm_output_find_by_crtc(struct drm_backend *b, uint32_t crtc_id);
586
587 struct drm_head *
588 drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id);
589
590 static inline bool
drm_view_transform_supported(struct weston_view * ev,struct weston_output * output)591 drm_view_transform_supported(struct weston_view *ev, struct weston_output *output)
592 {
593 struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
594
595 /* This will incorrectly disallow cases where the combination of
596 * buffer and view transformations match the output transform.
597 * Fixing this requires a full analysis of the transformation
598 * chain. */
599 if (ev->transform.enabled &&
600 ev->transform.matrix.type >= WESTON_MATRIX_TRANSFORM_ROTATE)
601 return false;
602
603 if (viewport->buffer.transform != output->transform)
604 return false;
605
606 return true;
607 }
608
609 int
610 drm_mode_ensure_blob(struct drm_backend *backend, struct drm_mode *mode);
611
612 struct drm_mode *
613 drm_output_choose_mode(struct drm_output *output,
614 struct weston_mode *target_mode);
615 void
616 update_head_from_connector(struct drm_head *head,
617 drmModeObjectProperties *props);
618
619 void
620 drm_mode_list_destroy(struct drm_backend *backend, struct wl_list *mode_list);
621
622 void
623 drm_output_print_modes(struct drm_output *output);
624
625 int
626 drm_output_set_mode(struct weston_output *base,
627 enum weston_drm_backend_output_mode mode,
628 const char *modeline);
629
630 void
631 drm_property_info_populate(struct drm_backend *b,
632 const struct drm_property_info *src,
633 struct drm_property_info *info,
634 unsigned int num_infos,
635 drmModeObjectProperties *props);
636 uint64_t
637 drm_property_get_value(struct drm_property_info *info,
638 const drmModeObjectProperties *props,
639 uint64_t def);
640 uint64_t *
641 drm_property_get_range_values(struct drm_property_info *info,
642 const drmModeObjectProperties *props);
643 int
644 drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane,
645 const drmModeObjectProperties *props,
646 const bool use_modifiers);
647 void
648 drm_property_info_free(struct drm_property_info *info, int num_props);
649
650 extern struct drm_property_enum_info plane_type_enums[];
651 extern const struct drm_property_info plane_props[];
652 extern struct drm_property_enum_info dpms_state_enums[];
653 extern struct drm_property_enum_info content_protection_enums[];
654 extern struct drm_property_enum_info hdcp_content_type_enums[];
655 extern const struct drm_property_info connector_props[];
656 extern const struct drm_property_info crtc_props[];
657
658 int
659 init_kms_caps(struct drm_backend *b);
660
661 int
662 drm_pending_state_test(struct drm_pending_state *pending_state);
663 int
664 drm_pending_state_apply(struct drm_pending_state *pending_state);
665 int
666 drm_pending_state_apply_sync(struct drm_pending_state *pending_state);
667
668 void
669 drm_output_set_gamma(struct weston_output *output_base,
670 uint16_t size, uint16_t *r, uint16_t *g, uint16_t *b);
671
672 void
673 drm_output_update_msc(struct drm_output *output, unsigned int seq);
674 void
675 drm_output_update_complete(struct drm_output *output, uint32_t flags,
676 unsigned int sec, unsigned int usec);
677 int
678 on_drm_input(int fd, uint32_t mask, void *data);
679
680 struct drm_fb *
681 drm_fb_ref(struct drm_fb *fb);
682 void
683 drm_fb_unref(struct drm_fb *fb);
684
685 struct drm_fb *
686 drm_fb_create_dumb(struct drm_backend *b, int width, int height,
687 uint32_t format);
688 struct drm_fb *
689 drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
690 bool is_opaque, enum drm_fb_type type);
691
692 #ifdef BUILD_DRM_GBM
693 extern struct drm_fb *
694 drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev);
695 extern bool
696 drm_can_scanout_dmabuf(struct weston_compositor *ec,
697 struct linux_dmabuf_buffer *dmabuf);
698 #else
699 static inline struct drm_fb *
drm_fb_get_from_view(struct drm_output_state * state,struct weston_view * ev)700 drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
701 {
702 return NULL;
703 }
704 static inline bool
drm_can_scanout_dmabuf(struct weston_compositor * ec,struct linux_dmabuf_buffer * dmabuf)705 drm_can_scanout_dmabuf(struct weston_compositor *ec,
706 struct linux_dmabuf_buffer *dmabuf)
707 {
708 return false;
709 }
710 #endif
711
712 struct drm_pending_state *
713 drm_pending_state_alloc(struct drm_backend *backend);
714 void
715 drm_pending_state_free(struct drm_pending_state *pending_state);
716 struct drm_output_state *
717 drm_pending_state_get_output(struct drm_pending_state *pending_state,
718 struct drm_output *output);
719
720
721 /**
722 * Mode for drm_output_state_duplicate.
723 */
724 enum drm_output_state_duplicate_mode {
725 DRM_OUTPUT_STATE_CLEAR_PLANES, /**< reset all planes to off */
726 DRM_OUTPUT_STATE_PRESERVE_PLANES, /**< preserve plane state */
727 };
728
729 struct drm_output_state *
730 drm_output_state_alloc(struct drm_output *output,
731 struct drm_pending_state *pending_state);
732 struct drm_output_state *
733 drm_output_state_duplicate(struct drm_output_state *src,
734 struct drm_pending_state *pending_state,
735 enum drm_output_state_duplicate_mode plane_mode);
736 void
737 drm_output_state_free(struct drm_output_state *state);
738 struct drm_plane_state *
739 drm_output_state_get_plane(struct drm_output_state *state_output,
740 struct drm_plane *plane);
741 struct drm_plane_state *
742 drm_output_state_get_existing_plane(struct drm_output_state *state_output,
743 struct drm_plane *plane);
744
745
746
747 struct drm_plane_state *
748 drm_plane_state_alloc(struct drm_output_state *state_output,
749 struct drm_plane *plane);
750 struct drm_plane_state *
751 drm_plane_state_duplicate(struct drm_output_state *state_output,
752 struct drm_plane_state *src);
753 void
754 drm_plane_state_free(struct drm_plane_state *state, bool force);
755 void
756 drm_plane_state_put_back(struct drm_plane_state *state);
757 bool
758 drm_plane_state_coords_for_view(struct drm_plane_state *state,
759 struct weston_view *ev, uint64_t zpos);
760 void
761 drm_plane_reset_state(struct drm_plane *plane);
762
763 void
764 drm_assign_planes(struct weston_output *output_base, void *repaint_data);
765
766 bool
767 drm_plane_is_available(struct drm_plane *plane, struct drm_output *output);
768
769 void
770 drm_output_render(struct drm_output_state *state, pixman_region32_t *damage);
771
772 int
773 parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format);
774
775 extern struct gl_renderer_interface *gl_renderer;
776
777 #ifdef BUILD_DRM_VIRTUAL
778 extern int
779 drm_backend_init_virtual_output_api(struct weston_compositor *compositor);
780 #else
781 inline static int
drm_backend_init_virtual_output_api(struct weston_compositor * compositor)782 drm_backend_init_virtual_output_api(struct weston_compositor *compositor)
783 {
784 return 0;
785 }
786 #endif
787
788 #ifdef BUILD_DRM_GBM
789 int
790 init_egl(struct drm_backend *b);
791
792 int
793 drm_output_init_egl(struct drm_output *output, struct drm_backend *b);
794
795 void
796 drm_output_fini_egl(struct drm_output *output);
797
798 struct drm_fb *
799 drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage);
800
801 void
802 renderer_switch_binding(struct weston_keyboard *keyboard,
803 const struct timespec *time, uint32_t key, void *data);
804 #else
805 inline static int
init_egl(struct drm_backend * b)806 init_egl(struct drm_backend *b)
807 {
808 weston_log("Compiled without GBM/EGL support\n");
809 return -1;
810 }
811
812 inline static int
drm_output_init_egl(struct drm_output * output,struct drm_backend * b)813 drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
814 {
815 return -1;
816 }
817
818 inline static void
drm_output_fini_egl(struct drm_output * output)819 drm_output_fini_egl(struct drm_output *output)
820 {
821 }
822
823 inline static struct drm_fb *
drm_output_render_gl(struct drm_output_state * state,pixman_region32_t * damage)824 drm_output_render_gl(struct drm_output_state *state, pixman_region32_t *damage)
825 {
826 return NULL;
827 }
828
829 inline static void
renderer_switch_binding(struct weston_keyboard * keyboard,const struct timespec * time,uint32_t key,void * data)830 renderer_switch_binding(struct weston_keyboard *keyboard,
831 const struct timespec *time, uint32_t key, void *data)
832 {
833 weston_log("Compiled without GBM/EGL support\n");
834 }
835 #endif
836