mirror of
https://github.com/brl/mutter.git
synced 2024-11-24 17:10:40 -05:00
drm-buffer: Replace 'use-modifier' boolean with flags
This lets us add more customization to the buffer instance without adding more boolean arguments. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1854>
This commit is contained in:
parent
99f51d2866
commit
6ba86366b3
@ -1260,6 +1260,7 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
|
||||
uint8_t buf[4 * cursor_width * cursor_height];
|
||||
uint i;
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaDrmBufferFlags flags;
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
|
||||
device_file = meta_device_pool_open (device_pool,
|
||||
@ -1293,7 +1294,9 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
|
||||
return;
|
||||
}
|
||||
|
||||
buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
|
||||
flags = META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
||||
buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, flags,
|
||||
&error);
|
||||
if (!buffer_gbm)
|
||||
{
|
||||
meta_warning ("Failed to create DRM buffer wrapper: %s",
|
||||
@ -1587,6 +1590,7 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer *renderer,
|
||||
struct gbm_device *gbm_device;
|
||||
struct gbm_bo *bo;
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaDrmBufferFlags flags;
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
|
||||
device_file = meta_device_pool_open (device_pool,
|
||||
@ -1633,7 +1637,9 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer *renderer,
|
||||
|
||||
unset_can_preprocess (cursor_sprite);
|
||||
|
||||
buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
|
||||
flags = META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
||||
buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, flags,
|
||||
&error);
|
||||
if (!buffer_gbm)
|
||||
{
|
||||
meta_warning ("Failed to create DRM buffer wrapper: %s",
|
||||
|
@ -242,7 +242,7 @@ init_dumb_buffer (MetaDrmBufferDumb *buffer_dumb,
|
||||
.handles = { create_arg.handle },
|
||||
.strides = { create_arg.pitch },
|
||||
};
|
||||
if (!meta_drm_buffer_ensure_fb_id (buffer, FALSE, &fb_args, error))
|
||||
if (!meta_drm_buffer_ensure_fb_id (buffer, &fb_args, error))
|
||||
goto err_add_fb;
|
||||
|
||||
map_arg = (struct drm_mode_map_dumb) {
|
||||
@ -303,6 +303,7 @@ meta_drm_buffer_dumb_new (MetaDeviceFile *device_file,
|
||||
|
||||
buffer_dumb = g_object_new (META_TYPE_DRM_BUFFER_DUMB,
|
||||
"device-file", device_file,
|
||||
"flags", META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS,
|
||||
NULL);
|
||||
|
||||
if (!init_dumb_buffer (buffer_dumb, width, height, format, error))
|
||||
|
@ -117,7 +117,6 @@ meta_drm_buffer_gbm_get_modifier (MetaDrmBuffer *buffer)
|
||||
static gboolean
|
||||
init_fb_id (MetaDrmBufferGbm *buffer_gbm,
|
||||
struct gbm_bo *bo,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
{
|
||||
MetaDrmFbArgs fb_args = { 0, };
|
||||
@ -148,7 +147,7 @@ init_fb_id (MetaDrmBufferGbm *buffer_gbm,
|
||||
fb_args.format = gbm_bo_get_format (bo);
|
||||
|
||||
if (!meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_gbm),
|
||||
use_modifiers, &fb_args, error))
|
||||
&fb_args, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
@ -156,7 +155,6 @@ init_fb_id (MetaDrmBufferGbm *buffer_gbm,
|
||||
|
||||
static gboolean
|
||||
lock_front_buffer (MetaDrmBufferGbm *buffer_gbm,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
{
|
||||
buffer_gbm->bo = gbm_surface_lock_front_buffer (buffer_gbm->surface);
|
||||
@ -169,23 +167,24 @@ lock_front_buffer (MetaDrmBufferGbm *buffer_gbm,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return init_fb_id (buffer_gbm, buffer_gbm->bo, use_modifiers, error);
|
||||
return init_fb_id (buffer_gbm, buffer_gbm->bo, error);
|
||||
}
|
||||
|
||||
MetaDrmBufferGbm *
|
||||
meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile *device_file,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
MetaDrmBufferFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
|
||||
buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
|
||||
"device-file", device_file,
|
||||
"flags", flags,
|
||||
NULL);
|
||||
buffer_gbm->surface = gbm_surface;
|
||||
|
||||
if (!lock_front_buffer (buffer_gbm, use_modifiers, error))
|
||||
if (!lock_front_buffer (buffer_gbm, error))
|
||||
{
|
||||
g_object_unref (buffer_gbm);
|
||||
return NULL;
|
||||
@ -195,18 +194,19 @@ meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile *device_file,
|
||||
}
|
||||
|
||||
MetaDrmBufferGbm *
|
||||
meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
|
||||
struct gbm_bo *bo,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
|
||||
struct gbm_bo *bo,
|
||||
MetaDrmBufferFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
|
||||
buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
|
||||
"device-file", device_file,
|
||||
"flags", flags,
|
||||
NULL);
|
||||
|
||||
if (!init_fb_id (buffer_gbm, bo, use_modifiers, error))
|
||||
if (!init_fb_id (buffer_gbm, bo, error))
|
||||
{
|
||||
g_object_unref (buffer_gbm);
|
||||
return NULL;
|
||||
|
@ -35,14 +35,14 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
|
||||
|
||||
MetaDrmBufferGbm * meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile *device_file,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
MetaDrmBufferFlags flags,
|
||||
GError **error);
|
||||
|
||||
|
||||
MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
|
||||
struct gbm_bo *gbm_bo,
|
||||
gboolean use_modifiers,
|
||||
GError **error);
|
||||
MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
|
||||
struct gbm_bo *gbm_bo,
|
||||
MetaDrmBufferFlags flags,
|
||||
GError **error);
|
||||
|
||||
struct gbm_bo * meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm);
|
||||
|
||||
|
@ -172,7 +172,6 @@ import_gbm_buffer (MetaDrmBufferImport *buffer_import,
|
||||
fb_args.handles[0] = gbm_bo_get_handle (imported_bo).u32;
|
||||
|
||||
ret = meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_import),
|
||||
FALSE /* use_modifiers */,
|
||||
&fb_args,
|
||||
error);
|
||||
|
||||
@ -194,6 +193,7 @@ meta_drm_buffer_import_new (MetaDeviceFile *device_file,
|
||||
|
||||
buffer_import = g_object_new (META_TYPE_DRM_BUFFER_IMPORT,
|
||||
"device-file", device_file,
|
||||
"flags", META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS,
|
||||
NULL);
|
||||
g_set_object (&buffer_import->importee, buffer_gbm);
|
||||
|
||||
|
@ -59,7 +59,6 @@ struct _MetaDrmBufferClass
|
||||
MetaDeviceFile * meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer);
|
||||
|
||||
gboolean meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
|
||||
gboolean use_modifiers,
|
||||
const MetaDrmFbArgs *fb_args,
|
||||
GError **error);
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "backends/native/meta-device-pool.h"
|
||||
#include "backends/native/meta-kms-utils.h"
|
||||
|
||||
#include "meta-private-enum-types.h"
|
||||
|
||||
#define INVALID_FB_ID 0U
|
||||
|
||||
enum
|
||||
@ -38,6 +40,7 @@ enum
|
||||
PROP_0,
|
||||
|
||||
PROP_DEVICE_FILE,
|
||||
PROP_FLAGS,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
@ -47,6 +50,8 @@ static GParamSpec *obj_props[N_PROPS];
|
||||
typedef struct _MetaDrmBufferPrivate
|
||||
{
|
||||
MetaDeviceFile *device_file;
|
||||
MetaDrmBufferFlags flags;
|
||||
|
||||
uint32_t fb_id;
|
||||
} MetaDrmBufferPrivate;
|
||||
|
||||
@ -63,7 +68,6 @@ meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer)
|
||||
|
||||
gboolean
|
||||
meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
|
||||
gboolean use_modifiers,
|
||||
const MetaDrmFbArgs *fb_args,
|
||||
GError **error)
|
||||
{
|
||||
@ -74,7 +78,8 @@ meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
|
||||
|
||||
fd = meta_device_file_get_fd (priv->device_file);
|
||||
|
||||
if (use_modifiers && fb_args->modifiers[0] != DRM_FORMAT_MOD_INVALID)
|
||||
if (!(priv->flags & META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS) &&
|
||||
fb_args->modifiers[0] != DRM_FORMAT_MOD_INVALID)
|
||||
{
|
||||
if (drmModeAddFB2WithModifiers (fd,
|
||||
fb_args->width,
|
||||
@ -239,6 +244,9 @@ meta_drm_buffer_get_property (GObject *object,
|
||||
case PROP_DEVICE_FILE:
|
||||
g_value_set_pointer (value, priv->device_file);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_flags (value, priv->flags);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -259,6 +267,9 @@ meta_drm_buffer_set_property (GObject *object,
|
||||
case PROP_DEVICE_FILE:
|
||||
priv->device_file = g_value_get_pointer (value);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_flags (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -311,5 +322,14 @@ meta_drm_buffer_class_init (MetaDrmBufferClass *klass)
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_props[PROP_FLAGS] =
|
||||
g_param_spec_flags ("flags",
|
||||
"flags",
|
||||
"MetaDrmBufferFlags",
|
||||
META_TYPE_DRM_BUFFER_FLAGS,
|
||||
META_DRM_BUFFER_FLAG_NONE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
||||
}
|
||||
|
@ -28,6 +28,12 @@
|
||||
|
||||
#include "cogl/cogl.h"
|
||||
|
||||
typedef enum _MetaDrmBufferFlags
|
||||
{
|
||||
META_DRM_BUFFER_FLAG_NONE = 0,
|
||||
META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS = 1 << 0,
|
||||
} MetaDrmBufferFlags;
|
||||
|
||||
#define META_TYPE_DRM_BUFFER (meta_drm_buffer_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (MetaDrmBuffer,
|
||||
meta_drm_buffer,
|
||||
|
@ -654,6 +654,7 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
|
||||
GError *error = NULL;
|
||||
gboolean use_modifiers;
|
||||
MetaDeviceFile *device_file;
|
||||
MetaDrmBufferFlags flags;
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
struct gbm_bo *bo;
|
||||
|
||||
@ -705,10 +706,15 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
|
||||
|
||||
use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
|
||||
device_file = secondary_gpu_state->renderer_gpu_data->device_file;
|
||||
|
||||
flags = META_DRM_BUFFER_FLAG_NONE;
|
||||
if (!use_modifiers)
|
||||
flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
||||
|
||||
buffer_gbm =
|
||||
meta_drm_buffer_gbm_new_lock_front (device_file,
|
||||
secondary_gpu_state->gbm.surface,
|
||||
use_modifiers,
|
||||
flags,
|
||||
&error);
|
||||
if (!buffer_gbm)
|
||||
{
|
||||
@ -1016,9 +1022,9 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
|
||||
ClutterFrame *frame = user_data;
|
||||
CoglOnscreenClass *parent_class;
|
||||
gboolean egl_context_changed = FALSE;
|
||||
gboolean use_modifiers;
|
||||
MetaPowerSave power_save_mode;
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaDrmBufferFlags buffer_flags;
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
MetaKmsCrtc *kms_crtc;
|
||||
MetaKmsDevice *kms_device;
|
||||
@ -1047,11 +1053,14 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
|
||||
g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
|
||||
g_clear_object (&onscreen_native->gbm.next_fb);
|
||||
|
||||
use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
|
||||
buffer_flags = META_DRM_BUFFER_FLAG_NONE;
|
||||
if (!meta_renderer_native_use_modifiers (renderer_native))
|
||||
buffer_flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
||||
|
||||
buffer_gbm =
|
||||
meta_drm_buffer_gbm_new_lock_front (render_device_file,
|
||||
onscreen_native->gbm.surface,
|
||||
use_modifiers,
|
||||
buffer_flags,
|
||||
&error);
|
||||
if (!buffer_gbm)
|
||||
{
|
||||
|
@ -804,6 +804,7 @@ endif
|
||||
if have_native_backend
|
||||
mutter_private_enum_sources += [
|
||||
'backends/native/meta-backend-native-types.h',
|
||||
'backends/native/meta-drm-buffer.h',
|
||||
'backends/native/meta-kms-types.h',
|
||||
]
|
||||
endif
|
||||
|
@ -694,6 +694,7 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
|
||||
uint32_t drm_format;
|
||||
uint64_t drm_modifier;
|
||||
uint32_t stride;
|
||||
MetaDrmBufferFlags flags;
|
||||
MetaDrmBufferGbm *fb;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
@ -719,10 +720,11 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fb = meta_drm_buffer_gbm_new_take (device_file,
|
||||
gbm_bo,
|
||||
drm_modifier != DRM_FORMAT_MOD_INVALID,
|
||||
&error);
|
||||
flags = META_DRM_BUFFER_FLAG_NONE;
|
||||
if (drm_modifier == DRM_FORMAT_MOD_INVALID)
|
||||
flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
||||
|
||||
fb = meta_drm_buffer_gbm_new_take (device_file, gbm_bo, flags, &error);
|
||||
if (!fb)
|
||||
{
|
||||
g_debug ("Failed to create scanout buffer: %s", error->message);
|
||||
|
@ -295,6 +295,7 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
|
||||
struct gbm_bo *gbm_bo;
|
||||
gboolean use_modifier;
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaDrmBufferFlags flags;
|
||||
MetaDrmBufferGbm *fb;
|
||||
|
||||
for (n_planes = 0; n_planes < META_WAYLAND_DMA_BUF_MAX_FDS; n_planes++)
|
||||
@ -321,10 +322,11 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fb = meta_drm_buffer_gbm_new_take (device_file,
|
||||
gbm_bo,
|
||||
use_modifier,
|
||||
&error);
|
||||
flags = META_DRM_BUFFER_FLAG_NONE;
|
||||
if (!use_modifier)
|
||||
flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
|
||||
|
||||
fb = meta_drm_buffer_gbm_new_take (device_file, gbm_bo, flags, &error);
|
||||
if (!fb)
|
||||
{
|
||||
g_debug ("Failed to create scanout buffer: %s", error->message);
|
||||
|
Loading…
Reference in New Issue
Block a user