[mutter/wip/nielsdg/add-yuv-support] WIP
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/nielsdg/add-yuv-support] WIP
- Date: Sat, 15 Jun 2019 04:53:21 +0000 (UTC)
commit 85ccd04211f319caa7466db21f1cbbaf10d056d4
Author: Niels De Graef <niels degraef barco com>
Date: Sat Jun 15 06:35:52 2019 +0200
WIP
cogl/cogl/cogl-multi-plane-texture.c | 52 ------------------------
cogl/cogl/cogl-multi-plane-texture.h | 18 --------
cogl/cogl/driver/gl/cogl-texture-2d-gl.c | 4 --
src/wayland/meta-wayland-buffer.c | 70 +++++++++++++++++++++++++-------
4 files changed, 56 insertions(+), 88 deletions(-)
---
diff --git a/cogl/cogl/cogl-multi-plane-texture.c b/cogl/cogl/cogl-multi-plane-texture.c
index e9cb916ab..209291579 100644
--- a/cogl/cogl/cogl-multi-plane-texture.c
+++ b/cogl/cogl/cogl-multi-plane-texture.c
@@ -127,58 +127,6 @@ cogl_multi_plane_texture_new_single_plane (CoglPixelFormat format,
return self;
}
-CoglMultiPlaneTexture *
-cogl_multi_plane_texture_new_from_bitmaps (CoglPixelFormat format,
- CoglBitmap **bitmaps, guint n_planes,
- GError **error)
-{
- guint i = 0;
- CoglMultiPlaneTexture *self = g_slice_new0 (CoglMultiPlaneTexture);
-
- _cogl_multi_plane_texture_object_new (self);
-
- self->format = format;
- self->n_planes = n_planes;
- self->planes = g_malloc (sizeof (CoglTexture *) * n_planes);
-
- for (i = 0; i < n_planes; i++)
- {
- CoglTexture *plane;
-
- plane = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmaps[i]));
-
- if (!cogl_texture_allocate (plane, error))
- {
- g_clear_pointer (&plane, cogl_object_unref);
-
- /* There's a chance we failed due to the buffer being NPOT size.
- * If so, try again with CoglTexture2DSliced (which does support this) */
- if (g_error_matches (*error,
- COGL_TEXTURE_ERROR,
- COGL_TEXTURE_ERROR_SIZE))
- {
- CoglTexture2DSliced *plane_sliced;
-
- g_clear_error (error);
-
- plane_sliced =
- cogl_texture_2d_sliced_new_from_bitmap (bitmaps[i],
- COGL_TEXTURE_MAX_WASTE);
- plane = COGL_TEXTURE (plane_sliced);
-
- if (!cogl_texture_allocate (plane, error))
- cogl_clear_object (&plane);
- }
- }
-
- cogl_object_unref (bitmaps[i]);
- self->planes[i] = plane;
- }
-
-
- return self;
-}
-
gchar *
cogl_multi_plane_texture_to_string (CoglMultiPlaneTexture *self)
{
diff --git a/cogl/cogl/cogl-multi-plane-texture.h b/cogl/cogl/cogl-multi-plane-texture.h
index c0d8d89b9..5a46cfa74 100644
--- a/cogl/cogl/cogl-multi-plane-texture.h
+++ b/cogl/cogl/cogl-multi-plane-texture.h
@@ -100,24 +100,6 @@ CoglMultiPlaneTexture * cogl_multi_plane_texture_new (CoglPixelFormat format,
CoglMultiPlaneTexture * cogl_multi_plane_texture_new_single_plane (CoglPixelFormat format,
CoglTexture *plane);
-/**
- * cogl_multi_plane_texture_new_from_bitmaps:
- * @format: The format of the new #CoglMultiPlaneTexture
- * @bitmaps: (transfer full): The planes of the texture, each as a #CoglBitmap
- * @n_planes: the number of planes the texture contains
- * @error: (out): Will be set if an error occurred
- *
- * Creates a #CoglMultiPlaneTexture from the given bitmaps and makes sure the
- * planes are uploaded to the GPU.
- *
- * Returns: (transfer full): A new #CoglMultiPlaneTexture. Use
- * cogl_object_unref() when you're done with it.
- */
-CoglMultiPlaneTexture *
-cogl_multi_plane_texture_new_from_bitmaps (CoglPixelFormat format,
- CoglBitmap **bitmaps, guint n_planes,
- GError **error);
-
/**
* cogl_multi_plane_texture_get_format:
* @self: a #CoglMultiPlaneTexture
diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
index fe4a53dfc..2f9e3424c 100644
--- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
+++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
@@ -202,8 +202,6 @@ allocate_from_bitmap (CoglTexture2D *tex_2d,
GLenum gl_format;
GLenum gl_type;
- g_warning ("allocate_from_bitmap()");
-
internal_format =
_cogl_texture_determine_internal_format (tex, cogl_bitmap_get_format (bmp));
@@ -344,8 +342,6 @@ allocate_from_gl_foreign (CoglTexture2D *tex_2d,
GLint gl_compressed = GL_FALSE;
GLenum gl_int_format = 0;
- g_warning ("allocate_from_egl_image_foreign()");
-
if (!ctx->texture_driver->allows_foreign_gl_target (ctx, GL_TEXTURE_2D))
{
_cogl_set_error (error,
diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c
index 3de148f7a..e86c0b569 100644
--- a/src/wayland/meta-wayland-buffer.c
+++ b/src/wayland/meta-wayland-buffer.c
@@ -178,6 +178,7 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
case WL_SHM_FORMAT_ARGB8888:
format = COGL_PIXEL_FORMAT_BGRA_8888_PRE;
+ components_out[0] = COGL_TEXTURE_COMPONENTS_RGBA;
break;
case WL_SHM_FORMAT_XRGB8888:
format = COGL_PIXEL_FORMAT_BGRA_8888;
@@ -247,7 +248,7 @@ shm_buffer_attach (MetaWaylandBuffer *buffer,
CoglPixelFormat subformats[3];
gsize plane_offset = 0;
guint8 *data;
- GPtrArray *bitmaps;
+ GPtrArray *planes;
/* Query the necessary parameters */
shm_buffer = wl_shm_buffer_get (buffer->resource);
@@ -278,10 +279,11 @@ shm_buffer_attach (MetaWaylandBuffer *buffer,
wl_shm_buffer_begin_access (shm_buffer);
data = wl_shm_buffer_get_data (shm_buffer);
- bitmaps = g_ptr_array_new_full (n_planes, cogl_object_unref);
+ planes = g_ptr_array_new_full (n_planes, cogl_object_unref);
for (i = 0; i < n_planes; i++)
{
- CoglBitmap *bitmap;
+ CoglBitmap *plane_bitmap;
+ CoglTexture *plane_texture;
/* Calculate the plane start in the buffer (consider subsampling) */
if (i > 0)
@@ -290,20 +292,56 @@ shm_buffer_attach (MetaWaylandBuffer *buffer,
g_warning ("Creating plane %u, h_factor = %u, v_factor = %u, plane_offset = %lu",
i, h_factors[i], v_factors[i], plane_offset);
- bitmap = cogl_bitmap_new_for_data (cogl_context,
- width / h_factors[i],
- height / v_factors[i],
- subformats[i],
- stride / h_factors[i],
- data + plane_offset);
- g_assert (bitmap);
+ /* Define the bitmap that only pertains to this plane */
+ plane_bitmap = cogl_bitmap_new_for_data (cogl_context,
+ width / h_factors[i],
+ height / v_factors[i],
+ subformats[i],
+ stride / h_factors[i],
+ data + plane_offset);
+ g_assert (plane_bitmap);
+
+ /* Then create a texture out of it so we can upload it to the GPU */
+ plane_texture = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (plane_bitmap));
+
+ /* Separately set the components (e.g. for XRGB, or NV12) */
+ cogl_texture_set_components (plane_texture, components[i]);
- g_ptr_array_add (bitmaps, bitmap);
+ if (!cogl_texture_allocate (plane_texture, error))
+ {
+ CoglTexture2DSliced *texture_sliced;
+
+ cogl_clear_object (&plane_texture);
+
+ /* If it didn't work due to an NPOT size, try again with an atlas texture */
+ if (!g_error_matches (*error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE))
+ {
+ cogl_object_unref (plane_bitmap);
+ goto failure;
+ }
+
+ g_clear_error (error);
+
+ texture_sliced =
+ cogl_texture_2d_sliced_new_from_bitmap (plane_bitmap,
+ COGL_TEXTURE_MAX_WASTE);
+ plane_texture = COGL_TEXTURE (texture_sliced);
+
+ cogl_texture_set_components (plane_texture, components[i]);
+
+ if (!cogl_texture_allocate (plane_texture, error))
+ {
+ cogl_clear_object (&plane_texture);
+ goto failure;
+ }
+ }
+
+ g_ptr_array_add (planes, plane_texture);
}
- *texture = cogl_multi_plane_texture_new_from_bitmaps (format,
- (CoglBitmap **) g_ptr_array_free (bitmaps, FALSE),
- n_planes, error);
+ *texture = cogl_multi_plane_texture_new (format,
+ (CoglTexture **) g_ptr_array_free (planes, FALSE),
+ n_planes);
wl_shm_buffer_end_access (shm_buffer);
@@ -313,6 +351,10 @@ shm_buffer_attach (MetaWaylandBuffer *buffer,
g_warning ("Got the following multiplane texture:\n%s", cogl_multi_plane_texture_to_string (*texture));
return TRUE;
+
+failure:
+ *texture = NULL;
+ return FALSE;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]