|
|
@ -15,6 +15,9 @@
|
|
|
|
#include <wlr/backend/interface.h>
|
|
|
|
#include <wlr/backend/interface.h>
|
|
|
|
#include <wlr/interfaces/wlr_output.h>
|
|
|
|
#include <wlr/interfaces/wlr_output.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
|
|
|
|
#include <wlr/render/matrix.h>
|
|
|
|
|
|
|
|
#include <wlr/render/gles2.h>
|
|
|
|
|
|
|
|
#include <wlr/render.h>
|
|
|
|
#include "drm.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "drm-util.h"
|
|
|
|
#include "drm-util.h"
|
|
|
|
|
|
|
|
|
|
|
@ -174,7 +177,7 @@ void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool wlr_drm_plane_renderer_init(struct wlr_drm_renderer *renderer,
|
|
|
|
static bool wlr_drm_plane_renderer_init(struct wlr_drm_renderer *renderer,
|
|
|
|
struct wlr_drm_plane *plane, uint32_t width, uint32_t height) {
|
|
|
|
struct wlr_drm_plane *plane, uint32_t width, uint32_t height, uint32_t flags) {
|
|
|
|
if (plane->width == width && plane->height == height) {
|
|
|
|
if (plane->width == width && plane->height == height) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -183,7 +186,7 @@ static bool wlr_drm_plane_renderer_init(struct wlr_drm_renderer *renderer,
|
|
|
|
plane->height = height;
|
|
|
|
plane->height = height;
|
|
|
|
|
|
|
|
|
|
|
|
plane->gbm = gbm_surface_create(renderer->gbm, width, height,
|
|
|
|
plane->gbm = gbm_surface_create(renderer->gbm, width, height,
|
|
|
|
GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
|
|
|
|
GBM_FORMAT_ARGB8888, GBM_BO_USE_RENDERING | flags);
|
|
|
|
if (!plane->gbm) {
|
|
|
|
if (!plane->gbm) {
|
|
|
|
wlr_log_errno(L_ERROR, "Failed to create GBM surface for plane");
|
|
|
|
wlr_log_errno(L_ERROR, "Failed to create GBM surface for plane");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -203,8 +206,6 @@ static void wlr_drm_plane_renderer_free(struct wlr_drm_renderer *renderer,
|
|
|
|
if (!renderer || !plane)
|
|
|
|
if (!renderer || !plane)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_DEBUG, "%s called", __func__);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (plane->front)
|
|
|
|
if (plane->front)
|
|
|
|
gbm_surface_release_buffer(plane->gbm, plane->front);
|
|
|
|
gbm_surface_release_buffer(plane->gbm, plane->front);
|
|
|
|
if (plane->back)
|
|
|
|
if (plane->back)
|
|
|
@ -215,12 +216,19 @@ static void wlr_drm_plane_renderer_free(struct wlr_drm_renderer *renderer,
|
|
|
|
if (plane->gbm)
|
|
|
|
if (plane->gbm)
|
|
|
|
gbm_surface_destroy(plane->gbm);
|
|
|
|
gbm_surface_destroy(plane->gbm);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (plane->wlr_surf)
|
|
|
|
|
|
|
|
wlr_surface_destroy(plane->wlr_surf);
|
|
|
|
|
|
|
|
if (plane->wlr_rend)
|
|
|
|
|
|
|
|
wlr_renderer_destroy(plane->wlr_rend);
|
|
|
|
|
|
|
|
|
|
|
|
plane->width = 0;
|
|
|
|
plane->width = 0;
|
|
|
|
plane->height = 0;
|
|
|
|
plane->height = 0;
|
|
|
|
plane->egl = EGL_NO_SURFACE;
|
|
|
|
plane->egl = EGL_NO_SURFACE;
|
|
|
|
plane->gbm = NULL;
|
|
|
|
plane->gbm = NULL;
|
|
|
|
plane->front = NULL;
|
|
|
|
plane->front = NULL;
|
|
|
|
plane->back = NULL;
|
|
|
|
plane->back = NULL;
|
|
|
|
|
|
|
|
plane->wlr_rend = NULL;
|
|
|
|
|
|
|
|
plane->wlr_surf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void free_fb(struct gbm_bo *bo, void *data) {
|
|
|
|
static void free_fb(struct gbm_bo *bo, void *data) {
|
|
|
@ -480,7 +488,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (!wlr_drm_plane_renderer_init(&drm->renderer, crtc->primary,
|
|
|
|
if (!wlr_drm_plane_renderer_init(&drm->renderer, crtc->primary,
|
|
|
|
mode->width, mode->height)) {
|
|
|
|
mode->width, mode->height, GBM_BO_USE_SCANOUT)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to initalise renderer for plane");
|
|
|
|
wlr_log(L_ERROR, "Failed to initalise renderer for plane");
|
|
|
|
goto error_enc;
|
|
|
|
goto error_enc;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -506,79 +514,95 @@ static void wlr_drm_output_transform(struct wlr_output_state *output,
|
|
|
|
output->base->transform = transform;
|
|
|
|
output->base->transform = transform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
|
|
|
|
bool wlr_drm_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc) {
|
|
|
|
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) {
|
|
|
|
if (!crtc || !crtc->cursor || !crtc->cursor->gbm)
|
|
|
|
struct wlr_backend_state *state = wl_container_of(output->renderer, state, renderer);
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
|
|
|
|
drmModeSetCursor(state->fd, output->crtc->id, 0, 0, 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!gbm_device_is_format_supported(state->renderer.gbm,
|
|
|
|
struct wlr_drm_plane *plane = crtc->cursor;
|
|
|
|
GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Failed to create cursor bo: ARGB8888 pixel format is "
|
|
|
|
uint32_t bo_handle = gbm_bo_get_handle(plane->back).u32;
|
|
|
|
"unsupported on this device");
|
|
|
|
if (drmModeSetCursor(drm->fd, crtc->id, bo_handle, plane->width, plane->height)) {
|
|
|
|
|
|
|
|
wlr_log_errno(L_ERROR, "Failed to set hardware cursor");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t bo_width, bo_height;
|
|
|
|
return true;
|
|
|
|
int ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret = drmGetCap(state->fd, DRM_CAP_CURSOR_WIDTH, &bo_width);
|
|
|
|
static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
|
|
|
|
bo_width = ret ? 64 : bo_width;
|
|
|
|
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) {
|
|
|
|
ret = drmGetCap(state->fd, DRM_CAP_CURSOR_HEIGHT, &bo_height);
|
|
|
|
struct wlr_backend_state *drm = wl_container_of(output->renderer, drm, renderer);
|
|
|
|
bo_height = ret ? 64 : bo_height;
|
|
|
|
struct wlr_drm_renderer *renderer = output->renderer;
|
|
|
|
|
|
|
|
struct wlr_drm_crtc *crtc = output->crtc;
|
|
|
|
|
|
|
|
struct wlr_drm_plane *plane = crtc->cursor;
|
|
|
|
|
|
|
|
|
|
|
|
if (width > bo_width || height > bo_width) {
|
|
|
|
if (!buf) {
|
|
|
|
wlr_log(L_INFO, "Cursor too large (max %dx%d)", (int)bo_width, (int)bo_height);
|
|
|
|
drmModeSetCursor(drm->fd, crtc->id, 0, 0, 0);
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
if (!plane) {
|
|
|
|
if (output->cursor_bo[i]) {
|
|
|
|
plane = calloc(1, sizeof(*plane));
|
|
|
|
continue;
|
|
|
|
if (!plane) {
|
|
|
|
|
|
|
|
wlr_log_errno(L_ERROR, "Allocation failed");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->cursor = plane;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
output->cursor_bo[i] = gbm_bo_create(state->renderer.gbm, bo_width, bo_height,
|
|
|
|
if (!plane->gbm) {
|
|
|
|
GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
uint64_t w, h;
|
|
|
|
|
|
|
|
ret = drmGetCap(drm->fd, DRM_CAP_CURSOR_WIDTH, &w);
|
|
|
|
|
|
|
|
w = ret ? 64 : w;
|
|
|
|
|
|
|
|
ret = drmGetCap(drm->fd, DRM_CAP_CURSOR_HEIGHT, &h);
|
|
|
|
|
|
|
|
h = ret ? 64 : h;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (width > w || height > h) {
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Cursor too large (max %dx%d)", (int)w, (int)h);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!output->cursor_bo[i]) {
|
|
|
|
if (!wlr_drm_plane_renderer_init(renderer, plane, w, h, GBM_BO_USE_CURSOR)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to create cursor bo");
|
|
|
|
wlr_log(L_ERROR, "Cannot allocate cursor resources");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct gbm_bo *bo;
|
|
|
|
wlr_matrix_surface(plane->matrix, plane->width, plane->height,
|
|
|
|
output->current_cursor ^= 1;
|
|
|
|
output->base->transform);
|
|
|
|
bo = output->cursor_bo[output->current_cursor];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t bo_stride = gbm_bo_get_stride(bo);
|
|
|
|
plane->wlr_rend = wlr_gles2_renderer_init();
|
|
|
|
uint8_t tmp[bo_stride * height];
|
|
|
|
if (!plane->wlr_rend)
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < height; ++i) {
|
|
|
|
plane->wlr_surf = wlr_render_surface_init(plane->wlr_rend);
|
|
|
|
memcpy(tmp + i * bo_stride, buf + i * stride * 4, width * 4);
|
|
|
|
if (!plane->wlr_surf)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (gbm_bo_write(bo, tmp, sizeof(tmp)) < 0) {
|
|
|
|
wlr_drm_plane_make_current(renderer, plane);
|
|
|
|
wlr_log(L_ERROR, "Failed to write cursor to bo");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t bo_handle = gbm_bo_get_handle(bo).u32;
|
|
|
|
wlr_surface_attach_pixels(plane->wlr_surf, WL_SHM_FORMAT_ARGB8888,
|
|
|
|
if (drmModeSetCursor(state->fd, output->crtc->id, bo_handle, bo_width, bo_height)) {
|
|
|
|
stride, width, height, buf);
|
|
|
|
wlr_log_errno(L_INFO, "Failed to set hardware cursor");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
glViewport(0, 0, plane->width, plane->height);
|
|
|
|
|
|
|
|
glClearColor(0, 0, 0, 0);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float matrix[16];
|
|
|
|
|
|
|
|
wlr_surface_get_matrix(plane->wlr_surf, &matrix, &plane->matrix, 0, 0);
|
|
|
|
|
|
|
|
wlr_render_with_matrix(plane->wlr_rend, plane->wlr_surf, &matrix);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_drm_plane_swap_buffers(renderer, plane);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return wlr_drm_crtc_set_cursor(drm, crtc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool wlr_drm_output_move_cursor(struct wlr_output_state *output,
|
|
|
|
static bool wlr_drm_output_move_cursor(struct wlr_output_state *output,
|
|
|
|
int x, int y) {
|
|
|
|
int x, int y) {
|
|
|
|
struct wlr_backend_state *state =
|
|
|
|
struct wlr_backend_state *drm =
|
|
|
|
wl_container_of(output->renderer, state, renderer);
|
|
|
|
wl_container_of(output->renderer, drm, renderer);
|
|
|
|
return !drmModeMoveCursor(state->fd, output->crtc->id, x, y);
|
|
|
|
return !drmModeMoveCursor(drm->fd, output->crtc->id, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
|
|
|
static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
|
|
@ -786,9 +810,14 @@ void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) {
|
|
|
|
restore = false;
|
|
|
|
restore = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wlr_drm_plane_renderer_free(renderer, output->crtc->overlay);
|
|
|
|
struct wlr_drm_crtc *crtc = output->crtc;
|
|
|
|
wlr_drm_plane_renderer_free(renderer, output->crtc->primary);
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
wlr_drm_plane_renderer_free(renderer, output->crtc->cursor);
|
|
|
|
wlr_drm_plane_renderer_free(renderer, crtc->planes[i]);
|
|
|
|
|
|
|
|
if (crtc->planes[i] && crtc->planes[i]->id == 0) {
|
|
|
|
|
|
|
|
free(crtc->planes[i]);
|
|
|
|
|
|
|
|
crtc->planes[i] = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
output->crtc = NULL;
|
|
|
|
output->crtc = NULL;
|
|
|
|
output->possible_crtc = 0;
|
|
|
|
output->possible_crtc = 0;
|
|
|
|