mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	backend/drm: remove wlr_drm_crtc_state.active
Replace it with drm_connector_state_active, which figures out whether the connector is active depending on the wlr_output_state to be applied.
This commit is contained in:
		
							parent
							
								
									485ecc11a6
								
							
						
					
					
						commit
						dfea0ff31d
					
				
					 4 changed files with 26 additions and 20 deletions
				
			
		| 
						 | 
					@ -55,13 +55,14 @@ static void atomic_add(struct atomic *atom, uint32_t id, uint32_t prop, uint64_t
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool create_mode_blob(struct wlr_drm_backend *drm,
 | 
					static bool create_mode_blob(struct wlr_drm_backend *drm,
 | 
				
			||||||
		struct wlr_drm_crtc *crtc, uint32_t *blob_id) {
 | 
							struct wlr_drm_connector *conn, const struct wlr_output_state *state,
 | 
				
			||||||
	if (!crtc->pending.active) {
 | 
							uint32_t *blob_id) {
 | 
				
			||||||
 | 
						if (!drm_connector_state_active(conn, state)) {
 | 
				
			||||||
		*blob_id = 0;
 | 
							*blob_id = 0;
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (drmModeCreatePropertyBlob(drm->fd, &crtc->pending.mode->drm_mode,
 | 
						if (drmModeCreatePropertyBlob(drm->fd, &conn->crtc->pending.mode->drm_mode,
 | 
				
			||||||
			sizeof(drmModeModeInfo), blob_id)) {
 | 
								sizeof(drmModeModeInfo), blob_id)) {
 | 
				
			||||||
		wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
 | 
							wlr_log_errno(WLR_ERROR, "Unable to create mode property blob");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
| 
						 | 
					@ -170,10 +171,11 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
 | 
				
			||||||
	struct wlr_drm_crtc *crtc = conn->crtc;
 | 
						struct wlr_drm_crtc *crtc = conn->crtc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool modeset = drm_connector_state_is_modeset(state);
 | 
						bool modeset = drm_connector_state_is_modeset(state);
 | 
				
			||||||
 | 
						bool active = drm_connector_state_active(conn, state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t mode_id = crtc->mode_id;
 | 
						uint32_t mode_id = crtc->mode_id;
 | 
				
			||||||
	if (modeset) {
 | 
						if (modeset) {
 | 
				
			||||||
		if (!create_mode_blob(drm, crtc, &mode_id)) {
 | 
							if (!create_mode_blob(drm, conn, state, &mode_id)) {
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -213,16 +215,14 @@ static bool atomic_crtc_commit(struct wlr_drm_backend *drm,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct atomic atom;
 | 
						struct atomic atom;
 | 
				
			||||||
	atomic_begin(&atom);
 | 
						atomic_begin(&atom);
 | 
				
			||||||
	atomic_add(&atom, conn->id, conn->props.crtc_id,
 | 
						atomic_add(&atom, conn->id, conn->props.crtc_id, active ? crtc->id : 0);
 | 
				
			||||||
		crtc->pending.active ? crtc->id : 0);
 | 
						if (modeset && active && conn->props.link_status != 0) {
 | 
				
			||||||
	if (modeset && crtc->pending.active &&
 | 
					 | 
				
			||||||
			conn->props.link_status != 0) {
 | 
					 | 
				
			||||||
		atomic_add(&atom, conn->id, conn->props.link_status,
 | 
							atomic_add(&atom, conn->id, conn->props.link_status,
 | 
				
			||||||
			DRM_MODE_LINK_STATUS_GOOD);
 | 
								DRM_MODE_LINK_STATUS_GOOD);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	atomic_add(&atom, crtc->id, crtc->props.mode_id, mode_id);
 | 
						atomic_add(&atom, crtc->id, crtc->props.mode_id, mode_id);
 | 
				
			||||||
	atomic_add(&atom, crtc->id, crtc->props.active, crtc->pending.active);
 | 
						atomic_add(&atom, crtc->id, crtc->props.active, active);
 | 
				
			||||||
	if (crtc->pending.active) {
 | 
						if (active) {
 | 
				
			||||||
		if (crtc->props.gamma_lut != 0) {
 | 
							if (crtc->props.gamma_lut != 0) {
 | 
				
			||||||
			atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut);
 | 
								atomic_add(&atom, crtc->id, crtc->props.gamma_lut, gamma_lut);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -363,7 +363,7 @@ static bool drm_crtc_page_flip(struct wlr_drm_connector *conn,
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assert(crtc->pending.active);
 | 
						assert(drm_connector_state_active(conn, state));
 | 
				
			||||||
	assert(plane_get_next_fb(crtc->primary));
 | 
						assert(plane_get_next_fb(crtc->primary));
 | 
				
			||||||
	if (!drm_crtc_commit(conn, state, DRM_MODE_PAGE_FLIP_EVENT)) {
 | 
						if (!drm_crtc_commit(conn, state, DRM_MODE_PAGE_FLIP_EVENT)) {
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
| 
						 | 
					@ -680,7 +680,6 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	struct wlr_drm_plane *plane = crtc->primary;
 | 
						struct wlr_drm_plane *plane = crtc->primary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	crtc->pending.active = true;
 | 
					 | 
				
			||||||
	crtc->pending.mode = mode;
 | 
						crtc->pending.mode = mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int width = mode->wlr_mode.width;
 | 
						int width = mode->wlr_mode.width;
 | 
				
			||||||
| 
						 | 
					@ -703,7 +702,6 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
 | 
				
			||||||
			"retrying without modifiers");
 | 
								"retrying without modifiers");
 | 
				
			||||||
		modifiers = false;
 | 
							modifiers = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		crtc->pending.active = true;
 | 
					 | 
				
			||||||
		crtc->pending.mode = mode;
 | 
							crtc->pending.mode = mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!drm_plane_init_surface(plane, drm, width, height, format,
 | 
							if (!drm_plane_init_surface(plane, drm, width, height, format,
 | 
				
			||||||
| 
						 | 
					@ -752,7 +750,6 @@ bool drm_connector_set_mode(struct wlr_drm_connector *conn,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (wlr_mode == NULL) {
 | 
						if (wlr_mode == NULL) {
 | 
				
			||||||
		if (conn->crtc != NULL) {
 | 
							if (conn->crtc != NULL) {
 | 
				
			||||||
			conn->crtc->pending.active = false;
 | 
					 | 
				
			||||||
			if (!drm_crtc_commit(conn, state, 0)) {
 | 
								if (!drm_crtc_commit(conn, state, 0)) {
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -1042,6 +1039,14 @@ bool drm_connector_state_is_modeset(const struct wlr_output_state *state) {
 | 
				
			||||||
		(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE);
 | 
							(WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_MODE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool drm_connector_state_active(struct wlr_drm_connector *conn,
 | 
				
			||||||
 | 
							const struct wlr_output_state *state) {
 | 
				
			||||||
 | 
						if (state->committed & WLR_OUTPUT_STATE_ENABLED) {
 | 
				
			||||||
 | 
							return state->enabled;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return conn->output.enabled;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const int32_t subpixel_map[] = {
 | 
					static const int32_t subpixel_map[] = {
 | 
				
			||||||
	[DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN,
 | 
						[DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN,
 | 
				
			||||||
	[DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB,
 | 
						[DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB,
 | 
				
			||||||
| 
						 | 
					@ -1060,7 +1065,6 @@ static void dealloc_crtc(struct wlr_drm_connector *conn) {
 | 
				
			||||||
	wlr_drm_conn_log(conn, WLR_DEBUG, "De-allocating CRTC %zu",
 | 
						wlr_drm_conn_log(conn, WLR_DEBUG, "De-allocating CRTC %zu",
 | 
				
			||||||
		conn->crtc - drm->crtcs);
 | 
							conn->crtc - drm->crtcs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	conn->crtc->pending.active = false;
 | 
					 | 
				
			||||||
	struct wlr_output_state state = {
 | 
						struct wlr_output_state state = {
 | 
				
			||||||
		.committed = WLR_OUTPUT_STATE_ENABLED,
 | 
							.committed = WLR_OUTPUT_STATE_ENABLED,
 | 
				
			||||||
		.enabled = false,
 | 
							.enabled = false,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,8 +15,10 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
 | 
				
			||||||
	struct wlr_drm_crtc *crtc = conn->crtc;
 | 
						struct wlr_drm_crtc *crtc = conn->crtc;
 | 
				
			||||||
	struct wlr_drm_plane *cursor = crtc->cursor;
 | 
						struct wlr_drm_plane *cursor = crtc->cursor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool active = drm_connector_state_active(conn, state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t fb_id = 0;
 | 
						uint32_t fb_id = 0;
 | 
				
			||||||
	if (crtc->pending.active) {
 | 
						if (active) {
 | 
				
			||||||
		struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
 | 
							struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
 | 
				
			||||||
		if (fb == NULL) {
 | 
							if (fb == NULL) {
 | 
				
			||||||
			wlr_log(WLR_ERROR, "%s: failed to acquire primary FB",
 | 
								wlr_log(WLR_ERROR, "%s: failed to acquire primary FB",
 | 
				
			||||||
| 
						 | 
					@ -30,14 +32,13 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
 | 
				
			||||||
		uint32_t *conns = NULL;
 | 
							uint32_t *conns = NULL;
 | 
				
			||||||
		size_t conns_len = 0;
 | 
							size_t conns_len = 0;
 | 
				
			||||||
		drmModeModeInfo *mode = NULL;
 | 
							drmModeModeInfo *mode = NULL;
 | 
				
			||||||
		if (crtc->pending.active) {
 | 
							if (active) {
 | 
				
			||||||
			conns = &conn->id;
 | 
								conns = &conn->id;
 | 
				
			||||||
			conns_len = 1;
 | 
								conns_len = 1;
 | 
				
			||||||
			mode = &crtc->pending.mode->drm_mode;
 | 
								mode = &crtc->pending.mode->drm_mode;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		uint32_t dpms = crtc->pending.active ?
 | 
							uint32_t dpms = active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
 | 
				
			||||||
			DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF;
 | 
					 | 
				
			||||||
		if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
 | 
							if (drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms,
 | 
				
			||||||
				dpms) != 0) {
 | 
									dpms) != 0) {
 | 
				
			||||||
			wlr_drm_conn_log_errno(conn, WLR_ERROR,
 | 
								wlr_drm_conn_log_errno(conn, WLR_ERROR,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,6 @@ struct wlr_drm_plane {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wlr_drm_crtc_state {
 | 
					struct wlr_drm_crtc_state {
 | 
				
			||||||
	bool active;
 | 
					 | 
				
			||||||
	struct wlr_drm_mode *mode;
 | 
						struct wlr_drm_mode *mode;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -160,6 +159,8 @@ size_t drm_crtc_get_gamma_lut_size(struct wlr_drm_backend *drm,
 | 
				
			||||||
struct wlr_drm_fb *plane_get_next_fb(struct wlr_drm_plane *plane);
 | 
					struct wlr_drm_fb *plane_get_next_fb(struct wlr_drm_plane *plane);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool drm_connector_state_is_modeset(const struct wlr_output_state *state);
 | 
					bool drm_connector_state_is_modeset(const struct wlr_output_state *state);
 | 
				
			||||||
 | 
					bool drm_connector_state_active(struct wlr_drm_connector *conn,
 | 
				
			||||||
 | 
						const struct wlr_output_state *state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define wlr_drm_conn_log(conn, verb, fmt, ...) \
 | 
					#define wlr_drm_conn_log(conn, verb, fmt, ...) \
 | 
				
			||||||
	wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
 | 
						wlr_log(verb, "connector %s: " fmt, conn->name, ##__VA_ARGS__)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue