mirror of
https://github.com/brl/mutter.git
synced 2024-11-24 17:10:40 -05:00
drm-buffer: Make the "types" actual types
There is no reason why we should have an internal type enum when we have all the infrastructure to just use multiple GObject types. Also there was no code sharing between the old "types", the only common API was getting the framebuffer ID, so lets make that a vfunc. https://gitlab.gnome.org/GNOME/mutter/merge_requests/584
This commit is contained in:
parent
ed56edc7ba
commit
91ac64bb44
65
src/backends/native/meta-drm-buffer-dumb.c
Normal file
65
src/backends/native/meta-drm-buffer-dumb.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
* Copyright (C) 2016 Red Hat
|
||||
* Copyright (C) 2018 DisplayLink (UK) Ltd.
|
||||
* Copyright (C) 2018 Canonical Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "backends/native/meta-drm-buffer-dumb.h"
|
||||
|
||||
struct _MetaDrmBufferDumb
|
||||
{
|
||||
MetaDrmBuffer parent;
|
||||
|
||||
uint32_t fb_id;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaDrmBufferDumb, meta_drm_buffer_dumb, META_TYPE_DRM_BUFFER)
|
||||
|
||||
MetaDrmBufferDumb *
|
||||
meta_drm_buffer_dumb_new (uint32_t dumb_fb_id)
|
||||
{
|
||||
MetaDrmBufferDumb *buffer_dumb;
|
||||
|
||||
buffer_dumb = g_object_new (META_TYPE_DRM_BUFFER_DUMB, NULL);
|
||||
buffer_dumb->fb_id = dumb_fb_id;
|
||||
|
||||
return buffer_dumb;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_dumb_get_fb_id (MetaDrmBuffer *buffer)
|
||||
{
|
||||
return META_DRM_BUFFER_DUMB (buffer)->fb_id;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_dumb_init (MetaDrmBufferDumb *buffer_dumb)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_dumb_class_init (MetaDrmBufferDumbClass *klass)
|
||||
{
|
||||
MetaDrmBufferClass *buffer_class = META_DRM_BUFFER_CLASS (klass);
|
||||
|
||||
buffer_class->get_fb_id = meta_drm_buffer_dumb_get_fb_id;
|
||||
}
|
35
src/backends/native/meta-drm-buffer-dumb.h
Normal file
35
src/backends/native/meta-drm-buffer-dumb.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Canonical Ltd.
|
||||
* Copyright (C) 2019 Red Hat Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef META_DRM_BUFFER_DUMB_H
|
||||
#define META_DRM_BUFFER_DUMB_H
|
||||
|
||||
#include "backends/native/meta-drm-buffer.h"
|
||||
|
||||
#define META_TYPE_DRM_BUFFER_DUMB (meta_drm_buffer_dumb_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaDrmBufferDumb,
|
||||
meta_drm_buffer_dumb,
|
||||
META, DRM_BUFFER_DUMB,
|
||||
MetaDrmBuffer)
|
||||
|
||||
MetaDrmBufferDumb * meta_drm_buffer_dumb_new (uint32_t dumb_fb_id);
|
||||
|
||||
#endif /* META_DRM_BUFFER_DUMB_H */
|
232
src/backends/native/meta-drm-buffer-gbm.c
Normal file
232
src/backends/native/meta-drm-buffer-gbm.c
Normal file
@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Intel Corporation.
|
||||
* Copyright (C) 2016 Red Hat
|
||||
* Copyright (C) 2018 DisplayLink (UK) Ltd.
|
||||
* Copyright (C) 2018 Canonical Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "backends/native/meta-drm-buffer-gbm.h"
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include <errno.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#define INVALID_FB_ID 0U
|
||||
|
||||
struct _MetaDrmBufferGbm
|
||||
{
|
||||
MetaDrmBuffer parent;
|
||||
|
||||
MetaGpuKms *gpu_kms;
|
||||
|
||||
struct gbm_surface *surface;
|
||||
|
||||
struct gbm_bo *bo;
|
||||
uint32_t fb_id;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaDrmBufferGbm, meta_drm_buffer_gbm, META_TYPE_DRM_BUFFER)
|
||||
|
||||
struct gbm_bo *
|
||||
meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm)
|
||||
{
|
||||
return buffer_gbm->bo;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
acquire_swapped_buffer (MetaDrmBufferGbm *buffer_gbm,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
{
|
||||
uint32_t handles[4] = {0, 0, 0, 0};
|
||||
uint32_t strides[4] = {0, 0, 0, 0};
|
||||
uint32_t offsets[4] = {0, 0, 0, 0};
|
||||
uint64_t modifiers[4] = {0, 0, 0, 0};
|
||||
uint32_t width, height;
|
||||
uint32_t format;
|
||||
struct gbm_bo *bo;
|
||||
int kms_fd;
|
||||
|
||||
kms_fd = meta_gpu_kms_get_fd (buffer_gbm->gpu_kms);
|
||||
|
||||
bo = gbm_surface_lock_front_buffer (buffer_gbm->surface);
|
||||
if (!bo)
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"gbm_surface_lock_front_buffer failed");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (gbm_bo_get_handle_for_plane (bo, 0).s32 == -1)
|
||||
{
|
||||
/* Failed to fetch handle to plane, falling back to old method */
|
||||
strides[0] = gbm_bo_get_stride (bo);
|
||||
handles[0] = gbm_bo_get_handle (bo).u32;
|
||||
offsets[0] = 0;
|
||||
modifiers[0] = DRM_FORMAT_MOD_INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < gbm_bo_get_plane_count (bo); i++)
|
||||
{
|
||||
strides[i] = gbm_bo_get_stride_for_plane (bo, i);
|
||||
handles[i] = gbm_bo_get_handle_for_plane (bo, i).u32;
|
||||
offsets[i] = gbm_bo_get_offset (bo, i);
|
||||
modifiers[i] = gbm_bo_get_modifier (bo);
|
||||
}
|
||||
}
|
||||
|
||||
width = gbm_bo_get_width (bo);
|
||||
height = gbm_bo_get_height (bo);
|
||||
format = gbm_bo_get_format (bo);
|
||||
|
||||
if (use_modifiers && modifiers[0] != DRM_FORMAT_MOD_INVALID)
|
||||
{
|
||||
if (drmModeAddFB2WithModifiers (kms_fd,
|
||||
width, height,
|
||||
format,
|
||||
handles,
|
||||
strides,
|
||||
offsets,
|
||||
modifiers,
|
||||
&buffer_gbm->fb_id,
|
||||
DRM_MODE_FB_MODIFIERS))
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
"drmModeAddFB2WithModifiers failed: %s",
|
||||
g_strerror (errno));
|
||||
gbm_surface_release_buffer (buffer_gbm->surface, bo);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else if (drmModeAddFB2 (kms_fd,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
handles,
|
||||
strides,
|
||||
offsets,
|
||||
&buffer_gbm->fb_id,
|
||||
0))
|
||||
{
|
||||
if (format != DRM_FORMAT_XRGB8888)
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"drmModeAddFB does not support format 0x%x",
|
||||
format);
|
||||
gbm_surface_release_buffer (buffer_gbm->surface, bo);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (drmModeAddFB (kms_fd,
|
||||
width,
|
||||
height,
|
||||
24,
|
||||
32,
|
||||
strides[0],
|
||||
handles[0],
|
||||
&buffer_gbm->fb_id))
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
"drmModeAddFB failed: %s",
|
||||
g_strerror (errno));
|
||||
gbm_surface_release_buffer (buffer_gbm->surface, bo);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_gbm->bo = bo;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
MetaDrmBufferGbm *
|
||||
meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
|
||||
buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM, NULL);
|
||||
buffer_gbm->gpu_kms = gpu_kms;
|
||||
buffer_gbm->surface = gbm_surface;
|
||||
|
||||
if (!acquire_swapped_buffer (buffer_gbm, use_modifiers, error))
|
||||
{
|
||||
g_object_unref (buffer_gbm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buffer_gbm;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
meta_drm_buffer_gbm_get_fb_id (MetaDrmBuffer *buffer)
|
||||
{
|
||||
return META_DRM_BUFFER_GBM (buffer)->fb_id;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_gbm_finalize (GObject *object)
|
||||
{
|
||||
MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (object);
|
||||
|
||||
if (buffer_gbm->fb_id != INVALID_FB_ID)
|
||||
{
|
||||
int kms_fd;
|
||||
|
||||
kms_fd = meta_gpu_kms_get_fd (buffer_gbm->gpu_kms);
|
||||
drmModeRmFB (kms_fd, buffer_gbm->fb_id);
|
||||
}
|
||||
|
||||
if (buffer_gbm->bo)
|
||||
gbm_surface_release_buffer (buffer_gbm->surface, buffer_gbm->bo);
|
||||
|
||||
G_OBJECT_CLASS (meta_drm_buffer_gbm_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_gbm_init (MetaDrmBufferGbm *buffer_gbm)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_gbm_class_init (MetaDrmBufferGbmClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
MetaDrmBufferClass *buffer_class = META_DRM_BUFFER_CLASS (klass);
|
||||
|
||||
object_class->finalize = meta_drm_buffer_gbm_finalize;
|
||||
|
||||
buffer_class->get_fb_id = meta_drm_buffer_gbm_get_fb_id;
|
||||
}
|
43
src/backends/native/meta-drm-buffer-gbm.h
Normal file
43
src/backends/native/meta-drm-buffer-gbm.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Canonical Ltd.
|
||||
* Copyright (C) 2019 Red Hat Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef META_DRM_BUFFER_GBM_H
|
||||
#define META_DRM_BUFFER_GBM_H
|
||||
|
||||
#include <gbm.h>
|
||||
|
||||
#include "backends/native/meta-drm-buffer.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
|
||||
#define META_TYPE_DRM_BUFFER_GBM (meta_drm_buffer_gbm_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
|
||||
meta_drm_buffer_gbm,
|
||||
META, DRM_BUFFER_GBM,
|
||||
MetaDrmBuffer)
|
||||
|
||||
MetaDrmBufferGbm * meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
GError **error);
|
||||
|
||||
struct gbm_bo * meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm);
|
||||
|
||||
#endif /* META_DRM_BUFFER_GBM_H */
|
@ -26,165 +26,12 @@
|
||||
|
||||
#include "backends/native/meta-drm-buffer.h"
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
#include <errno.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
G_DEFINE_ABSTRACT_TYPE (MetaDrmBuffer, meta_drm_buffer, G_TYPE_OBJECT)
|
||||
|
||||
#define INVALID_FB_ID 0U
|
||||
|
||||
typedef enum _MetaDrmBufferType
|
||||
uint32_t
|
||||
meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer)
|
||||
{
|
||||
META_DRM_BUFFER_TYPE_GBM,
|
||||
META_DRM_BUFFER_TYPE_WRAPPED_DUMB
|
||||
} MetaDrmBufferType;
|
||||
|
||||
struct _MetaDrmBuffer
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
MetaDrmBufferType type;
|
||||
|
||||
union
|
||||
{
|
||||
uint32_t fb_id;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t fb_id;
|
||||
struct gbm_surface *surface;
|
||||
struct gbm_bo *bo;
|
||||
MetaGpuKms *gpu_kms;
|
||||
} gbm;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t fb_id;
|
||||
} wrapped_dumb;
|
||||
};
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaDrmBuffer, meta_drm_buffer, G_TYPE_OBJECT)
|
||||
|
||||
static gboolean
|
||||
meta_drm_buffer_acquire_swapped_buffer (MetaDrmBuffer *buffer,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
{
|
||||
uint32_t handles[4] = {0, 0, 0, 0};
|
||||
uint32_t strides[4] = {0, 0, 0, 0};
|
||||
uint32_t offsets[4] = {0, 0, 0, 0};
|
||||
uint64_t modifiers[4] = {0, 0, 0, 0};
|
||||
uint32_t width, height, format;
|
||||
struct gbm_bo *bo;
|
||||
int i;
|
||||
int kms_fd;
|
||||
|
||||
g_assert (buffer->type == META_DRM_BUFFER_TYPE_GBM);
|
||||
g_assert (!buffer->gbm.bo);
|
||||
g_assert (buffer->gbm.surface);
|
||||
g_assert (buffer->gbm.gpu_kms);
|
||||
|
||||
kms_fd = meta_gpu_kms_get_fd (buffer->gbm.gpu_kms);
|
||||
|
||||
bo = gbm_surface_lock_front_buffer (buffer->gbm.surface);
|
||||
if (!bo)
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"gbm_surface_lock_front_buffer failed");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (gbm_bo_get_handle_for_plane (bo, 0).s32 == -1)
|
||||
{
|
||||
/* Failed to fetch handle to plane, falling back to old method */
|
||||
strides[0] = gbm_bo_get_stride (bo);
|
||||
handles[0] = gbm_bo_get_handle (bo).u32;
|
||||
offsets[0] = 0;
|
||||
modifiers[0] = DRM_FORMAT_MOD_INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < gbm_bo_get_plane_count (bo); i++)
|
||||
{
|
||||
strides[i] = gbm_bo_get_stride_for_plane (bo, i);
|
||||
handles[i] = gbm_bo_get_handle_for_plane (bo, i).u32;
|
||||
offsets[i] = gbm_bo_get_offset (bo, i);
|
||||
modifiers[i] = gbm_bo_get_modifier (bo);
|
||||
}
|
||||
}
|
||||
|
||||
width = gbm_bo_get_width (bo);
|
||||
height = gbm_bo_get_height (bo);
|
||||
format = gbm_bo_get_format (bo);
|
||||
|
||||
if (use_modifiers && modifiers[0] != DRM_FORMAT_MOD_INVALID)
|
||||
{
|
||||
if (drmModeAddFB2WithModifiers (kms_fd,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
handles,
|
||||
strides,
|
||||
offsets,
|
||||
modifiers,
|
||||
&buffer->fb_id,
|
||||
DRM_MODE_FB_MODIFIERS))
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
"drmModeAddFB2WithModifiers failed: %s",
|
||||
g_strerror (errno));
|
||||
gbm_surface_release_buffer (buffer->gbm.surface, bo);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else if (drmModeAddFB2 (kms_fd,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
handles,
|
||||
strides,
|
||||
offsets,
|
||||
&buffer->fb_id,
|
||||
0))
|
||||
{
|
||||
if (format != DRM_FORMAT_XRGB8888)
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"drmModeAddFB does not support format 0x%x",
|
||||
format);
|
||||
gbm_surface_release_buffer (buffer->gbm.surface, bo);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (drmModeAddFB (kms_fd,
|
||||
width,
|
||||
height,
|
||||
24,
|
||||
32,
|
||||
strides[0],
|
||||
handles[0],
|
||||
&buffer->fb_id))
|
||||
{
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
"drmModeAddFB failed: %s",
|
||||
g_strerror (errno));
|
||||
gbm_surface_release_buffer (buffer->gbm.surface, bo);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
buffer->gbm.bo = bo;
|
||||
|
||||
return TRUE;
|
||||
return META_DRM_BUFFER_GET_CLASS (buffer)->get_fb_id (buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -192,88 +39,7 @@ meta_drm_buffer_init (MetaDrmBuffer *buffer)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_finalize (GObject *object)
|
||||
{
|
||||
MetaDrmBuffer *buffer = META_DRM_BUFFER (object);
|
||||
|
||||
if (buffer->type == META_DRM_BUFFER_TYPE_GBM)
|
||||
{
|
||||
if (buffer->gbm.gpu_kms != NULL &&
|
||||
buffer->gbm.fb_id != INVALID_FB_ID)
|
||||
{
|
||||
int kms_fd;
|
||||
|
||||
kms_fd = meta_gpu_kms_get_fd (buffer->gbm.gpu_kms);
|
||||
drmModeRmFB (kms_fd, buffer->fb_id);
|
||||
buffer->fb_id = INVALID_FB_ID;
|
||||
}
|
||||
|
||||
if (buffer->gbm.surface &&
|
||||
buffer->gbm.bo)
|
||||
{
|
||||
gbm_surface_release_buffer (buffer->gbm.surface,
|
||||
buffer->gbm.bo);
|
||||
}
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (meta_drm_buffer_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_drm_buffer_class_init (MetaDrmBufferClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = meta_drm_buffer_finalize;
|
||||
}
|
||||
|
||||
MetaDrmBuffer *
|
||||
meta_drm_buffer_new_from_gbm (MetaGpuKms *gpu_kms,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
{
|
||||
MetaDrmBuffer *buffer;
|
||||
|
||||
buffer = g_object_new (META_TYPE_DRM_BUFFER, NULL);
|
||||
buffer->type = META_DRM_BUFFER_TYPE_GBM;
|
||||
buffer->gbm.gpu_kms = gpu_kms;
|
||||
buffer->gbm.surface = gbm_surface;
|
||||
|
||||
if (!meta_drm_buffer_acquire_swapped_buffer (buffer,
|
||||
use_modifiers,
|
||||
error))
|
||||
{
|
||||
g_object_unref (buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
MetaDrmBuffer *
|
||||
meta_drm_buffer_new_from_dumb (uint32_t dumb_fb_id)
|
||||
{
|
||||
MetaDrmBuffer *buffer;
|
||||
|
||||
buffer = g_object_new (META_TYPE_DRM_BUFFER, NULL);
|
||||
buffer->type = META_DRM_BUFFER_TYPE_WRAPPED_DUMB;
|
||||
buffer->wrapped_dumb.fb_id = dumb_fb_id;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
meta_drm_buffer_get_fb_id (const MetaDrmBuffer *buffer)
|
||||
{
|
||||
return buffer->fb_id;
|
||||
}
|
||||
|
||||
struct gbm_bo *
|
||||
meta_drm_buffer_get_bo (const MetaDrmBuffer *buffer)
|
||||
{
|
||||
g_return_val_if_fail (buffer->type == META_DRM_BUFFER_TYPE_GBM, NULL);
|
||||
|
||||
return buffer->gbm.bo;
|
||||
}
|
||||
|
@ -22,28 +22,25 @@
|
||||
#ifndef META_DRM_BUFFER_H
|
||||
#define META_DRM_BUFFER_H
|
||||
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
|
||||
#include <gbm.h>
|
||||
#include <glib-object.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define META_TYPE_DRM_BUFFER (meta_drm_buffer_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaDrmBuffer,
|
||||
meta_drm_buffer,
|
||||
META, DRM_BUFFER,
|
||||
GObject)
|
||||
G_DECLARE_DERIVABLE_TYPE (MetaDrmBuffer,
|
||||
meta_drm_buffer,
|
||||
META, DRM_BUFFER,
|
||||
GObject)
|
||||
|
||||
MetaDrmBuffer *
|
||||
meta_drm_buffer_new_from_gbm (MetaGpuKms *gpu_kms,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
GError **error);
|
||||
struct _MetaDrmBufferClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
uint32_t (* get_fb_id) (MetaDrmBuffer *buffer);
|
||||
};
|
||||
|
||||
MetaDrmBuffer *
|
||||
meta_drm_buffer_new_from_dumb (uint32_t dumb_fb_id);
|
||||
|
||||
uint32_t meta_drm_buffer_get_fb_id (const MetaDrmBuffer *buffer);
|
||||
|
||||
struct gbm_bo *meta_drm_buffer_get_bo (const MetaDrmBuffer *buffer);
|
||||
uint32_t meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer);
|
||||
|
||||
#endif /* META_DRM_BUFFER_H */
|
||||
|
@ -58,6 +58,8 @@
|
||||
#include "backends/meta-output.h"
|
||||
#include "backends/meta-renderer-view.h"
|
||||
#include "backends/native/meta-crtc-kms.h"
|
||||
#include "backends/native/meta-drm-buffer-dumb.h"
|
||||
#include "backends/native/meta-drm-buffer-gbm.h"
|
||||
#include "backends/native/meta-drm-buffer.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
#include "backends/native/meta-monitor-manager-kms.h"
|
||||
@ -2067,6 +2069,8 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
|
||||
MetaRendererNative *renderer_native = renderer_gpu_data->renderer_native;
|
||||
MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
|
||||
GError *error = NULL;
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
struct gbm_bo *bo;
|
||||
|
||||
if (!meta_egl_make_current (egl,
|
||||
renderer_gpu_data->egl_display,
|
||||
@ -2082,12 +2086,14 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
|
||||
|
||||
*egl_context_changed = TRUE;
|
||||
|
||||
buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
|
||||
bo = meta_drm_buffer_gbm_get_bo (buffer_gbm);
|
||||
if (!meta_renderer_native_gles3_blit_shared_bo (egl,
|
||||
renderer_native->gles3,
|
||||
renderer_gpu_data->egl_display,
|
||||
renderer_gpu_data->secondary.egl_context,
|
||||
secondary_gpu_state->egl_surface,
|
||||
meta_drm_buffer_get_bo (onscreen_native->gbm.next_fb),
|
||||
bo,
|
||||
&error))
|
||||
{
|
||||
g_warning ("Failed to blit shared framebuffer: %s", error->message);
|
||||
@ -2106,14 +2112,14 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen,
|
||||
}
|
||||
|
||||
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
||||
secondary_gpu_state->gbm.next_fb =
|
||||
meta_drm_buffer_new_from_gbm (secondary_gpu_state->gpu_kms,
|
||||
secondary_gpu_state->gbm.surface,
|
||||
renderer_native->use_modifiers,
|
||||
&error);
|
||||
buffer_gbm = meta_drm_buffer_gbm_new (secondary_gpu_state->gpu_kms,
|
||||
secondary_gpu_state->gbm.surface,
|
||||
renderer_native->use_modifiers,
|
||||
&error);
|
||||
secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
|
||||
if (!secondary_gpu_state->gbm.next_fb)
|
||||
{
|
||||
g_warning ("meta_drm_buffer_new_from_gbm failed: %s",
|
||||
g_warning ("meta_drm_buffer_gbm_new failed: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
@ -2196,6 +2202,7 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
|
||||
CoglBitmap *dumb_bitmap;
|
||||
CoglPixelFormat cogl_format;
|
||||
gboolean ret;
|
||||
MetaDrmBufferDumb *buffer_dumb;
|
||||
|
||||
width = cogl_framebuffer_get_width (framebuffer);
|
||||
height = cogl_framebuffer_get_height (framebuffer);
|
||||
@ -2237,8 +2244,8 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
|
||||
cogl_object_unref (dumb_bitmap);
|
||||
|
||||
g_clear_object (&secondary_gpu_state->gbm.next_fb);
|
||||
secondary_gpu_state->gbm.next_fb =
|
||||
meta_drm_buffer_new_from_dumb (target_fb_id);
|
||||
buffer_dumb = meta_drm_buffer_dumb_new (target_fb_id);
|
||||
secondary_gpu_state->gbm.next_fb = META_DRM_BUFFER (buffer_dumb);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2326,6 +2333,7 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
|
||||
gboolean egl_context_changed = FALSE;
|
||||
MetaPowerSave power_save_mode;
|
||||
g_autoptr (GError) error = NULL;
|
||||
MetaDrmBufferGbm *buffer_gbm;
|
||||
|
||||
/*
|
||||
* Wait for the flip callback before continuing, as we might have started the
|
||||
@ -2349,14 +2357,15 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
|
||||
case META_RENDERER_NATIVE_MODE_GBM:
|
||||
g_warn_if_fail (onscreen_native->gbm.next_fb == NULL);
|
||||
g_clear_object (&onscreen_native->gbm.next_fb);
|
||||
onscreen_native->gbm.next_fb =
|
||||
meta_drm_buffer_new_from_gbm (render_gpu,
|
||||
onscreen_native->gbm.surface,
|
||||
renderer_native->use_modifiers,
|
||||
&error);
|
||||
|
||||
buffer_gbm = meta_drm_buffer_gbm_new (render_gpu,
|
||||
onscreen_native->gbm.surface,
|
||||
renderer_native->use_modifiers,
|
||||
&error);
|
||||
onscreen_native->gbm.next_fb = META_DRM_BUFFER (buffer_gbm);
|
||||
if (!onscreen_native->gbm.next_fb)
|
||||
{
|
||||
g_warning ("meta_drm_buffer_new_from_gbm failed: %s",
|
||||
g_warning ("meta_drm_buffer_gbm_new failed: %s",
|
||||
error->message);
|
||||
return;
|
||||
}
|
||||
|
@ -574,6 +574,10 @@ if have_native_backend
|
||||
'backends/native/meta-crtc-kms.h',
|
||||
'backends/native/meta-cursor-renderer-native.c',
|
||||
'backends/native/meta-cursor-renderer-native.h',
|
||||
'backends/native/meta-drm-buffer-dumb.c',
|
||||
'backends/native/meta-drm-buffer-dumb.h',
|
||||
'backends/native/meta-drm-buffer-gbm.c',
|
||||
'backends/native/meta-drm-buffer-gbm.h',
|
||||
'backends/native/meta-drm-buffer.c',
|
||||
'backends/native/meta-drm-buffer.h',
|
||||
'backends/native/meta-gpu-kms.c',
|
||||
|
Loading…
Reference in New Issue
Block a user