mirror of
https://github.com/brl/mutter.git
synced 2024-11-21 23:50:41 -05:00
drm-buffer: Add getters for more metadata
Mostly calls into gbm_bo_* API, or something somewhat similar when on dumb buffers. Added API are: * get offset for plane * get bpp (bits per pixel) * get modifier This will allow users of MetaDrmBuffer to avoid having to "extract" the gbm_bo to get these metadata. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1854>
This commit is contained in:
parent
bece36b4ad
commit
e078718180
@ -25,6 +25,7 @@
|
||||
|
||||
#include "backends/native/meta-drm-buffer-dumb.h"
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include <gio/gio.h>
|
||||
#include <xf86drm.h>
|
||||
#include <fcntl.h>
|
||||
@ -44,6 +45,7 @@ struct _MetaDrmBufferDumb
|
||||
int stride_bytes;
|
||||
uint32_t drm_format;
|
||||
int dmabuf_fd;
|
||||
int offset;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaDrmBufferDumb, meta_drm_buffer_dumb, META_TYPE_DRM_BUFFER)
|
||||
@ -80,6 +82,84 @@ meta_drm_buffer_dumb_get_format (MetaDrmBuffer *buffer)
|
||||
return buffer_dumb->drm_format;
|
||||
}
|
||||
|
||||
static int
|
||||
meta_drm_buffer_dumb_get_bpp (MetaDrmBuffer *buffer)
|
||||
{
|
||||
MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (buffer);
|
||||
|
||||
switch (buffer_dumb->drm_format)
|
||||
{
|
||||
case DRM_FORMAT_C8:
|
||||
case DRM_FORMAT_R8:
|
||||
case DRM_FORMAT_RGB332:
|
||||
case DRM_FORMAT_BGR233:
|
||||
return 8;
|
||||
case DRM_FORMAT_GR88:
|
||||
case DRM_FORMAT_XRGB4444:
|
||||
case DRM_FORMAT_XBGR4444:
|
||||
case DRM_FORMAT_RGBX4444:
|
||||
case DRM_FORMAT_BGRX4444:
|
||||
case DRM_FORMAT_ARGB4444:
|
||||
case DRM_FORMAT_ABGR4444:
|
||||
case DRM_FORMAT_RGBA4444:
|
||||
case DRM_FORMAT_BGRA4444:
|
||||
case DRM_FORMAT_XRGB1555:
|
||||
case DRM_FORMAT_XBGR1555:
|
||||
case DRM_FORMAT_RGBX5551:
|
||||
case DRM_FORMAT_BGRX5551:
|
||||
case DRM_FORMAT_ARGB1555:
|
||||
case DRM_FORMAT_ABGR1555:
|
||||
case DRM_FORMAT_RGBA5551:
|
||||
case DRM_FORMAT_BGRA5551:
|
||||
case DRM_FORMAT_RGB565:
|
||||
case DRM_FORMAT_BGR565:
|
||||
return 16;
|
||||
case DRM_FORMAT_RGB888:
|
||||
case DRM_FORMAT_BGR888:
|
||||
return 24;
|
||||
case DRM_FORMAT_XRGB8888:
|
||||
case DRM_FORMAT_XBGR8888:
|
||||
case DRM_FORMAT_RGBX8888:
|
||||
case DRM_FORMAT_BGRX8888:
|
||||
case DRM_FORMAT_ARGB8888:
|
||||
case DRM_FORMAT_ABGR8888:
|
||||
case DRM_FORMAT_RGBA8888:
|
||||
case DRM_FORMAT_BGRA8888:
|
||||
case DRM_FORMAT_XRGB2101010:
|
||||
case DRM_FORMAT_XBGR2101010:
|
||||
case DRM_FORMAT_RGBX1010102:
|
||||
case DRM_FORMAT_BGRX1010102:
|
||||
case DRM_FORMAT_ARGB2101010:
|
||||
case DRM_FORMAT_ABGR2101010:
|
||||
case DRM_FORMAT_RGBA1010102:
|
||||
case DRM_FORMAT_BGRA1010102:
|
||||
return 32;
|
||||
case DRM_FORMAT_XBGR16161616F:
|
||||
case DRM_FORMAT_ABGR16161616F:
|
||||
return 64;
|
||||
default:
|
||||
g_warn_if_reached ();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
meta_drm_buffer_dumb_get_offset (MetaDrmBuffer *buffer,
|
||||
int plane)
|
||||
{
|
||||
MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (buffer);
|
||||
|
||||
g_warn_if_fail (plane == 0);
|
||||
|
||||
return buffer_dumb->offset;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_dumb_get_modifier (MetaDrmBuffer *buffer)
|
||||
{
|
||||
return DRM_FORMAT_MOD_LINEAR;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_to_dmabuf_fd (MetaDrmBufferDumb *buffer_dumb,
|
||||
GError **error)
|
||||
@ -196,6 +276,7 @@ init_dumb_buffer (MetaDrmBufferDumb *buffer_dumb,
|
||||
buffer_dumb->height = height;
|
||||
buffer_dumb->stride_bytes = create_arg.pitch;
|
||||
buffer_dumb->drm_format = format;
|
||||
buffer_dumb->offset = map_arg.offset;
|
||||
|
||||
return TRUE;
|
||||
|
||||
@ -283,5 +364,8 @@ meta_drm_buffer_dumb_class_init (MetaDrmBufferDumbClass *klass)
|
||||
buffer_class->get_width = meta_drm_buffer_dumb_get_width;
|
||||
buffer_class->get_height = meta_drm_buffer_dumb_get_height;
|
||||
buffer_class->get_stride = meta_drm_buffer_dumb_get_stride;
|
||||
buffer_class->get_bpp = meta_drm_buffer_dumb_get_bpp;
|
||||
buffer_class->get_format = meta_drm_buffer_dumb_get_format;
|
||||
buffer_class->get_offset = meta_drm_buffer_dumb_get_offset;
|
||||
buffer_class->get_modifier = meta_drm_buffer_dumb_get_modifier;
|
||||
}
|
||||
|
@ -81,6 +81,14 @@ meta_drm_buffer_gbm_get_stride (MetaDrmBuffer *buffer)
|
||||
return gbm_bo_get_stride (buffer_gbm->bo);
|
||||
}
|
||||
|
||||
static int
|
||||
meta_drm_buffer_gbm_get_bpp (MetaDrmBuffer *buffer)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
|
||||
|
||||
return gbm_bo_get_bpp (buffer_gbm->bo);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_gbm_get_format (MetaDrmBuffer *buffer)
|
||||
{
|
||||
@ -89,6 +97,23 @@ meta_drm_buffer_gbm_get_format (MetaDrmBuffer *buffer)
|
||||
return gbm_bo_get_format (buffer_gbm->bo);
|
||||
}
|
||||
|
||||
static int
|
||||
meta_drm_buffer_gbm_get_offset (MetaDrmBuffer *buffer,
|
||||
int plane)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
|
||||
|
||||
return gbm_bo_get_offset (buffer_gbm->bo, plane);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_gbm_get_modifier (MetaDrmBuffer *buffer)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
|
||||
|
||||
return gbm_bo_get_modifier (buffer_gbm->bo);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
init_fb_id (MetaDrmBufferGbm *buffer_gbm,
|
||||
struct gbm_bo *bo,
|
||||
@ -469,6 +494,9 @@ meta_drm_buffer_gbm_class_init (MetaDrmBufferGbmClass *klass)
|
||||
buffer_class->get_width = meta_drm_buffer_gbm_get_width;
|
||||
buffer_class->get_height = meta_drm_buffer_gbm_get_height;
|
||||
buffer_class->get_stride = meta_drm_buffer_gbm_get_stride;
|
||||
buffer_class->get_bpp = meta_drm_buffer_gbm_get_bpp;
|
||||
buffer_class->get_format = meta_drm_buffer_gbm_get_format;
|
||||
buffer_class->get_offset = meta_drm_buffer_gbm_get_offset;
|
||||
buffer_class->get_modifier = meta_drm_buffer_gbm_get_modifier;
|
||||
buffer_class->fill_timings = meta_drm_buffer_gbm_fill_timings;
|
||||
}
|
||||
|
@ -68,6 +68,14 @@ meta_drm_buffer_import_get_stride (MetaDrmBuffer *buffer)
|
||||
return meta_drm_buffer_get_stride (META_DRM_BUFFER (buffer_import->importee));
|
||||
}
|
||||
|
||||
static int
|
||||
meta_drm_buffer_import_get_bpp (MetaDrmBuffer *buffer)
|
||||
{
|
||||
MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
|
||||
|
||||
return meta_drm_buffer_get_bpp (META_DRM_BUFFER (buffer_import->importee));
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_import_get_format (MetaDrmBuffer *buffer)
|
||||
{
|
||||
@ -76,6 +84,25 @@ meta_drm_buffer_import_get_format (MetaDrmBuffer *buffer)
|
||||
return meta_drm_buffer_get_format (META_DRM_BUFFER (buffer_import->importee));
|
||||
}
|
||||
|
||||
static int
|
||||
meta_drm_buffer_import_get_offset (MetaDrmBuffer *buffer,
|
||||
int offset)
|
||||
{
|
||||
MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
|
||||
MetaDrmBuffer *importee = META_DRM_BUFFER (buffer_import->importee);
|
||||
|
||||
return meta_drm_buffer_get_offset (importee, offset);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_import_get_modifier (MetaDrmBuffer *buffer)
|
||||
{
|
||||
MetaDrmBufferImport *buffer_import = META_DRM_BUFFER_IMPORT (buffer);
|
||||
MetaDrmBuffer *importee = META_DRM_BUFFER (buffer_import->importee);
|
||||
|
||||
return meta_drm_buffer_get_modifier (importee);
|
||||
}
|
||||
|
||||
static struct gbm_bo *
|
||||
dmabuf_to_gbm_bo (struct gbm_device *importer,
|
||||
int dmabuf_fd,
|
||||
@ -205,5 +232,8 @@ meta_drm_buffer_import_class_init (MetaDrmBufferImportClass *klass)
|
||||
buffer_class->get_width = meta_drm_buffer_import_get_width;
|
||||
buffer_class->get_height = meta_drm_buffer_import_get_height;
|
||||
buffer_class->get_stride = meta_drm_buffer_import_get_stride;
|
||||
buffer_class->get_bpp = meta_drm_buffer_import_get_bpp;
|
||||
buffer_class->get_format = meta_drm_buffer_import_get_format;
|
||||
buffer_class->get_offset = meta_drm_buffer_import_get_offset;
|
||||
buffer_class->get_modifier = meta_drm_buffer_import_get_modifier;
|
||||
}
|
||||
|
@ -39,10 +39,17 @@ struct _MetaDrmBufferClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
int (* export_fd) (MetaDrmBuffer *buffer,
|
||||
GError **error);
|
||||
|
||||
int (* get_width) (MetaDrmBuffer *buffer);
|
||||
int (* get_height) (MetaDrmBuffer *buffer);
|
||||
int (* get_stride) (MetaDrmBuffer *buffer);
|
||||
int (* get_bpp) (MetaDrmBuffer *buffer);
|
||||
uint32_t (* get_format) (MetaDrmBuffer *buffer);
|
||||
int (* get_offset) (MetaDrmBuffer *buffer,
|
||||
int plane);
|
||||
uint32_t (* get_modifier) (MetaDrmBuffer *buffer);
|
||||
|
||||
gboolean (* fill_timings) (MetaDrmBuffer *buffer,
|
||||
CoglFrameInfo *info,
|
||||
|
@ -179,12 +179,31 @@ meta_drm_buffer_get_stride (MetaDrmBuffer *buffer)
|
||||
return META_DRM_BUFFER_GET_CLASS (buffer)->get_stride (buffer);
|
||||
}
|
||||
|
||||
int
|
||||
meta_drm_buffer_get_bpp (MetaDrmBuffer *buffer)
|
||||
{
|
||||
return META_DRM_BUFFER_GET_CLASS (buffer)->get_bpp (buffer);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
meta_drm_buffer_get_format (MetaDrmBuffer *buffer)
|
||||
{
|
||||
return META_DRM_BUFFER_GET_CLASS (buffer)->get_format (buffer);
|
||||
}
|
||||
|
||||
int
|
||||
meta_drm_buffer_get_offset (MetaDrmBuffer *buffer,
|
||||
int plane)
|
||||
{
|
||||
return META_DRM_BUFFER_GET_CLASS (buffer)->get_offset (buffer, plane);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
meta_drm_buffer_get_modifier (MetaDrmBuffer *buffer)
|
||||
{
|
||||
return META_DRM_BUFFER_GET_CLASS (buffer)->get_modifier (buffer);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_drm_buffer_supports_fill_timings (MetaDrmBuffer *buffer)
|
||||
{
|
||||
|
@ -42,8 +42,15 @@ int meta_drm_buffer_get_height (MetaDrmBuffer *buffer);
|
||||
|
||||
int meta_drm_buffer_get_stride (MetaDrmBuffer *buffer);
|
||||
|
||||
int meta_drm_buffer_get_bpp (MetaDrmBuffer *buffer);
|
||||
|
||||
uint32_t meta_drm_buffer_get_format (MetaDrmBuffer *buffer);
|
||||
|
||||
int meta_drm_buffer_get_offset (MetaDrmBuffer *buffer,
|
||||
int plane);
|
||||
|
||||
uint32_t meta_drm_buffer_get_modifier (MetaDrmBuffer *buffer);
|
||||
|
||||
gboolean meta_drm_buffer_supports_fill_timings (MetaDrmBuffer *buffer);
|
||||
|
||||
gboolean meta_drm_buffer_fill_timings (MetaDrmBuffer *buffer,
|
||||
|
Loading…
Reference in New Issue
Block a user