diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-08-28 21:58:18 -0300 |
---|---|---|
committer | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2020-09-01 13:05:24 -0300 |
commit | 661fe7769dab5e13fad324b051fc7999f9df79ad (patch) | |
tree | 8b7c0962bd97d3c6b59359097a71bf87b4c3a872 | |
parent | ea7be8b9eb841b7000a3b406b1bb9c3841fff446 (diff) | |
download | mutter-661fe7769dab5e13fad324b051fc7999f9df79ad.tar.gz |
backends/native: Move pixel format helper to separate file
The pixel format helper will be reused by the next commits, and
it doesn't make sense to simply expose it as MetaRendererNative
API.
Move it to a separate file.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1421
-rw-r--r-- | src/backends/native/meta-cogl-utils.c | 82 | ||||
-rw-r--r-- | src/backends/native/meta-cogl-utils.h | 34 | ||||
-rw-r--r-- | src/backends/native/meta-renderer-native.c | 89 | ||||
-rw-r--r-- | src/meson.build | 2 |
4 files changed, 132 insertions, 75 deletions
diff --git a/src/backends/native/meta-cogl-utils.c b/src/backends/native/meta-cogl-utils.c new file mode 100644 index 000000000..86a8b2c04 --- /dev/null +++ b/src/backends/native/meta-cogl-utils.c @@ -0,0 +1,82 @@ +/* meta-cogl-utils.c + * + * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "backends/native/meta-cogl-utils.h" + +#include <drm_fourcc.h> + +typedef struct _PixelFormatMap { + uint32_t drm_format; + CoglPixelFormat cogl_format; + CoglTextureComponents cogl_components; +} PixelFormatMap; + +static const PixelFormatMap pixel_format_map[] = { +/* DRM formats are defined as little-endian, not machine endian. */ +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + { DRM_FORMAT_RGB565, COGL_PIXEL_FORMAT_RGB_565, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, +#elif G_BYTE_ORDER == G_BIG_ENDIAN + /* DRM_FORMAT_RGB565 cannot be expressed. */ + { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, + { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, + { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, +#else +#error "unexpected G_BYTE_ORDER" +#endif +}; + +gboolean +meta_cogl_pixel_format_from_drm_format (uint32_t drm_format, + CoglPixelFormat *out_format, + CoglTextureComponents *out_components) +{ + const size_t n = G_N_ELEMENTS (pixel_format_map); + size_t i; + + for (i = 0; i < n; i++) + { + if (pixel_format_map[i].drm_format == drm_format) + break; + } + + if (i == n) + return FALSE; + + if (out_format) + *out_format = pixel_format_map[i].cogl_format; + + if (out_components) + *out_components = pixel_format_map[i].cogl_components; + + return TRUE; +} diff --git a/src/backends/native/meta-cogl-utils.h b/src/backends/native/meta-cogl-utils.h new file mode 100644 index 000000000..365bbe663 --- /dev/null +++ b/src/backends/native/meta-cogl-utils.h @@ -0,0 +1,34 @@ +/* meta-cogl-utils.h + * + * Copyright 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + + + +#pragma once + +#include <cogl/cogl.h> + +G_BEGIN_DECLS + +gboolean +meta_cogl_pixel_format_from_drm_format (uint32_t drm_format, + CoglPixelFormat *out_format, + CoglTextureComponents *out_components); + +G_END_DECLS diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index c4b89193e..cf29fc9b5 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -57,6 +57,7 @@ #include "backends/meta-logical-monitor.h" #include "backends/meta-output.h" #include "backends/meta-renderer-view.h" +#include "backends/native/meta-cogl-utils.h" #include "backends/native/meta-crtc-kms.h" #include "backends/native/meta-drm-buffer-dumb.h" #include "backends/native/meta-drm-buffer-gbm.h" @@ -256,11 +257,6 @@ meta_renderer_native_get_egl (MetaRendererNative *renderer_native); static void free_current_secondary_bo (CoglOnscreen *onscreen); -static gboolean -cogl_pixel_format_from_drm_format (uint32_t drm_format, - CoglPixelFormat *out_format, - CoglTextureComponents *out_components); - static void meta_renderer_native_queue_modes_reset (MetaRendererNative *renderer_native); @@ -568,9 +564,9 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen) /* Check if any of our preferred formats are supported. */ for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++) { - g_assert (cogl_pixel_format_from_drm_format (preferred_formats[k], - NULL, - NULL)); + g_assert (meta_cogl_pixel_format_from_drm_format (preferred_formats[k], + NULL, + NULL)); for (i = 0; i < formats->len; i++) { @@ -590,7 +586,7 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen) { drm_format = g_array_index (formats, uint32_t, i); - if (cogl_pixel_format_from_drm_format (drm_format, NULL, NULL)) + if (meta_cogl_pixel_format_from_drm_format (drm_format, NULL, NULL)) return drm_format; } @@ -1563,7 +1559,9 @@ create_dma_buf_framebuffer (MetaRendererNative *renderer_native, CoglOffscreen *cogl_fbo; int ret; - ret = cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL); + ret = meta_cogl_pixel_format_from_drm_format (drm_format, + &cogl_format, + NULL); g_assert (ret); strides[0] = stride; @@ -1641,9 +1639,9 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre g_assert (cogl_framebuffer_get_width (framebuffer) == dumb_fb->width); g_assert (cogl_framebuffer_get_height (framebuffer) == dumb_fb->height); - ret = cogl_pixel_format_from_drm_format (dumb_fb->drm_format, - &cogl_format, - NULL); + ret = meta_cogl_pixel_format_from_drm_format (dumb_fb->drm_format, + &cogl_format, + NULL); g_assert (ret); dmabuf_fd = meta_dumb_buffer_ensure_dmabuf_fd (dumb_fb, @@ -1687,65 +1685,6 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre return TRUE; } -typedef struct _PixelFormatMap { - uint32_t drm_format; - CoglPixelFormat cogl_format; - CoglTextureComponents cogl_components; -} PixelFormatMap; - -static const PixelFormatMap pixel_format_map[] = { -/* DRM formats are defined as little-endian, not machine endian. */ -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - { DRM_FORMAT_RGB565, COGL_PIXEL_FORMAT_RGB_565, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, -#elif G_BYTE_ORDER == G_BIG_ENDIAN - /* DRM_FORMAT_RGB565 cannot be expressed. */ - { DRM_FORMAT_ABGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_XBGR8888, COGL_PIXEL_FORMAT_ABGR_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_ARGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_XRGB8888, COGL_PIXEL_FORMAT_ARGB_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_BGRA8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_BGRX8888, COGL_PIXEL_FORMAT_BGRA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, - { DRM_FORMAT_RGBA8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGBA }, - { DRM_FORMAT_RGBX8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_COMPONENTS_RGB }, -#else -#error "unexpected G_BYTE_ORDER" -#endif -}; - -static gboolean -cogl_pixel_format_from_drm_format (uint32_t drm_format, - CoglPixelFormat *out_format, - CoglTextureComponents *out_components) -{ - const size_t n = G_N_ELEMENTS (pixel_format_map); - size_t i; - - for (i = 0; i < n; i++) - { - if (pixel_format_map[i].drm_format == drm_format) - break; - } - - if (i == n) - return FALSE; - - if (out_format) - *out_format = pixel_format_map[i].cogl_format; - - if (out_components) - *out_components = pixel_format_map[i].cogl_components; - - return TRUE; -} - static void copy_shared_framebuffer_cpu (CoglOnscreen *onscreen, MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state, @@ -1767,9 +1706,9 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen, g_assert (cogl_framebuffer_get_width (framebuffer) == dumb_fb->width); g_assert (cogl_framebuffer_get_height (framebuffer) == dumb_fb->height); - ret = cogl_pixel_format_from_drm_format (dumb_fb->drm_format, - &cogl_format, - NULL); + ret = meta_cogl_pixel_format_from_drm_format (dumb_fb->drm_format, + &cogl_format, + NULL); g_assert (ret); dumb_bitmap = cogl_bitmap_new_for_data (cogl_context, diff --git a/src/meson.build b/src/meson.build index e260d2588..eaa35bb23 100644 --- a/src/meson.build +++ b/src/meson.build @@ -633,6 +633,8 @@ if have_native_backend 'backends/native/meta-barrier-native.h', 'backends/native/meta-clutter-backend-native.c', 'backends/native/meta-clutter-backend-native.h', + 'backends/native/meta-cogl-utils.c', + 'backends/native/meta-cogl-utils.h', 'backends/native/meta-crtc-kms.c', 'backends/native/meta-crtc-kms.h', 'backends/native/meta-crtc-mode-kms.c', |