uterm: video: return buffer information on display_use()

uterm_display_use() now returns the current back-buffer index when called.
It returns <0 on error. Whether OpenGL is supported is returned via a new
parameter "opengl". Set it to NULL if you're not interested.

Note that a backend might support OpenGL _and_ memory-mapped buffer
access. But you shouldn't rely on uterm_display_use() to return the
correct buffer-index if uterm_display_get_buffers() is not supported. For
instance the DRM-3D backend always returns 0 as buffer index as it has no
way of detecting it, yet.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2013-01-14 20:57:15 +01:00
parent 0b25c9f68a
commit 3eb9cc6f50
8 changed files with 46 additions and 17 deletions

View File

@ -201,6 +201,7 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp)
unsigned int cols, rows; unsigned int cols, rows;
struct kmscon_font_attr attr = { "", 0, 20, false, false, 0, 0 }; struct kmscon_font_attr attr = { "", 0, 20, false, false, 0, 0 };
const char *be; const char *be;
bool opengl;
attr.ppi = term->conf->font_ppi; attr.ppi = term->conf->font_ppi;
attr.points = term->conf->font_size; attr.points = term->conf->font_size;
@ -242,10 +243,10 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp)
kmscon_font_ref(scr->bold_font); kmscon_font_ref(scr->bold_font);
} }
ret = uterm_display_use(scr->disp); ret = uterm_display_use(scr->disp, &opengl);
if (term->conf->render_engine) if (term->conf->render_engine)
be = term->conf->render_engine; be = term->conf->render_engine;
else if (!ret) else if (ret >= 0 && opengl)
be = "gltex"; be = "gltex";
else else
be = "bbulk"; be = "bbulk";

View File

