mirror of
https://github.com/brl/mutter.git
synced 2024-11-21 15:40:41 -05:00
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
This commit is contained in:
parent
ea7be8b9eb
commit
661fe7769d
82
src/backends/native/meta-cogl-utils.c
Normal file
82
src/backends/native/meta-cogl-utils.c
Normal file
@ -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;
|
||||
}
|
34
src/backends/native/meta-cogl-utils.h
Normal file
34
src/backends/native/meta-cogl-utils.h
Normal file
@ -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
|
@ -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,
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user