mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 22:25:58 +01:00
backend/drm: make wlr_drm_plane.{pending,queued,current}_fb pointers
This will be useful once we start re-using wlr_drm_fb.
This commit is contained in:
parent
64da8f0c8d
commit
5b1b43c68c
6 changed files with 46 additions and 40 deletions
|
@ -134,7 +134,7 @@ static void set_plane_props(struct atomic *atom, struct wlr_drm_backend *drm,
|
|||
uint32_t id = plane->id;
|
||||
const union wlr_drm_plane_props *props = &plane->props;
|
||||
struct wlr_drm_fb *fb = plane_get_next_fb(plane);
|
||||
if (!fb->id) {
|
||||
if (fb == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to acquire FB");
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -324,9 +324,9 @@ static bool drm_connector_attach_render(struct wlr_output *output,
|
|||
static void drm_plane_set_committed(struct wlr_drm_plane *plane) {
|
||||
drm_fb_move(&plane->queued_fb, &plane->pending_fb);
|
||||
|
||||
struct wlr_buffer *queued = plane->queued_fb.wlr_buf;
|
||||
if (queued != NULL) {
|
||||
wlr_swapchain_set_buffer_submitted(plane->surf.swapchain, queued);
|
||||
if (plane->queued_fb && plane->queued_fb->wlr_buf) {
|
||||
wlr_swapchain_set_buffer_submitted(plane->surf.swapchain,
|
||||
plane->queued_fb->wlr_buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ static bool drm_crtc_page_flip(struct wlr_drm_connector *conn) {
|
|||
}
|
||||
|
||||
assert(crtc->pending.active);
|
||||
assert(plane_get_next_fb(crtc->primary)->bo);
|
||||
assert(plane_get_next_fb(crtc->primary));
|
||||
if (!drm_crtc_commit(conn, DRM_MODE_PAGE_FLIP_EVENT)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -638,11 +638,11 @@ static bool drm_connector_export_dmabuf(struct wlr_output *output,
|
|||
return false;
|
||||
}
|
||||
|
||||
struct wlr_drm_fb *fb = &crtc->primary->queued_fb;
|
||||
if (fb->wlr_buf == NULL) {
|
||||
fb = &crtc->primary->current_fb;
|
||||
struct wlr_drm_fb *fb = crtc->primary->queued_fb;
|
||||
if (fb == NULL) {
|
||||
fb = crtc->primary->current_fb;
|
||||
}
|
||||
if (fb->wlr_buf == NULL) {
|
||||
if (fb == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -657,13 +657,13 @@ static bool drm_connector_export_dmabuf(struct wlr_output *output,
|
|||
}
|
||||
|
||||
struct wlr_drm_fb *plane_get_next_fb(struct wlr_drm_plane *plane) {
|
||||
if (plane->pending_fb.bo) {
|
||||
return &plane->pending_fb;
|
||||
if (plane->pending_fb) {
|
||||
return plane->pending_fb;
|
||||
}
|
||||
if (plane->queued_fb.bo) {
|
||||
return &plane->queued_fb;
|
||||
if (plane->queued_fb) {
|
||||
return plane->queued_fb;
|
||||
}
|
||||
return &plane->current_fb;
|
||||
return plane->current_fb;
|
||||
}
|
||||
|
||||
static bool drm_connector_pageflip_renderer(struct wlr_drm_connector *conn) {
|
||||
|
@ -676,7 +676,7 @@ static bool drm_connector_pageflip_renderer(struct wlr_drm_connector *conn) {
|
|||
|
||||
// drm_crtc_page_flip expects a FB to be available
|
||||
struct wlr_drm_plane *plane = crtc->primary;
|
||||
if (!plane_get_next_fb(plane)->bo) {
|
||||
if (!plane_get_next_fb(plane)) {
|
||||
if (!drm_surface_render_black_frame(&plane->surf)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1466,10 +1466,10 @@ static void page_flip_handler(int fd, unsigned seq,
|
|||
}
|
||||
|
||||
struct wlr_drm_plane *plane = conn->crtc->primary;
|
||||
if (plane->queued_fb.bo) {
|
||||
if (plane->queued_fb) {
|
||||
drm_fb_move(&plane->current_fb, &plane->queued_fb);
|
||||
}
|
||||
if (conn->crtc->cursor && conn->crtc->cursor->queued_fb.bo) {
|
||||
if (conn->crtc->cursor && conn->crtc->cursor->queued_fb) {
|
||||
drm_fb_move(&conn->crtc->cursor->current_fb,
|
||||
&conn->crtc->cursor->queued_fb);
|
||||
}
|
||||
|
@ -1480,8 +1480,8 @@ static void page_flip_handler(int fd, unsigned seq,
|
|||
* data between the GPUs, even if we were using the direct scanout
|
||||
* interface.
|
||||
*/
|
||||
if (!drm->parent && plane->current_fb.wlr_buf &&
|
||||
wlr_client_buffer_get(plane->current_fb.wlr_buf)) {
|
||||
if (!drm->parent && plane->current_fb->wlr_buf &&
|
||||
wlr_client_buffer_get(plane->current_fb->wlr_buf)) {
|
||||
present_flags |= WLR_OUTPUT_PRESENT_ZERO_COPY;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
|
|||
uint32_t fb_id = 0;
|
||||
if (crtc->pending.active) {
|
||||
struct wlr_drm_fb *fb = plane_get_next_fb(crtc->primary);
|
||||
if (!fb->id) {
|
||||
if (fb == NULL) {
|
||||
wlr_log(WLR_ERROR, "%s: failed to acquire primary FB",
|
||||
conn->output.name);
|
||||
return false;
|
||||
|
@ -76,7 +76,7 @@ static bool legacy_crtc_commit(struct wlr_drm_backend *drm,
|
|||
|
||||
if (cursor != NULL && drm_connector_is_cursor_visible(conn)) {
|
||||
struct wlr_drm_fb *cursor_fb = plane_get_next_fb(cursor);
|
||||
if (!cursor_fb->bo) {
|
||||
if (cursor_fb == NULL) {
|
||||
wlr_drm_conn_log(conn, WLR_DEBUG, "Failed to acquire cursor FB");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -291,12 +291,13 @@ bool drm_plane_init_surface(struct wlr_drm_plane *plane,
|
|||
return ok;
|
||||
}
|
||||
|
||||
void drm_fb_clear(struct wlr_drm_fb *fb) {
|
||||
if (!fb->bo) {
|
||||
assert(!fb->wlr_buf);
|
||||
void drm_fb_clear(struct wlr_drm_fb **fb_ptr) {
|
||||
if (*fb_ptr == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_drm_fb *fb = *fb_ptr;
|
||||
|
||||
struct gbm_device *gbm = gbm_bo_get_device(fb->bo);
|
||||
if (drmModeRmFB(gbm_device_get_fd(gbm), fb->id) != 0) {
|
||||
wlr_log(WLR_ERROR, "drmModeRmFB failed");
|
||||
|
@ -305,11 +306,12 @@ void drm_fb_clear(struct wlr_drm_fb *fb) {
|
|||
gbm_bo_destroy(fb->bo);
|
||||
wlr_buffer_unlock(fb->wlr_buf);
|
||||
wlr_buffer_unlock(fb->mgpu_wlr_buf);
|
||||
free(fb);
|
||||
|
||||
memset(fb, 0, sizeof(*fb));
|
||||
*fb_ptr = NULL;
|
||||
}
|
||||
|
||||
bool drm_fb_lock_surface(struct wlr_drm_fb *fb, struct wlr_drm_backend *drm,
|
||||
bool drm_fb_lock_surface(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm,
|
||||
struct wlr_drm_surface *surf, struct wlr_drm_surface *mgpu) {
|
||||
assert(surf->back_buffer != NULL);
|
||||
|
||||
|
@ -319,7 +321,7 @@ bool drm_fb_lock_surface(struct wlr_drm_fb *fb, struct wlr_drm_backend *drm,
|
|||
// making another context current.
|
||||
drm_surface_unset_current(surf);
|
||||
|
||||
bool ok = drm_fb_import(fb, drm, buffer, mgpu, NULL);
|
||||
bool ok = drm_fb_import(fb_ptr, drm, buffer, mgpu, NULL);
|
||||
wlr_buffer_unlock(buffer);
|
||||
return ok;
|
||||
}
|
||||
|
@ -361,10 +363,13 @@ static struct gbm_bo *get_bo_for_dmabuf(struct gbm_device *gbm,
|
|||
}
|
||||
}
|
||||
|
||||
bool drm_fb_import(struct wlr_drm_fb *fb, struct wlr_drm_backend *drm,
|
||||
bool drm_fb_import(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm,
|
||||
struct wlr_buffer *buf, struct wlr_drm_surface *mgpu,
|
||||
struct wlr_drm_format_set *set) {
|
||||
drm_fb_clear(fb);
|
||||
struct wlr_drm_fb *fb = calloc(1, sizeof(*fb));
|
||||
if (!fb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fb->wlr_buf = wlr_buffer_lock(buf);
|
||||
|
||||
|
@ -410,6 +415,8 @@ bool drm_fb_import(struct wlr_drm_fb *fb, struct wlr_drm_backend *drm,
|
|||
goto error_get_fb_for_bo;
|
||||
}
|
||||
|
||||
drm_fb_move(fb_ptr, &fb);
|
||||
|
||||
return true;
|
||||
|
||||
error_get_fb_for_bo:
|
||||
|
@ -418,15 +425,14 @@ error_get_dmabuf:
|
|||
wlr_buffer_unlock(fb->mgpu_wlr_buf);
|
||||
error_mgpu_wlr_buf:
|
||||
wlr_buffer_unlock(fb->wlr_buf);
|
||||
memset(fb, 0, sizeof(*fb));
|
||||
free(fb);
|
||||
return false;
|
||||
}
|
||||
|
||||
void drm_fb_move(struct wlr_drm_fb *new, struct wlr_drm_fb *old) {
|
||||
void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old) {
|
||||
drm_fb_clear(new);
|
||||
|
||||
*new = *old;
|
||||
memset(old, 0, sizeof(*old));
|
||||
*old = NULL;
|
||||
}
|
||||
|
||||
bool drm_surface_render_black_frame(struct wlr_drm_surface *surf) {
|
||||
|
|
|
@ -24,11 +24,11 @@ struct wlr_drm_plane {
|
|||
struct wlr_drm_surface mgpu_surf;
|
||||
|
||||
/* Buffer to be submitted to the kernel on the next page-flip */
|
||||
struct wlr_drm_fb pending_fb;
|
||||
struct wlr_drm_fb *pending_fb;
|
||||
/* Buffer submitted to the kernel, will be presented on next vblank */
|
||||
struct wlr_drm_fb queued_fb;
|
||||
struct wlr_drm_fb *queued_fb;
|
||||
/* Buffer currently displayed on screen */
|
||||
struct wlr_drm_fb current_fb;
|
||||
struct wlr_drm_fb *current_fb;
|
||||
|
||||
struct wlr_drm_format_set formats;
|
||||
|
||||
|
|
|
@ -45,14 +45,14 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer);
|
|||
bool drm_surface_make_current(struct wlr_drm_surface *surf, int *buffer_age);
|
||||
void drm_surface_unset_current(struct wlr_drm_surface *surf);
|
||||
|
||||
void drm_fb_clear(struct wlr_drm_fb *fb);
|
||||
bool drm_fb_lock_surface(struct wlr_drm_fb *fb, struct wlr_drm_backend *drm,
|
||||
bool drm_fb_lock_surface(struct wlr_drm_fb **fb, struct wlr_drm_backend *drm,
|
||||
struct wlr_drm_surface *surf, struct wlr_drm_surface *mgpu);
|
||||
bool drm_fb_import(struct wlr_drm_fb *fb, struct wlr_drm_backend *drm,
|
||||
bool drm_fb_import(struct wlr_drm_fb **fb, struct wlr_drm_backend *drm,
|
||||
struct wlr_buffer *buf, struct wlr_drm_surface *mgpu,
|
||||
struct wlr_drm_format_set *set);
|
||||
|
||||
void drm_fb_move(struct wlr_drm_fb *new, struct wlr_drm_fb *old);
|
||||
void drm_fb_clear(struct wlr_drm_fb **fb);
|
||||
void drm_fb_move(struct wlr_drm_fb **new, struct wlr_drm_fb **old);
|
||||
|
||||
bool drm_surface_render_black_frame(struct wlr_drm_surface *surf);
|
||||
|
||||
|
|
Loading…
Reference in a new issue