Compare commits
2 Commits
main
...
wip/nields
Author | SHA1 | Date | |
---|---|---|---|
63e618479c | |||
151c6fdd84 |
@ -46,3 +46,4 @@
|
||||
#mesondefine COGL_HAS_X11_SUPPORT
|
||||
#mesondefine COGL_HAS_XLIB
|
||||
#mesondefine COGL_HAS_XLIB_SUPPORT
|
||||
#mesondefine COGL_HAS_LIBDRM
|
||||
|
@ -29,6 +29,7 @@
|
||||
*/
|
||||
|
||||
#include "cogl-config.h"
|
||||
#include "cogl-defines.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
@ -308,3 +309,66 @@ cogl_pixel_format_to_string (CoglPixelFormat format)
|
||||
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
#ifdef COGL_HAS_LIBDRM
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -38,7 +38,12 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef COGL_HAS_LIBDRM
|
||||
#include <drm_fourcc.h>
|
||||
#endif
|
||||
|
||||
#include <cogl/cogl-defines.h>
|
||||
#include <cogl/cogl-texture-components.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
@ -58,6 +63,9 @@ G_BEGIN_DECLS
|
||||
*
|
||||
* Other examples of factors that can influence the layout in memory are the
|
||||
* system's endianness.
|
||||
*
|
||||
* This file also contains methods to map Linux DRM 4CC codes to
|
||||
* CoglPixelFormats.
|
||||
*/
|
||||
|
||||
#define COGL_A_BIT (1 << 4)
|
||||
@ -295,6 +303,34 @@ _cogl_pixel_format_is_endian_dependant (CoglPixelFormat format);
|
||||
const char *
|
||||
cogl_pixel_format_to_string (CoglPixelFormat format);
|
||||
|
||||
#ifdef COGL_HAS_LIBDRM
|
||||
|
||||
/* added in libdrm 2.4.95 */
|
||||
#ifndef DRM_FORMAT_INVALID
|
||||
#define DRM_FORMAT_INVALID 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* cogl_pixel_format_from_drm_format:
|
||||
* @drm_format: The DRM 4CC code (as specified in drm_fourcc.h)
|
||||
* @out_format: (out) (optional): The corresponding #CoglPixelFormat (if successful)
|
||||
* @out_components: (out) (optional): The corresponding #CoglTextureComponents,
|
||||
* if sucessful.
|
||||
*
|
||||
* Does an internal lookup to find a #CoglPixelFormat that matches the given
|
||||
* DRM 4CC code. If no such format could be found, this function will return
|
||||
* %FALSE and the output parameters will stay untouched.
|
||||
*
|
||||
* Returns: %TRUE if a #CoglPixelFormat corresponding to the 4CC code exists,
|
||||
* %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cogl_pixel_format_from_drm_format (uint32_t drm_format,
|
||||
CoglPixelFormat *out_format,
|
||||
CoglTextureComponents *out_components);
|
||||
|
||||
#endif /* COGL_HAS_LIBDRM */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_PIXEL_FORMAT_H__ */
|
||||
|
80
cogl/cogl/cogl-texture-components.h
Normal file
80
cogl/cogl/cogl-texture-components.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Cogl
|
||||
*
|
||||
* A Low Level GPU Graphics and Utilities API
|
||||
*
|
||||
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
|
||||
#error "Only <cogl/cogl.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __COGL_TEXTURE_COMPONENTS_H__
|
||||
#define __COGL_TEXTURE_COMPONENTS_H__
|
||||
|
||||
#include <cogl/cogl-types.h>
|
||||
#include <cogl/cogl-macros.h>
|
||||
#include <cogl/cogl-defines.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* SECTION:cogl-texture-components
|
||||
* @short_description: Functions for creating and manipulating textures
|
||||
*
|
||||
* CoglTextureComponents can be used to specify what components of a
|
||||
* #CoglTexture can be used for sampling later. This affects how data is
|
||||
* uploaded to the GPU.
|
||||
*/
|
||||
|
||||
/**
|
||||
* CoglTextureComponents:
|
||||
* @COGL_TEXTURE_COMPONENTS_A: Only the alpha component
|
||||
* @COGL_TEXTURE_COMPONENTS_RG: Red and green components. Note that
|
||||
* this can only be used if the %COGL_FEATURE_ID_TEXTURE_RG feature
|
||||
* is advertised.
|
||||
* @COGL_TEXTURE_COMPONENTS_RGB: Red, green and blue components
|
||||
* @COGL_TEXTURE_COMPONENTS_RGBA: Red, green, blue and alpha components
|
||||
* @COGL_TEXTURE_COMPONENTS_DEPTH: Only a depth component
|
||||
*
|
||||
* See cogl_texture_set_components().
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
typedef enum _CoglTextureComponents
|
||||
{
|
||||
COGL_TEXTURE_COMPONENTS_A = 1,
|
||||
COGL_TEXTURE_COMPONENTS_RG,
|
||||
COGL_TEXTURE_COMPONENTS_RGB,
|
||||
COGL_TEXTURE_COMPONENTS_RGBA,
|
||||
COGL_TEXTURE_COMPONENTS_DEPTH
|
||||
} CoglTextureComponents;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_TEXTURE_COMPONENTS_H__ */
|
@ -122,29 +122,6 @@ uint32_t cogl_texture_error_quark (void);
|
||||
gboolean
|
||||
cogl_is_texture (void *object);
|
||||
|
||||
/**
|
||||
* CoglTextureComponents:
|
||||
* @COGL_TEXTURE_COMPONENTS_A: Only the alpha component
|
||||
* @COGL_TEXTURE_COMPONENTS_RG: Red and green components. Note that
|
||||
* this can only be used if the %COGL_FEATURE_ID_TEXTURE_RG feature
|
||||
* is advertised.
|
||||
* @COGL_TEXTURE_COMPONENTS_RGB: Red, green and blue components
|
||||
* @COGL_TEXTURE_COMPONENTS_RGBA: Red, green, blue and alpha components
|
||||
* @COGL_TEXTURE_COMPONENTS_DEPTH: Only a depth component
|
||||
*
|
||||
* See cogl_texture_set_components().
|
||||
*
|
||||
* Since: 1.18
|
||||
*/
|
||||
typedef enum _CoglTextureComponents
|
||||
{
|
||||
COGL_TEXTURE_COMPONENTS_A = 1,
|
||||
COGL_TEXTURE_COMPONENTS_RG,
|
||||
COGL_TEXTURE_COMPONENTS_RGB,
|
||||
COGL_TEXTURE_COMPONENTS_RGBA,
|
||||
COGL_TEXTURE_COMPONENTS_DEPTH
|
||||
} CoglTextureComponents;
|
||||
|
||||
/**
|
||||
* cogl_texture_set_components:
|
||||
* @texture: a #CoglTexture pointer.
|
||||
|
@ -12,6 +12,7 @@ cdata.set('COGL_HAS_X11', have_x11)
|
||||
cdata.set('COGL_HAS_X11_SUPPORT', have_x11)
|
||||
cdata.set('COGL_HAS_XLIB', have_x11)
|
||||
cdata.set('COGL_HAS_XLIB_SUPPORT', have_x11)
|
||||
cdata.set('COGL_HAS_LIBDRM', have_native_backend and libdrm_dep.found())
|
||||
|
||||
cogl_defines_h = configure_file(
|
||||
input: 'cogl-defines.h.meson',
|
||||
@ -93,6 +94,7 @@ cogl_headers = [
|
||||
'cogl-texture.h',
|
||||
'cogl-texture-2d.h',
|
||||
'cogl-texture-2d-sliced.h',
|
||||
'cogl-texture-components.h',
|
||||
'cogl-types.h',
|
||||
'cogl.h',
|
||||
]
|
||||
|
@ -75,11 +75,6 @@
|
||||
#define EGL_DRM_MASTER_FD_EXT 0x333C
|
||||
#endif
|
||||
|
||||
/* added in libdrm 2.4.95 */
|
||||
#ifndef DRM_FORMAT_INVALID
|
||||
#define DRM_FORMAT_INVALID 0
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
@ -251,11 +246,6 @@ static void
|
||||
free_next_secondary_bo (MetaGpuKms *gpu_kms,
|
||||
MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state);
|
||||
|
||||
static gboolean
|
||||
cogl_pixel_format_from_drm_format (uint32_t drm_format,
|
||||
CoglPixelFormat *out_format,
|
||||
CoglTextureComponents *out_components);
|
||||
|
||||
static void
|
||||
meta_renderer_native_gpu_data_free (MetaRendererNativeGpuData *renderer_gpu_data)
|
||||
{
|
||||
@ -1823,65 +1813,6 @@ secondary_gpu_get_next_dumb_buffer (MetaOnscreenNativeSecondaryGpuState *seconda
|
||||
return &secondary_gpu_state->cpu.dumb_fbs[0];
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -43,10 +43,6 @@
|
||||
|
||||
#include "linux-dmabuf-unstable-v1-server-protocol.h"
|
||||
|
||||
#ifndef DRM_FORMAT_MOD_INVALID
|
||||
#define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
|
||||
#endif
|
||||
|
||||
#define META_WAYLAND_DMA_BUF_MAX_FDS 4
|
||||
|
||||
struct _MetaWaylandDmaBufBuffer
|
||||
@ -84,28 +80,15 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
||||
if (buffer->dma_buf.texture)
|
||||
return TRUE;
|
||||
|
||||
switch (dma_buf->drm_format)
|
||||
/*
|
||||
* NOTE: The cogl_format here is only used for texture color channel
|
||||
* swizzling as compared to COGL_PIXEL_FORMAT_ARGB. It is *not* used
|
||||
* for accessing the buffer memory. EGL will access the buffer
|
||||
* memory according to the DRM fourcc code. Cogl will not mmap
|
||||
* and access the buffer memory at all.
|
||||
*/
|
||||
if (!cogl_pixel_format_from_drm_format (dma_buf->drm_format, &cogl_format, NULL))
|
||||
{
|
||||
/*
|
||||
* NOTE: The cogl_format here is only used for texture color channel
|
||||
* swizzling as compared to COGL_PIXEL_FORMAT_ARGB. It is *not* used
|
||||
* for accessing the buffer memory. EGL will access the buffer
|
||||
* memory according to the DRM fourcc code. Cogl will not mmap
|
||||
* and access the buffer memory at all.
|
||||
*/
|
||||
case DRM_FORMAT_XRGB8888:
|
||||
cogl_format = COGL_PIXEL_FORMAT_RGB_888;
|
||||
break;
|
||||
case DRM_FORMAT_ARGB8888:
|
||||
cogl_format = COGL_PIXEL_FORMAT_ARGB_8888_PRE;
|
||||
break;
|
||||
case DRM_FORMAT_ARGB2101010:
|
||||
cogl_format = COGL_PIXEL_FORMAT_ARGB_2101010_PRE;
|
||||
break;
|
||||
case DRM_FORMAT_RGB565:
|
||||
cogl_format = COGL_PIXEL_FORMAT_RGB_565;
|
||||
break;
|
||||
default:
|
||||
g_set_error (error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"Unsupported buffer format %d", dma_buf->drm_format);
|
||||
|
Reference in New Issue
Block a user