cogl/driver: Abstract GL specific vfuncs

By moving them up from the abstract Driver to DriverGL.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4132>
This commit is contained in:
Bilal Elmoussaoui 2024-12-11 10:04:49 +01:00
parent 2769c25cf7
commit 1f2ba427b6
9 changed files with 71 additions and 56 deletions

View File

@ -42,6 +42,7 @@
#include "cogl/cogl-framebuffer-private.h"
#include "cogl/cogl-blit.h"
#include "cogl/cogl-private.h"
#include "cogl/driver/gl/cogl-driver-gl-private.h"
#include <stdlib.h>
@ -193,7 +194,8 @@ _cogl_atlas_get_initial_size (CoglContext *ctx,
unsigned int *map_width,
unsigned int *map_height)
{
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
unsigned int size;
@ -203,7 +205,7 @@ _cogl_atlas_get_initial_size (CoglContext *ctx,
g_return_if_fail (cogl_pixel_format_get_n_planes (format) == 1);
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
format,
&gl_intformat,
@ -244,14 +246,15 @@ _cogl_atlas_create_map (CoglContext *ctx,
unsigned int n_textures,
CoglAtlasRepositionData *textures)
{
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
format,
&gl_intformat,

View File

@ -30,6 +30,7 @@
#include "config.h"
#include "cogl/driver/gl/cogl-driver-gl-private.h"
#include "cogl/cogl-private.h"
#include "cogl/cogl-bitmap-private.h"
#include "cogl/cogl-context-private.h"
@ -780,7 +781,8 @@ _cogl_bitmap_convert_for_upload (CoglBitmap *src_bmp,
{
CoglContext *ctx = _cogl_bitmap_get_context (src_bmp);
CoglPixelFormat src_format = cogl_bitmap_get_format (src_bmp);
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver);
CoglBitmap *dst_bmp;
g_return_val_if_fail (internal_format != COGL_PIXEL_FORMAT_ANY, NULL);
@ -814,7 +816,7 @@ _cogl_bitmap_convert_for_upload (CoglBitmap *src_bmp,
CoglPixelFormat closest_format;
closest_format =
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver,
ctx,
internal_format,
NULL, /* ignore gl intformat */

View File

@ -59,22 +59,6 @@ struct _CoglDriverClass
CoglGraphicsResetStatus (* get_graphics_reset_status) (CoglDriver *driver,
CoglContext *context);
/* TODO: factor this out since this is OpenGL specific and
* so can be ignored by non-OpenGL drivers. */
CoglPixelFormat (* pixel_format_to_gl) (CoglDriver *driver,
CoglContext *context,
CoglPixelFormat format,
GLenum *out_glintformat,
GLenum *out_glformat,
GLenum *out_gltype);
CoglPixelFormat (* get_read_pixels_format) (CoglDriver *driver,
CoglContext *context,
CoglPixelFormat from,
CoglPixelFormat to,
GLenum *gl_format_out,
GLenum *gl_type_out);
gboolean (* update_features) (CoglDriver *driver,
CoglContext *context,
GError **error);

View File

@ -40,10 +40,6 @@ typedef struct _CoglDriverGLPrivate
GLuint next_fake_sampler_object_number;
} CoglDriverGLPrivate;
struct _CoglDriverGLClass
{
CoglDriverClass parent_class;
};
G_DECLARE_DERIVABLE_TYPE (CoglDriverGL,
cogl_driver_gl,
@ -51,6 +47,25 @@ G_DECLARE_DERIVABLE_TYPE (CoglDriverGL,
DRIVER_GL,
CoglDriver);
struct _CoglDriverGLClass
{
CoglDriverClass parent_class;
CoglPixelFormat (* pixel_format_to_gl) (CoglDriverGL *driver,
CoglContext *context,
CoglPixelFormat format,
GLenum *out_glintformat,
GLenum *out_glformat,
GLenum *out_gltype);
CoglPixelFormat (* get_read_pixels_format) (CoglDriverGL *driver,
CoglContext *context,
CoglPixelFormat from,
CoglPixelFormat to,
GLenum *gl_format_out,
GLenum *gl_type_out);
};
#define COGL_TYPE_DRIVER_GL (cogl_driver_gl_get_type ())
CoglDriverGLPrivate * cogl_driver_gl_get_private (CoglDriverGL *driver);

View File

@ -41,6 +41,7 @@
#include "cogl/driver/gl/cogl-framebuffer-gl-private.h"
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
#include "cogl/driver/gl/cogl-buffer-gl-private.h"
#include "cogl/driver/gl/cogl-driver-gl-private.h"
#include <glib.h>
#include <string.h>
@ -404,7 +405,7 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver,
CoglPixelFormat format = cogl_bitmap_get_format (bitmap);
CoglPixelFormat internal_format =
cogl_framebuffer_get_internal_format (framebuffer);
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGLClass *driver_gl_klass = COGL_DRIVER_GL_GET_CLASS (ctx->driver);
CoglPixelFormat read_format;
GLenum gl_format;
GLenum gl_type;
@ -443,12 +444,12 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver,
else
pack_invert_set = FALSE;
read_format = driver_klass->get_read_pixels_format (ctx->driver,
ctx,
internal_format,
format,
&gl_format,
&gl_type);
read_format = driver_gl_klass->get_read_pixels_format (COGL_DRIVER_GL (ctx->driver),
ctx,
internal_format,
format,
&gl_format,
&gl_type);
format_mismatch =
(read_format & ~COGL_PREMULT_BIT) != (format & ~COGL_PREMULT_BIT);

View File

@ -28,6 +28,7 @@
#include "config.h"
#include "cogl/driver/gl/cogl-driver-gl-private.h"
#include "cogl/driver/gl/cogl-pipeline-gl-private.h"
#include "cogl/driver/gl/cogl-texture-driver-gl-private.h"
#include "cogl/driver/gl/cogl-texture-2d-gl-private.h"
@ -69,7 +70,8 @@ cogl_texture_driver_gl_texture_2d_can_create (CoglTextureDriver *driver,
{
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
@ -78,7 +80,7 @@ cogl_texture_driver_gl_texture_2d_can_create (CoglTextureDriver *driver,
if (cogl_pixel_format_get_n_planes (internal_format) != 1)
return FALSE;
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
internal_format,
&gl_intformat,
@ -109,8 +111,8 @@ allocate_with_size (CoglTexture2D *tex_2d,
int width = loader->src.sized.width;
int height = loader->src.sized.height;
CoglContext *ctx = cogl_texture_get_context (tex);
CoglDriverClass *driver_klass =
COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
GLenum gl_intformat;
@ -134,7 +136,7 @@ allocate_with_size (CoglTexture2D *tex_2d,
return FALSE;
}
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
internal_format,
&gl_intformat,
@ -181,8 +183,8 @@ allocate_from_bitmap (CoglTexture2D *tex_2d,
CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglBitmap *bmp = loader->src.bitmap.bitmap;
CoglContext *ctx = _cogl_bitmap_get_context (bmp);
CoglDriverClass *driver_klass =
COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
CoglPixelFormat internal_format;
@ -215,13 +217,13 @@ allocate_from_bitmap (CoglTexture2D *tex_2d,
if (upload_bmp == NULL)
return FALSE;
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
cogl_bitmap_get_format (upload_bmp),
NULL, /* internal format */
&gl_format,
&gl_type);
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
internal_format,
&gl_intformat,
@ -467,7 +469,8 @@ cogl_texture_driver_gl_texture_2d_copy_from_bitmap (CoglTextureDriver *driver,
{
CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = cogl_texture_get_context (tex);
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
CoglBitmap *upload_bmp;
@ -490,7 +493,7 @@ cogl_texture_driver_gl_texture_2d_copy_from_bitmap (CoglTextureDriver *driver,
cogl_pixel_format_get_n_planes (upload_format) != 1)
return FALSE;
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
upload_format,
NULL, /* internal gl format */

View File

@ -64,7 +64,7 @@ cogl_driver_gl3_context_init (CoglDriver *driver,
}
static CoglPixelFormat
cogl_driver_gl3_pixel_format_to_gl (CoglDriver *driver,
cogl_driver_gl3_pixel_format_to_gl (CoglDriverGL *driver,
CoglContext *context,
CoglPixelFormat format,
GLenum *out_glintformat,
@ -359,7 +359,7 @@ cogl_driver_gl3_pixel_format_to_gl (CoglDriver *driver,
}
static CoglPixelFormat
cogl_driver_gl3_get_read_pixels_format (CoglDriver *driver,
cogl_driver_gl3_get_read_pixels_format (CoglDriverGL *driver,
CoglContext *context,
CoglPixelFormat from,
CoglPixelFormat to,
@ -600,11 +600,13 @@ static void
cogl_driver_gl3_class_init (CoglDriverGL3Class *klass)
{
CoglDriverClass *driver_klass = COGL_DRIVER_CLASS (klass);
CoglDriverGLClass *driver_gl_klass = COGL_DRIVER_GL_CLASS (klass);
driver_klass->context_init = cogl_driver_gl3_context_init;
driver_klass->pixel_format_to_gl = cogl_driver_gl3_pixel_format_to_gl;
driver_klass->get_read_pixels_format = cogl_driver_gl3_get_read_pixels_format;
driver_klass->update_features = cogl_driver_gl3_update_features;
driver_gl_klass->get_read_pixels_format = cogl_driver_gl3_get_read_pixels_format;
driver_gl_klass->pixel_format_to_gl = cogl_driver_gl3_pixel_format_to_gl;
}
static void

View File

@ -48,6 +48,7 @@
#include "cogl/driver/gl/cogl-util-gl-private.h"
#include "cogl/driver/gl/cogl-texture-gl-private.h"
#include "cogl/driver/gl/cogl-bitmap-gl-private.h"
#include "cogl/driver/gl/cogl-driver-gl-private.h"
#include <string.h>
#include <stdlib.h>
@ -482,9 +483,10 @@ cogl_texture_driver_gl3_find_best_gl_get_data_format (CoglTextureDriver *driver,
GLenum *closest_gl_format,
GLenum *closest_gl_type)
{
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (context->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (context->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
return driver_klass->pixel_format_to_gl (context->driver,
return driver_klass->pixel_format_to_gl (driver_gl,
context,
format,
NULL, /* don't need */
@ -509,7 +511,8 @@ cogl_texture_driver_gl3_texture_2d_gl_get_data (CoglTextureDriver *driver,
CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
CoglTextureDriverClass *tex_driver =
COGL_TEXTURE_DRIVER_GET_CLASS (ctx->texture_driver);
CoglDriverClass *driver_klass = COGL_DRIVER_GET_CLASS (ctx->driver);
CoglDriverGL *driver_gl = COGL_DRIVER_GL (ctx->driver);
CoglDriverGLClass *driver_klass = COGL_DRIVER_GL_GET_CLASS (driver_gl);
uint8_t bpp;
int width = cogl_texture_get_width (COGL_TEXTURE (tex_2d));
GLenum gl_format;
@ -520,7 +523,7 @@ cogl_texture_driver_gl3_texture_2d_gl_get_data (CoglTextureDriver *driver,
bpp = cogl_pixel_format_get_bytes_per_pixel (format, 0);
driver_klass->pixel_format_to_gl (ctx->driver,
driver_klass->pixel_format_to_gl (driver_gl,
ctx,
format,
NULL, /* internal format */

View File

@ -96,7 +96,7 @@
G_DEFINE_FINAL_TYPE (CoglDriverGLES2, cogl_driver_gles2, COGL_TYPE_DRIVER_GL)
static CoglPixelFormat
cogl_driver_gles2_pixel_format_to_gl (CoglDriver *driver,
cogl_driver_gles2_pixel_format_to_gl (CoglDriverGL *driver,
CoglContext *context,
CoglPixelFormat format,
GLenum *out_glintformat,
@ -477,7 +477,7 @@ cogl_driver_gles2_pixel_format_to_gl (CoglDriver *driver,
}
static CoglPixelFormat
cogl_driver_gles2_get_read_pixels_format (CoglDriver *driver,
cogl_driver_gles2_get_read_pixels_format (CoglDriverGL *driver,
CoglContext *context,
CoglPixelFormat from,
CoglPixelFormat to,
@ -865,10 +865,12 @@ static void
cogl_driver_gles2_class_init (CoglDriverGLES2Class *klass)
{
CoglDriverClass *driver_klass = COGL_DRIVER_CLASS (klass);
CoglDriverGLClass *driver_gl_klass = COGL_DRIVER_GL_CLASS (klass);
driver_klass->pixel_format_to_gl = cogl_driver_gles2_pixel_format_to_gl;
driver_klass->get_read_pixels_format = cogl_driver_gles2_get_read_pixels_format;
driver_klass->update_features = cogl_driver_gles2_update_features;
driver_gl_klass->get_read_pixels_format = cogl_driver_gles2_get_read_pixels_format;
driver_gl_klass->pixel_format_to_gl = cogl_driver_gles2_pixel_format_to_gl;
}
static void