@ -147,6 +147,7 @@ static int gltex_set(struct kmscon_text *txt)
GLint s; GLint s;
const char *ext; const char *ext;
struct uterm_mode *mode; struct uterm_mode *mode;
bool opengl;
memset(gt, 0, sizeof(*gt)); memset(gt, 0, sizeof(*gt));
shl_dlist_init(&gt->atlases); shl_dlist_init(&gt->atlases);
@ -163,8 +164,8 @@ static int gltex_set(struct kmscon_text *txt)
if (ret) if (ret)
goto err_htable; goto err_htable;
ret = uterm_display_use(txt->disp); ret = uterm_display_use(txt->disp, &opengl);
if (ret) { if (ret < 0 || !opengl) {
if (ret == -EOPNOTSUPP) if (ret == -EOPNOTSUPP)
log_error("display doesn't support hardware-acceleration"); log_error("display doesn't support hardware-acceleration");
goto err_bold_htable; goto err_bold_htable;
@ -231,7 +232,7 @@ static void gltex_unset(struct kmscon_text *txt)
struct atlas *atlas; struct atlas *atlas;
bool gl = true; bool gl = true;
ret = uterm_display_use(txt->disp); ret = uterm_display_use(txt->disp, NULL);
if (ret) { if (ret) {
gl = false; gl = false;
log_warning("cannot activate OpenGL-CTX during destruction"); log_warning("cannot activate OpenGL-CTX during destruction");
@ -526,7 +527,7 @@ static int gltex_prepare(struct kmscon_text *txt)
struct shl_dlist *iter; struct shl_dlist *iter;
int ret; int ret;
ret = uterm_display_use(txt->disp); ret = uterm_display_use(txt->disp, NULL);
if (ret) if (ret)
return ret; return ret;

View File

@ -430,6 +430,19 @@ static int display_set_dpms(struct uterm_display *disp, int state)
return 0; return 0;
} }
static int display_use(struct uterm_display *disp, bool *opengl)
{
struct fbdev_display *dfb = disp->data;
if (opengl)
*opengl = false;
if (!(disp->flags & DISPLAY_DBUF))
return 0;
return dfb->bufid ^ 1;
}
static int display_get_buffers(struct uterm_display *disp, static int display_get_buffers(struct uterm_display *disp,
struct uterm_video_buffer *buffer, struct uterm_video_buffer *buffer,
unsigned int formats) unsigned int formats)
@ -499,7 +512,7 @@ static const struct display_ops fbdev_display_ops = {
.activate = display_activate, .activate = display_activate,
.deactivate = display_deactivate, .deactivate = display_deactivate,
.set_dpms = display_set_dpms, .set_dpms = display_set_dpms,
.use = NULL, .use = display_use,
.get_buffers = display_get_buffers, .get_buffers = display_get_buffers,
.swap = display_swap, .swap = display_swap,
.blit = uterm_fbdev_display_blit, .blit = uterm_fbdev_display_blit,

View File

@ -415,12 +415,12 @@ int uterm_display_get_dpms(const struct uterm_display *disp)
return disp->dpms; return disp->dpms;
} }
int uterm_display_use(struct uterm_display *disp) int uterm_display_use(struct uterm_display *disp, bool *opengl)
{ {
if (!disp || !display_is_online(disp)) if (!disp || !display_is_online(disp))
return -EINVAL; return -EINVAL;
return VIDEO_CALL(disp->ops->use, -EOPNOTSUPP, disp); return VIDEO_CALL(disp->ops->use, -EOPNOTSUPP, disp, opengl);
} }
int uterm_display_get_buffers(struct uterm_display *disp, int uterm_display_get_buffers(struct uterm_display *disp,

View File

@ -164,7 +164,7 @@ void uterm_display_deactivate(struct uterm_display *disp);
int uterm_display_set_dpms(struct uterm_display *disp, int state); int uterm_display_set_dpms(struct uterm_display *disp, int state);
int uterm_display_get_dpms(const struct uterm_display *disp); int uterm_display_get_dpms(const struct uterm_display *disp);
int uterm_display_use(struct uterm_display *disp); int uterm_display_use(struct uterm_display *disp, bool *opengl);
int uterm_display_get_buffers(struct uterm_display *disp, int uterm_display_get_buffers(struct uterm_display *disp,
struct uterm_video_buffer *buffer, struct uterm_video_buffer *buffer,
unsigned int formats); unsigned int formats);

View File

@ -305,7 +305,7 @@ static void display_deactivate(struct uterm_display *disp)
disp->current_mode = NULL; disp->current_mode = NULL;
} }
static int display_use(struct uterm_display *disp) static int display_use(struct uterm_display *disp, bool *opengl)
{ {
struct uterm_drm3d_display *d3d = uterm_drm_display_get_data(disp); struct uterm_drm3d_display *d3d = uterm_drm_display_get_data(disp);
struct uterm_drm3d_video *v3d; struct uterm_drm3d_video *v3d;
@ -317,6 +317,10 @@ static int display_use(struct uterm_display *disp)
return -EFAULT; return -EFAULT;
} }
if (opengl)
*opengl = true;
/* TODO: lets find a way how to retrieve the current front buffer */
return 0; return 0;
} }
@ -461,7 +465,7 @@ static int display_blit(struct uterm_display *disp,
return -EINVAL; return -EINVAL;
v3d = uterm_drm_video_get_data(disp->video); v3d = uterm_drm_video_get_data(disp->video);
ret = display_use(disp); ret = display_use(disp, NULL);
if (ret) if (ret)
return ret; return ret;
ret = init_shaders(disp->video); ret = init_shaders(disp->video);
@ -590,7 +594,7 @@ static int display_blend(struct uterm_display *disp,
return -EINVAL; return -EINVAL;
v3d = uterm_drm_video_get_data(disp->video); v3d = uterm_drm_video_get_data(disp->video);
ret = display_use(disp); ret = display_use(disp, NULL);
if (ret) if (ret)
return ret; return ret;
ret = init_shaders(disp->video); ret = init_shaders(disp->video);
@ -748,7 +752,7 @@ static int display_fill(struct uterm_display *disp,
int ret; int ret;
v3d = uterm_drm_video_get_data(disp->video); v3d = uterm_drm_video_get_data(disp->video);
ret = display_use(disp); ret = display_use(disp, NULL);
if (ret) if (ret)
return ret; return ret;
ret = init_shaders(disp->video); ret = init_shaders(disp->video);
@ -843,7 +847,7 @@ static void show_displays(struct uterm_video *video)
if (iter->dpms != UTERM_DPMS_ON) if (iter->dpms != UTERM_DPMS_ON)
continue; continue;
ret = display_use(iter); ret = display_use(iter, NULL);
if (ret) if (ret)
continue; continue;

View File

@ -240,6 +240,16 @@ static void display_deactivate(struct uterm_display *disp)
disp->current_mode = NULL; disp->current_mode = NULL;
} }
static int display_use(struct uterm_display *disp, bool *opengl)
{
struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp);
if (opengl)
*opengl = false;
return d2d->current_rb ^ 1;
}
static int display_get_buffers(struct uterm_display *disp, static int display_get_buffers(struct uterm_display *disp,
struct uterm_video_buffer *buffer, struct uterm_video_buffer *buffer,
unsigned int formats) unsigned int formats)
@ -449,7 +459,7 @@ static const struct display_ops dumb_display_ops = {
.activate = display_activate, .activate = display_activate,
.deactivate = display_deactivate, .deactivate = display_deactivate,
.set_dpms = uterm_drm_display_set_dpms, .set_dpms = uterm_drm_display_set_dpms,
.use = NULL, .use = display_use,
.get_buffers = display_get_buffers, .get_buffers = display_get_buffers,
.swap = display_swap, .swap = display_swap,
.blit = display_blit, .blit = display_blit,

View File

@ -53,7 +53,7 @@ struct display_ops {
int (*activate) (struct uterm_display *disp, struct uterm_mode *mode); int (*activate) (struct uterm_display *disp, struct uterm_mode *mode);
void (*deactivate) (struct uterm_display *disp); void (*deactivate) (struct uterm_display *disp);
int (*set_dpms) (struct uterm_display *disp, int state); int (*set_dpms) (struct uterm_display *disp, int state);
int (*use) (struct uterm_display *disp); int (*use) (struct uterm_display *disp, bool *opengl);
int (*get_buffers) (struct uterm_display *disp, int (*get_buffers) (struct uterm_display *disp,
struct uterm_video_buffer *buffer, struct uterm_video_buffer *buffer,
unsigned int formats); unsigned int formats);