weston: Port DRM backend to new output handling API
This is a complete port of the DRM backend that uses
the recently added output handling API for output
configuration.
Output can be configured at runtime by passing the
necessary configuration parameters, which can be
filled in manually or obtained from the configuration
file using previously added functionality. It is
required that the scale and transform values are set
using the previously added functionality.
After everything has been set, output needs to be
enabled manually using weston_output_enable().
v2:
- Added missing drmModeFreeCrtc() to drm_output_enable()
cleanup list in case of failure.
- Split drm_backend_disable() into drm_backend_deinit()
to accomodate for changes in the first patch in the
series. Moved restoring original crtc to
drm_output_destroy().
v3:
- Moved origcrtc allocation to drm_output_set_mode().
- Swapped connector_get_current_mode() and
drm_output_add_mode() calls in drm_output_set_mode()
to match current weston.
- Moved crtc_allocator and connector_allocator update
from drm_output_enable() to create_output_for_connector()
to avoid problems when more than one monitor is connected
at startup and crtc allocator wasn't updated before
create_output_for_connector() was called second time,
resulting in one screen being turned off.
- Moved crtc_allocator and connector_allocator update from
drm_output_deinit() to drm_output_destroy(), as it
should not be called on drm_output_disable().
- Use weston_compositor_add_pending_output().
- Bump weston_drm_backend_config version to 2.
v4:
- Reset output->original_crtc to NULL if drm_output_set_mode()
fails.
- Remove unneeded log message when disabling an output when a
pageflip is pending.
- Document that create_output_for_connector() takes ownership
of the connector.
- Free the connector if create output conditionals are not met
in create_outputs() and update_outputs().
Signed-off-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/libweston/compositor-drm.h b/libweston/compositor-drm.h
index 1266031..8f89a2b 100644
--- a/libweston/compositor-drm.h
+++ b/libweston/compositor-drm.h
@@ -29,12 +29,13 @@
#define WESTON_COMPOSITOR_DRM_H
#include "compositor.h"
+#include "plugin-registry.h"
#ifdef __cplusplus
extern "C" {
#endif
-#define WESTON_DRM_BACKEND_CONFIG_VERSION 1
+#define WESTON_DRM_BACKEND_CONFIG_VERSION 2
struct libinput_device;
@@ -51,8 +52,17 @@
WESTON_DRM_BACKEND_OUTPUT_PREFERRED,
};
-struct weston_drm_backend_output_config {
- struct weston_backend_output_config base;
+#define WESTON_DRM_OUTPUT_API_NAME "weston_drm_output_api_v1"
+
+struct weston_drm_output_api {
+ /** The mode to be used by the output. Refer to the documentation
+ * of WESTON_DRM_BACKEND_OUTPUT_PREFERRED for details.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+ int (*set_mode)(struct weston_output *output,
+ enum weston_drm_backend_output_mode mode,
+ const char *modeline);
/** The pixel format to be used by the output. Valid values are:
* - NULL - The format set at backend creation time will be used;
@@ -60,15 +70,26 @@
* - "rgb565"
* - "xrgb2101010"
*/
- char *gbm_format;
+ void (*set_gbm_format)(struct weston_output *output,
+ const char *gbm_format);
+
/** The seat to be used by the output. Set to NULL to use the
- * default seat. */
- char *seat;
- /** The modeline to be used by the output. Refer to the documentation
- * of WESTON_DRM_BACKEND_OUTPUT_PREFERRED for details. */
- char *modeline;
+ * default seat.
+ */
+ void (*set_seat)(struct weston_output *output,
+ const char *seat);
};
+static inline const struct weston_drm_output_api *
+weston_drm_output_get_api(struct weston_compositor *compositor)
+{
+ const void *api;
+ api = weston_plugin_api_get(compositor, WESTON_DRM_OUTPUT_API_NAME,
+ sizeof(struct weston_drm_output_api));
+
+ return (const struct weston_drm_output_api *)api;
+}
+
/** The backend configuration struct.
*
* weston_drm_backend_config contains the configuration used by a DRM
@@ -109,17 +130,6 @@
*/
char *gbm_format;
- /** 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);
-
/** Callback used to configure input devices.
*
* This function will be called by the backend when a new input device