drm: Implement hardware plane support

Adds the ability for drm to place native surfaces on harware planes.

ref 33b50238d2
This commit is contained in:
Derek Foreman 2017-06-29 17:15:36 -05:00
parent dc3873c8db
commit fbb676584e
1 changed files with 120 additions and 0 deletions

View File

@ -1,10 +1,19 @@
#include "evas_engine.h"
#include "../software_generic/evas_native_common.h"
typedef struct _Render_Engine
{
Render_Engine_Software_Generic generic;
int fd;
} Render_Engine;
struct scanout_handle
{
Evas_Native_Scanout_Handler handler;
void *data;
};
static Evas_Func func, pfunc;
int _evas_engine_drm_log_dom;
@ -21,6 +30,8 @@ _render_engine_setup(Evas_Engine_Info_Drm *info, int w, int h)
ob = _outbuf_setup(info, w, h);
if (!ob) goto err;
re->fd = info->info.fd;
if (!evas_render_engine_software_generic_init(&re->generic, ob,
_outbuf_state_get,
_outbuf_rotation_get,
@ -108,6 +119,113 @@ eng_output_free(void *engine EINA_UNUSED, void *data)
}
}
static Ecore_Drm2_Fb *
drm_import_simple_dmabuf(int fd, struct dmabuf_attributes *attributes)
{
unsigned int stride[4] = { 0 };
int dmabuf_fd[4] = { 0 };
int i;
for (i = 0; i < attributes->n_planes; i++)
{
stride[i] = attributes->stride[i];
dmabuf_fd[i] = attributes->fd[i];
}
return ecore_drm2_fb_dmabuf_import(fd, attributes->width,
attributes->height, 32, 32,
attributes->format, stride,
dmabuf_fd, attributes->n_planes);
}
static void
_eng_fb_release(Ecore_Drm2_Fb *fb EINA_UNUSED, Ecore_Drm2_Fb_Status status, void *data)
{
struct scanout_handle *sh;
sh = data;
if (status == ECORE_DRM2_FB_STATUS_DELETED)
{
free(sh);
return;
}
if (!sh->handler) return;
switch (status)
{
case ECORE_DRM2_FB_STATUS_SCANOUT_ON:
sh->handler(sh->data, EVAS_NATIVE_SURFACE_STATUS_SCANOUT_ON);
break;
case ECORE_DRM2_FB_STATUS_SCANOUT_OFF:
sh->handler(sh->data, EVAS_NATIVE_SURFACE_STATUS_SCANOUT_OFF);
break;
case ECORE_DRM2_FB_STATUS_PLANE_ASSIGN:
sh->handler(sh->data, EVAS_NATIVE_SURFACE_STATUS_PLANE_ASSIGN);
break;
case ECORE_DRM2_FB_STATUS_PLANE_RELEASE:
sh->handler(sh->data, EVAS_NATIVE_SURFACE_STATUS_PLANE_RELEASE);
break;
default:
ERR("Unhandled framebuffer status");
}
}
static void *
eng_image_plane_assign(void *data, void *image, int x, int y)
{
Render_Engine *re;
Outbuf *ob;
RGBA_Image *img;
Native *n;
Ecore_Drm2_Fb *fb = NULL;
Ecore_Drm2_Plane *plane;
struct scanout_handle *g;
EINA_SAFETY_ON_NULL_RETURN_VAL(image, EINA_FALSE);
re = (Render_Engine *)data;
EINA_SAFETY_ON_NULL_RETURN_VAL(re, EINA_FALSE);
ob = re->generic.ob;
EINA_SAFETY_ON_NULL_RETURN_VAL(ob, EINA_FALSE);
img = image;
n = img->native.data;
/* Perhaps implementable on other surface types, but we're
* sticking to this one for now */
if (n->ns.type != EVAS_NATIVE_SURFACE_WL_DMABUF) return NULL;
fb = drm_import_simple_dmabuf(re->fd, &n->ns_data.wl_surface_dmabuf.attr);
if (!fb) return NULL;
g = calloc(1, sizeof(struct scanout_handle));
if (!g) goto out;
g->handler = n->ns.data.wl_dmabuf.scanout.handler;
g->data = n->ns.data.wl_dmabuf.scanout.data;
ecore_drm2_fb_status_handler_set(fb, _eng_fb_release, g);
/* Fail or not, we're going to drop that fb and let refcounting get rid of
* it later
*/
plane = ecore_drm2_plane_assign(ob->priv.output, fb, x, y);
out:
ecore_drm2_fb_discard(fb);
return plane;
}
static void
eng_image_plane_release(void *data EINA_UNUSED, void *image EINA_UNUSED, void *plin)
{
Ecore_Drm2_Plane *plane = plin;
ecore_drm2_plane_release(plane);
}
static int
module_open(Evas_Module *em)
{
@ -139,6 +257,8 @@ module_open(Evas_Module *em)
EVAS_API_OVERRIDE(setup, &func, eng_);
EVAS_API_OVERRIDE(update, &func, eng_);
EVAS_API_OVERRIDE(output_free, &func, eng_);
EVAS_API_OVERRIDE(image_plane_assign, &func, eng_);
EVAS_API_OVERRIDE(image_plane_release, &func, eng_);
/* advertise our engine functions */
em->functions = (void *)(&func);