diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index c71e9143e2e..e326215e523 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -25,54 +25,53 @@ * Kristian Høgsberg */ +#include +#include +#include +#include #include #include -#include +#include #include #include -#include -#include -#include -#include -#include +#include #include #include -#include #ifdef HAVE_LIBDRM #include #include "drm-uapi/drm_fourcc.h" #endif #include #include -#include #include +#include #include "dri_screen.h" #ifdef HAVE_WAYLAND_PLATFORM -#include -#include "wayland-drm.h" -#include "wayland-drm-client-protocol.h" #include "linux-dmabuf-unstable-v1-client-protocol.h" +#include "wayland-drm-client-protocol.h" +#include "wayland-drm.h" +#include #endif #ifdef HAVE_X11_PLATFORM #include "X11/Xlibint.h" #endif -#include "egldefines.h" -#include "egl_dri2.h" #include "GL/mesa_glinterop.h" #include "loader/loader.h" +#include "mapi/glapi/glapi.h" +#include "pipe/p_screen.h" +#include "util/bitscan.h" +#include "util/driconf.h" #include "util/libsync.h" #include "util/os_file.h" #include "util/u_atomic.h" #include "util/u_call_once.h" -#include "util/u_vector.h" -#include "mapi/glapi/glapi.h" -#include "util/bitscan.h" -#include "util/driconf.h" #include "util/u_math.h" -#include "pipe/p_screen.h" +#include "util/u_vector.h" +#include "egl_dri2.h" +#include "egldefines.h" #define NUM_ATTRIBS 12 @@ -149,8 +148,8 @@ dri2_gl_flush() static void (*glFlush)(void); static util_once_flag once = UTIL_ONCE_FLAG_INIT; - util_call_once_data(&once, - (util_call_once_data_func)dri2_gl_flush_get, &glFlush); + util_call_once_data(&once, (util_call_once_data_func)dri2_gl_flush_get, + &glFlush); /* if glFlush is not available things are horribly broken */ if (!glFlush) { @@ -174,9 +173,9 @@ dri_is_thread_safe(UNUSED void *loaderPrivate) if (!loaderPrivate) return false; - _EGLDisplay *display = dri2_surf->base.Resource.Display; + _EGLDisplay *display = dri2_surf->base.Resource.Display; - Display *xdpy = (Display*)display->PlatformDisplay; + Display *xdpy = (Display *)display->PlatformDisplay; /* Check Xlib is running in thread safe mode when running on EGL/X11-xlib * platform @@ -192,20 +191,19 @@ dri_is_thread_safe(UNUSED void *loaderPrivate) } const __DRIbackgroundCallableExtension background_callable_extension = { - .base = { __DRI_BACKGROUND_CALLABLE, 2 }, + .base = {__DRI_BACKGROUND_CALLABLE, 2}, .setBackgroundContext = dri_set_background_context, - .isThreadSafe = dri_is_thread_safe, + .isThreadSafe = dri_is_thread_safe, }; const __DRIuseInvalidateExtension use_invalidate = { - .base = { __DRI_USE_INVALIDATE, 1 }, + .base = {__DRI_USE_INVALIDATE, 1}, }; static void -dri2_get_pbuffer_drawable_info(__DRIdrawable * draw, - int *x, int *y, int *w, int *h, - void *loaderPrivate) +dri2_get_pbuffer_drawable_info(__DRIdrawable *draw, int *x, int *y, int *w, + int *h, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; @@ -222,28 +220,27 @@ dri2_get_bytes_per_pixel(struct dri2_egl_surface *dri2_surf) } static void -dri2_put_image(__DRIdrawable * draw, int op, - int x, int y, int w, int h, +dri2_put_image(__DRIdrawable *draw, int op, int x, int y, int w, int h, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; const int bpp = dri2_get_bytes_per_pixel(dri2_surf); const int width = dri2_surf->base.Width; const int height = dri2_surf->base.Height; - const int dst_stride = width*bpp; - const int src_stride = w*bpp; - const int x_offset = x*bpp; + const int dst_stride = width * bpp; + const int src_stride = w * bpp; + const int x_offset = x * bpp; int copy_width = src_stride; if (!dri2_surf->swrast_device_buffer) - dri2_surf->swrast_device_buffer = malloc(height*dst_stride); + dri2_surf->swrast_device_buffer = malloc(height * dst_stride); if (dri2_surf->swrast_device_buffer) { const char *src = data; char *dst = dri2_surf->swrast_device_buffer; dst += x_offset; - dst += y*dst_stride; + dst += y * dst_stride; /* Drivers are allowed to submit OOB PutImage requests, so clip here. */ if (copy_width > dst_stride - x_offset) @@ -260,17 +257,16 @@ dri2_put_image(__DRIdrawable * draw, int op, } static void -dri2_get_image(__DRIdrawable * read, - int x, int y, int w, int h, - char *data, void *loaderPrivate) +dri2_get_image(__DRIdrawable *read, int x, int y, int w, int h, char *data, + void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; const int bpp = dri2_get_bytes_per_pixel(dri2_surf); const int width = dri2_surf->base.Width; const int height = dri2_surf->base.Height; - const int src_stride = width*bpp; - const int dst_stride = w*bpp; - const int x_offset = x*bpp; + const int src_stride = width * bpp; + const int dst_stride = w * bpp; + const int x_offset = x * bpp; int copy_width = dst_stride; const char *src = dri2_surf->swrast_device_buffer; char *dst = data; @@ -281,7 +277,7 @@ dri2_get_image(__DRIdrawable * read, } src += x_offset; - src += y*src_stride; + src += y * src_stride; /* Drivers are allowed to submit OOB GetImage requests, so clip here. */ if (copy_width > src_stride - x_offset) @@ -294,32 +290,31 @@ dri2_get_image(__DRIdrawable * read, src += src_stride; dst += dst_stride; } - } /* HACK: technically we should have swrast_null, instead of these. */ const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension = { - .base = { __DRI_SWRAST_LOADER, 1 }, + .base = {__DRI_SWRAST_LOADER, 1}, .getDrawableInfo = dri2_get_pbuffer_drawable_info, - .putImage = dri2_put_image, - .getImage = dri2_get_image, + .putImage = dri2_put_image, + .getImage = dri2_get_image, }; static const EGLint dri2_to_egl_attribute_map[__DRI_ATTRIB_MAX] = { - [__DRI_ATTRIB_BUFFER_SIZE ] = EGL_BUFFER_SIZE, - [__DRI_ATTRIB_LEVEL] = EGL_LEVEL, - [__DRI_ATTRIB_LUMINANCE_SIZE] = EGL_LUMINANCE_SIZE, - [__DRI_ATTRIB_DEPTH_SIZE] = EGL_DEPTH_SIZE, - [__DRI_ATTRIB_STENCIL_SIZE] = EGL_STENCIL_SIZE, - [__DRI_ATTRIB_SAMPLE_BUFFERS] = EGL_SAMPLE_BUFFERS, - [__DRI_ATTRIB_SAMPLES] = EGL_SAMPLES, - [__DRI_ATTRIB_MAX_PBUFFER_WIDTH] = EGL_MAX_PBUFFER_WIDTH, - [__DRI_ATTRIB_MAX_PBUFFER_HEIGHT] = EGL_MAX_PBUFFER_HEIGHT, - [__DRI_ATTRIB_MAX_PBUFFER_PIXELS] = EGL_MAX_PBUFFER_PIXELS, - [__DRI_ATTRIB_MAX_SWAP_INTERVAL] = EGL_MAX_SWAP_INTERVAL, - [__DRI_ATTRIB_MIN_SWAP_INTERVAL] = EGL_MIN_SWAP_INTERVAL, - [__DRI_ATTRIB_YINVERTED] = EGL_Y_INVERTED_NOK, + [__DRI_ATTRIB_BUFFER_SIZE] = EGL_BUFFER_SIZE, + [__DRI_ATTRIB_LEVEL] = EGL_LEVEL, + [__DRI_ATTRIB_LUMINANCE_SIZE] = EGL_LUMINANCE_SIZE, + [__DRI_ATTRIB_DEPTH_SIZE] = EGL_DEPTH_SIZE, + [__DRI_ATTRIB_STENCIL_SIZE] = EGL_STENCIL_SIZE, + [__DRI_ATTRIB_SAMPLE_BUFFERS] = EGL_SAMPLE_BUFFERS, + [__DRI_ATTRIB_SAMPLES] = EGL_SAMPLES, + [__DRI_ATTRIB_MAX_PBUFFER_WIDTH] = EGL_MAX_PBUFFER_WIDTH, + [__DRI_ATTRIB_MAX_PBUFFER_HEIGHT] = EGL_MAX_PBUFFER_HEIGHT, + [__DRI_ATTRIB_MAX_PBUFFER_PIXELS] = EGL_MAX_PBUFFER_PIXELS, + [__DRI_ATTRIB_MAX_SWAP_INTERVAL] = EGL_MAX_SWAP_INTERVAL, + [__DRI_ATTRIB_MIN_SWAP_INTERVAL] = EGL_MIN_SWAP_INTERVAL, + [__DRI_ATTRIB_YINVERTED] = EGL_Y_INVERTED_NOK, }; const __DRIconfig * @@ -347,12 +342,16 @@ dri2_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) void dri2_get_shifts_and_sizes(const __DRIcoreExtension *core, const __DRIconfig *config, int *shifts, - unsigned int *sizes) + unsigned int *sizes) { - core->getConfigAttrib(config, __DRI_ATTRIB_RED_SHIFT, (unsigned int *)&shifts[0]); - core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SHIFT, (unsigned int *)&shifts[1]); - core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SHIFT, (unsigned int *)&shifts[2]); - core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SHIFT, (unsigned int *)&shifts[3]); + core->getConfigAttrib(config, __DRI_ATTRIB_RED_SHIFT, + (unsigned int *)&shifts[0]); + core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SHIFT, + (unsigned int *)&shifts[1]); + core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SHIFT, + (unsigned int *)&shifts[2]); + core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SHIFT, + (unsigned int *)&shifts[3]); core->getConfigAttrib(config, __DRI_ATTRIB_RED_SIZE, &sizes[0]); core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SIZE, &sizes[1]); core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SIZE, &sizes[2]); @@ -361,8 +360,7 @@ dri2_get_shifts_and_sizes(const __DRIcoreExtension *core, void dri2_get_render_type_float(const __DRIcoreExtension *core, - const __DRIconfig *config, - bool *is_float) + const __DRIconfig *config, bool *is_float) { unsigned int render_type; @@ -408,8 +406,8 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, unsigned int attrib, value, double_buffer; bool srgb = false; EGLint key, bind_to_texture_rgb, bind_to_texture_rgba; - int dri_shifts[4] = { -1, -1, -1, -1 }; - unsigned int dri_sizes[4] = { 0, 0, 0, 0 }; + int dri_shifts[4] = {-1, -1, -1, -1}; + unsigned int dri_sizes[4] = {0, 0, 0, 0}; _EGLConfig *matching_config; EGLint num_configs = 0; EGLint config_id; @@ -498,7 +496,7 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, dri_shifts[2] = value; break; - case __DRI_ATTRIB_ALPHA_SIZE: + case __DRI_ATTRIB_ALPHA_SIZE: dri_sizes[3] = value; base.AlphaSize = value; break; @@ -546,7 +544,7 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, if (attr_list) for (int i = 0; attr_list[i] != EGL_NONE; i += 2) - _eglSetConfigKey(&base, attr_list[i], attr_list[i+1]); + _eglSetConfigKey(&base, attr_list[i], attr_list[i + 1]); if (rgba_shifts && memcmp(rgba_shifts, dri_shifts, sizeof(dri_shifts))) return NULL; @@ -557,8 +555,9 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, base.NativeRenderable = EGL_TRUE; base.SurfaceType = surface_type; - if (surface_type & (EGL_PBUFFER_BIT | - (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { + if (surface_type & + (EGL_PBUFFER_BIT | + (disp->Extensions.NOK_texture_from_pixmap ? EGL_PIXMAP_BIT : 0))) { base.BindToTextureRGB = bind_to_texture_rgb; if (base.AlphaSize > 0) base.BindToTextureRGBA = bind_to_texture_rgba; @@ -566,8 +565,7 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, if (double_buffer) { surface_type &= ~EGL_PIXMAP_BIT; - } - else { + } else { surface_type &= ~EGL_WINDOW_BIT; } @@ -586,21 +584,20 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, } config_id = base.ConfigID; - base.ConfigID = EGL_DONT_CARE; + base.ConfigID = EGL_DONT_CARE; base.SurfaceType = EGL_DONT_CARE; - num_configs = _eglFilterArray(disp->Configs, (void **) &matching_config, 1, - (_EGLArrayForEach) dri2_match_config, &base); + num_configs = _eglFilterArray(disp->Configs, (void **)&matching_config, 1, + (_EGLArrayForEach)dri2_match_config, &base); if (num_configs == 1) { - conf = (struct dri2_egl_config *) matching_config; + conf = (struct dri2_egl_config *)matching_config; if (!conf->dri_config[double_buffer][srgb]) conf->dri_config[double_buffer][srgb] = dri_config; else /* a similar config type is already added (unlikely) => discard */ return NULL; - } - else if (num_configs == 0) { + } else if (num_configs == 0) { conf = calloc(1, sizeof *conf); if (conf == NULL) return NULL; @@ -612,8 +609,7 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, conf->base.ConfigID = config_id; _eglLinkConfig(&conf->base); - } - else { + } else { unreachable("duplicates should not be possible"); return NULL; } @@ -627,7 +623,7 @@ EGLBoolean dri2_add_pbuffer_configs_for_visuals(_EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - unsigned int format_count[ARRAY_SIZE(dri2_pbuffer_visuals)] = { 0 }; + unsigned int format_count[ARRAY_SIZE(dri2_pbuffer_visuals)] = {0}; unsigned int config_count = 0; for (unsigned i = 0; dri2_dpy->driver_configs[i] != NULL; i++) { @@ -635,8 +631,9 @@ dri2_add_pbuffer_configs_for_visuals(_EGLDisplay *disp) struct dri2_egl_config *dri2_conf; dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], - config_count + 1, EGL_PBUFFER_BIT, NULL, - dri2_pbuffer_visuals[j].rgba_shifts, dri2_pbuffer_visuals[j].rgba_sizes); + config_count + 1, EGL_PBUFFER_BIT, NULL, + dri2_pbuffer_visuals[j].rgba_shifts, + dri2_pbuffer_visuals[j].rgba_sizes); if (dri2_conf) { if (dri2_conf->base.ConfigID == config_count + 1) @@ -649,7 +646,7 @@ dri2_add_pbuffer_configs_for_visuals(_EGLDisplay *disp) for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) { if (!format_count[i]) { _eglLog(_EGL_DEBUG, "No DRI config supports native format %s", - dri2_pbuffer_visuals[i].format_name); + dri2_pbuffer_visuals[i].format_name); } } @@ -686,7 +683,7 @@ dri2_lookup_egl_image_validated(void *image, void *data) __DRIimage * dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) { - (void) screen; + (void)screen; if (!dri2_validate_egl_image(image, data)) return NULL; @@ -695,55 +692,61 @@ dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data) } const __DRIimageLookupExtension image_lookup_extension = { - .base = { __DRI_IMAGE_LOOKUP, 2 }, + .base = {__DRI_IMAGE_LOOKUP, 2}, - .lookupEGLImage = dri2_lookup_egl_image, - .validateEGLImage = dri2_validate_egl_image, + .lookupEGLImage = dri2_lookup_egl_image, + .validateEGLImage = dri2_validate_egl_image, .lookupEGLImageValidated = dri2_lookup_egl_image_validated, }; - static const struct dri_extension_match dri3_driver_extensions[] = { - { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core), false }, - { __DRI_MESA, 1, offsetof(struct dri2_egl_display, mesa), false }, - { __DRI_IMAGE_DRIVER, 1, offsetof(struct dri2_egl_display, image_driver), false }, - { __DRI_CONFIG_OPTIONS, 2, offsetof(struct dri2_egl_display, configOptions), true }, + {__DRI_CORE, 1, offsetof(struct dri2_egl_display, core), false}, + {__DRI_MESA, 1, offsetof(struct dri2_egl_display, mesa), false}, + {__DRI_IMAGE_DRIVER, 1, offsetof(struct dri2_egl_display, image_driver), + false}, + {__DRI_CONFIG_OPTIONS, 2, offsetof(struct dri2_egl_display, configOptions), + true}, }; static const struct dri_extension_match dri2_driver_extensions[] = { - { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core), false }, - { __DRI_MESA, 1, offsetof(struct dri2_egl_display, mesa), false }, - { __DRI_DRI2, 4, offsetof(struct dri2_egl_display, dri2), false }, - { __DRI_CONFIG_OPTIONS, 2, offsetof(struct dri2_egl_display, configOptions), true }, + {__DRI_CORE, 1, offsetof(struct dri2_egl_display, core), false}, + {__DRI_MESA, 1, offsetof(struct dri2_egl_display, mesa), false}, + {__DRI_DRI2, 4, offsetof(struct dri2_egl_display, dri2), false}, + {__DRI_CONFIG_OPTIONS, 2, offsetof(struct dri2_egl_display, configOptions), + true}, }; static const struct dri_extension_match dri2_core_extensions[] = { - { __DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush), false }, - { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer), false }, - { __DRI_IMAGE, 6, offsetof(struct dri2_egl_display, image), false }, + {__DRI2_FLUSH, 1, offsetof(struct dri2_egl_display, flush), false}, + {__DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer), false}, + {__DRI_IMAGE, 6, offsetof(struct dri2_egl_display, image), false}, }; static const struct dri_extension_match swrast_driver_extensions[] = { - { __DRI_CORE, 1, offsetof(struct dri2_egl_display, core), false }, - { __DRI_MESA, 1, offsetof(struct dri2_egl_display, mesa), false }, - { __DRI_SWRAST, 4, offsetof(struct dri2_egl_display, swrast), false }, - { __DRI_CONFIG_OPTIONS, 2, offsetof(struct dri2_egl_display, configOptions), true }, + {__DRI_CORE, 1, offsetof(struct dri2_egl_display, core), false}, + {__DRI_MESA, 1, offsetof(struct dri2_egl_display, mesa), false}, + {__DRI_SWRAST, 4, offsetof(struct dri2_egl_display, swrast), false}, + {__DRI_CONFIG_OPTIONS, 2, offsetof(struct dri2_egl_display, configOptions), + true}, }; static const struct dri_extension_match swrast_core_extensions[] = { - { __DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer), false }, + {__DRI_TEX_BUFFER, 2, offsetof(struct dri2_egl_display, tex_buffer), false}, }; static const struct dri_extension_match optional_core_extensions[] = { - { __DRI2_CONFIG_QUERY, 1, offsetof(struct dri2_egl_display, config), true }, - { __DRI2_FENCE, 2, offsetof(struct dri2_egl_display, fence), true }, - { __DRI2_BUFFER_DAMAGE, 1, offsetof(struct dri2_egl_display, buffer_damage), true }, - { __DRI2_INTEROP, 1, offsetof(struct dri2_egl_display, interop), true }, - { __DRI_IMAGE, 6, offsetof(struct dri2_egl_display, image), true }, - { __DRI2_FLUSH_CONTROL, 1, offsetof(struct dri2_egl_display, flush_control), true }, - { __DRI2_BLOB, 1, offsetof(struct dri2_egl_display, blob), true }, - { __DRI_MUTABLE_RENDER_BUFFER_DRIVER, 1, offsetof(struct dri2_egl_display, mutable_render_buffer), true }, - { __DRI_KOPPER, 1, offsetof(struct dri2_egl_display, kopper), true }, + {__DRI2_CONFIG_QUERY, 1, offsetof(struct dri2_egl_display, config), true}, + {__DRI2_FENCE, 2, offsetof(struct dri2_egl_display, fence), true}, + {__DRI2_BUFFER_DAMAGE, 1, offsetof(struct dri2_egl_display, buffer_damage), + true}, + {__DRI2_INTEROP, 1, offsetof(struct dri2_egl_display, interop), true}, + {__DRI_IMAGE, 6, offsetof(struct dri2_egl_display, image), true}, + {__DRI2_FLUSH_CONTROL, 1, offsetof(struct dri2_egl_display, flush_control), + true}, + {__DRI2_BLOB, 1, offsetof(struct dri2_egl_display, blob), true}, + {__DRI_MUTABLE_RENDER_BUFFER_DRIVER, 1, + offsetof(struct dri2_egl_display, mutable_render_buffer), true}, + {__DRI_KOPPER, 1, offsetof(struct dri2_egl_display, kopper), true}, }; static const __DRIextension ** @@ -755,8 +758,7 @@ dri2_open_driver(_EGLDisplay *disp) NULL, }; - return loader_open_driver(dri2_dpy->driver_name, - &dri2_dpy->driver, + return loader_open_driver(dri2_dpy->driver_name, &dri2_dpy->driver, search_path_vars); } @@ -772,7 +774,8 @@ dri2_load_driver_common(_EGLDisplay *disp, if (!extensions) return EGL_FALSE; - if (!loader_bind_extensions(dri2_dpy, driver_extensions, num_matches, extensions)) { + if (!loader_bind_extensions(dri2_dpy, driver_extensions, num_matches, + extensions)) { dlclose(dri2_dpy->driver); dri2_dpy->driver = NULL; return EGL_FALSE; @@ -785,39 +788,42 @@ dri2_load_driver_common(_EGLDisplay *disp, EGLBoolean dri2_load_driver(_EGLDisplay *disp) { - return dri2_load_driver_common(disp, dri2_driver_extensions, ARRAY_SIZE(dri2_driver_extensions)); + return dri2_load_driver_common(disp, dri2_driver_extensions, + ARRAY_SIZE(dri2_driver_extensions)); } EGLBoolean dri2_load_driver_dri3(_EGLDisplay *disp) { - return dri2_load_driver_common(disp, dri3_driver_extensions, ARRAY_SIZE(dri3_driver_extensions)); + return dri2_load_driver_common(disp, dri3_driver_extensions, + ARRAY_SIZE(dri3_driver_extensions)); } EGLBoolean dri2_load_driver_swrast(_EGLDisplay *disp) { - return dri2_load_driver_common(disp, swrast_driver_extensions, ARRAY_SIZE(swrast_driver_extensions)); + return dri2_load_driver_common(disp, swrast_driver_extensions, + ARRAY_SIZE(swrast_driver_extensions)); } static const char * dri2_query_driver_name(_EGLDisplay *disp) { - struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - return dri2_dpy->driver_name; + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + return dri2_dpy->driver_name; } static char * dri2_query_driver_config(_EGLDisplay *disp) { - struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); - char *ret; + struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); + char *ret; - ret = dri2_dpy->configOptions->getXml(dri2_dpy->driver_name); + ret = dri2_dpy->configOptions->getXml(dri2_dpy->driver_name); - mtx_unlock(&dri2_dpy->lock); + mtx_unlock(&dri2_dpy->lock); - return ret; + return ret; } static int @@ -849,7 +855,7 @@ dri2_setup_screen(_EGLDisplay *disp) dri2_dpy->default_swap_interval = 1; disp->ClientAPIs = 0; - if ((api_mask & (1 <<__DRI_API_OPENGL)) && _eglIsApiValid(EGL_OPENGL_API)) + if ((api_mask & (1 << __DRI_API_OPENGL)) && _eglIsApiValid(EGL_OPENGL_API)) disp->ClientAPIs |= EGL_OPENGL_BIT; if ((api_mask & (1 << __DRI_API_GLES)) && _eglIsApiValid(EGL_OPENGL_ES_API)) disp->ClientAPIs |= EGL_OPENGL_ES_BIT; @@ -865,22 +871,23 @@ dri2_setup_screen(_EGLDisplay *disp) disp->Extensions.KHR_surfaceless_context = EGL_TRUE; if (dri2_dpy->configOptions) { - disp->Extensions.MESA_query_driver = EGL_TRUE; + disp->Extensions.MESA_query_driver = EGL_TRUE; } /* Report back to EGL the bitmask of priorities supported */ - disp->Extensions.IMG_context_priority = get_screen_param(disp, PIPE_CAP_CONTEXT_PRIORITY_MASK); + disp->Extensions.IMG_context_priority = + get_screen_param(disp, PIPE_CAP_CONTEXT_PRIORITY_MASK); disp->Extensions.EXT_pixel_format_float = EGL_TRUE; - if (pscreen->is_format_supported(pscreen, - PIPE_FORMAT_B8G8R8A8_SRGB, + if (pscreen->is_format_supported(pscreen, PIPE_FORMAT_B8G8R8A8_SRGB, PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_RENDER_TARGET)) { disp->Extensions.KHR_gl_colorspace = EGL_TRUE; } - disp->Extensions.EXT_create_context_robustness = get_screen_param(disp, PIPE_CAP_DEVICE_RESET_STATUS_QUERY); + disp->Extensions.EXT_create_context_robustness = + get_screen_param(disp, PIPE_CAP_DEVICE_RESET_STATUS_QUERY); if (dri2_dpy->fence) { disp->Extensions.KHR_fence_sync = EGL_TRUE; @@ -903,8 +910,10 @@ dri2_setup_screen(_EGLDisplay *disp) dri2_dpy->image->getCapabilities != NULL) { int capabilities; - capabilities = dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen_render_gpu); - disp->Extensions.MESA_drm_image = (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0; + capabilities = + dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen_render_gpu); + disp->Extensions.MESA_drm_image = + (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0; if (dri2_dpy->image->base.version >= 11) disp->Extensions.MESA_image_dma_buf_export = EGL_TRUE; @@ -988,30 +997,25 @@ dri2_create_screen(_EGLDisplay *disp) char *driver_name_display_gpu; if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) { - driver_name_display_gpu = loader_get_driver_for_fd(dri2_dpy->fd_display_gpu); + driver_name_display_gpu = + loader_get_driver_for_fd(dri2_dpy->fd_display_gpu); if (driver_name_display_gpu) { /* check if driver name is matching so that non mesa drivers * will not crash. */ if (strcmp(dri2_dpy->driver_name, driver_name_display_gpu) == 0) { - dri2_dpy->dri_screen_display_gpu = - dri2_dpy->mesa->createNewScreen(0, dri2_dpy->fd_display_gpu, - dri2_dpy->loader_extensions, - dri2_dpy->driver_extensions, - &dri2_dpy->driver_configs, - disp); + dri2_dpy->dri_screen_display_gpu = dri2_dpy->mesa->createNewScreen( + 0, dri2_dpy->fd_display_gpu, dri2_dpy->loader_extensions, + dri2_dpy->driver_extensions, &dri2_dpy->driver_configs, disp); } free(driver_name_display_gpu); } } int screen_fd = dri2_dpy->swrast ? -1 : dri2_dpy->fd_render_gpu; - dri2_dpy->dri_screen_render_gpu = - dri2_dpy->mesa->createNewScreen(0, screen_fd, - dri2_dpy->loader_extensions, - dri2_dpy->driver_extensions, - &dri2_dpy->driver_configs, - disp); + dri2_dpy->dri_screen_render_gpu = dri2_dpy->mesa->createNewScreen( + 0, screen_fd, dri2_dpy->loader_extensions, dri2_dpy->driver_extensions, + &dri2_dpy->driver_configs, disp); if (dri2_dpy->dri_screen_render_gpu == NULL) { _eglLog(_EGL_WARNING, "egl: failed to create dri2 screen"); @@ -1034,23 +1038,29 @@ dri2_setup_extensions(_EGLDisplay *disp) extensions = dri2_dpy->core->getExtensions(dri2_dpy->dri_screen_render_gpu); if (dri2_dpy->image_driver || dri2_dpy->dri2 || disp->Options.Zink) { - if (!loader_bind_extensions(dri2_dpy, dri2_core_extensions, ARRAY_SIZE(dri2_core_extensions), extensions)) + if (!loader_bind_extensions(dri2_dpy, dri2_core_extensions, + ARRAY_SIZE(dri2_core_extensions), extensions)) return EGL_FALSE; } else { - if (!loader_bind_extensions(dri2_dpy, swrast_core_extensions, ARRAY_SIZE(swrast_core_extensions), extensions)) + if (!loader_bind_extensions(dri2_dpy, swrast_core_extensions, + ARRAY_SIZE(swrast_core_extensions), + extensions)) return EGL_FALSE; } #ifdef HAVE_DRI3_MODIFIERS dri2_dpy->multibuffers_available = - (dri2_dpy->dri3_major_version > 1 || (dri2_dpy->dri3_major_version == 1 && - dri2_dpy->dri3_minor_version >= 2)) && - (dri2_dpy->present_major_version > 1 || (dri2_dpy->present_major_version == 1 && - dri2_dpy->present_minor_version >= 2)) && + (dri2_dpy->dri3_major_version > 1 || + (dri2_dpy->dri3_major_version == 1 && + dri2_dpy->dri3_minor_version >= 2)) && + (dri2_dpy->present_major_version > 1 || + (dri2_dpy->present_major_version == 1 && + dri2_dpy->present_minor_version >= 2)) && (dri2_dpy->image && dri2_dpy->image->base.version >= 15); #endif - loader_bind_extensions(dri2_dpy, optional_core_extensions, ARRAY_SIZE(optional_core_extensions), extensions); + loader_bind_extensions(dri2_dpy, optional_core_extensions, + ARRAY_SIZE(optional_core_extensions), extensions); return EGL_TRUE; } @@ -1158,14 +1168,15 @@ dri2_display_destroy(_EGLDisplay *disp) dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen_display_gpu); } - if (dri2_dpy->fd_display_gpu >= 0 &&dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) + if (dri2_dpy->fd_display_gpu >= 0 && + dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) close(dri2_dpy->fd_display_gpu); if (dri2_dpy->fd_render_gpu >= 0) close(dri2_dpy->fd_render_gpu); - /* Don't dlclose the driver when building with the address sanitizer, so you - * get good symbols from the leak reports. - */ + /* Don't dlclose the driver when building with the address sanitizer, so + * you get good symbols from the leak reports. + */ #if !BUILT_WITH_ASAN || defined(NDEBUG) if (dri2_dpy->driver) dlclose(dri2_dpy->driver); @@ -1198,7 +1209,7 @@ dri2_display_destroy(_EGLDisplay *disp) */ if (disp->Platform != _EGL_PLATFORM_DRM && dri2_dpy->driver_configs) { for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) - free((__DRIconfig *) dri2_dpy->driver_configs[i]); + free((__DRIconfig *)dri2_dpy->driver_configs[i]); free(dri2_dpy->driver_configs); } free(dri2_dpy); @@ -1216,9 +1227,9 @@ dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf, return NULL; if (!dri2_surf->local_buffers[att]) { - dri2_surf->local_buffers[att] = - dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen_render_gpu, att, format, - dri2_surf->base.Width, dri2_surf->base.Height); + dri2_surf->local_buffers[att] = dri2_dpy->dri2->allocateBuffer( + dri2_dpy->dri_screen_render_gpu, att, format, dri2_surf->base.Width, + dri2_surf->base.Height); } return dri2_surf->local_buffers[att]; @@ -1273,39 +1284,39 @@ dri2_create_context_attribs_error(int dri_error) egl_error = EGL_BAD_ALLOC; break; - /* From the EGL_KHR_create_context spec, section "Errors": - * - * * If does not support a client API context compatible - * with the requested API major and minor version, [...] context flags, - * and context reset notification behavior (for client API types where - * these attributes are supported), then an EGL_BAD_MATCH error is - * generated. - * - * * If an OpenGL ES context is requested and the values for - * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and - * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that - * is not defined, than an EGL_BAD_MATCH error is generated. - * - * * If an OpenGL context is requested, the requested version is - * greater than 3.2, and the value for attribute - * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any - * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and - * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than - * one of these bits set; or if the implementation does not support - * the requested profile, then an EGL_BAD_MATCH error is generated. - */ + /* From the EGL_KHR_create_context spec, section "Errors": + * + * * If does not support a client API context compatible + * with the requested API major and minor version, [...] context + * flags, and context reset notification behavior (for client API types + * where these attributes are supported), then an EGL_BAD_MATCH error is + * generated. + * + * * If an OpenGL ES context is requested and the values for + * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and + * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that + * is not defined, than an EGL_BAD_MATCH error is generated. + * + * * If an OpenGL context is requested, the requested version is + * greater than 3.2, and the value for attribute + * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any + * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and + * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than + * one of these bits set; or if the implementation does not support + * the requested profile, then an EGL_BAD_MATCH error is generated. + */ case __DRI_CTX_ERROR_BAD_API: case __DRI_CTX_ERROR_BAD_VERSION: case __DRI_CTX_ERROR_BAD_FLAG: egl_error = EGL_BAD_MATCH; break; - /* From the EGL_KHR_create_context spec, section "Errors": - * - * * If an attribute name or attribute value in is not - * recognized (including unrecognized bits in bitmask attributes), - * then an EGL_BAD_ATTRIBUTE error is generated." - */ + /* From the EGL_KHR_create_context spec, section "Errors": + * + * * If an attribute name or attribute value in is not + * recognized (including unrecognized bits in bitmask attributes), + * then an EGL_BAD_ATTRIBUTE error is generated." + */ case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE: case __DRI_CTX_ERROR_UNKNOWN_FLAG: egl_error = EGL_BAD_ATTRIBUTE; @@ -1323,8 +1334,7 @@ dri2_create_context_attribs_error(int dri_error) static bool dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx, struct dri2_egl_display *dri2_dpy, - uint32_t *ctx_attribs, - unsigned *num_attribs) + uint32_t *ctx_attribs, unsigned *num_attribs) { int pos = 0; @@ -1340,7 +1350,8 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx, ctx_attribs[pos++] = dri2_ctx->base.Flags; } - if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) { + if (dri2_ctx->base.ResetNotificationStrategy != + EGL_NO_RESET_NOTIFICATION_KHR) { ctx_attribs[pos++] = __DRI_CTX_ATTRIB_RESET_STRATEGY; ctx_attribs[pos++] = __DRI_CTX_RESET_LOSE_CONTEXT; } @@ -1367,7 +1378,8 @@ dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx, ctx_attribs[pos++] = val; } - if (dri2_ctx->base.ReleaseBehavior == EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR) { + if (dri2_ctx->base.ReleaseBehavior == + EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR) { ctx_attribs[pos++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR; ctx_attribs[pos++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE; } @@ -1397,8 +1409,7 @@ dri2_create_context(_EGLDisplay *disp, _EGLConfig *conf, struct dri2_egl_context *dri2_ctx; struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); struct dri2_egl_context *dri2_ctx_shared = dri2_egl_context(share_list); - __DRIcontext *shared = - dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL; + __DRIcontext *shared = dri2_ctx_shared ? dri2_ctx_shared->dri_context : NULL; struct dri2_egl_config *dri2_config = dri2_egl_config(conf); const __DRIconfig *dri_config; int api; @@ -1433,10 +1444,10 @@ dri2_create_context(_EGLDisplay *disp, _EGLConfig *conf, } break; case EGL_OPENGL_API: - if ((dri2_ctx->base.ClientMajorVersion >= 4 - || (dri2_ctx->base.ClientMajorVersion == 3 - && dri2_ctx->base.ClientMinorVersion >= 2)) - && dri2_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) + if ((dri2_ctx->base.ClientMajorVersion >= 4 || + (dri2_ctx->base.ClientMajorVersion == 3 && + dri2_ctx->base.ClientMinorVersion >= 2)) && + dri2_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) api = __DRI_API_OPENGL_CORE; else if (dri2_ctx->base.ClientMajorVersion == 3 && dri2_ctx->base.ClientMinorVersion == 1) @@ -1461,23 +1472,16 @@ dri2_create_context(_EGLDisplay *disp, _EGLConfig *conf, dri_config = dri2_config->dri_config[1][0]; else dri_config = dri2_config->dri_config[0][0]; - } - else + } else dri_config = NULL; if (!dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs, &num_attribs)) goto cleanup; - dri2_ctx->dri_context = - dri2_dpy->mesa->createContext(dri2_dpy->dri_screen_render_gpu, - api, - dri_config, - shared, - num_attribs / 2, - ctx_attribs, - &error, - dri2_ctx); + dri2_ctx->dri_context = dri2_dpy->mesa->createContext( + dri2_dpy->dri_screen_render_gpu, api, dri_config, shared, num_attribs / 2, + ctx_attribs, &error, dri2_ctx); dri2_create_context_attribs_error(error); if (!dri2_ctx->dri_context) @@ -1487,7 +1491,7 @@ dri2_create_context(_EGLDisplay *disp, _EGLConfig *conf, return &dri2_ctx->base; - cleanup: +cleanup: mtx_unlock(&dri2_dpy->lock); free(dri2_ctx); return NULL; @@ -1512,8 +1516,8 @@ dri2_destroy_context(_EGLDisplay *disp, _EGLContext *ctx) EGLBoolean dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, - _EGLConfig *conf, const EGLint *attrib_list, - EGLBoolean enable_out_fence, void *native_surface) + _EGLConfig *conf, const EGLint *attrib_list, + EGLBoolean enable_out_fence, void *native_surface) { struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -1530,7 +1534,7 @@ dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, } static void -dri2_surface_set_out_fence_fd( _EGLSurface *surf, int fence_fd) +dri2_surface_set_out_fence_fd(_EGLSurface *surf, int fence_fd) { struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); @@ -1562,8 +1566,8 @@ dri2_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) } static void -dri2_surf_update_fence_fd(_EGLContext *ctx, - _EGLDisplay *disp, _EGLSurface *surf) +dri2_surf_update_fence_fd(_EGLContext *ctx, _EGLDisplay *disp, + _EGLSurface *surf) { __DRIcontext *dri_ctx = dri2_egl_context(ctx)->dri_context; struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -1576,8 +1580,8 @@ dri2_surf_update_fence_fd(_EGLContext *ctx, fence = dri2_dpy->fence->create_fence_fd(dri_ctx, -1); if (fence) { - fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen_render_gpu, - fence); + fence_fd = + dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen_render_gpu, fence); dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen_render_gpu, fence); } dri2_surface_set_out_fence_fd(surf, fence_fd); @@ -1586,15 +1590,13 @@ dri2_surf_update_fence_fd(_EGLContext *ctx, EGLBoolean dri2_create_drawable(struct dri2_egl_display *dri2_dpy, const __DRIconfig *config, - struct dri2_egl_surface *dri2_surf, - void *loaderPrivate) + struct dri2_egl_surface *dri2_surf, void *loaderPrivate) { if (dri2_dpy->kopper) { - dri2_surf->dri_drawable = - dri2_dpy->kopper->createNewDrawable(dri2_dpy->dri_screen_render_gpu, - config, loaderPrivate, - dri2_surf->base.Type == EGL_PBUFFER_BIT || - dri2_surf->base.Type == EGL_PIXMAP_BIT); + dri2_surf->dri_drawable = dri2_dpy->kopper->createNewDrawable( + dri2_dpy->dri_screen_render_gpu, config, loaderPrivate, + dri2_surf->base.Type == EGL_PBUFFER_BIT || + dri2_surf->base.Type == EGL_PIXMAP_BIT); } else { __DRIcreateNewDrawableFunc createNewDrawable; if (dri2_dpy->image_driver) @@ -1606,8 +1608,8 @@ dri2_create_drawable(struct dri2_egl_display *dri2_dpy, else return _eglError(EGL_BAD_ALLOC, "no createNewDrawable"); - dri2_surf->dri_drawable = createNewDrawable(dri2_dpy->dri_screen_render_gpu, - config, loaderPrivate); + dri2_surf->dri_drawable = createNewDrawable( + dri2_dpy->dri_screen_render_gpu, config, loaderPrivate); } if (dri2_surf->dri_drawable == NULL) return _eglError(EGL_BAD_ALLOC, "createNewDrawable"); @@ -1619,8 +1621,8 @@ dri2_create_drawable(struct dri2_egl_display *dri2_dpy, * Called via eglMakeCurrent(), drv->MakeCurrent(). */ static EGLBoolean -dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, - _EGLSurface *rsurf, _EGLContext *ctx) +dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf, + _EGLContext *ctx) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); @@ -1679,9 +1681,9 @@ dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, egl_error = EGL_BAD_MATCH; /* undo the previous _eglBindContext */ - _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf); - assert(&dri2_ctx->base == ctx && - tmp_dsurf == dsurf && + _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, + &tmp_rsurf); + assert(&dri2_ctx->base == ctx && tmp_dsurf == dsurf && tmp_rsurf == rsurf); _eglPutSurface(dsurf); @@ -1692,15 +1694,18 @@ dri2_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _eglPutSurface(old_rsurf); _eglPutContext(old_ctx); - ddraw = (old_dsurf) ? dri2_dpy->vtbl->get_dri_drawable(old_dsurf) : NULL; - rdraw = (old_rsurf) ? dri2_dpy->vtbl->get_dri_drawable(old_rsurf) : NULL; + ddraw = + (old_dsurf) ? dri2_dpy->vtbl->get_dri_drawable(old_dsurf) : NULL; + rdraw = + (old_rsurf) ? dri2_dpy->vtbl->get_dri_drawable(old_rsurf) : NULL; cctx = (old_ctx) ? dri2_egl_context(old_ctx)->dri_context : NULL; /* undo the previous dri2_dpy->core->unbindContext */ if (dri2_dpy->core->bindContext(cctx, ddraw, rdraw)) { if (old_dsurf && _eglSurfaceInSharedBufferMode(old_dsurf) && old_dri2_dpy->vtbl->set_shared_buffer_mode) { - old_dri2_dpy->vtbl->set_shared_buffer_mode(old_disp, old_dsurf, true); + old_dri2_dpy->vtbl->set_shared_buffer_mode(old_disp, old_dsurf, + true); } return _eglError(egl_error, "eglMakeCurrent"); @@ -1763,19 +1768,18 @@ dri2_surface_get_dri_drawable(_EGLSurface *surf) return dri2_surf->dri_drawable; } -static _EGLSurface* +static _EGLSurface * dri2_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); - _EGLSurface *ret = - dri2_dpy->vtbl->create_window_surface(disp, conf, native_window, - attrib_list); + _EGLSurface *ret = dri2_dpy->vtbl->create_window_surface( + disp, conf, native_window, attrib_list); mtx_unlock(&dri2_dpy->lock); return ret; } -static _EGLSurface* +static _EGLSurface * dri2_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list) { @@ -1791,7 +1795,7 @@ dri2_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, return ret; } -static _EGLSurface* +static _EGLSurface * dri2_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { @@ -1825,8 +1829,9 @@ dri2_swap_interval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval) * do our swapbuffers. */ void -dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw, - enum __DRI2throttleReason throttle_reason) +dri2_flush_drawable_for_swapbuffers_flags( + _EGLDisplay *disp, _EGLSurface *draw, + enum __DRI2throttleReason throttle_reason) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(draw); @@ -1837,7 +1842,7 @@ dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw, * * "If surface is not bound to the calling thread’s current * context, an EGL_BAD_SURFACE error is generated." - */ + */ _EGLContext *ctx = _eglGetCurrentContext(); struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); @@ -1846,11 +1851,10 @@ dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw, * "The contents of ancillary buffers are always undefined * after calling eglSwapBuffers." */ - dri2_dpy->flush->flush_with_flags(dri2_ctx->dri_context, - dri_drawable, - __DRI2_FLUSH_DRAWABLE | - __DRI2_FLUSH_INVALIDATE_ANCILLARY, - throttle_reason); + dri2_dpy->flush->flush_with_flags( + dri2_ctx->dri_context, dri_drawable, + __DRI2_FLUSH_DRAWABLE | __DRI2_FLUSH_INVALIDATE_ANCILLARY, + throttle_reason); } else { dri2_dpy->flush->flush(dri_drawable); } @@ -1860,7 +1864,8 @@ dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw, void dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw) { - dri2_flush_drawable_for_swapbuffers_flags(disp, draw, __DRI2_THROTTLE_SWAPBUFFER); + dri2_flush_drawable_for_swapbuffers_flags(disp, draw, + __DRI2_THROTTLE_SWAPBUFFER); } static EGLBoolean @@ -1897,8 +1902,8 @@ dri2_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *surf, if (ctx && surf) dri2_surf_update_fence_fd(ctx, disp, surf); if (dri2_dpy->vtbl->swap_buffers_with_damage) - ret = dri2_dpy->vtbl->swap_buffers_with_damage(disp, surf, - rects, n_rects); + ret = + dri2_dpy->vtbl->swap_buffers_with_damage(disp, surf, rects, n_rects); else ret = dri2_dpy->vtbl->swap_buffers(disp, surf); @@ -1913,8 +1918,8 @@ dri2_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *surf, } static EGLBoolean -dri2_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *surf, - EGLint numRects, const EGLint *rects) +dri2_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *surf, EGLint numRects, + const EGLint *rects) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); @@ -1935,13 +1940,14 @@ dri2_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *surf, } static EGLBoolean -dri2_set_damage_region(_EGLDisplay *disp, _EGLSurface *surf, - EGLint *rects, EGLint n_rects) +dri2_set_damage_region(_EGLDisplay *disp, _EGLSurface *surf, EGLint *rects, + EGLint n_rects) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); __DRIdrawable *drawable = dri2_dpy->vtbl->get_dri_drawable(surf); - if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region) { + if (!dri2_dpy->buffer_damage || + !dri2_dpy->buffer_damage->set_damage_region) { mtx_unlock(&dri2_dpy->lock); return EGL_FALSE; } @@ -1952,8 +1958,8 @@ dri2_set_damage_region(_EGLDisplay *disp, _EGLSurface *surf, } static EGLBoolean -dri2_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *surf, - EGLint x, EGLint y, EGLint width, EGLint height) +dri2_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *surf, EGLint x, EGLint y, + EGLint width, EGLint height) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); EGLBoolean ret = EGL_FALSE; @@ -1967,12 +1973,15 @@ dri2_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *surf, } static EGLBoolean -dri2_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_target) +dri2_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, + void *native_pixmap_target) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); if (!dri2_dpy->vtbl->copy_buffers) - return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_NATIVE_PIXMAP, "no support for native pixmaps"); - EGLBoolean ret = dri2_dpy->vtbl->copy_buffers(disp, surf, native_pixmap_target); + return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_NATIVE_PIXMAP, + "no support for native pixmaps"); + EGLBoolean ret = + dri2_dpy->vtbl->copy_buffers(disp, surf, native_pixmap_target); mtx_unlock(&dri2_dpy->lock); return ret; } @@ -2050,8 +2059,7 @@ dri2_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) assert(!"Unexpected texture target in dri2_bind_tex_image()"); } - dri2_dpy->tex_buffer->setTexBuffer2(dri2_ctx->dri_context, - target, format, + dri2_dpy->tex_buffer->setTexBuffer2(dri2_ctx->dri_context, target, format, dri_drawable); mtx_unlock(&dri2_dpy->lock); @@ -2065,7 +2073,7 @@ dri2_release_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); struct dri2_egl_context *dri2_ctx; _EGLContext *ctx; - GLint target; + GLint target; __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf); ctx = _eglGetCurrentContext(); @@ -2086,8 +2094,8 @@ dri2_release_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) if (dri2_dpy->tex_buffer->base.version >= 3 && dri2_dpy->tex_buffer->releaseTexBuffer != NULL) { - dri2_dpy->tex_buffer->releaseTexBuffer(dri2_ctx->dri_context, - target, dri_drawable); + dri2_dpy->tex_buffer->releaseTexBuffer(dri2_ctx->dri_context, target, + dri_drawable); } mtx_unlock(&dri2_dpy->lock); @@ -2095,13 +2103,13 @@ dri2_release_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) return EGL_TRUE; } -static _EGLImage* +static _EGLImage * dri2_create_image(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); - _EGLImage *ret = dri2_dpy->vtbl->create_image(disp, ctx, target, buffer, - attr_list); + _EGLImage *ret = + dri2_dpy->vtbl->create_image(disp, ctx, target, buffer, attr_list); mtx_unlock(&dri2_dpy->lock); return ret; } @@ -2159,7 +2167,7 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); - GLuint renderbuffer = (GLuint) (uintptr_t) buffer; + GLuint renderbuffer = (GLuint)(uintptr_t)buffer; __DRIimage *dri_image; if (renderbuffer == 0) { @@ -2177,17 +2185,18 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, unsigned error = ~0; dri_image = dri2_dpy->image->createImageFromRenderbuffer2( - dri2_ctx->dri_context, renderbuffer, NULL, &error); + dri2_ctx->dri_context, renderbuffer, NULL, &error); assert(!!dri_image == (error == __DRI_IMAGE_ERROR_SUCCESS)); if (!dri_image) { - _eglError(egl_error_from_dri_image_error(error), "dri2_create_image_khr"); + _eglError(egl_error_from_dri_image_error(error), + "dri2_create_image_khr"); return EGL_NO_IMAGE_KHR; } } else { dri_image = dri2_dpy->image->createImageFromRenderbuffer( - dri2_ctx->dri_context, renderbuffer, NULL); + dri2_ctx->dri_context, renderbuffer, NULL); if (!dri_image) { _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr"); return EGL_NO_IMAGE_KHR; @@ -2210,11 +2219,11 @@ static const struct wl_drm_components_descriptor { EGLint components; int nplanes; } wl_drm_components[] = { - { __DRI_IMAGE_COMPONENTS_RGB, EGL_TEXTURE_RGB, 1 }, - { __DRI_IMAGE_COMPONENTS_RGBA, EGL_TEXTURE_RGBA, 1 }, - { __DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3 }, - { __DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2 }, - { __DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2 }, + {__DRI_IMAGE_COMPONENTS_RGB, EGL_TEXTURE_RGB, 1}, + {__DRI_IMAGE_COMPONENTS_RGBA, EGL_TEXTURE_RGBA, 1}, + {__DRI_IMAGE_COMPONENTS_Y_U_V, EGL_TEXTURE_Y_U_V_WL, 3}, + {__DRI_IMAGE_COMPONENTS_Y_UV, EGL_TEXTURE_Y_UV_WL, 2}, + {__DRI_IMAGE_COMPONENTS_Y_XUXV, EGL_TEXTURE_Y_XUXV_WL, 2}, }; static _EGLImage * @@ -2230,9 +2239,9 @@ dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx, int32_t plane; buffer = wayland_drm_buffer_get(dri2_dpy->wl_server_drm, - (struct wl_resource *) _buffer); + (struct wl_resource *)_buffer); if (!buffer) - return NULL; + return NULL; if (!_eglParseImageAttribList(&attrs, disp, attr_list)) return NULL; @@ -2272,8 +2281,8 @@ dri2_get_sync_values_chromium(_EGLDisplay *disp, _EGLSurface *surf, } static EGLBoolean -dri2_get_msc_rate_angle(_EGLDisplay *disp, _EGLSurface *surf, - EGLint *numerator, EGLint *denominator) +dri2_get_msc_rate_angle(_EGLDisplay *disp, _EGLSurface *surf, EGLint *numerator, + EGLint *denominator) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); if (!dri2_dpy->vtbl->get_msc_rate) @@ -2296,14 +2305,13 @@ dri2_create_image_khr_texture_error(int dri_error) static _EGLImage * dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, - EGLenum target, - EGLClientBuffer buffer, - const EGLint *attr_list) + EGLenum target, EGLClientBuffer buffer, + const EGLint *attr_list) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); struct dri2_egl_image *dri2_img; - GLuint texture = (GLuint) (uintptr_t) buffer; + GLuint texture = (GLuint)(uintptr_t)buffer; _EGLImageAttribs attrs; GLuint depth; GLenum gl_target; @@ -2362,14 +2370,9 @@ dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, _eglInitImage(&dri2_img->base, disp); - dri2_img->dri_image = - dri2_dpy->image->createImageFromTexture(dri2_ctx->dri_context, - gl_target, - texture, - depth, - attrs.GLTextureLevel, - &error, - NULL); + dri2_img->dri_image = dri2_dpy->image->createImageFromTexture( + dri2_ctx->dri_context, gl_target, texture, depth, attrs.GLTextureLevel, + &error, NULL); dri2_create_image_khr_texture_error(error); if (!dri2_img->dri_image) { @@ -2380,8 +2383,8 @@ dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, } static EGLBoolean -dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, - EGLint attribute, EGLint *value) +dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint *value) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); EGLBoolean ret; @@ -2395,7 +2398,7 @@ dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, return ret; } -static struct wl_buffer* +static struct wl_buffer * dri2_create_wayland_buffer_from_image(_EGLDisplay *disp, _EGLImage *img) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); @@ -2412,22 +2415,22 @@ dri2_create_wayland_buffer_from_image(_EGLDisplay *disp, _EGLImage *img) #ifdef HAVE_LIBDRM static _EGLImage * dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, - EGLClientBuffer buffer, const EGLint *attr_list) + EGLClientBuffer buffer, + const EGLint *attr_list) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); EGLint format, name, pitch; _EGLImageAttribs attrs; __DRIimage *dri_image; - name = (EGLint) (uintptr_t) buffer; + name = (EGLint)(uintptr_t)buffer; if (!_eglParseImageAttribList(&attrs, disp, attr_list)) return NULL; if (attrs.Width <= 0 || attrs.Height <= 0 || attrs.DRMBufferStrideMESA <= 0) { - _eglError(EGL_BAD_PARAMETER, - "bad width, height or stride"); + _eglError(EGL_BAD_PARAMETER, "bad width, height or stride"); return NULL; } @@ -2442,14 +2445,9 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx, return NULL; } - dri_image = - dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu, - attrs.Width, - attrs.Height, - format, - name, - pitch, - NULL); + dri_image = dri2_dpy->image->createImageFromName( + dri2_dpy->dri_screen_render_gpu, attrs.Width, attrs.Height, format, name, + pitch, NULL); return dri2_create_image_from_dri(disp, dri_image); } @@ -2458,21 +2456,21 @@ static EGLBoolean dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) { /** - * The spec says: - * - * "Required attributes and their values are as follows: - * - * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels - * - * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified - * by drm_fourcc.h and used as the pixel_format parameter of the - * drm_mode_fb_cmd2 ioctl." - * - * and - * - * "* If is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is - * incomplete, EGL_BAD_PARAMETER is generated." - */ + * The spec says: + * + * "Required attributes and their values are as follows: + * + * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels + * + * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified + * by drm_fourcc.h and used as the pixel_format parameter of the + * drm_mode_fb_cmd2 ioctl." + * + * and + * + * "* If is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is + * incomplete, EGL_BAD_PARAMETER is generated." + */ if (attrs->Width <= 0 || attrs->Height <= 0 || !attrs->DMABufFourCC.IsPresent) return _eglError(EGL_BAD_PARAMETER, "attribute(s) missing"); @@ -2500,7 +2498,8 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) for (unsigned i = 0; i < DMA_BUF_MAX_PLANES; ++i) { if (attrs->DMABufPlaneModifiersLo[i].IsPresent != attrs->DMABufPlaneModifiersHi[i].IsPresent) - return _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing"); + return _eglError(EGL_BAD_PARAMETER, + "modifier attribute lo or hi missing"); } /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't @@ -2508,12 +2507,13 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs) for (unsigned i = 1; i < DMA_BUF_MAX_PLANES; ++i) { if (attrs->DMABufPlaneFds[i].IsPresent) { if ((attrs->DMABufPlaneModifiersLo[0].IsPresent != - attrs->DMABufPlaneModifiersLo[i].IsPresent) || + attrs->DMABufPlaneModifiersLo[i].IsPresent) || (attrs->DMABufPlaneModifiersLo[0].Value != - attrs->DMABufPlaneModifiersLo[i].Value) || + attrs->DMABufPlaneModifiersLo[i].Value) || (attrs->DMABufPlaneModifiersHi[0].Value != - attrs->DMABufPlaneModifiersHi[i].Value)) - return _eglError(EGL_BAD_PARAMETER, "modifier attributes not equal"); + attrs->DMABufPlaneModifiersHi[i].Value)) + return _eglError(EGL_BAD_PARAMETER, + "modifier attributes not equal"); } } @@ -2644,11 +2644,11 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs) } /** - * The spec says: - * - * "* If is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is - * incomplete, EGL_BAD_PARAMETER is generated." - */ + * The spec says: + * + * "* If is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is + * incomplete, EGL_BAD_PARAMETER is generated." + */ for (unsigned i = 0; i < plane_n; ++i) { if (!attrs->DMABufPlaneFds[i].IsPresent || !attrs->DMABufPlaneOffsets[i].IsPresent || @@ -2679,8 +2679,8 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs) } static EGLBoolean -dri2_query_dma_buf_formats(_EGLDisplay *disp, EGLint max, - EGLint *formats, EGLint *count) +dri2_query_dma_buf_formats(_EGLDisplay *disp, EGLint max, EGLint *formats, + EGLint *count) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); if (max < 0 || (max > 0 && formats == NULL)) { @@ -2692,8 +2692,8 @@ dri2_query_dma_buf_formats(_EGLDisplay *disp, EGLint max, dri2_dpy->image->queryDmaBufFormats == NULL) goto fail; - if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen_render_gpu, max, - formats, count)) + if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen_render_gpu, + max, formats, count)) goto fail; if (max > 0) { @@ -2718,20 +2718,23 @@ fail: } static EGLBoolean -dri2_query_dma_buf_modifiers(_EGLDisplay *disp, EGLint format, - EGLint max, EGLuint64KHR *modifiers, - EGLBoolean *external_only, EGLint *count) +dri2_query_dma_buf_modifiers(_EGLDisplay *disp, EGLint format, EGLint max, + EGLuint64KHR *modifiers, EGLBoolean *external_only, + EGLint *count) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); if (dri2_num_fourcc_format_planes(format) == 0) - return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid fourcc format"); + return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, + "invalid fourcc format"); if (max < 0) - return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid value for max count of formats"); + return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, + "invalid value for max count of formats"); if (max > 0 && modifiers == NULL) - return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid modifiers array"); + return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, + "invalid modifiers array"); if (dri2_dpy->image->base.version < 15 || dri2_dpy->image->queryDmaBufModifiers == NULL) { @@ -2739,11 +2742,11 @@ dri2_query_dma_buf_modifiers(_EGLDisplay *disp, EGLint format, return EGL_FALSE; } - if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen_render_gpu, format, - max, modifiers, - (unsigned int *) external_only, - count) == false) - return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, "invalid format"); + if (dri2_dpy->image->queryDmaBufModifiers( + dri2_dpy->dri_screen_render_gpu, format, max, modifiers, + (unsigned int *)external_only, count) == false) + return dri2_egl_error_unlock(dri2_dpy, EGL_BAD_PARAMETER, + "invalid format"); mtx_unlock(&dri2_dpy->lock); @@ -2822,46 +2825,33 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx, if (!has_modifier) modifier = DRM_FORMAT_MOD_INVALID; - dri_image = - dri2_dpy->image->createImageFromDmaBufs3(dri2_dpy->dri_screen_render_gpu, - attrs.Width, attrs.Height, attrs.DMABufFourCC.Value, - modifier, fds, num_fds, pitches, offsets, - attrs.DMABufYuvColorSpaceHint.Value, - attrs.DMABufSampleRangeHint.Value, - attrs.DMABufChromaHorizontalSiting.Value, - attrs.DMABufChromaVerticalSiting.Value, - attrs.ProtectedContent ? __DRI_IMAGE_PROTECTED_CONTENT_FLAG : 0, - &error, - NULL); - } - else if (has_modifier) { + dri_image = dri2_dpy->image->createImageFromDmaBufs3( + dri2_dpy->dri_screen_render_gpu, attrs.Width, attrs.Height, + attrs.DMABufFourCC.Value, modifier, fds, num_fds, pitches, offsets, + attrs.DMABufYuvColorSpaceHint.Value, attrs.DMABufSampleRangeHint.Value, + attrs.DMABufChromaHorizontalSiting.Value, + attrs.DMABufChromaVerticalSiting.Value, + attrs.ProtectedContent ? __DRI_IMAGE_PROTECTED_CONTENT_FLAG : 0, + &error, NULL); + } else if (has_modifier) { if (dri2_dpy->image->base.version < 15 || dri2_dpy->image->createImageFromDmaBufs2 == NULL) { _eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier"); return EGL_NO_IMAGE_KHR; } - dri_image = - dri2_dpy->image->createImageFromDmaBufs2(dri2_dpy->dri_screen_render_gpu, - attrs.Width, attrs.Height, attrs.DMABufFourCC.Value, - modifier, fds, num_fds, pitches, offsets, - attrs.DMABufYuvColorSpaceHint.Value, - attrs.DMABufSampleRangeHint.Value, - attrs.DMABufChromaHorizontalSiting.Value, - attrs.DMABufChromaVerticalSiting.Value, - &error, - NULL); - } - else { - dri_image = - dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen_render_gpu, - attrs.Width, attrs.Height, attrs.DMABufFourCC.Value, - fds, num_fds, pitches, offsets, - attrs.DMABufYuvColorSpaceHint.Value, - attrs.DMABufSampleRangeHint.Value, - attrs.DMABufChromaHorizontalSiting.Value, - attrs.DMABufChromaVerticalSiting.Value, - &error, - NULL); + dri_image = dri2_dpy->image->createImageFromDmaBufs2( + dri2_dpy->dri_screen_render_gpu, attrs.Width, attrs.Height, + attrs.DMABufFourCC.Value, modifier, fds, num_fds, pitches, offsets, + attrs.DMABufYuvColorSpaceHint.Value, attrs.DMABufSampleRangeHint.Value, + attrs.DMABufChromaHorizontalSiting.Value, + attrs.DMABufChromaVerticalSiting.Value, &error, NULL); + } else { + dri_image = dri2_dpy->image->createImageFromDmaBufs( + dri2_dpy->dri_screen_render_gpu, attrs.Width, attrs.Height, + attrs.DMABufFourCC.Value, fds, num_fds, pitches, offsets, + attrs.DMABufYuvColorSpaceHint.Value, attrs.DMABufSampleRangeHint.Value, + attrs.DMABufChromaHorizontalSiting.Value, + attrs.DMABufChromaVerticalSiting.Value, &error, NULL); } egl_error = egl_error_from_dri_image_error(error); @@ -2906,10 +2896,8 @@ dri2_create_drm_image_mesa(_EGLDisplay *disp, const EGLint *attr_list) goto fail; } - valid_mask = - EGL_DRM_BUFFER_USE_SCANOUT_MESA | - EGL_DRM_BUFFER_USE_SHARE_MESA | - EGL_DRM_BUFFER_USE_CURSOR_MESA; + valid_mask = EGL_DRM_BUFFER_USE_SCANOUT_MESA | + EGL_DRM_BUFFER_USE_SHARE_MESA | EGL_DRM_BUFFER_USE_CURSOR_MESA; if (attrs.DRMBufferUseMESA & ~valid_mask) { _eglError(EGL_BAD_PARAMETER, __func__); goto fail; @@ -2932,9 +2920,8 @@ dri2_create_drm_image_mesa(_EGLDisplay *disp, const EGLint *attr_list) _eglInitImage(&dri2_img->base, disp); dri2_img->dri_image = - dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu, - attrs.Width, attrs.Height, - format, dri_use, dri2_img); + dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu, attrs.Width, + attrs.Height, format, dri_use, dri2_img); if (dri2_img->dri_image == NULL) { free(dri2_img); _eglError(EGL_BAD_ALLOC, "dri2_create_drm_image_mesa"); @@ -2951,8 +2938,8 @@ fail: } static EGLBoolean -dri2_export_drm_image_mesa(_EGLDisplay *disp, _EGLImage *img, - EGLint *name, EGLint *handle, EGLint *stride) +dri2_export_drm_image_mesa(_EGLDisplay *disp, _EGLImage *img, EGLint *name, + EGLint *handle, EGLint *stride) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); struct dri2_egl_image *dri2_img = dri2_egl_image(img); @@ -3013,7 +3000,7 @@ dri2_export_dma_buf_image_query_mesa(_EGLDisplay *disp, _EGLImage *img, dri2_dpy->image->queryImage(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes); if (nplanes) - *nplanes = num_planes; + *nplanes = num_planes; if (fourcc) dri2_dpy->image->queryImage(dri2_img->dri_image, @@ -3024,17 +3011,15 @@ dri2_export_dma_buf_image_query_mesa(_EGLDisplay *disp, _EGLImage *img, uint64_t modifier = DRM_FORMAT_MOD_INVALID; bool query; - query = dri2_dpy->image->queryImage(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, - &mod_hi); - query &= dri2_dpy->image->queryImage(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, - &mod_lo); + query = dri2_dpy->image->queryImage( + dri2_img->dri_image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &mod_hi); + query &= dri2_dpy->image->queryImage( + dri2_img->dri_image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &mod_lo); if (query) - modifier = combine_u32_into_u64 (mod_hi, mod_lo); + modifier = combine_u32_into_u64(mod_hi, mod_lo); for (int i = 0; i < num_planes; i++) - modifiers[i] = modifier; + modifiers[i] = modifier; } mtx_unlock(&dri2_dpy->lock); @@ -3043,8 +3028,8 @@ dri2_export_dma_buf_image_query_mesa(_EGLDisplay *disp, _EGLImage *img, } static EGLBoolean -dri2_export_dma_buf_image_mesa(_EGLDisplay *disp, _EGLImage *img, - int *fds, EGLint *strides, EGLint *offsets) +dri2_export_dma_buf_image_mesa(_EGLDisplay *disp, _EGLImage *img, int *fds, + EGLint *strides, EGLint *offsets) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); struct dri2_egl_image *dri2_img = dri2_egl_image(img); @@ -3066,8 +3051,8 @@ dri2_export_dma_buf_image_mesa(_EGLDisplay *disp, _EGLImage *img, /* rework later to provide multiple fds/strides/offsets */ if (fds) - dri2_dpy->image->queryImage(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_FD, fds); + dri2_dpy->image->queryImage(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_FD, + fds); if (strides) dri2_dpy->image->queryImage(dri2_img->dri_image, @@ -3075,8 +3060,8 @@ dri2_export_dma_buf_image_mesa(_EGLDisplay *disp, _EGLImage *img, if (offsets) { int img_offset; - bool ret = dri2_dpy->image->queryImage(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_OFFSET, &img_offset); + bool ret = dri2_dpy->image->queryImage( + dri2_img->dri_image, __DRI_IMAGE_ATTRIB_OFFSET, &img_offset); if (ret) offsets[0] = img_offset; else @@ -3103,7 +3088,8 @@ dri2_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target, case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: case EGL_GL_TEXTURE_3D_KHR: - return dri2_create_image_khr_texture(disp, ctx, target, buffer, attr_list); + return dri2_create_image_khr_texture(disp, ctx, target, buffer, + attr_list); case EGL_GL_RENDERBUFFER_KHR: return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list); #ifdef HAVE_LIBDRM @@ -3148,28 +3134,19 @@ dri2_wl_reference_buffer(void *user_data, uint32_t name, int fd, int dri_components = 0; if (fd == -1) - img = dri2_dpy->image->createImageFromNames(dri2_dpy->dri_screen_render_gpu, - buffer->width, - buffer->height, - buffer->format, - (int*)&name, 1, - buffer->stride, - buffer->offset, - NULL); + img = dri2_dpy->image->createImageFromNames( + dri2_dpy->dri_screen_render_gpu, buffer->width, buffer->height, + buffer->format, (int *)&name, 1, buffer->stride, buffer->offset, NULL); else - img = dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen_render_gpu, - buffer->width, - buffer->height, - buffer->format, - &fd, 1, - buffer->stride, - buffer->offset, - NULL); + img = dri2_dpy->image->createImageFromFds( + dri2_dpy->dri_screen_render_gpu, buffer->width, buffer->height, + buffer->format, &fd, 1, buffer->stride, buffer->offset, NULL); if (img == NULL) return; - dri2_dpy->image->queryImage(img, __DRI_IMAGE_ATTRIB_COMPONENTS, &dri_components); + dri2_dpy->image->queryImage(img, __DRI_IMAGE_ATTRIB_COMPONENTS, + &dri_components); buffer->driver_format = NULL; for (int i = 0; i < ARRAY_SIZE(wl_drm_components); i++) @@ -3196,7 +3173,7 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); const struct wayland_drm_callbacks wl_drm_callbacks = { - .authenticate = (int(*)(void *, uint32_t)) dri2_dpy->vtbl->authenticate, + .authenticate = (int (*)(void *, uint32_t))dri2_dpy->vtbl->authenticate, .reference_buffer = dri2_wl_reference_buffer, .release_buffer = dri2_wl_release_buffer, .is_format_supported = dri2_wl_is_format_supported, @@ -3221,8 +3198,7 @@ dri2_bind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy) flags |= WAYLAND_DRM_PRIME; dri2_dpy->wl_server_drm = - wayland_drm_init(wl_dpy, device_name, - &wl_drm_callbacks, disp, flags); + wayland_drm_init(wl_dpy, device_name, &wl_drm_callbacks, disp, flags); free(device_name); @@ -3250,7 +3226,7 @@ dri2_unbind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy) struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); if (!dri2_dpy->wl_server_drm) - return EGL_FALSE; + return EGL_FALSE; wayland_drm_uninit(dri2_dpy->wl_server_drm); dri2_dpy->wl_server_drm = NULL; @@ -3259,7 +3235,8 @@ dri2_unbind_wayland_display_wl(_EGLDisplay *disp, struct wl_display *wl_dpy) } static EGLBoolean -dri2_query_wayland_buffer_wl(_EGLDisplay *disp, struct wl_resource *buffer_resource, +dri2_query_wayland_buffer_wl(_EGLDisplay *disp, + struct wl_resource *buffer_resource, EGLint attribute, EGLint *value) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -3311,7 +3288,8 @@ dri2_egl_unref_sync(struct dri2_egl_display *dri2_dpy, } if (dri2_sync->fence) - dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen_render_gpu, dri2_sync->fence); + dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen_render_gpu, + dri2_sync->fence); free(dri2_sync); } @@ -3351,8 +3329,7 @@ dri2_create_sync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list) case EGL_SYNC_CL_EVENT_KHR: dri2_sync->fence = dri2_dpy->fence->get_fence_from_cl_event( - dri2_dpy->dri_screen_render_gpu, - dri2_sync->base.CLEvent); + dri2_dpy->dri_screen_render_gpu, dri2_sync->base.CLEvent); /* this can only happen if the cl_event passed in is invalid. */ if (!dri2_sync->fence) { _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); @@ -3396,8 +3373,7 @@ dri2_create_sync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list) case EGL_SYNC_NATIVE_FENCE_ANDROID: if (dri2_dpy->fence->create_fence_fd) { dri2_sync->fence = dri2_dpy->fence->create_fence_fd( - dri2_ctx->dri_context, - dri2_sync->base.SyncFd); + dri2_ctx->dri_context, dri2_sync->base.SyncFd); } if (!dri2_sync->fence) { _eglError(EGL_BAD_ATTRIBUTE, "eglCreateSyncKHR"); @@ -3460,8 +3436,8 @@ dri2_dup_native_fence_fd(_EGLDisplay *disp, _EGLSync *sync) /* try to retrieve the actual native fence fd.. if rendering is * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD: */ - sync->SyncFd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen_render_gpu, - dri2_sync->fence); + sync->SyncFd = dri2_dpy->fence->get_fence_fd( + dri2_dpy->dri_screen_render_gpu, dri2_sync->fence); } mtx_unlock(&dri2_dpy->lock); @@ -3478,8 +3454,7 @@ dri2_dup_native_fence_fd(_EGLDisplay *disp, _EGLSync *sync) } static void -dri2_set_blob_cache_funcs(_EGLDisplay *disp, - EGLSetBlobFuncANDROID set, +dri2_set_blob_cache_funcs(_EGLDisplay *disp, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get) { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); @@ -3488,8 +3463,8 @@ dri2_set_blob_cache_funcs(_EGLDisplay *disp, } static EGLint -dri2_client_wait_sync(_EGLDisplay *disp, _EGLSync *sync, - EGLint flags, EGLTime timeout) +dri2_client_wait_sync(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, + EGLTime timeout) { _EGLContext *ctx = _eglGetCurrentContext(); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -3514,9 +3489,9 @@ dri2_client_wait_sync(_EGLDisplay *disp, _EGLSync *sync, case EGL_SYNC_FENCE_KHR: case EGL_SYNC_NATIVE_FENCE_ANDROID: case EGL_SYNC_CL_EVENT_KHR: - if (dri2_dpy->fence->client_wait_sync(dri2_ctx ? dri2_ctx->dri_context : NULL, - dri2_sync->fence, wait_flags, - timeout)) + if (dri2_dpy->fence->client_wait_sync( + dri2_ctx ? dri2_ctx->dri_context : NULL, dri2_sync->fence, + wait_flags, timeout)) dri2_sync->base.SyncStatus = EGL_SIGNALED_KHR; else ret = EGL_TIMEOUT_EXPIRED_KHR; @@ -3613,8 +3588,8 @@ dri2_server_wait_sync(_EGLDisplay *disp, _EGLSync *sync) struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); struct dri2_egl_sync *dri2_sync = dri2_egl_sync(sync); - dri2_dpy->fence->server_wait_sync(dri2_ctx->dri_context, - dri2_sync->fence, 0); + dri2_dpy->fence->server_wait_sync(dri2_ctx->dri_context, dri2_sync->fence, + 0); return EGL_TRUE; } @@ -3646,8 +3621,8 @@ dri2_interop_export_object(_EGLDisplay *disp, _EGLContext *ctx, } static int -dri2_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, - unsigned count, struct mesa_glinterop_export_in *objects, +dri2_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, unsigned count, + struct mesa_glinterop_export_in *objects, GLsync *sync) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -3656,7 +3631,8 @@ dri2_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, if (!dri2_dpy->interop || dri2_dpy->interop->base.version < 2) return MESA_GLINTEROP_UNSUPPORTED; - return dri2_dpy->interop->flush_objects(dri2_ctx->dri_context, count, objects, sync); + return dri2_dpy->interop->flush_objects(dri2_ctx->dri_context, count, + objects, sync); } const _EGLDriver _eglDriver = { diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 7693fed3543..ec6ca6c6e9c 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -32,11 +32,11 @@ #include #ifdef HAVE_X11_PLATFORM -#include +#include #include #include +#include #include -#include #include "loader_dri_helper.h" #ifdef HAVE_DRI3 @@ -82,18 +82,18 @@ struct zwp_linux_dmabuf_feedback_v1; #include "eglconfig.h" #include "eglcontext.h" +#include "eglcurrent.h" #include "egldevice.h" #include "egldisplay.h" #include "egldriver.h" -#include "eglcurrent.h" +#include "eglimage.h" #include "egllog.h" #include "eglsurface.h" -#include "eglimage.h" #include "eglsync.h" -#include "util/u_vector.h" -#include "util/u_dynarray.h" #include "util/bitset.h" +#include "util/u_dynarray.h" +#include "util/u_vector.h" struct wl_buffer; @@ -102,17 +102,17 @@ struct dri2_egl_display_vtbl { int (*authenticate)(_EGLDisplay *disp, uint32_t id); /* mandatory */ - _EGLSurface* (*create_window_surface)(_EGLDisplay *disp, _EGLConfig *config, + _EGLSurface *(*create_window_surface)(_EGLDisplay *disp, _EGLConfig *config, void *native_window, const EGLint *attrib_list); /* optional */ - _EGLSurface* (*create_pixmap_surface)(_EGLDisplay *disp, _EGLConfig *config, + _EGLSurface *(*create_pixmap_surface)(_EGLDisplay *disp, _EGLConfig *config, void *native_pixmap, const EGLint *attrib_list); /* optional */ - _EGLSurface* (*create_pbuffer_surface)(_EGLDisplay *disp, _EGLConfig *config, + _EGLSurface *(*create_pbuffer_surface)(_EGLDisplay *disp, _EGLConfig *config, const EGLint *attrib_list); /* mandatory */ @@ -123,7 +123,7 @@ struct dri2_egl_display_vtbl { EGLint interval); /* mandatory */ - _EGLImage* (*create_image)(_EGLDisplay *disp, _EGLContext *ctx, + _EGLImage *(*create_image)(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list); @@ -131,7 +131,8 @@ struct dri2_egl_display_vtbl { EGLBoolean (*swap_buffers)(_EGLDisplay *disp, _EGLSurface *surf); /* optional - falls back to .swap_buffers */ - EGLBoolean (*swap_buffers_with_damage)(_EGLDisplay *disp, _EGLSurface *surface, + EGLBoolean (*swap_buffers_with_damage)(_EGLDisplay *disp, + _EGLSurface *surface, const EGLint *rects, EGLint n_rects); /* optional */ @@ -139,9 +140,8 @@ struct dri2_egl_display_vtbl { EGLint numRects, const EGLint *rects); /* optional */ - EGLBoolean (*post_sub_buffer)(_EGLDisplay *disp, _EGLSurface *surf, - EGLint x, EGLint y, - EGLint width, EGLint height); + EGLBoolean (*post_sub_buffer)(_EGLDisplay *disp, _EGLSurface *surf, EGLint x, + EGLint y, EGLint width, EGLint height); /* optional */ EGLBoolean (*copy_buffers)(_EGLDisplay *disp, _EGLSurface *surf, @@ -155,7 +155,7 @@ struct dri2_egl_display_vtbl { EGLint attribute, EGLint *value); /* optional */ - struct wl_buffer* (*create_wayland_buffer_from_image)(_EGLDisplay *disp, + struct wl_buffer *(*create_wayland_buffer_from_image)(_EGLDisplay *disp, _EGLImage *img); /* optional */ @@ -215,8 +215,7 @@ struct dmabuf_feedback { }; #endif -struct dri2_egl_display -{ +struct dri2_egl_display { const struct dri2_egl_display_vtbl *vtbl; mtx_t lock; @@ -224,11 +223,11 @@ struct dri2_egl_display int dri2_major; int dri2_minor; __DRIscreen *dri_screen_render_gpu; - /* dri_screen_display_gpu holds display GPU in case of prime gpu offloading else - * dri_screen_render_gpu and dri_screen_display_gpu is same. - * In case of prime gpu offloading, if display and render driver names are different - * (potentially not compatible), dri_screen_display_gpu will be NULL but fd_display_gpu - * will still hold fd for display driver. + /* dri_screen_display_gpu holds display GPU in case of prime gpu offloading + * else dri_screen_render_gpu and dri_screen_display_gpu is same. In case of + * prime gpu offloading, if display and render driver names are different + * (potentially not compatible), dri_screen_display_gpu will be NULL but + * fd_display_gpu will still hold fd for display driver. */ __DRIscreen *dri_screen_display_gpu; bool own_dri_screen; @@ -319,14 +318,12 @@ struct dri2_egl_display bool is_render_node; }; -struct dri2_egl_context -{ +struct dri2_egl_context { _EGLContext base; __DRIcontext *dri_context; }; -struct dri2_egl_surface -{ +struct dri2_egl_surface { _EGLSurface base; __DRIdrawable *dri_drawable; __DRIbuffer buffers[5]; @@ -418,14 +415,12 @@ struct dri2_egl_surface char *swrast_device_buffer; }; -struct dri2_egl_config -{ +struct dri2_egl_config { _EGLConfig base; const __DRIconfig *dri_config[2][2]; }; -struct dri2_egl_image -{ +struct dri2_egl_image { _EGLImage base; __DRIimage *dri_image; }; @@ -455,7 +450,8 @@ dri2_egl_display_lock(_EGLDisplay *disp) } static inline EGLBoolean -dri2_egl_error_unlock(struct dri2_egl_display *dri2_dpy, EGLint err, const char *msg) +dri2_egl_error_unlock(struct dri2_egl_display *dri2_dpy, EGLint err, + const char *msg) { mtx_unlock(&dri2_dpy->lock); return _eglError(err, msg); @@ -502,13 +498,12 @@ dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data); void dri2_get_shifts_and_sizes(const __DRIcoreExtension *core, - const __DRIconfig *config, int *shifts, - unsigned int *sizes); + const __DRIconfig *config, int *shifts, + unsigned int *sizes); void dri2_get_render_type_float(const __DRIcoreExtension *core, - const __DRIconfig *config, - bool *is_float); + const __DRIconfig *config, bool *is_float); unsigned int dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy, @@ -547,7 +542,9 @@ dri2_initialize_x11(_EGLDisplay *disp) return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built"); } static inline void -dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) {} +dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) +{ +} static inline unsigned int dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth) { @@ -567,7 +564,9 @@ dri2_initialize_drm(_EGLDisplay *disp) return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built"); } static inline void -dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {} +dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) +{ +} #endif #ifdef HAVE_WAYLAND_PLATFORM @@ -576,7 +575,7 @@ dri2_initialize_wayland(_EGLDisplay *disp); void dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy); bool -dri2_wl_is_format_supported(void* user_data, uint32_t format); +dri2_wl_is_format_supported(void *user_data, uint32_t format); #else static inline EGLBoolean dri2_initialize_wayland(_EGLDisplay *disp) @@ -584,7 +583,9 @@ dri2_initialize_wayland(_EGLDisplay *disp) return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built"); } static inline void -dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {} +dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) +{ +} #endif #ifdef HAVE_ANDROID_PLATFORM @@ -604,11 +605,14 @@ dri2_initialize_surfaceless(_EGLDisplay *disp); EGLBoolean dri2_initialize_device(_EGLDisplay *disp); static inline void -dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ } +dri2_teardown_device(struct dri2_egl_display *dri2_dpy) +{ /* noop */ +} void -dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw, - enum __DRI2throttleReason throttle_reason); +dri2_flush_drawable_for_swapbuffers_flags( + _EGLDisplay *disp, _EGLSurface *draw, + enum __DRI2throttleReason throttle_reason); void dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw); @@ -623,17 +627,17 @@ dri2_set_WL_bind_wayland_display(_EGLDisplay *disp) struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); if (dri2_dpy->device_name && dri2_dpy->image) { - if (dri2_dpy->image->base.version >= 10 && - dri2_dpy->image->getCapabilities != NULL) { - int capabilities; + if (dri2_dpy->image->base.version >= 10 && + dri2_dpy->image->getCapabilities != NULL) { + int capabilities; - capabilities = - dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen_render_gpu); - disp->Extensions.WL_bind_wayland_display = - (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0; - } else { - disp->Extensions.WL_bind_wayland_display = EGL_TRUE; - } + capabilities = + dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen_render_gpu); + disp->Extensions.WL_bind_wayland_display = + (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0; + } else { + disp->Extensions.WL_bind_wayland_display = EGL_TRUE; + } } #endif } @@ -650,8 +654,8 @@ dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf); EGLBoolean dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, - _EGLConfig *conf, const EGLint *attrib_list, - EGLBoolean enable_out_fence, void *native_surface); + _EGLConfig *conf, const EGLint *attrib_list, + EGLBoolean enable_out_fence, void *native_surface); void dri2_fini_surface(_EGLSurface *surf); @@ -659,13 +663,12 @@ dri2_fini_surface(_EGLSurface *surf); EGLBoolean dri2_create_drawable(struct dri2_egl_display *dri2_dpy, const __DRIconfig *config, - struct dri2_egl_surface *dri2_surf, - void *loaderPrivate); + struct dri2_egl_surface *dri2_surf, void *loaderPrivate); static inline uint64_t combine_u32_into_u64(uint32_t hi, uint32_t lo) { - return (((uint64_t) hi) << 32) | (((uint64_t) lo) & 0xffffffff); + return (((uint64_t)hi) << 32) | (((uint64_t)lo) & 0xffffffff); } #endif /* EGL_DRI2_INCLUDED */ diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index e0fd45a1241..f9bc174b657 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -27,32 +27,32 @@ * DEALINGS IN THE SOFTWARE. */ -#include -#include #include #include +#include #include -#include #include #include +#include +#include +#include #include #include -#include #include "util/compiler.h" -#include "util/os_file.h" #include "util/libsync.h" +#include "util/os_file.h" -#include "loader.h" #include "egl_dri2.h" +#include "loader.h" #include "platform_android.h" #ifdef HAVE_DRM_GRALLOC -#include #include "gralloc_drm.h" +#include #endif /* HAVE_DRM_GRALLOC */ -#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1)) +#define ALIGN(val, align) (((val) + (align)-1) & ~((align)-1)) enum chroma_order { YCbCr, @@ -61,7 +61,7 @@ enum chroma_order { struct droid_yuv_format { /* Lookup keys */ - int native; /* HAL_PIXEL_FORMAT_ */ + int native; /* HAL_PIXEL_FORMAT_ */ enum chroma_order chroma_order; /* chroma order is {Cb, Cr} or {Cr, Cb} */ int chroma_step; /* Distance in bytes between subsequent chroma pixels. */ @@ -73,17 +73,17 @@ struct droid_yuv_format { * on native format and information contained in android_ycbcr struct. */ static const struct droid_yuv_format droid_yuv_formats[] = { /* Native format, YCrCb, Chroma step, DRI image FourCC */ - { HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12 }, - { HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420 }, - { HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420 }, - { HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420 }, + {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12}, + {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420}, + {HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420}, + {HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420}, /* HACK: See droid_create_image_from_prime_fds() and * https://issuetracker.google.com/32077885. */ - { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12 }, - { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420 }, - { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420 }, - { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV }, - { HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888 }, + {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12}, + {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420}, + {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420}, + {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV}, + {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888}, }; static int @@ -121,7 +121,8 @@ get_format_bpp(int native) case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: /* * HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. - * TODO: Remove this once https://issuetracker.google.com/32077885 is fixed. + * TODO: Remove this once https://issuetracker.google.com/32077885 is + * fixed. */ case HAL_PIXEL_FORMAT_RGBX_8888: case HAL_PIXEL_FORMAT_BGRA_8888: @@ -140,20 +141,28 @@ get_format_bpp(int native) } /* createImageFromFds requires fourcc format */ -static int get_fourcc(int native) +static int +get_fourcc(int native) { switch (native) { - case HAL_PIXEL_FORMAT_RGB_565: return DRM_FORMAT_RGB565; - case HAL_PIXEL_FORMAT_BGRA_8888: return DRM_FORMAT_ARGB8888; - case HAL_PIXEL_FORMAT_RGBA_8888: return DRM_FORMAT_ABGR8888; + case HAL_PIXEL_FORMAT_RGB_565: + return DRM_FORMAT_RGB565; + case HAL_PIXEL_FORMAT_BGRA_8888: + return DRM_FORMAT_ARGB8888; + case HAL_PIXEL_FORMAT_RGBA_8888: + return DRM_FORMAT_ABGR8888; case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: /* * HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. - * TODO: Remove this once https://issuetracker.google.com/32077885 is fixed. + * TODO: Remove this once https://issuetracker.google.com/32077885 is + * fixed. */ - case HAL_PIXEL_FORMAT_RGBX_8888: return DRM_FORMAT_XBGR8888; - case HAL_PIXEL_FORMAT_RGBA_FP16: return DRM_FORMAT_ABGR16161616F; - case HAL_PIXEL_FORMAT_RGBA_1010102: return DRM_FORMAT_ABGR2101010; + case HAL_PIXEL_FORMAT_RGBX_8888: + return DRM_FORMAT_XBGR8888; + case HAL_PIXEL_FORMAT_RGBA_FP16: + return DRM_FORMAT_ABGR16161616F; + case HAL_PIXEL_FORMAT_RGBA_1010102: + return DRM_FORMAT_ABGR2101010; default: _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", native); } @@ -210,8 +219,8 @@ get_yuv_buffer_info(struct dri2_egl_display *dri2_dpy, } memset(&ycbcr, 0, sizeof(ycbcr)); - ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, - 0, 0, 0, 0, 0, &ycbcr); + ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, 0, 0, 0, + 0, 0, &ycbcr); if (ret) { /* HACK: See native_window_buffer_get_buffer_info() and * https://issuetracker.google.com/32077885.*/ @@ -229,8 +238,11 @@ get_yuv_buffer_info(struct dri2_egl_display *dri2_dpy, * values of subsequent pixels, assumed to be the same for Cb and Cr. */ drm_fourcc = get_fourcc_yuv(buf->format, chroma_order, ycbcr.chroma_step); if (drm_fourcc == -1) { - _eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = %d", - buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb", ycbcr.chroma_step); + _eglLog(_EGL_WARNING, + "unsupported YUV format, native = %x, chroma_order = %s, " + "chroma_step = %d", + buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb", + ycbcr.chroma_step); return -EINVAL; } @@ -239,7 +251,7 @@ get_yuv_buffer_info(struct dri2_egl_display *dri2_dpy, .height = buf->height, .drm_fourcc = drm_fourcc, .num_planes = ycbcr.chroma_step == 2 ? 2 : 3, - .fds = { -1, -1, -1, -1 }, + .fds = {-1, -1, -1, -1}, .modifier = DRM_FORMAT_MOD_INVALID, .yuv_color_space = EGL_ITU_REC601_EXT, .sample_range = EGL_YUV_NARROW_RANGE_EXT, @@ -337,10 +349,10 @@ native_window_buffer_get_buffer_info(struct dri2_egl_display *dri2_dpy, .height = buf->height, .drm_fourcc = drm_fourcc, .num_planes = num_planes, - .fds = { fds[0], -1, -1, -1 }, + .fds = {fds[0], -1, -1, -1}, .modifier = DRM_FORMAT_MOD_INVALID, - .offsets = { 0, 0, 0, 0 }, - .pitches = { pitch, 0, 0, 0 }, + .offsets = {0, 0, 0, 0}, + .pitches = {pitch, 0, 0, 0}, .yuv_color_space = EGL_ITU_REC601_EXT, .sample_range = EGL_YUV_NARROW_RANGE_EXT, .horizontal_siting = EGL_YUV_CHROMA_SITING_0_EXT, @@ -355,13 +367,14 @@ native_window_buffer_get_buffer_info(struct dri2_egl_display *dri2_dpy, * offsets and strides. If we have this, we can skip straight to * createImageFromDmaBufs2() and avoid all the guessing and recalculations. * This also gives us the modifier and plane offsets/strides for multiplanar - * compressed buffers (eg Intel CCS buffers) in order to make that work in Android. + * compressed buffers (eg Intel CCS buffers) in order to make that work in + * Android. */ static const char cros_gralloc_module_name[] = "CrOS Gralloc"; -#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4 -#define CROS_GRALLOC_DRM_GET_USAGE 5 +#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4 +#define CROS_GRALLOC_DRM_GET_USAGE 5 #define CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT 0x1 struct cros_gralloc0_buffer_info { @@ -383,14 +396,14 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy, if (strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) == 0 && dri2_dpy->gralloc->perform && dri2_dpy->gralloc->perform(dri2_dpy->gralloc, - CROS_GRALLOC_DRM_GET_BUFFER_INFO, - buf->handle, &info) == 0) { + CROS_GRALLOC_DRM_GET_BUFFER_INFO, buf->handle, + &info) == 0) { *out_buf_info = (struct buffer_info){ .width = buf->width, .height = buf->height, .drm_fourcc = info.drm_fourcc, .num_planes = info.num_fds, - .fds = { -1, -1, -1, -1 }, + .fds = {-1, -1, -1, -1}, .modifier = info.modifier, .yuv_color_space = EGL_ITU_REC601_EXT, .sample_range = EGL_YUV_NARROW_RANGE_EXT, @@ -411,8 +424,7 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy, static __DRIimage * droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy, - struct buffer_info *buf_info, - void *priv) + struct buffer_info *buf_info, void *priv) { unsigned error; @@ -423,8 +435,7 @@ droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy, buf_info->drm_fourcc, buf_info->modifier, buf_info->fds, buf_info->num_planes, buf_info->pitches, buf_info->offsets, buf_info->yuv_color_space, buf_info->sample_range, - buf_info->horizontal_siting, buf_info->vertical_siting, &error, - priv); + buf_info->horizontal_siting, buf_info->vertical_siting, &error, priv); } return dri2_dpy->image->createImageFromDmaBufs( @@ -536,7 +547,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf) } static EGLBoolean -droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf) +droid_window_enqueue_buffer(_EGLDisplay *disp, + struct dri2_egl_surface *dri2_surf) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -597,8 +609,10 @@ droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode) _eglLog(_EGL_DEBUG, "%s: mode=%d", __func__, mode); if (ANativeWindow_setSharedBufferMode(window, mode)) { - _eglLog(_EGL_WARNING, "failed ANativeWindow_setSharedBufferMode" - "(window=%p, mode=%d)", window, mode); + _eglLog(_EGL_WARNING, + "failed ANativeWindow_setSharedBufferMode" + "(window=%p, mode=%d)", + window, mode); return false; } @@ -616,7 +630,8 @@ droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode) return true; #else - _eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__, __LINE__); + _eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__, + __LINE__); return false; #endif } @@ -639,8 +654,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, dri2_surf->in_fence_fd = -1; - if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, - true, native_window)) + if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, true, + native_window)) goto cleanup_surface; if (type == EGL_WINDOW_BIT) { @@ -667,8 +682,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, /* Required buffer caching slots. */ buffer_count = min_undequeued_buffers + 2; - dri2_surf->color_buffers = calloc(buffer_count, - sizeof(*dri2_surf->color_buffers)); + dri2_surf->color_buffers = + calloc(buffer_count, sizeof(*dri2_surf->color_buffers)); if (!dri2_surf->color_buffers) { _eglError(EGL_BAD_ALLOC, "droid_create_surface"); goto cleanup_surface; @@ -676,8 +691,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, dri2_surf->color_buffers_count = buffer_count; if (format != dri2_conf->base.NativeVisualID) { - _eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", - format, dri2_conf->base.NativeVisualID); + _eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", format, + dri2_conf->base.NativeVisualID); } ANativeWindow_query(window, ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, @@ -699,10 +714,10 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, } } - config = dri2_get_dri_config(dri2_conf, type, - dri2_surf->base.GLColorspace); + config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace); if (!config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_surface; } @@ -728,16 +743,15 @@ static _EGLSurface * droid_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list) { - return droid_create_surface(disp, EGL_WINDOW_BIT, conf, - native_window, attrib_list); + return droid_create_surface(disp, EGL_WINDOW_BIT, conf, native_window, + attrib_list); } static _EGLSurface * droid_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { - return droid_create_surface(disp, EGL_PBUFFER_BIT, conf, - NULL, attrib_list); + return droid_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list); } static EGLBoolean @@ -756,13 +770,15 @@ droid_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) } if (dri2_surf->dri_image_back) { - _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__); + _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, + __LINE__); dri2_dpy->image->destroyImage(dri2_surf->dri_image_back); dri2_surf->dri_image_back = NULL; } if (dri2_surf->dri_image_front) { - _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__); + _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, + __LINE__); dri2_dpy->image->destroyImage(dri2_surf->dri_image_front); dri2_surf->dri_image_front = NULL; } @@ -832,15 +848,13 @@ get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format) * and mesa doesn't have the implementation of this case. * Add warning message, but not treat it as error. */ - _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface"); + _eglLog( + _EGL_DEBUG, + "DRI driver requested unsupported front buffer for window surface"); } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) { - dri2_surf->dri_image_front = - dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu, - dri2_surf->base.Width, - dri2_surf->base.Height, - format, - 0, - NULL); + dri2_surf->dri_image_front = dri2_dpy->image->createImage( + dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width, + dri2_surf->base.Height, format, 0, NULL); if (!dri2_surf->dri_image_front) { _eglLog(_EGL_WARNING, "dri2_image_front allocation failed"); return -1; @@ -874,20 +888,24 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back); } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) { - /* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically, - * the spec states that they have a back buffer but no front buffer, in - * contrast to pixmaps, which have a front buffer but no back buffer. + /* The EGL 1.5 spec states that pbuffers are single-buffered. + * Specifically, the spec states that they have a back buffer but no front + * buffer, in contrast to pixmaps, which have a front buffer but no back + * buffer. * - * Single-buffered surfaces with no front buffer confuse Mesa; so we deviate - * from the spec, following the precedent of Mesa's EGL X11 platform. The - * X11 platform correctly assigns pbuffers to single-buffered configs, but - * assigns the pbuffer a front buffer instead of a back buffer. + * Single-buffered surfaces with no front buffer confuse Mesa; so we + * deviate from the spec, following the precedent of Mesa's EGL X11 + * platform. The X11 platform correctly assigns pbuffers to + * single-buffered configs, but assigns the pbuffer a front buffer instead + * of a back buffer. * * Pbuffers in the X11 platform mostly work today, so let's just copy its * behavior instead of trying to fix (and hence potentially breaking) the * world. */ - _eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for pbuffer surface"); + _eglLog( + _EGL_DEBUG, + "DRI driver requested unsupported back buffer for pbuffer surface"); } return 0; @@ -899,12 +917,9 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) * return error when the allocation for supported buffer failed. */ static int -droid_image_get_buffers(__DRIdrawable *driDrawable, - unsigned int format, - uint32_t *stamp, - void *loaderPrivate, - uint32_t buffer_mask, - struct __DRIimageList *images) +droid_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format, + uint32_t *stamp, void *loaderPrivate, + uint32_t buffer_mask, struct __DRIimageList *images) { struct dri2_egl_surface *dri2_surf = loaderPrivate; @@ -979,8 +994,7 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) * for which there is no pending change to the EGL_RENDER_BUFFER * attribute, eglSwapBuffers has no effect. */ - if (has_mutable_rb && - draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER && + if (has_mutable_rb && draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER && draw->ActiveRenderBuffer == EGL_SINGLE_BUFFER) { _eglLog(_EGL_DEBUG, "%s: remain in shared buffer mode", __func__); return EGL_TRUE; @@ -997,7 +1011,8 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) if (dri2_surf->back) dri2_surf->back->age = 1; - dri2_flush_drawable_for_swapbuffers_flags(disp, draw, __DRI2_NOTHROTTLE_SWAPBUFFER); + dri2_flush_drawable_for_swapbuffers_flags(disp, draw, + __DRI2_NOTHROTTLE_SWAPBUFFER); /* dri2_surf->buffer can be null even when no error has occurred. For * example, if the user has called no GL rendering commands since the @@ -1013,9 +1028,9 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) /* Update the shared buffer mode */ if (has_mutable_rb && draw->ActiveRenderBuffer != draw->RequestedRenderBuffer) { - bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER); - _eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", - __func__, mode); + bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER); + _eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", __func__, + mode); if (!droid_set_shared_buffer_mode(disp, draw, mode)) return EGL_FALSE; @@ -1026,20 +1041,28 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) } #ifdef HAVE_DRM_GRALLOC -static int get_format(int format) +static int +get_format(int format) { switch (format) { - case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FORMAT_ARGB8888; - case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FORMAT_RGB565; - case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FORMAT_ABGR8888; + case HAL_PIXEL_FORMAT_BGRA_8888: + return __DRI_IMAGE_FORMAT_ARGB8888; + case HAL_PIXEL_FORMAT_RGB_565: + return __DRI_IMAGE_FORMAT_RGB565; + case HAL_PIXEL_FORMAT_RGBA_8888: + return __DRI_IMAGE_FORMAT_ABGR8888; case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: /* * HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. - * TODO: Revert this once https://issuetracker.google.com/32077885 is fixed. + * TODO: Revert this once https://issuetracker.google.com/32077885 is + * fixed. */ - case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FORMAT_XBGR8888; - case HAL_PIXEL_FORMAT_RGBA_FP16: return __DRI_IMAGE_FORMAT_ABGR16161616F; - case HAL_PIXEL_FORMAT_RGBA_1010102: return __DRI_IMAGE_FORMAT_ABGR2101010; + case HAL_PIXEL_FORMAT_RGBX_8888: + return __DRI_IMAGE_FORMAT_XBGR8888; + case HAL_PIXEL_FORMAT_RGBA_FP16: + return __DRI_IMAGE_FORMAT_ABGR16161616F; + case HAL_PIXEL_FORMAT_RGBA_1010102: + return __DRI_IMAGE_FORMAT_ABGR2101010; default: _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format); } @@ -1047,8 +1070,7 @@ static int get_format(int format) } static __DRIimage * -droid_create_image_from_name(_EGLDisplay *disp, - struct ANativeWindowBuffer *buf, +droid_create_image_from_name(_EGLDisplay *disp, struct ANativeWindowBuffer *buf, void *priv) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); @@ -1063,48 +1085,42 @@ droid_create_image_from_name(_EGLDisplay *disp, format = get_format(buf->format); if (format == -1) - return NULL; + return NULL; - return - dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu, - buf->width, - buf->height, - format, - name, - buf->stride, - priv); + return dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu, + buf->width, buf->height, format, + name, buf->stride, priv); } #endif /* HAVE_DRM_GRALLOC */ static EGLBoolean -droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf, - EGLint attribute, EGLint *value) +droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint *value) { struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); switch (attribute) { - case EGL_WIDTH: - if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) { - ANativeWindow_query(dri2_surf->window, - ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, value); - return EGL_TRUE; - } - break; - case EGL_HEIGHT: - if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) { - ANativeWindow_query(dri2_surf->window, - ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, value); - return EGL_TRUE; - } - break; - default: - break; + case EGL_WIDTH: + if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) { + ANativeWindow_query(dri2_surf->window, + ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, value); + return EGL_TRUE; + } + break; + case EGL_HEIGHT: + if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) { + ANativeWindow_query(dri2_surf->window, + ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, value); + return EGL_TRUE; + } + break; + default: + break; } return _eglQuerySurface(disp, surf, attribute, value); } static _EGLImage * -dri2_create_image_android_native_buffer(_EGLDisplay *disp, - _EGLContext *ctx, +dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx, struct ANativeWindowBuffer *buf) { if (ctx != NULL) { @@ -1113,7 +1129,8 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp, * * If is EGL_NATIVE_BUFFER_ANDROID and is not * EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated. */ - _eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for " + _eglError(EGL_BAD_CONTEXT, + "eglCreateEGLImageKHR: for " "EGL_NATIVE_BUFFER_ANDROID, the context must be " "EGL_NO_CONTEXT"); return NULL; @@ -1149,15 +1166,15 @@ droid_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target, { switch (target) { case EGL_NATIVE_BUFFER_ANDROID: - return dri2_create_image_android_native_buffer(disp, ctx, - (struct ANativeWindowBuffer *) buffer); + return dri2_create_image_android_native_buffer( + disp, ctx, (struct ANativeWindowBuffer *)buffer); default: return dri2_create_image_khr(disp, ctx, target, buffer, attr_list); } } static void -droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) +droid_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) { } @@ -1195,8 +1212,8 @@ droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf, case __DRI_BUFFER_ACCUM: case __DRI_BUFFER_DEPTH_STENCIL: case __DRI_BUFFER_HIZ: - local = dri2_egl_surface_alloc_local_buffer(dri2_surf, - attachments[i], attachments[i + 1]); + local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i], + attachments[i + 1]); if (local) { *buf = *local; @@ -1218,17 +1235,17 @@ droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf, } static __DRIbuffer * -droid_get_buffers_with_format(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +droid_get_buffers_with_format(__DRIdrawable *driDrawable, int *width, + int *height, unsigned int *attachments, int count, + int *out_count, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; if (update_buffers(dri2_surf) < 0) return NULL; - *out_count = droid_get_buffers_parse_attachments(dri2_surf, attachments, count); + *out_count = + droid_get_buffers_parse_attachments(dri2_surf, attachments, count); if (width) *width = dri2_surf->base.Width; @@ -1257,7 +1274,7 @@ droid_destroy_loader_image_state(void *loaderPrivate) #if ANDROID_API_LEVEL >= 26 if (loaderPrivate) { AHardwareBuffer_release( - ANativeWindowBuffer_getHardwareBuffer(loaderPrivate)); + ANativeWindowBuffer_getHardwareBuffer(loaderPrivate)); } #endif } @@ -1271,16 +1288,16 @@ droid_add_configs_for_visuals(_EGLDisplay *disp) int rgba_shifts[4]; unsigned int rgba_sizes[4]; } visuals[] = { - { HAL_PIXEL_FORMAT_RGBA_8888, { 0, 8, 16, 24 }, { 8, 8, 8, 8 } }, - { HAL_PIXEL_FORMAT_RGBX_8888, { 0, 8, 16, -1 }, { 8, 8, 8, 0 } }, - { HAL_PIXEL_FORMAT_RGB_565, { 11, 5, 0, -1 }, { 5, 6, 5, 0 } }, + {HAL_PIXEL_FORMAT_RGBA_8888, {0, 8, 16, 24}, {8, 8, 8, 8}}, + {HAL_PIXEL_FORMAT_RGBX_8888, {0, 8, 16, -1}, {8, 8, 8, 0}}, + {HAL_PIXEL_FORMAT_RGB_565, {11, 5, 0, -1}, {5, 6, 5, 0}}, /* This must be after HAL_PIXEL_FORMAT_RGBA_8888, we only keep BGRA * visual if it turns out RGBA visual is not available. */ - { HAL_PIXEL_FORMAT_BGRA_8888, { 16, 8, 0, 24 }, { 8, 8, 8, 8 } }, + {HAL_PIXEL_FORMAT_BGRA_8888, {16, 8, 0, 24}, {8, 8, 8, 8}}, }; - unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 }; + unsigned int format_count[ARRAY_SIZE(visuals)] = {0}; int config_count = 0; /* The nesting of loops is significant here. Also significant is the order @@ -1312,17 +1329,20 @@ droid_add_configs_for_visuals(_EGLDisplay *disp) const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; const EGLint config_attrs[] = { - EGL_NATIVE_VISUAL_ID, visuals[i].format, - EGL_NATIVE_VISUAL_TYPE, visuals[i].format, - EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE, - EGL_RECORDABLE_ANDROID, EGL_TRUE, - EGL_NONE, + EGL_NATIVE_VISUAL_ID, + visuals[i].format, + EGL_NATIVE_VISUAL_TYPE, + visuals[i].format, + EGL_FRAMEBUFFER_TARGET_ANDROID, + EGL_TRUE, + EGL_RECORDABLE_ANDROID, + EGL_TRUE, + EGL_NONE, }; - struct dri2_egl_config *dri2_conf = - dri2_add_config(disp, dri2_dpy->driver_configs[j], - config_count + 1, surface_type, config_attrs, - visuals[i].rgba_shifts, visuals[i].rgba_sizes); + struct dri2_egl_config *dri2_conf = dri2_add_config( + disp, dri2_dpy->driver_configs[j], config_count + 1, surface_type, + config_attrs, visuals[i].rgba_shifts, visuals[i].rgba_sizes); if (dri2_conf) { if (dri2_conf->base.ConfigID == config_count + 1) config_count++; @@ -1359,13 +1379,13 @@ static const struct dri2_egl_display_vtbl droid_display_vtbl = { #ifdef HAVE_DRM_GRALLOC static const __DRIdri2LoaderExtension droid_dri2_loader_extension = { - .base = { __DRI_DRI2_LOADER, 5 }, + .base = {__DRI_DRI2_LOADER, 5}, - .getBuffers = NULL, - .flushFrontBuffer = droid_flush_front_buffer, - .getBuffersWithFormat = droid_get_buffers_with_format, - .getCapability = droid_get_capability, - .destroyLoaderImageState = droid_destroy_loader_image_state, + .getBuffers = NULL, + .flushFrontBuffer = droid_flush_front_buffer, + .getBuffersWithFormat = droid_get_buffers_with_format, + .getCapability = droid_get_capability, + .destroyLoaderImageState = droid_destroy_loader_image_state, }; static const __DRIextension *droid_dri2_loader_extensions[] = { @@ -1380,13 +1400,13 @@ static const __DRIextension *droid_dri2_loader_extensions[] = { #endif /* HAVE_DRM_GRALLOC */ static const __DRIimageLoaderExtension droid_image_loader_extension = { - .base = { __DRI_IMAGE_LOADER, 4 }, + .base = {__DRI_IMAGE_LOADER, 4}, - .getBuffers = droid_image_get_buffers, - .flushFrontBuffer = droid_flush_front_buffer, - .getCapability = droid_get_capability, - .flushSwapBuffers = NULL, - .destroyLoaderImageState = droid_destroy_loader_image_state, + .getBuffers = droid_image_get_buffers, + .flushFrontBuffer = droid_flush_front_buffer, + .getCapability = droid_get_capability, + .flushSwapBuffers = NULL, + .destroyLoaderImageState = droid_destroy_loader_image_state, }; static void @@ -1451,9 +1471,10 @@ droid_display_shared_buffer(__DRIdrawable *driDrawable, int fence_fd, handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back); } -static const __DRImutableRenderBufferLoaderExtension droid_mutable_render_buffer_extension = { - .base = { __DRI_MUTABLE_RENDER_BUFFER_LOADER, 1 }, - .displaySharedBuffer = droid_display_shared_buffer, +static const __DRImutableRenderBufferLoaderExtension + droid_mutable_render_buffer_extension = { + .base = {__DRI_MUTABLE_RENDER_BUFFER_LOADER, 1}, + .displaySharedBuffer = droid_display_shared_buffer, }; static const __DRIextension *droid_image_loader_extensions[] = { @@ -1540,10 +1561,10 @@ droid_filter_device(_EGLDisplay *disp, int fd, const char *vendor) static EGLBoolean droid_probe_device(_EGLDisplay *disp, bool swrast) { - /* Check that the device is supported, by attempting to: - * - load the dri module - * - and, create a screen - */ + /* Check that the device is supported, by attempting to: + * - load the dri module + * - and, create a screen + */ if (!droid_load_driver(disp, swrast)) return EGL_FALSE; @@ -1567,8 +1588,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast) if (dri2_dpy->gralloc->perform) err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc, - GRALLOC_MODULE_PERFORM_GET_DRM_FD, - &fd); + GRALLOC_MODULE_PERFORM_GET_DRM_FD, &fd); if (err || fd < 0) { _eglLog(_EGL_WARNING, "fail to get drm fd"); return EGL_FALSE; @@ -1589,7 +1609,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast) { #define MAX_DRM_DEVICES 64 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL }; + drmDevicePtr device, devices[MAX_DRM_DEVICES] = {NULL}; int num_devices; char *vendor_name = NULL; @@ -1616,8 +1636,8 @@ droid_open_device(_EGLDisplay *disp, bool swrast) dri2_dpy->fd_render_gpu = loader_open_device(device->nodes[node_type]); if (dri2_dpy->fd_render_gpu < 0) { - _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", - __func__, device->nodes[node_type]); + _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", __func__, + device->nodes[node_type]); continue; } @@ -1652,7 +1672,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast) if (dri2_dpy->fd_render_gpu < 0) { _eglLog(_EGL_WARNING, "Failed to open %s DRM device", - vendor_name ? "desired": "any"); + vendor_name ? "desired" : "any"); return EGL_FALSE; } @@ -1684,7 +1704,7 @@ dri2_initialize_android(_EGLDisplay *disp) goto cleanup; } - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; device_opened = droid_open_device(disp, disp->Options.ForceSoftware); if (!device_opened) { @@ -1768,9 +1788,9 @@ dri2_initialize_android(_EGLDisplay *disp) if (!strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) && dri2_dpy->gralloc->perform && dri2_dpy->gralloc->perform( - dri2_dpy->gralloc, CROS_GRALLOC_DRM_GET_USAGE, - CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT, - &front_rendering_usage) == 0) { + dri2_dpy->gralloc, CROS_GRALLOC_DRM_GET_USAGE, + CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT, + &front_rendering_usage) == 0) { dri2_dpy->front_rendering_usage = front_rendering_usage; disp->Extensions.KHR_mutable_render_buffer = EGL_TRUE; } diff --git a/src/egl/drivers/dri2/platform_android.h b/src/egl/drivers/dri2/platform_android.h index a2015df228a..23c73167506 100644 --- a/src/egl/drivers/dri2/platform_android.h +++ b/src/egl/drivers/dri2/platform_android.h @@ -63,24 +63,21 @@ ANativeWindow_getFormat(struct ANativeWindow *window) static inline int ANativeWindow_dequeueBuffer(struct ANativeWindow *window, - struct ANativeWindowBuffer **buffer, - int *fenceFd) + struct ANativeWindowBuffer **buffer, int *fenceFd) { return window->dequeueBuffer(window, buffer, fenceFd); } static inline int ANativeWindow_queueBuffer(struct ANativeWindow *window, - struct ANativeWindowBuffer *buffer, - int fenceFd) + struct ANativeWindowBuffer *buffer, int fenceFd) { return window->queueBuffer(window, buffer, fenceFd); } static inline int ANativeWindow_cancelBuffer(struct ANativeWindow *window, - struct ANativeWindowBuffer *buffer, - int fenceFd) + struct ANativeWindowBuffer *buffer, int fenceFd) { return window->cancelBuffer(window, buffer, fenceFd); } @@ -106,8 +103,7 @@ ANativeWindow_setSwapInterval(struct ANativeWindow *window, int interval) static inline int ANativeWindow_query(const struct ANativeWindow *window, - enum ANativeWindowQuery what, - int *value) + enum ANativeWindowQuery what, int *value) { switch (what) { case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS: @@ -149,7 +145,8 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, #else static inline int mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, - struct buffer_info *out_buf_info) { + struct buffer_info *out_buf_info) +{ return -ENOTSUP; } #endif /* USE_IMAPPER4_METADATA_API */ diff --git a/src/egl/drivers/dri2/platform_android_mapper.cpp b/src/egl/drivers/dri2/platform_android_mapper.cpp index 2a5d1d95006..385a187ed31 100644 --- a/src/egl/drivers/dri2/platform_android_mapper.cpp +++ b/src/egl/drivers/dri2/platform_android_mapper.cpp @@ -25,13 +25,13 @@ #include "platform_android.h" -#include #include #include #include #include #include #include +#include using aidl::android::hardware::graphics::common::ChromaSiting; using aidl::android::hardware::graphics::common::Dataspace; @@ -39,26 +39,26 @@ using aidl::android::hardware::graphics::common::ExtendableType; using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; +using android::hardware::hidl_handle; +using android::hardware::hidl_vec; using android::hardware::graphics::common::V1_2::BufferUsage; using android::hardware::graphics::mapper::V4_0::Error; using android::hardware::graphics::mapper::V4_0::IMapper; -using android::hardware::hidl_handle; -using android::hardware::hidl_vec; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; Error GetMetadata(android::sp mapper, const native_handle_t *buffer, - MetadataType type, hidl_vec* metadata) + MetadataType type, hidl_vec *metadata) { Error error = Error::NONE; - auto native_handle = const_cast(buffer); + auto native_handle = const_cast(buffer); auto ret = mapper->get(native_handle, type, - [&](const auto& get_error, const auto& get_metadata) { - error = get_error; - *metadata = get_metadata; + [&](const auto &get_error, const auto &get_metadata) { + error = get_error; + *metadata = get_metadata; }); if (!ret.isOk()) @@ -67,21 +67,22 @@ GetMetadata(android::sp mapper, const native_handle_t *buffer, return error; } -std::optional> GetPlaneLayouts( - android::sp mapper, const native_handle_t *buffer) +std::optional> +GetPlaneLayouts(android::sp mapper, const native_handle_t *buffer) { hidl_vec encoded_layouts; - Error error = GetMetadata(mapper, buffer, - android::gralloc4::MetadataType_PlaneLayouts, - &encoded_layouts); + Error error = + GetMetadata(mapper, buffer, android::gralloc4::MetadataType_PlaneLayouts, + &encoded_layouts); if (error != Error::NONE) return std::nullopt; std::vector plane_layouts; - auto status = android::gralloc4::decodePlaneLayouts(encoded_layouts, &plane_layouts); + auto status = + android::gralloc4::decodePlaneLayouts(encoded_layouts, &plane_layouts); if (status != android::OK) return std::nullopt; @@ -89,8 +90,7 @@ std::optional> GetPlaneLayouts( return plane_layouts; } -extern "C" -{ +extern "C" { int mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, @@ -108,20 +108,26 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, buf_info.height = buf->height; hidl_vec encoded_format; - auto err = GetMetadata(mapper, buf->handle, android::gralloc4::MetadataType_PixelFormatFourCC, &encoded_format); + auto err = GetMetadata(mapper, buf->handle, + android::gralloc4::MetadataType_PixelFormatFourCC, + &encoded_format); if (err != Error::NONE) return -EINVAL; - auto status = android::gralloc4::decodePixelFormatFourCC(encoded_format, &buf_info.drm_fourcc); + auto status = android::gralloc4::decodePixelFormatFourCC( + encoded_format, &buf_info.drm_fourcc); if (status != android::OK) return -EINVAL; hidl_vec encoded_modifier; - err = GetMetadata(mapper, buf->handle, android::gralloc4::MetadataType_PixelFormatModifier, &encoded_modifier); + err = GetMetadata(mapper, buf->handle, + android::gralloc4::MetadataType_PixelFormatModifier, + &encoded_modifier); if (err != Error::NONE) return -EINVAL; - status = android::gralloc4::decodePixelFormatModifier(encoded_modifier, &buf_info.modifier); + status = android::gralloc4::decodePixelFormatModifier(encoded_modifier, + &buf_info.modifier); if (status != android::OK) return -EINVAL; @@ -130,79 +136,89 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, if (!layouts_opt) return -EINVAL; - std::vector& layouts = *layouts_opt; + std::vector &layouts = *layouts_opt; buf_info.num_planes = layouts.size(); bool per_plane_unique_fd = buf->handle->numFds == buf_info.num_planes; for (uint32_t i = 0; i < layouts.size(); i++) { - buf_info.fds[i] = per_plane_unique_fd ? buf->handle->data[i] : buf->handle->data[0]; + buf_info.fds[i] = + per_plane_unique_fd ? buf->handle->data[i] : buf->handle->data[0]; buf_info.pitches[i] = layouts[i].strideInBytes; buf_info.offsets[i] = layouts[i].offsetInBytes; } /* optional attributes */ hidl_vec encoded_chroma_siting; - err = GetMetadata(mapper, buf->handle, android::gralloc4::MetadataType_ChromaSiting, &encoded_chroma_siting); + err = GetMetadata(mapper, buf->handle, + android::gralloc4::MetadataType_ChromaSiting, + &encoded_chroma_siting); if (err == Error::NONE) { ExtendableType chroma_siting_ext; - status = android::gralloc4::decodeChromaSiting(encoded_chroma_siting, &chroma_siting_ext); + status = android::gralloc4::decodeChromaSiting(encoded_chroma_siting, + &chroma_siting_ext); if (status != android::OK) return -EINVAL; - ChromaSiting chroma_siting = android::gralloc4::getStandardChromaSitingValue(chroma_siting_ext); + ChromaSiting chroma_siting = + android::gralloc4::getStandardChromaSitingValue(chroma_siting_ext); switch (chroma_siting) { - case ChromaSiting::SITED_INTERSTITIAL: - buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0_5; - buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5; - break; - case ChromaSiting::COSITED_HORIZONTAL: - buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0; - buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5; - break; - default: - break; + case ChromaSiting::SITED_INTERSTITIAL: + buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0_5; + buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5; + break; + case ChromaSiting::COSITED_HORIZONTAL: + buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0; + buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5; + break; + default: + break; } } hidl_vec encoded_dataspace; - err = GetMetadata(mapper, buf->handle, android::gralloc4:: MetadataType_Dataspace, &encoded_dataspace); + err = GetMetadata(mapper, buf->handle, + android::gralloc4::MetadataType_Dataspace, + &encoded_dataspace); if (err == Error::NONE) { Dataspace dataspace; - status = android::gralloc4::decodeDataspace(encoded_dataspace, &dataspace); + status = + android::gralloc4::decodeDataspace(encoded_dataspace, &dataspace); if (status != android::OK) return -EINVAL; - Dataspace standard = (Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK); + Dataspace standard = + (Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK); switch (standard) { - case Dataspace::STANDARD_BT709: - buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC709; - break; - case Dataspace::STANDARD_BT601_625: - case Dataspace::STANDARD_BT601_625_UNADJUSTED: - case Dataspace::STANDARD_BT601_525: - case Dataspace::STANDARD_BT601_525_UNADJUSTED: - buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC601; - break; - case Dataspace::STANDARD_BT2020: - case Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE: - buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC2020; - break; - default: - break; + case Dataspace::STANDARD_BT709: + buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC709; + break; + case Dataspace::STANDARD_BT601_625: + case Dataspace::STANDARD_BT601_625_UNADJUSTED: + case Dataspace::STANDARD_BT601_525: + case Dataspace::STANDARD_BT601_525_UNADJUSTED: + buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC601; + break; + case Dataspace::STANDARD_BT2020: + case Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE: + buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC2020; + break; + default: + break; } - Dataspace range = (Dataspace)((int)dataspace & (uint32_t)Dataspace::RANGE_MASK); + Dataspace range = + (Dataspace)((int)dataspace & (uint32_t)Dataspace::RANGE_MASK); switch (range) { - case Dataspace::RANGE_FULL: - buf_info.sample_range = __DRI_YUV_FULL_RANGE; - break; - case Dataspace::RANGE_LIMITED: - buf_info.sample_range = __DRI_YUV_NARROW_RANGE; - break; - default: - break; + case Dataspace::RANGE_FULL: + buf_info.sample_range = __DRI_YUV_FULL_RANGE; + break; + case Dataspace::RANGE_LIMITED: + buf_info.sample_range = __DRI_YUV_NARROW_RANGE; + break; + default: + break; } } diff --git a/src/egl/drivers/dri2/platform_device.c b/src/egl/drivers/dri2/platform_device.c index 59b669d615b..15f82a5f469 100644 --- a/src/egl/drivers/dri2/platform_device.c +++ b/src/egl/drivers/dri2/platform_device.c @@ -30,31 +30,27 @@ #include #endif -#include -#include -#include #include -#include -#include #include +#include +#include +#include #include +#include +#include -#include "egl_dri2.h" -#include "loader.h" -#include "kopper_interface.h" #include "util/u_debug.h" +#include "egl_dri2.h" +#include "kopper_interface.h" +#include "loader.h" -static __DRIimage* +static __DRIimage * device_alloc_image(struct dri2_egl_display *dri2_dpy, struct dri2_egl_surface *dri2_surf) { return dri2_dpy->image->createImage( - dri2_dpy->dri_screen_render_gpu, - dri2_surf->base.Width, - dri2_surf->base.Height, - dri2_surf->visual, - 0, - NULL); + dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width, + dri2_surf->base.Height, dri2_surf->visual, 0, NULL); } static void @@ -73,12 +69,9 @@ device_free_images(struct dri2_egl_surface *dri2_surf) } static int -device_image_get_buffers(__DRIdrawable *driDrawable, - unsigned int format, - uint32_t *stamp, - void *loaderPrivate, - uint32_t buffer_mask, - struct __DRIimageList *buffers) +device_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format, + uint32_t *stamp, void *loaderPrivate, + uint32_t buffer_mask, struct __DRIimageList *buffers) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_display *dri2_dpy = @@ -105,8 +98,7 @@ device_image_get_buffers(__DRIdrawable *driDrawable, if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) { if (!dri2_surf->front) - dri2_surf->front = - device_alloc_image(dri2_dpy, dri2_surf); + dri2_surf->front = device_alloc_image(dri2_dpy, dri2_surf); buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT; buffers->front = dri2_surf->front; @@ -138,11 +130,11 @@ dri2_device_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, false, NULL)) goto cleanup_surface; - config = dri2_get_dri_config(dri2_conf, type, - dri2_surf->base.GLColorspace); + config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace); if (!config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_surface; } @@ -155,9 +147,9 @@ dri2_device_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, return &dri2_surf->base; - cleanup_surface: - free(dri2_surf); - return NULL; +cleanup_surface: + free(dri2_surf); + return NULL; } static EGLBoolean @@ -207,16 +199,16 @@ device_get_capability(void *loaderPrivate, enum dri_loader_cap cap) } static const __DRIimageLoaderExtension image_loader_extension = { - .base = { __DRI_IMAGE_LOADER, 2 }, - .getBuffers = device_image_get_buffers, + .base = {__DRI_IMAGE_LOADER, 2}, + .getBuffers = device_image_get_buffers, .flushFrontBuffer = device_flush_front_buffer, - .getCapability = device_get_capability, + .getCapability = device_get_capability, }; static const __DRIkopperLoaderExtension kopper_loader_extension = { - .base = { __DRI_KOPPER_LOADER, 1 }, + .base = {__DRI_KOPPER_LOADER, 1}, - .SetSurfaceCreateInfo = NULL, + .SetSurfaceCreateInfo = NULL, }; static const __DRIextension *image_loader_extensions[] = { @@ -253,24 +245,24 @@ device_get_fd(_EGLDisplay *disp, _EGLDevice *dev) if (dev != _eglAddDevice(fd, false)) return -1; - /* kms_swrast only work with primary node. It used to work with render node in - * the past because some downstream kernel carry a patch to enable dumb bo - * ioctl on render nodes. + /* kms_swrast only work with primary node. It used to work with render + * node in the past because some downstream kernel carry a patch to enable + * dumb bo ioctl on render nodes. */ - char *node = kms_swrast ? drmGetPrimaryDeviceNameFromFd(fd) : - drmGetRenderDeviceNameFromFd(fd); + char *node = kms_swrast ? drmGetPrimaryDeviceNameFromFd(fd) + : drmGetRenderDeviceNameFromFd(fd); /* Don't close the internal fd, get render node one based on it. */ fd = loader_open_device(node); free(node); return fd; } - const char *node = _eglQueryDeviceStringEXT(dev, kms_swrast ? - EGL_DRM_DEVICE_FILE_EXT : - EGL_DRM_RENDER_NODE_FILE_EXT); + const char *node = _eglQueryDeviceStringEXT( + dev, kms_swrast ? EGL_DRM_DEVICE_FILE_EXT : EGL_DRM_RENDER_NODE_FILE_EXT); return loader_open_device(node); #else - _eglLog(_EGL_FATAL, "Driver bug: Built without libdrm, yet using a HW device"); + _eglLog(_EGL_FATAL, + "Driver bug: Built without libdrm, yet using a HW device"); return -1; #endif } @@ -279,7 +271,8 @@ static bool device_probe_device(_EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - bool request_software = debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); + bool request_software = + debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); if (request_software) _eglLog(_EGL_WARNING, "Not allowed to force software rendering when " @@ -320,7 +313,6 @@ err_name: close(dri2_dpy->fd_render_gpu); dri2_dpy->fd_render_gpu = dri2_dpy->fd_display_gpu = -1; return false; - } static bool @@ -350,7 +342,7 @@ dri2_initialize_device(_EGLDisplay *disp) { _EGLDevice *dev; struct dri2_egl_display *dri2_dpy; - const char* err; + const char *err; dri2_dpy = calloc(1, sizeof *dri2_dpy); if (!dri2_dpy) @@ -362,7 +354,7 @@ dri2_initialize_device(_EGLDisplay *disp) dri2_dpy->fd_render_gpu = -1; dri2_dpy->fd_display_gpu = -1; disp->Device = dev; - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; err = "DRI2: failed to load driver"; if (_eglDeviceSupports(dev, _EGL_DEVICE_DRM)) { if (!device_probe_device(disp)) @@ -371,7 +363,8 @@ dri2_initialize_device(_EGLDisplay *disp) if (!device_probe_device_sw(disp)) goto cleanup; } else { - _eglLog(_EGL_FATAL, "Driver bug: exposed device is neither DRM nor SOFTWARE one"); + _eglLog(_EGL_FATAL, + "Driver bug: exposed device is neither DRM nor SOFTWARE one"); return EGL_FALSE; } @@ -387,7 +380,8 @@ dri2_initialize_device(_EGLDisplay *disp) dri2_setup_screen(disp); #ifdef HAVE_WAYLAND_PLATFORM - dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); + dri2_dpy->device_name = + loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); #endif dri2_set_WL_bind_wayland_display(disp); diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index ebc73db5252..9b58ed9a724 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -25,16 +25,16 @@ * Kristian Høgsberg */ -#include -#include -#include -#include -#include #include -#include -#include #include +#include +#include +#include +#include #include +#include +#include +#include #include "util/os_file.h" @@ -72,8 +72,8 @@ release_buffer(struct gbm_surface *_surf, struct gbm_bo *bo) for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { if (dri2_surf->color_buffers[i].bo == bo) { - dri2_surf->color_buffers[i].locked = false; - break; + dri2_surf->color_buffers[i].locked = false; + break; } } } @@ -86,7 +86,7 @@ has_free_buffers(struct gbm_surface *_surf) for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) if (!dri2_surf->color_buffers[i].locked) - return 1; + return 1; return 0; } @@ -162,7 +162,8 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, dri2_surf->base.GLColorspace); if (!config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_surf; } @@ -173,7 +174,7 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, surf = gbm_dri_surface(surface); dri2_surf->gbm_surf = surf; - dri2_surf->base.Width = surf->base.v0.width; + dri2_surf->base.Width = surf->base.v0.width; dri2_surf->base.Height = surf->base.v0.height; surf->dri_private = dri2_surf; @@ -182,7 +183,7 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, return &dri2_surf->base; - cleanup_surf: +cleanup_surf: free(dri2_surf); return NULL; @@ -212,7 +213,7 @@ dri2_drm_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { if (dri2_surf->color_buffers[i].bo) - gbm_bo_destroy(dri2_surf->color_buffers[i].bo); + gbm_bo_destroy(dri2_surf->color_buffers[i].bo); } dri2_egl_surface_free_local_buffers(dri2_surf); @@ -233,11 +234,11 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) if (dri2_surf->back == NULL) { for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { - if (!dri2_surf->color_buffers[i].locked && - dri2_surf->color_buffers[i].age >= age) { - dri2_surf->back = &dri2_surf->color_buffers[i]; - age = dri2_surf->color_buffers[i].age; - } + if (!dri2_surf->color_buffers[i].locked && + dri2_surf->color_buffers[i].age >= age) { + dri2_surf->back = &dri2_surf->color_buffers[i]; + age = dri2_surf->color_buffers[i].age; + } } } @@ -245,23 +246,17 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) return -1; if (dri2_surf->back->bo == NULL) { if (surf->base.v0.modifiers) - dri2_surf->back->bo = gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base, - surf->base.v0.width, - surf->base.v0.height, - surf->base.v0.format, - surf->base.v0.modifiers, - surf->base.v0.count); + dri2_surf->back->bo = gbm_bo_create_with_modifiers( + &dri2_dpy->gbm_dri->base, surf->base.v0.width, surf->base.v0.height, + surf->base.v0.format, surf->base.v0.modifiers, surf->base.v0.count); else { unsigned flags = surf->base.v0.flags; if (dri2_surf->base.ProtectedContent) flags |= GBM_BO_USE_PROTECTED; - dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base, - surf->base.v0.width, - surf->base.v0.height, - surf->base.v0.format, - flags); + dri2_surf->back->bo = + gbm_bo_create(&dri2_dpy->gbm_dri->base, surf->base.v0.width, + surf->base.v0.height, surf->base.v0.format, flags); } - } if (dri2_surf->back->bo == NULL) return -1; @@ -282,11 +277,9 @@ get_swrast_front_bo(struct dri2_egl_surface *dri2_surf) } if (dri2_surf->current->bo == NULL) - dri2_surf->current->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base, - surf->base.v0.width, - surf->base.v0.height, - surf->base.v0.format, - surf->base.v0.flags); + dri2_surf->current->bo = gbm_bo_create( + &dri2_dpy->gbm_dri->base, surf->base.v0.width, surf->base.v0.height, + surf->base.v0.format, surf->base.v0.flags); if (dri2_surf->current->bo == NULL) return -1; @@ -314,10 +307,9 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer) } static __DRIbuffer * -dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, int *width, + int *height, unsigned int *attachments, + int count, int *out_count, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int i, j; @@ -330,22 +322,22 @@ dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, switch (attachments[i]) { case __DRI_BUFFER_BACK_LEFT: - if (get_back_bo(dri2_surf) < 0) { - _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer"); - return NULL; - } + if (get_back_bo(dri2_surf) < 0) { + _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer"); + return NULL; + } back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]); - break; + break; default: - local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i], + local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i], attachments[i + 1]); - if (!local) { - _eglError(EGL_BAD_ALLOC, "failed to allocate local buffer"); - return NULL; - } - dri2_surf->buffers[j] = *local; - break; + if (!local) { + _eglError(EGL_BAD_ALLOC, "failed to allocate local buffer"); + return NULL; + } + dri2_surf->buffers[j] = *local; + break; } } @@ -360,10 +352,9 @@ dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, } static __DRIbuffer * -dri2_drm_get_buffers(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2_drm_get_buffers(__DRIdrawable *driDrawable, int *width, int *height, + unsigned int *attachments, int count, int *out_count, + void *loaderPrivate) { unsigned int *attachments_with_format; __DRIbuffer *buffer; @@ -376,15 +367,13 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable, } for (int i = 0; i < count; ++i) { - attachments_with_format[2*i] = attachments[i]; - attachments_with_format[2*i + 1] = format; + attachments_with_format[2 * i] = attachments[i]; + attachments_with_format[2 * i + 1] = format; } - buffer = - dri2_drm_get_buffers_with_format(driDrawable, - width, height, - attachments_with_format, count, - out_count, loaderPrivate); + buffer = dri2_drm_get_buffers_with_format(driDrawable, width, height, + attachments_with_format, count, + out_count, loaderPrivate); free(attachments_with_format); @@ -392,12 +381,9 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable, } static int -dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, - unsigned int format, - uint32_t *stamp, - void *loaderPrivate, - uint32_t buffer_mask, - struct __DRIimageList *buffers) +dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format, + uint32_t *stamp, void *loaderPrivate, + uint32_t buffer_mask, struct __DRIimageList *buffers) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct gbm_dri_bo *bo; @@ -413,10 +399,10 @@ dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, } static void -dri2_drm_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) +dri2_drm_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) { - (void) driDrawable; - (void) loaderPrivate; + (void)driDrawable; + (void)loaderPrivate; } static EGLBoolean @@ -466,10 +452,11 @@ dri2_drm_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surface) static _EGLImage * dri2_drm_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, - EGLClientBuffer buffer, const EGLint *attr_list) + EGLClientBuffer buffer, + const EGLint *attr_list) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *) buffer); + struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *)buffer); struct dri2_egl_image *dri2_img; dri2_img = malloc(sizeof *dri2_img); @@ -511,15 +498,8 @@ dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id) } static void -swrast_put_image2(__DRIdrawable *driDrawable, - int op, - int x, - int y, - int width, - int height, - int stride, - char *data, - void *loaderPrivate) +swrast_put_image2(__DRIdrawable *driDrawable, int op, int x, int y, int width, + int height, int stride, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int internal_stride; @@ -528,8 +508,7 @@ swrast_put_image2(__DRIdrawable *driDrawable, int x_bytes, width_bytes; char *src, *dst; - if (op != __DRI_SWRAST_IMAGE_OP_DRAW && - op != __DRI_SWRAST_IMAGE_OP_SWAP) + if (op != __DRI_SWRAST_IMAGE_OP_DRAW && op != __DRI_SWRAST_IMAGE_OP_SWAP) return; if (get_swrast_front_bo(dri2_surf) < 0) @@ -562,13 +541,8 @@ swrast_put_image2(__DRIdrawable *driDrawable, } static void -swrast_get_image(__DRIdrawable *driDrawable, - int x, - int y, - int width, - int height, - char *data, - void *loaderPrivate) +swrast_get_image(__DRIdrawable *driDrawable, int x, int y, int width, + int height, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int internal_stride, stride; @@ -643,12 +617,14 @@ drm_add_configs_for_visuals(_EGLDisplay *disp) continue; const EGLint attr_list[] = { - EGL_NATIVE_VISUAL_ID, visuals[j].gbm_format, + EGL_NATIVE_VISUAL_ID, + visuals[j].gbm_format, EGL_NONE, }; - dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], - config_count + 1, EGL_WINDOW_BIT, attr_list, NULL, NULL); + dri2_conf = + dri2_add_config(disp, dri2_dpy->driver_configs[i], config_count + 1, + EGL_WINDOW_BIT, attr_list, NULL, NULL); if (dri2_conf) { if (dri2_conf->base.ConfigID == config_count + 1) config_count++; @@ -693,7 +669,7 @@ dri2_initialize_drm(_EGLDisplay *disp) dri2_dpy->fd_render_gpu = -1; dri2_dpy->fd_display_gpu = -1; - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; gbm = disp->PlatformDisplay; if (gbm == NULL) { @@ -731,7 +707,8 @@ dri2_initialize_drm(_EGLDisplay *disp) disp->Device = dev; dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->driver_name); - dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER; + dri2_dpy->is_render_node = + drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER; /* render nodes cannot use Gem names, and thus do not support * the __DRI_DRI2_LOADER extension */ @@ -761,7 +738,8 @@ dri2_initialize_drm(_EGLDisplay *disp) dri2_dpy->gbm_dri->get_buffers = dri2_drm_get_buffers; dri2_dpy->gbm_dri->flush_front_buffer = dri2_drm_flush_front_buffer; - dri2_dpy->gbm_dri->get_buffers_with_format = dri2_drm_get_buffers_with_format; + dri2_dpy->gbm_dri->get_buffers_with_format = + dri2_drm_get_buffers_with_format; dri2_dpy->gbm_dri->image_get_buffers = dri2_drm_image_get_buffers; dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2; dri2_dpy->gbm_dri->swrast_get_image = swrast_get_image; @@ -787,7 +765,8 @@ dri2_initialize_drm(_EGLDisplay *disp) disp->Extensions.EXT_buffer_age = EGL_TRUE; #ifdef HAVE_WAYLAND_PLATFORM - dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); + dri2_dpy->device_name = + loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); #endif dri2_set_WL_bind_wayland_display(disp); diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c index 15c98ac29fc..0e7248b065f 100644 --- a/src/egl/drivers/dri2/platform_surfaceless.c +++ b/src/egl/drivers/dri2/platform_surfaceless.c @@ -23,31 +23,27 @@ * DEALINGS IN THE SOFTWARE. */ -#include -#include -#include -#include #include -#include -#include #include +#include +#include +#include #include +#include +#include +#include #include "egl_dri2.h" -#include "loader.h" #include "kopper_interface.h" +#include "loader.h" -static __DRIimage* +static __DRIimage * surfaceless_alloc_image(struct dri2_egl_display *dri2_dpy, - struct dri2_egl_surface *dri2_surf) + struct dri2_egl_surface *dri2_surf) { return dri2_dpy->image->createImage( - dri2_dpy->dri_screen_render_gpu, - dri2_surf->base.Width, - dri2_surf->base.Height, - dri2_surf->visual, - 0, - NULL); + dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width, + dri2_surf->base.Height, dri2_surf->visual, 0, NULL); } static void @@ -66,12 +62,10 @@ surfaceless_free_images(struct dri2_egl_surface *dri2_surf) } static int -surfaceless_image_get_buffers(__DRIdrawable *driDrawable, - unsigned int format, - uint32_t *stamp, - void *loaderPrivate, - uint32_t buffer_mask, - struct __DRIimageList *buffers) +surfaceless_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format, + uint32_t *stamp, void *loaderPrivate, + uint32_t buffer_mask, + struct __DRIimageList *buffers) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_display *dri2_dpy = @@ -98,8 +92,7 @@ surfaceless_image_get_buffers(__DRIdrawable *driDrawable, if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) { if (!dri2_surf->front) - dri2_surf->front = - surfaceless_alloc_image(dri2_dpy, dri2_surf); + dri2_surf->front = surfaceless_alloc_image(dri2_dpy, dri2_surf); buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT; buffers->front = dri2_surf->front; @@ -131,11 +124,11 @@ dri2_surfaceless_create_surface(_EGLDisplay *disp, EGLint type, false, NULL)) goto cleanup_surface; - config = dri2_get_dri_config(dri2_conf, type, - dri2_surf->base.GLColorspace); + config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace); if (!config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_surface; } @@ -148,9 +141,9 @@ dri2_surfaceless_create_surface(_EGLDisplay *disp, EGLint type, return &dri2_surf->base; - cleanup_surface: - free(dri2_surf); - return NULL; +cleanup_surface: + free(dri2_surf); + return NULL; } static EGLBoolean @@ -173,7 +166,7 @@ dri2_surfaceless_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { return dri2_surfaceless_create_surface(disp, EGL_PBUFFER_BIT, conf, - attrib_list); + attrib_list); } static const struct dri2_egl_display_vtbl dri2_surfaceless_display_vtbl = { @@ -201,34 +194,28 @@ surfaceless_get_capability(void *loaderPrivate, enum dri_loader_cap cap) } static const __DRIkopperLoaderExtension kopper_loader_extension = { - .base = { __DRI_KOPPER_LOADER, 1 }, + .base = {__DRI_KOPPER_LOADER, 1}, - .SetSurfaceCreateInfo = NULL, + .SetSurfaceCreateInfo = NULL, }; static const __DRIimageLoaderExtension image_loader_extension = { - .base = { __DRI_IMAGE_LOADER, 2 }, - .getBuffers = surfaceless_image_get_buffers, + .base = {__DRI_IMAGE_LOADER, 2}, + .getBuffers = surfaceless_image_get_buffers, .flushFrontBuffer = surfaceless_flush_front_buffer, - .getCapability = surfaceless_get_capability, + .getCapability = surfaceless_get_capability, }; static const __DRIextension *image_loader_extensions[] = { - &image_loader_extension.base, - &image_lookup_extension.base, - &use_invalidate.base, - &background_callable_extension.base, - &kopper_loader_extension.base, - NULL, + &image_loader_extension.base, &image_lookup_extension.base, + &use_invalidate.base, &background_callable_extension.base, + &kopper_loader_extension.base, NULL, }; static const __DRIextension *swrast_loader_extensions[] = { - &swrast_pbuffer_loader_extension.base, - &image_loader_extension.base, - &image_lookup_extension.base, - &use_invalidate.base, - &kopper_loader_extension.base, - NULL, + &swrast_pbuffer_loader_extension.base, &image_loader_extension.base, + &image_lookup_extension.base, &use_invalidate.base, + &kopper_loader_extension.base, NULL, }; static bool @@ -237,7 +224,7 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast) #define MAX_DRM_DEVICES 64 const unsigned node_type = swrast ? DRM_NODE_PRIMARY : DRM_NODE_RENDER; struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL }; + drmDevicePtr device, devices[MAX_DRM_DEVICES] = {NULL}; int i, num_devices; num_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices)); @@ -268,9 +255,8 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast) * are unavailable since 6c5ab, and kms_swrast is more * feature complete than swrast. */ - if (driver_name && - (strcmp(driver_name, "vgem") == 0 || - strcmp(driver_name, "virtio_gpu") == 0)) + if (driver_name && (strcmp(driver_name, "vgem") == 0 || + strcmp(driver_name, "virtio_gpu") == 0)) dri2_dpy->driver_name = strdup("kms_swrast"); free(driver_name); } else { @@ -326,7 +312,7 @@ EGLBoolean dri2_initialize_surfaceless(_EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy; - const char* err; + const char *err; bool driver_loaded = false; dri2_dpy = calloc(1, sizeof *dri2_dpy); @@ -335,7 +321,7 @@ dri2_initialize_surfaceless(_EGLDisplay *disp) dri2_dpy->fd_render_gpu = -1; dri2_dpy->fd_display_gpu = -1; - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; /* When ForceSoftware is false, we try the HW driver. When ForceSoftware * is true, we try kms_swrast and swrast in order. @@ -365,7 +351,8 @@ dri2_initialize_surfaceless(_EGLDisplay *disp) dri2_setup_screen(disp); #ifdef HAVE_WAYLAND_PLATFORM - dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); + dri2_dpy->device_name = + loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); #endif dri2_set_WL_bind_wayland_display(disp); diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index 5fcbcf5e5e4..eef62594ade 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -27,32 +27,32 @@ * Benjamin Franzke */ +#include +#include +#include +#include #include #include #include -#include -#include -#include #include -#include -#include -#include #include #include "drm-uapi/drm_fourcc.h" #include +#include +#include -#include "egl_dri2.h" -#include "loader_dri_helper.h" -#include "loader.h" -#include "util/u_vector.h" #include "util/anon_file.h" +#include "util/u_vector.h" +#include "egl_dri2.h" #include "eglglobals.h" #include "kopper_interface.h" +#include "loader.h" +#include "loader_dri_helper.h" -#include -#include -#include "wayland-drm-client-protocol.h" #include "linux-dmabuf-unstable-v1-client-protocol.h" +#include "wayland-drm-client-protocol.h" +#include +#include /* * The index of entries in this table is used as a bitmask in @@ -78,87 +78,119 @@ static const struct dri2_wl_visual { } dri2_wl_visuals[] = { { "ABGR16F", - WL_DRM_FORMAT_ABGR16F, WL_SHM_FORMAT_ABGR16161616F, - __DRI_IMAGE_FORMAT_ABGR16161616F, 0, 64, - { 0, 16, 32, 48 }, - { 16, 16, 16, 16 }, + WL_DRM_FORMAT_ABGR16F, + WL_SHM_FORMAT_ABGR16161616F, + __DRI_IMAGE_FORMAT_ABGR16161616F, + 0, + 64, + {0, 16, 32, 48}, + {16, 16, 16, 16}, }, { "XBGR16F", - WL_DRM_FORMAT_XBGR16F, WL_SHM_FORMAT_XBGR16161616F, - __DRI_IMAGE_FORMAT_XBGR16161616F, 0, 64, - { 0, 16, 32, -1 }, - { 16, 16, 16, 0 }, + WL_DRM_FORMAT_XBGR16F, + WL_SHM_FORMAT_XBGR16161616F, + __DRI_IMAGE_FORMAT_XBGR16161616F, + 0, + 64, + {0, 16, 32, -1}, + {16, 16, 16, 0}, }, { "XRGB2101010", - WL_DRM_FORMAT_XRGB2101010, WL_SHM_FORMAT_XRGB2101010, - __DRI_IMAGE_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XBGR2101010, 32, - { 20, 10, 0, -1 }, - { 10, 10, 10, 0 }, + WL_DRM_FORMAT_XRGB2101010, + WL_SHM_FORMAT_XRGB2101010, + __DRI_IMAGE_FORMAT_XRGB2101010, + __DRI_IMAGE_FORMAT_XBGR2101010, + 32, + {20, 10, 0, -1}, + {10, 10, 10, 0}, }, { "ARGB2101010", - WL_DRM_FORMAT_ARGB2101010, WL_SHM_FORMAT_ARGB2101010, - __DRI_IMAGE_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ABGR2101010, 32, - { 20, 10, 0, 30 }, - { 10, 10, 10, 2 }, + WL_DRM_FORMAT_ARGB2101010, + WL_SHM_FORMAT_ARGB2101010, + __DRI_IMAGE_FORMAT_ARGB2101010, + __DRI_IMAGE_FORMAT_ABGR2101010, + 32, + {20, 10, 0, 30}, + {10, 10, 10, 2}, }, { "XBGR2101010", - WL_DRM_FORMAT_XBGR2101010, WL_SHM_FORMAT_XBGR2101010, - __DRI_IMAGE_FORMAT_XBGR2101010, __DRI_IMAGE_FORMAT_XRGB2101010, 32, - { 0, 10, 20, -1 }, - { 10, 10, 10, 0 }, + WL_DRM_FORMAT_XBGR2101010, + WL_SHM_FORMAT_XBGR2101010, + __DRI_IMAGE_FORMAT_XBGR2101010, + __DRI_IMAGE_FORMAT_XRGB2101010, + 32, + {0, 10, 20, -1}, + {10, 10, 10, 0}, }, { "ABGR2101010", - WL_DRM_FORMAT_ABGR2101010, WL_SHM_FORMAT_ABGR2101010, - __DRI_IMAGE_FORMAT_ABGR2101010, __DRI_IMAGE_FORMAT_ARGB2101010, 32, - { 0, 10, 20, 30 }, - { 10, 10, 10, 2 }, + WL_DRM_FORMAT_ABGR2101010, + WL_SHM_FORMAT_ABGR2101010, + __DRI_IMAGE_FORMAT_ABGR2101010, + __DRI_IMAGE_FORMAT_ARGB2101010, + 32, + {0, 10, 20, 30}, + {10, 10, 10, 2}, }, { "XRGB8888", - WL_DRM_FORMAT_XRGB8888, WL_SHM_FORMAT_XRGB8888, - __DRI_IMAGE_FORMAT_XRGB8888, __DRI_IMAGE_FORMAT_NONE, 32, - { 16, 8, 0, -1 }, - { 8, 8, 8, 0 }, + WL_DRM_FORMAT_XRGB8888, + WL_SHM_FORMAT_XRGB8888, + __DRI_IMAGE_FORMAT_XRGB8888, + __DRI_IMAGE_FORMAT_NONE, + 32, + {16, 8, 0, -1}, + {8, 8, 8, 0}, }, { "ARGB8888", - WL_DRM_FORMAT_ARGB8888, WL_SHM_FORMAT_ARGB8888, - __DRI_IMAGE_FORMAT_ARGB8888, __DRI_IMAGE_FORMAT_NONE, 32, - { 16, 8, 0, 24 }, - { 8, 8, 8, 8 }, + WL_DRM_FORMAT_ARGB8888, + WL_SHM_FORMAT_ARGB8888, + __DRI_IMAGE_FORMAT_ARGB8888, + __DRI_IMAGE_FORMAT_NONE, + 32, + {16, 8, 0, 24}, + {8, 8, 8, 8}, }, { "ABGR8888", - WL_DRM_FORMAT_ABGR8888, WL_SHM_FORMAT_ABGR8888, - __DRI_IMAGE_FORMAT_ABGR8888, __DRI_IMAGE_FORMAT_NONE, 32, - { 0, 8, 16, 24 }, - { 8, 8, 8, 8 }, + WL_DRM_FORMAT_ABGR8888, + WL_SHM_FORMAT_ABGR8888, + __DRI_IMAGE_FORMAT_ABGR8888, + __DRI_IMAGE_FORMAT_NONE, + 32, + {0, 8, 16, 24}, + {8, 8, 8, 8}, }, { "XBGR8888", - WL_DRM_FORMAT_XBGR8888, WL_SHM_FORMAT_XBGR8888, - __DRI_IMAGE_FORMAT_XBGR8888, __DRI_IMAGE_FORMAT_NONE, 32, - { 0, 8, 16, -1 }, - { 8, 8, 8, 0 }, + WL_DRM_FORMAT_XBGR8888, + WL_SHM_FORMAT_XBGR8888, + __DRI_IMAGE_FORMAT_XBGR8888, + __DRI_IMAGE_FORMAT_NONE, + 32, + {0, 8, 16, -1}, + {8, 8, 8, 0}, }, { "RGB565", - WL_DRM_FORMAT_RGB565, WL_SHM_FORMAT_RGB565, - __DRI_IMAGE_FORMAT_RGB565, __DRI_IMAGE_FORMAT_NONE, 16, - { 11, 5, 0, -1 }, - { 5, 6, 5, 0 }, + WL_DRM_FORMAT_RGB565, + WL_SHM_FORMAT_RGB565, + __DRI_IMAGE_FORMAT_RGB565, + __DRI_IMAGE_FORMAT_NONE, + 16, + {11, 5, 0, -1}, + {5, 6, 5, 0}, }, }; static int dri2_wl_visual_idx_from_config(struct dri2_egl_display *dri2_dpy, - const __DRIconfig *config, - bool force_opaque) + const __DRIconfig *config, bool force_opaque) { int shifts[4]; unsigned int sizes[4]; @@ -168,10 +200,10 @@ dri2_wl_visual_idx_from_config(struct dri2_egl_display *dri2_dpy, for (unsigned int i = 0; i < ARRAY_SIZE(dri2_wl_visuals); i++) { const struct dri2_wl_visual *wl_visual = &dri2_wl_visuals[i]; - int cmp_rgb_shifts = memcmp(shifts, wl_visual->rgba_shifts, - 3 * sizeof(shifts[0])); - int cmp_rgb_sizes = memcmp(sizes, wl_visual->rgba_sizes, - 3 * sizeof(sizes[0])); + int cmp_rgb_shifts = + memcmp(shifts, wl_visual->rgba_shifts, 3 * sizeof(shifts[0])); + int cmp_rgb_sizes = + memcmp(sizes, wl_visual->rgba_sizes, 3 * sizeof(sizes[0])); if (cmp_rgb_shifts == 0 && cmp_rgb_sizes == 0 && wl_visual->rgba_shifts[3] == (force_opaque ? -1 : shifts[3]) && @@ -219,9 +251,9 @@ dri2_wl_visual_idx_from_shm_format(uint32_t shm_format) } bool -dri2_wl_is_format_supported(void* user_data, uint32_t format) +dri2_wl_is_format_supported(void *user_data, uint32_t format) { - _EGLDisplay *disp = (_EGLDisplay *) user_data; + _EGLDisplay *disp = (_EGLDisplay *)user_data; struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); int j = dri2_wl_visual_idx_from_fourcc(format); @@ -229,9 +261,8 @@ dri2_wl_is_format_supported(void* user_data, uint32_t format) return false; for (int i = 0; dri2_dpy->driver_configs[i]; i++) - if (j == dri2_wl_visual_idx_from_config(dri2_dpy, - dri2_dpy->driver_configs[i], - false)) + if (j == dri2_wl_visual_idx_from_config( + dri2_dpy, dri2_dpy->driver_configs[i], false)) return true; return false; @@ -253,7 +284,7 @@ wl_buffer_release(void *data, struct wl_buffer *buffer) if (dri2_surf->color_buffers[i].wl_buffer == buffer) break; - assert (i < ARRAY_SIZE(dri2_surf->color_buffers)); + assert(i < ARRAY_SIZE(dri2_surf->color_buffers)); if (dri2_surf->color_buffers[i].wl_release) { wl_buffer_destroy(buffer); @@ -298,8 +329,8 @@ dri2_wl_formats_init(struct dri2_wl_formats *formats) /* Here we have an array of u_vector's to store the modifiers supported by * each format in the bitmask. */ - formats->modifiers = calloc(formats->num_formats, - sizeof(*formats->modifiers)); + formats->modifiers = + calloc(formats->num_formats, sizeof(*formats->modifiers)); if (!formats->modifiers) goto err_modifier; @@ -323,14 +354,16 @@ err: } static void -dmabuf_feedback_format_table_fini(struct dmabuf_feedback_format_table *format_table) +dmabuf_feedback_format_table_fini( + struct dmabuf_feedback_format_table *format_table) { if (format_table->data && format_table->data != MAP_FAILED) munmap(format_table->data, format_table->size); } static void -dmabuf_feedback_format_table_init(struct dmabuf_feedback_format_table *format_table) +dmabuf_feedback_format_table_init( + struct dmabuf_feedback_format_table *format_table) { memset(format_table, 0, sizeof(*format_table)); } @@ -357,8 +390,8 @@ dmabuf_feedback_fini(struct dmabuf_feedback *dmabuf_feedback) { dmabuf_feedback_tranche_fini(&dmabuf_feedback->pending_tranche); - util_dynarray_foreach(&dmabuf_feedback->tranches, - struct dmabuf_feedback_tranche, tranche) + util_dynarray_foreach (&dmabuf_feedback->tranches, + struct dmabuf_feedback_tranche, tranche) dmabuf_feedback_tranche_fini(tranche); util_dynarray_fini(&dmabuf_feedback->tranches); @@ -417,10 +450,10 @@ destroy_window_callback(void *data) static struct wl_surface * get_wl_surface_proxy(struct wl_egl_window *window) { - /* Version 3 of wl_egl_window introduced a version field at the same - * location where a pointer to wl_surface was stored. Thus, if - * window->version is dereferenceable, we've been given an older version of - * wl_egl_window, and window->version points to wl_surface */ + /* Version 3 of wl_egl_window introduced a version field at the same + * location where a pointer to wl_surface was stored. Thus, if + * window->version is dereferenceable, we've been given an older version of + * wl_egl_window, and window->version points to wl_surface */ if (_eglPointerIsDereferenceable((void *)(window->version))) { return wl_proxy_create_wrapper((void *)(window->version)); } @@ -428,23 +461,25 @@ get_wl_surface_proxy(struct wl_egl_window *window) } static void -surface_dmabuf_feedback_format_table(void *data, - struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, - int32_t fd, uint32_t size) +surface_dmabuf_feedback_format_table( + void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + int32_t fd, uint32_t size) { struct dri2_egl_surface *dri2_surf = data; struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback; feedback->format_table.size = size; - feedback->format_table.data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + feedback->format_table.data = + mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); } static void -surface_dmabuf_feedback_main_device(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - struct wl_array *device) +surface_dmabuf_feedback_main_device( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + struct wl_array *device) { struct dri2_egl_surface *dri2_surf = data; struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback; @@ -467,9 +502,9 @@ surface_dmabuf_feedback_main_device(void *data, } static void -surface_dmabuf_feedback_tranche_target_device(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - struct wl_array *device) +surface_dmabuf_feedback_tranche_target_device( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + struct wl_array *device) { struct dri2_egl_surface *dri2_surf = data; struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback; @@ -479,9 +514,9 @@ surface_dmabuf_feedback_tranche_target_device(void *data, } static void -surface_dmabuf_feedback_tranche_flags(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - uint32_t flags) +surface_dmabuf_feedback_tranche_flags( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + uint32_t flags) { struct dri2_egl_surface *dri2_surf = data; struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback; @@ -490,9 +525,9 @@ surface_dmabuf_feedback_tranche_flags(void *data, } static void -surface_dmabuf_feedback_tranche_formats(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - struct wl_array *indices) +surface_dmabuf_feedback_tranche_formats( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + struct wl_array *indices) { struct dri2_egl_surface *dri2_surf = data; struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback; @@ -502,11 +537,13 @@ surface_dmabuf_feedback_tranche_formats(void *data, int visual_idx; /* Compositor may advertise or not a format table. If it does, we use it. - * Otherwise, we steal the most recent advertised format table. If we don't have - * a most recent advertised format table, compositor did something wrong. */ + * Otherwise, we steal the most recent advertised format table. If we don't + * have a most recent advertised format table, compositor did something + * wrong. */ if (feedback->format_table.data == NULL) { feedback->format_table = dri2_surf->dmabuf_feedback.format_table; - dmabuf_feedback_format_table_init(&dri2_surf->dmabuf_feedback.format_table); + dmabuf_feedback_format_table_init( + &dri2_surf->dmabuf_feedback.format_table); } if (feedback->format_table.data == MAP_FAILED) { _eglLog(_EGL_WARNING, "wayland-egl: we could not map the format table " @@ -515,13 +552,14 @@ surface_dmabuf_feedback_tranche_formats(void *data, return; } if (feedback->format_table.data == NULL) { - _eglLog(_EGL_WARNING, "wayland-egl: compositor didn't advertise a format " - "table, so we won't be able to use this batch of dma-buf " - "feedback events."); + _eglLog(_EGL_WARNING, + "wayland-egl: compositor didn't advertise a format " + "table, so we won't be able to use this batch of dma-buf " + "feedback events."); return; } - wl_array_for_each(index, indices) { + wl_array_for_each (index, indices) { format = feedback->format_table.data[*index].format; modifier = feedback->format_table.data[*index].modifier; @@ -543,8 +581,8 @@ surface_dmabuf_feedback_tranche_formats(void *data, } static void -surface_dmabuf_feedback_tranche_done(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) +surface_dmabuf_feedback_tranche_done( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) { struct dri2_egl_surface *dri2_surf = data; struct dmabuf_feedback *feedback = &dri2_surf->pending_dmabuf_feedback; @@ -557,8 +595,8 @@ surface_dmabuf_feedback_tranche_done(void *data, } static void -surface_dmabuf_feedback_done(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) +surface_dmabuf_feedback_done( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) { struct dri2_egl_surface *dri2_surf = data; @@ -575,14 +613,14 @@ surface_dmabuf_feedback_done(void *data, } static const struct zwp_linux_dmabuf_feedback_v1_listener -surface_dmabuf_feedback_listener = { - .format_table = surface_dmabuf_feedback_format_table, - .main_device = surface_dmabuf_feedback_main_device, - .tranche_target_device = surface_dmabuf_feedback_tranche_target_device, - .tranche_flags = surface_dmabuf_feedback_tranche_flags, - .tranche_formats = surface_dmabuf_feedback_tranche_formats, - .tranche_done = surface_dmabuf_feedback_tranche_done, - .done = surface_dmabuf_feedback_done, + surface_dmabuf_feedback_listener = { + .format_table = surface_dmabuf_feedback_format_table, + .main_device = surface_dmabuf_feedback_main_device, + .tranche_target_device = surface_dmabuf_feedback_tranche_target_device, + .tranche_flags = surface_dmabuf_feedback_tranche_flags, + .tranche_formats = surface_dmabuf_feedback_tranche_formats, + .tranche_done = surface_dmabuf_feedback_tranche_done, + .done = surface_dmabuf_feedback_done, }; /** @@ -624,7 +662,8 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, dri2_surf->base.GLColorspace); if (!config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_surf; } @@ -648,12 +687,12 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, continue; } - int cmp_rgb_shifts = memcmp(transparent_visual->rgba_shifts, - opaque_visual->rgba_shifts, - 3 * sizeof(opaque_visual->rgba_shifts[0])); - int cmp_rgb_sizes = memcmp(transparent_visual->rgba_sizes, - opaque_visual->rgba_sizes, - 3 * sizeof(opaque_visual->rgba_sizes[0])); + int cmp_rgb_shifts = + memcmp(transparent_visual->rgba_shifts, opaque_visual->rgba_shifts, + 3 * sizeof(opaque_visual->rgba_shifts[0])); + int cmp_rgb_sizes = + memcmp(transparent_visual->rgba_sizes, opaque_visual->rgba_sizes, + 3 * sizeof(opaque_visual->rgba_sizes[0])); if (cmp_rgb_shifts == 0 && cmp_rgb_sizes == 0) { found_opaque_equivalent = true; @@ -708,8 +747,9 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, wl_proxy_set_queue((struct wl_proxy *)dri2_surf->wl_surface_wrapper, dri2_surf->wl_queue); - if (dri2_dpy->wl_dmabuf && zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >= - ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION) { + if (dri2_dpy->wl_dmabuf && + zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >= + ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION) { dmabuf_wrapper = wl_proxy_create_wrapper(dri2_dpy->wl_dmabuf); if (!dmabuf_wrapper) { _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); @@ -717,14 +757,13 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, } wl_proxy_set_queue((struct wl_proxy *)dmabuf_wrapper, dri2_surf->wl_queue); - dri2_surf->wl_dmabuf_feedback = - zwp_linux_dmabuf_v1_get_surface_feedback(dmabuf_wrapper, - dri2_surf->wl_surface_wrapper); + dri2_surf->wl_dmabuf_feedback = zwp_linux_dmabuf_v1_get_surface_feedback( + dmabuf_wrapper, dri2_surf->wl_surface_wrapper); wl_proxy_wrapper_destroy(dmabuf_wrapper); - zwp_linux_dmabuf_feedback_v1_add_listener(dri2_surf->wl_dmabuf_feedback, - &surface_dmabuf_feedback_listener, - dri2_surf); + zwp_linux_dmabuf_feedback_v1_add_listener( + dri2_surf->wl_dmabuf_feedback, &surface_dmabuf_feedback_listener, + dri2_surf); if (dmabuf_feedback_init(&dri2_surf->pending_dmabuf_feedback) < 0) { zwp_linux_dmabuf_feedback_v1_destroy(dri2_surf->wl_dmabuf_feedback); @@ -747,28 +786,28 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, dri2_surf->wl_win->resize_callback = resize_callback; if (!dri2_create_drawable(dri2_dpy, config, dri2_surf, dri2_surf)) - goto cleanup_dmabuf_feedback; + goto cleanup_dmabuf_feedback; dri2_surf->base.SwapInterval = dri2_dpy->default_swap_interval; return &dri2_surf->base; - cleanup_dmabuf_feedback: +cleanup_dmabuf_feedback: if (dri2_surf->wl_dmabuf_feedback) { zwp_linux_dmabuf_feedback_v1_destroy(dri2_surf->wl_dmabuf_feedback); dmabuf_feedback_fini(&dri2_surf->dmabuf_feedback); dmabuf_feedback_fini(&dri2_surf->pending_dmabuf_feedback); } - cleanup_surf_wrapper: +cleanup_surf_wrapper: wl_proxy_wrapper_destroy(dri2_surf->wl_surface_wrapper); - cleanup_dpy_wrapper: +cleanup_dpy_wrapper: wl_proxy_wrapper_destroy(dri2_surf->wl_dpy_wrapper); - cleanup_drm: +cleanup_drm: if (dri2_surf->wl_drm_wrapper) wl_proxy_wrapper_destroy(dri2_surf->wl_drm_wrapper); - cleanup_queue: +cleanup_queue: wl_event_queue_destroy(dri2_surf->wl_queue); - cleanup_surf: +cleanup_surf: free(dri2_surf); return NULL; @@ -785,7 +824,7 @@ dri2_wl_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, * EGL_BAD_PARAMETER. */ _eglError(EGL_BAD_PARAMETER, "cannot create EGL pixmap surfaces on " - "Wayland"); + "Wayland"); return NULL; } @@ -888,7 +927,8 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf) static void create_dri_image_from_dmabuf_feedback(struct dri2_egl_surface *dri2_surf, - unsigned int dri_image_format, uint32_t use_flags) + unsigned int dri_image_format, + uint32_t use_flags) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); @@ -914,8 +954,8 @@ create_dri_image_from_dmabuf_feedback(struct dri2_egl_surface *dri2_surf, * tranches whose target device differs from the main device, as compositors * do not expose (in dma-buf feedback tranches) formats/modifiers that are * incompatible with the main device. */ - util_dynarray_foreach(&dri2_surf->dmabuf_feedback.tranches, - struct dmabuf_feedback_tranche, tranche) { + util_dynarray_foreach (&dri2_surf->dmabuf_feedback.tranches, + struct dmabuf_feedback_tranche, tranche) { /* Ignore tranches that do not contain dri2_surf->format */ if (!BITSET_TEST(tranche->formats.formats_bitmap, visual_idx)) continue; @@ -934,13 +974,11 @@ create_dri_image_from_dmabuf_feedback(struct dri2_egl_surface *dri2_surf, if (tranche->flags & ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT) flags |= __DRI_IMAGE_USE_SCANOUT; - dri2_surf->back->dri_image = - loader_dri_create_image(dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, - dri2_surf->base.Width, - dri2_surf->base.Height, - dri_image_format, - (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : flags, - modifiers, num_modifiers, NULL); + dri2_surf->back->dri_image = loader_dri_create_image( + dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, + dri2_surf->base.Width, dri2_surf->base.Height, dri_image_format, + (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : flags, + modifiers, num_modifiers, NULL); if (dri2_surf->back->dri_image) return; @@ -972,13 +1010,11 @@ create_dri_image(struct dri2_egl_surface *dri2_surf, /* If our DRIImage implementation does not support createImageWithModifiers, * then fall back to the old createImage, and hope it allocates an image * which is acceptable to the winsys. */ - dri2_surf->back->dri_image = - loader_dri_create_image(dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, - dri2_surf->base.Width, - dri2_surf->base.Height, - dri_image_format, - (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : use_flags, - modifiers, num_modifiers, NULL); + dri2_surf->back->dri_image = loader_dri_create_image( + dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, dri2_surf->base.Width, + dri2_surf->base.Height, dri_image_format, + (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) ? 0 : use_flags, + modifiers, num_modifiers, NULL); } static int @@ -998,15 +1034,17 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) /* Substitute dri image format if server does not support original format */ if (!BITSET_TEST(dri2_dpy->formats.formats_bitmap, visual_idx)) - linear_dri_image_format = dri2_wl_visuals[visual_idx].alt_dri_image_format; + linear_dri_image_format = + dri2_wl_visuals[visual_idx].alt_dri_image_format; /* These asserts hold, as long as dri2_wl_visuals[] is self-consistent and * the PRIME substitution logic in dri2_wl_add_configs_for_visuals() is free * of bugs. */ assert(linear_dri_image_format != __DRI_IMAGE_FORMAT_NONE); - assert(BITSET_TEST(dri2_dpy->formats.formats_bitmap, - dri2_wl_visual_idx_from_dri_image_format(linear_dri_image_format))); + assert(BITSET_TEST( + dri2_dpy->formats.formats_bitmap, + dri2_wl_visual_idx_from_dri_image_format(linear_dri_image_format))); /* There might be a buffer release already queued that wasn't processed */ wl_display_dispatch_queue_pending(dri2_dpy->wl_dpy, dri2_surf->wl_queue); @@ -1019,8 +1057,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) if (dri2_surf->color_buffers[i].locked) continue; - if (!dri2_surf->back || - !dri2_surf->back->dri_image || + if (!dri2_surf->back || !dri2_surf->back->dri_image || (dri2_surf->color_buffers[i].age > 0 && dri2_surf->color_buffers[i].age < dri2_surf->back->age)) dri2_surf->back = &dri2_surf->color_buffers[i]; @@ -1035,9 +1072,8 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) * event. So, we spam the server with roundtrips as they always cause a * client flush. */ - if (wl_display_roundtrip_queue(dri2_dpy->wl_dpy, - dri2_surf->wl_queue) < 0) - return -1; + if (wl_display_roundtrip_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) < 0) + return -1; } if (dri2_surf->back == NULL) @@ -1058,14 +1094,11 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) __DRIimage *linear_copy_display_gpu_image = NULL; if (dri2_dpy->dri_screen_display_gpu) { - linear_copy_display_gpu_image = - loader_dri_create_image(dri2_dpy->dri_screen_display_gpu, - dri2_dpy->image, - dri2_surf->base.Width, - dri2_surf->base.Height, - linear_dri_image_format, - use_flags | __DRI_IMAGE_USE_LINEAR, - &linear_mod, 1, NULL); + linear_copy_display_gpu_image = loader_dri_create_image( + dri2_dpy->dri_screen_display_gpu, dri2_dpy->image, + dri2_surf->base.Width, dri2_surf->base.Height, + linear_dri_image_format, use_flags | __DRI_IMAGE_USE_LINEAR, + &linear_mod, 1, NULL); if (linear_copy_display_gpu_image) { int i, ret; @@ -1075,12 +1108,13 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) int offsets[4]; if (!dri2_dpy->image->queryImage(linear_copy_display_gpu_image, - __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes)) + __DRI_IMAGE_ATTRIB_NUM_PLANES, + &num_planes)) num_planes = 1; for (i = 0; i < num_planes; i++) { __DRIimage *image = dri2_dpy->image->fromPlanar( - linear_copy_display_gpu_image, i, NULL); + linear_copy_display_gpu_image, i, NULL); if (!image) { assert(i == 0); @@ -1090,10 +1124,10 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) buffer_fds[i] = -1; ret = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD, &buffer_fds[i]); - ret &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, - &strides[i]); - ret &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_OFFSET, - &offsets[i]); + ret &= dri2_dpy->image->queryImage( + image, __DRI_IMAGE_ATTRIB_STRIDE, &strides[i]); + ret &= dri2_dpy->image->queryImage( + image, __DRI_IMAGE_ATTRIB_OFFSET, &offsets[i]); if (image != linear_copy_display_gpu_image) dri2_dpy->image->destroyImage(image); @@ -1111,16 +1145,12 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) /* The linear buffer was created in the display GPU's vram, so we * need to make it visible to render GPU */ - dri2_surf->back->linear_copy = - dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen_render_gpu, - dri2_surf->base.Width, - dri2_surf->base.Height, - loader_image_format_to_fourcc( - linear_dri_image_format), - &buffer_fds[0], num_planes, - &strides[0], - &offsets[0], - dri2_surf->back); + dri2_surf->back->linear_copy = dri2_dpy->image->createImageFromFds( + dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width, + dri2_surf->base.Height, + loader_image_format_to_fourcc(linear_dri_image_format), + &buffer_fds[0], num_planes, &strides[0], &offsets[0], + dri2_surf->back); for (i = 0; i < num_planes; ++i) { if (buffer_fds[i] != -1) close(buffer_fds[i]); @@ -1130,13 +1160,11 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) } if (!dri2_surf->back->linear_copy) { - dri2_surf->back->linear_copy = - loader_dri_create_image(dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, - dri2_surf->base.Width, - dri2_surf->base.Height, - linear_dri_image_format, - use_flags | __DRI_IMAGE_USE_LINEAR, - &linear_mod, 1, NULL); + dri2_surf->back->linear_copy = loader_dri_create_image( + dri2_dpy->dri_screen_render_gpu, dri2_dpy->image, + dri2_surf->base.Width, dri2_surf->base.Height, + linear_dri_image_format, use_flags | __DRI_IMAGE_USE_LINEAR, + &linear_mod, 1, NULL); } if (dri2_surf->back->linear_copy == NULL) @@ -1145,7 +1173,8 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) if (dri2_surf->back->dri_image == NULL) { if (dri2_surf->wl_dmabuf_feedback) - create_dri_image_from_dmabuf_feedback(dri2_surf, dri_image_format, use_flags); + create_dri_image_from_dmabuf_feedback(dri2_surf, dri_image_format, + use_flags); if (dri2_surf->back->dri_image == NULL) create_dri_image(dri2_surf, dri_image_format, use_flags); dri2_surf->back->age = 0; @@ -1159,7 +1188,6 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) return 0; } - static void back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer) { @@ -1196,7 +1224,7 @@ update_buffers(struct dri2_egl_surface *dri2_surf) (dri2_surf->base.Width != dri2_surf->wl_win->width || dri2_surf->base.Height != dri2_surf->wl_win->height)) { - dri2_surf->base.Width = dri2_surf->wl_win->width; + dri2_surf->base.Width = dri2_surf->wl_win->width; dri2_surf->base.Height = dri2_surf->wl_win->height; dri2_surf->dx = dri2_surf->wl_win->dx; dri2_surf->dy = dri2_surf->wl_win->dy; @@ -1225,7 +1253,8 @@ update_buffers(struct dri2_egl_surface *dri2_surf) wl_buffer_destroy(dri2_surf->color_buffers[i].wl_buffer); dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image); if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) - dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy); + dri2_dpy->image->destroyImage( + dri2_surf->color_buffers[i].linear_copy); dri2_surf->color_buffers[i].wl_buffer = NULL; dri2_surf->color_buffers[i].dri_image = NULL; dri2_surf->color_buffers[i].linear_copy = NULL; @@ -1246,10 +1275,9 @@ update_buffers_if_needed(struct dri2_egl_surface *dri2_surf) } static __DRIbuffer * -dri2_wl_get_buffers_with_format(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2_wl_get_buffers_with_format(__DRIdrawable *driDrawable, int *width, + int *height, unsigned int *attachments, + int count, int *out_count, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int i, j; @@ -1288,10 +1316,9 @@ dri2_wl_get_buffers_with_format(__DRIdrawable * driDrawable, } static __DRIbuffer * -dri2_wl_get_buffers(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2_wl_get_buffers(__DRIdrawable *driDrawable, int *width, int *height, + unsigned int *attachments, int count, int *out_count, + void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; unsigned int *attachments_with_format; @@ -1308,15 +1335,13 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable, } for (int i = 0; i < count; ++i) { - attachments_with_format[2*i] = attachments[i]; - attachments_with_format[2*i + 1] = dri2_wl_visuals[visual_idx].bpp; + attachments_with_format[2 * i] = attachments[i]; + attachments_with_format[2 * i + 1] = dri2_wl_visuals[visual_idx].bpp; } - buffer = - dri2_wl_get_buffers_with_format(driDrawable, - width, height, - attachments_with_format, count, - out_count, loaderPrivate); + buffer = dri2_wl_get_buffers_with_format(driDrawable, width, height, + attachments_with_format, count, + out_count, loaderPrivate); free(attachments_with_format); @@ -1324,11 +1349,8 @@ dri2_wl_get_buffers(__DRIdrawable * driDrawable, } static int -image_get_buffers(__DRIdrawable *driDrawable, - unsigned int format, - uint32_t *stamp, - void *loaderPrivate, - uint32_t buffer_mask, +image_get_buffers(__DRIdrawable *driDrawable, unsigned int format, + uint32_t *stamp, void *loaderPrivate, uint32_t buffer_mask, struct __DRIimageList *buffers) { struct dri2_egl_surface *dri2_surf = loaderPrivate; @@ -1343,10 +1365,10 @@ image_get_buffers(__DRIdrawable *driDrawable, } static void -dri2_wl_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) +dri2_wl_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) { - (void) driDrawable; - (void) loaderPrivate; + (void)driDrawable; + (void)loaderPrivate; } static unsigned @@ -1363,25 +1385,24 @@ dri2_wl_get_capability(void *loaderPrivate, enum dri_loader_cap cap) } static const __DRIdri2LoaderExtension dri2_loader_extension = { - .base = { __DRI_DRI2_LOADER, 4 }, + .base = {__DRI_DRI2_LOADER, 4}, - .getBuffers = dri2_wl_get_buffers, - .flushFrontBuffer = dri2_wl_flush_front_buffer, + .getBuffers = dri2_wl_get_buffers, + .flushFrontBuffer = dri2_wl_flush_front_buffer, .getBuffersWithFormat = dri2_wl_get_buffers_with_format, - .getCapability = dri2_wl_get_capability, + .getCapability = dri2_wl_get_capability, }; static const __DRIimageLoaderExtension image_loader_extension = { - .base = { __DRI_IMAGE_LOADER, 2 }, + .base = {__DRI_IMAGE_LOADER, 2}, - .getBuffers = image_get_buffers, - .flushFrontBuffer = dri2_wl_flush_front_buffer, - .getCapability = dri2_wl_get_capability, + .getBuffers = image_get_buffers, + .flushFrontBuffer = dri2_wl_flush_front_buffer, + .getCapability = dri2_wl_get_capability, }; static void -wayland_throttle_callback(void *data, - struct wl_callback *callback, +wayland_throttle_callback(void *data, struct wl_callback *callback, uint32_t time) { struct dri2_egl_surface *dri2_surf = data; @@ -1391,19 +1412,17 @@ wayland_throttle_callback(void *data, } static const struct wl_callback_listener throttle_listener = { - .done = wayland_throttle_callback -}; + .done = wayland_throttle_callback}; static EGLBoolean -get_fourcc(struct dri2_egl_display *dri2_dpy, - __DRIimage *image, int *fourcc) +get_fourcc(struct dri2_egl_display *dri2_dpy, __DRIimage *image, int *fourcc) { EGLBoolean query; int dri_format; int visual_idx; - query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FOURCC, - fourcc); + query = + dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FOURCC, fourcc); if (query) return true; @@ -1422,8 +1441,7 @@ get_fourcc(struct dri2_egl_display *dri2_dpy, static struct wl_buffer * create_wl_buffer(struct dri2_egl_display *dri2_dpy, - struct dri2_egl_surface *dri2_surf, - __DRIimage *image) + struct dri2_egl_surface *dri2_surf, __DRIimage *image) { struct wl_buffer *ret = NULL; EGLBoolean query; @@ -1431,8 +1449,8 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, uint64_t modifier = DRM_FORMAT_MOD_INVALID; query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_WIDTH, &width); - query &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, - &height); + query &= + dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, &height); query &= get_fourcc(dri2_dpy, image, &fourcc); if (!query) return NULL; @@ -1445,12 +1463,10 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, if (dri2_dpy->image->base.version >= 15) { int mod_hi, mod_lo; - query = dri2_dpy->image->queryImage(image, - __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, - &mod_hi); - query &= dri2_dpy->image->queryImage(image, - __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, - &mod_lo); + query = dri2_dpy->image->queryImage( + image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &mod_hi); + query &= dri2_dpy->image->queryImage( + image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &mod_lo); if (query) { modifier = combine_u32_into_u64(mod_hi, mod_lo); } @@ -1462,7 +1478,8 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, assert(visual_idx != -1); uint64_t *mod; - u_vector_foreach(mod, &dri2_dpy->formats.modifiers[visual_idx]) { + u_vector_foreach(mod, &dri2_dpy->formats.modifiers[visual_idx]) + { if (*mod == DRM_FORMAT_MOD_INVALID) { mod_invalid_supported = true; } @@ -1489,7 +1506,7 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, * and the wl_buffer inherits it race-free. */ params = zwp_linux_dmabuf_v1_create_params(dri2_dpy->wl_dmabuf); if (dri2_surf) - wl_proxy_set_queue((struct wl_proxy *) params, dri2_surf->wl_queue); + wl_proxy_set_queue((struct wl_proxy *)params, dri2_surf->wl_queue); for (i = 0; i < num_planes; i++) { __DRIimage *p_image; @@ -1502,15 +1519,12 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, p_image = image; } - query = dri2_dpy->image->queryImage(p_image, - __DRI_IMAGE_ATTRIB_FD, - &fd); - query &= dri2_dpy->image->queryImage(p_image, - __DRI_IMAGE_ATTRIB_STRIDE, - &stride); - query &= dri2_dpy->image->queryImage(p_image, - __DRI_IMAGE_ATTRIB_OFFSET, - &offset); + query = + dri2_dpy->image->queryImage(p_image, __DRI_IMAGE_ATTRIB_FD, &fd); + query &= dri2_dpy->image->queryImage( + p_image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); + query &= dri2_dpy->image->queryImage( + p_image, __DRI_IMAGE_ATTRIB_OFFSET, &offset); if (image != p_image) dri2_dpy->image->destroyImage(p_image); @@ -1538,7 +1552,8 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, return NULL; query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD, &fd); - query &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); + query &= + dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride); if (!query) { if (fd >= 0) close(fd); @@ -1554,19 +1569,17 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy, } static EGLBoolean -try_damage_buffer(struct dri2_egl_surface *dri2_surf, - const EGLint *rects, +try_damage_buffer(struct dri2_egl_surface *dri2_surf, const EGLint *rects, EGLint n_rects) { - if (wl_proxy_get_version((struct wl_proxy *) dri2_surf->wl_surface_wrapper) - < WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) + if (wl_proxy_get_version((struct wl_proxy *)dri2_surf->wl_surface_wrapper) < + WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) return EGL_FALSE; for (int i = 0; i < n_rects; i++) { const int *rect = &rects[i * 4]; - wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper, - rect[0], + wl_surface_damage_buffer(dri2_surf->wl_surface_wrapper, rect[0], dri2_surf->base.Height - rect[1] - rect[3], rect[2], rect[3]); } @@ -1577,10 +1590,8 @@ try_damage_buffer(struct dri2_egl_surface *dri2_surf, * Called via eglSwapBuffers(), drv->SwapBuffers(). */ static EGLBoolean -dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, - _EGLSurface *draw, - const EGLint *rects, - EGLint n_rects) +dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw, + const EGLint *rects, EGLint n_rects) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); @@ -1602,8 +1613,8 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, dri2_dpy->flush->invalidate(dri2_surf->dri_drawable); while (dri2_surf->throttle_callback != NULL) - if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, - dri2_surf->wl_queue) == -1) + if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) == + -1) return -1; for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) @@ -1618,8 +1629,8 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, if (draw->SwapInterval > 0) { dri2_surf->throttle_callback = wl_surface_frame(dri2_surf->wl_surface_wrapper); - wl_callback_add_listener(dri2_surf->throttle_callback, - &throttle_listener, dri2_surf); + wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener, + dri2_surf); } dri2_surf->back->age = 1; @@ -1639,15 +1650,15 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, dri2_surf->current->wl_release = false; - wl_buffer_add_listener(dri2_surf->current->wl_buffer, - &wl_buffer_listener, dri2_surf); + wl_buffer_add_listener(dri2_surf->current->wl_buffer, &wl_buffer_listener, + dri2_surf); } wl_surface_attach(dri2_surf->wl_surface_wrapper, - dri2_surf->current->wl_buffer, - dri2_surf->dx, dri2_surf->dy); + dri2_surf->current->wl_buffer, dri2_surf->dx, + dri2_surf->dy); - dri2_surf->wl_win->attached_width = dri2_surf->base.Width; + dri2_surf->wl_win->attached_width = dri2_surf->base.Width; dri2_surf->wl_win->attached_height = dri2_surf->base.Height; /* reset resize growing parameters */ dri2_surf->dx = 0; @@ -1657,19 +1668,17 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, * ignore the damage region and post maximum damage, due to * https://bugs.freedesktop.org/78190 */ if (!n_rects || !try_damage_buffer(dri2_surf, rects, n_rects)) - wl_surface_damage(dri2_surf->wl_surface_wrapper, - 0, 0, INT32_MAX, INT32_MAX); + wl_surface_damage(dri2_surf->wl_surface_wrapper, 0, 0, INT32_MAX, + INT32_MAX); if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) { _EGLContext *ctx = _eglGetCurrentContext(); struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); - dri2_dpy->image->blitImage(dri2_ctx->dri_context, - dri2_surf->current->linear_copy, - dri2_surf->current->dri_image, - 0, 0, dri2_surf->base.Width, - dri2_surf->base.Height, - 0, 0, dri2_surf->base.Width, - dri2_surf->base.Height, 0); + dri2_dpy->image->blitImage( + dri2_ctx->dri_context, dri2_surf->current->linear_copy, + dri2_surf->current->dri_image, 0, 0, dri2_surf->base.Width, + dri2_surf->base.Height, 0, 0, dri2_surf->base.Width, + dri2_surf->base.Height, 0); } wl_surface_commit(dri2_surf->wl_surface_wrapper); @@ -1680,8 +1689,8 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp, * buffer */ if (dri2_surf->throttle_callback == NULL) { dri2_surf->throttle_callback = wl_display_sync(dri2_surf->wl_dpy_wrapper); - wl_callback_add_listener(dri2_surf->throttle_callback, - &throttle_listener, dri2_surf); + wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener, + dri2_surf); } wl_display_flush(dri2_dpy->wl_dpy); @@ -1735,7 +1744,7 @@ dri2_wl_create_wayland_buffer_from_image(_EGLDisplay *disp, _EGLImage *img) * buffer can get is a buffer release, which doesn't happen with an explicit * attach. */ if (buffer) - wl_proxy_set_queue((struct wl_proxy *) buffer, NULL); + wl_proxy_set_queue((struct wl_proxy *)buffer, NULL); return buffer; @@ -1879,28 +1888,31 @@ static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = { static void wl_drm_bind(struct dri2_egl_display *dri2_dpy) { - dri2_dpy->wl_drm = wl_registry_bind(dri2_dpy->wl_registry, dri2_dpy->wl_drm_name, - &wl_drm_interface, dri2_dpy->wl_drm_version); + dri2_dpy->wl_drm = + wl_registry_bind(dri2_dpy->wl_registry, dri2_dpy->wl_drm_name, + &wl_drm_interface, dri2_dpy->wl_drm_version); wl_drm_add_listener(dri2_dpy->wl_drm, &drm_listener, dri2_dpy); } static void -default_dmabuf_feedback_format_table(void *data, - struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, - int32_t fd, uint32_t size) +default_dmabuf_feedback_format_table( + void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + int32_t fd, uint32_t size) { struct dri2_egl_display *dri2_dpy = data; dri2_dpy->format_table.size = size; - dri2_dpy->format_table.data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + dri2_dpy->format_table.data = + mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); close(fd); } static void -default_dmabuf_feedback_main_device(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - struct wl_array *device) +default_dmabuf_feedback_main_device( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + struct wl_array *device) { struct dri2_egl_display *dri2_dpy = data; char *node; @@ -1924,25 +1936,25 @@ default_dmabuf_feedback_main_device(void *data, } static void -default_dmabuf_feedback_tranche_target_device(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - struct wl_array *device) +default_dmabuf_feedback_tranche_target_device( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + struct wl_array *device) { /* ignore this event */ } static void -default_dmabuf_feedback_tranche_flags(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - uint32_t flags) +default_dmabuf_feedback_tranche_flags( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + uint32_t flags) { /* ignore this event */ } static void -default_dmabuf_feedback_tranche_formats(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, - struct wl_array *indices) +default_dmabuf_feedback_tranche_formats( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback, + struct wl_array *indices) { struct dri2_egl_display *dri2_dpy = data; uint64_t *modifier_ptr, modifier; @@ -1957,13 +1969,14 @@ default_dmabuf_feedback_tranche_formats(void *data, return; } if (dri2_dpy->format_table.data == NULL) { - _eglLog(_EGL_WARNING, "wayland-egl: compositor didn't advertise a format " - "table, so we won't be able to use this batch of dma-buf " - "feedback events."); + _eglLog(_EGL_WARNING, + "wayland-egl: compositor didn't advertise a format " + "table, so we won't be able to use this batch of dma-buf " + "feedback events."); return; } - wl_array_for_each(index, indices) { + wl_array_for_each (index, indices) { format = dri2_dpy->format_table.data[*index].format; modifier = dri2_dpy->format_table.data[*index].modifier; @@ -1980,28 +1993,28 @@ default_dmabuf_feedback_tranche_formats(void *data, } static void -default_dmabuf_feedback_tranche_done(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) +default_dmabuf_feedback_tranche_done( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) { /* ignore this event */ } static void -default_dmabuf_feedback_done(void *data, - struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) +default_dmabuf_feedback_done( + void *data, struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback) { /* ignore this event */ } static const struct zwp_linux_dmabuf_feedback_v1_listener -dmabuf_feedback_listener = { - .format_table = default_dmabuf_feedback_format_table, - .main_device = default_dmabuf_feedback_main_device, - .tranche_target_device = default_dmabuf_feedback_tranche_target_device, - .tranche_flags = default_dmabuf_feedback_tranche_flags, - .tranche_formats = default_dmabuf_feedback_tranche_formats, - .tranche_done = default_dmabuf_feedback_tranche_done, - .done = default_dmabuf_feedback_done, + dmabuf_feedback_listener = { + .format_table = default_dmabuf_feedback_format_table, + .main_device = default_dmabuf_feedback_main_device, + .tranche_target_device = default_dmabuf_feedback_tranche_target_device, + .tranche_flags = default_dmabuf_feedback_tranche_flags, + .tranche_formats = default_dmabuf_feedback_tranche_formats, + .tranche_done = default_dmabuf_feedback_tranche_done, + .done = default_dmabuf_feedback_done, }; static void @@ -2014,10 +2027,11 @@ registry_handle_global_drm(void *data, struct wl_registry *registry, if (strcmp(interface, wl_drm_interface.name) == 0) { dri2_dpy->wl_drm_version = MIN2(version, 2); dri2_dpy->wl_drm_name = name; - } else if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 && version >= 3) { - dri2_dpy->wl_dmabuf = - wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface, - MIN2(version, ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION)); + } else if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 && + version >= 3) { + dri2_dpy->wl_dmabuf = wl_registry_bind( + registry, name, &zwp_linux_dmabuf_v1_interface, + MIN2(version, ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION)); zwp_linux_dmabuf_v1_add_listener(dri2_dpy->wl_dmabuf, &dmabuf_listener, dri2_dpy); } @@ -2078,7 +2092,7 @@ static EGLBoolean dri2_wl_add_configs_for_visuals(_EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); - unsigned int format_count[ARRAY_SIZE(dri2_wl_visuals)] = { 0 }; + unsigned int format_count[ARRAY_SIZE(dri2_wl_visuals)] = {0}; unsigned int count = 0; bool assigned; @@ -2091,8 +2105,9 @@ dri2_wl_add_configs_for_visuals(_EGLDisplay *disp) if (!BITSET_TEST(dri2_dpy->formats.formats_bitmap, j)) continue; - dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], - count + 1, EGL_WINDOW_BIT, NULL, dri2_wl_visuals[j].rgba_shifts, dri2_wl_visuals[j].rgba_sizes); + dri2_conf = dri2_add_config( + disp, dri2_dpy->driver_configs[i], count + 1, EGL_WINDOW_BIT, NULL, + dri2_wl_visuals[j].rgba_shifts, dri2_wl_visuals[j].rgba_sizes); if (dri2_conf) { if (dri2_conf->base.ConfigID == count + 1) count++; @@ -2107,8 +2122,7 @@ dri2_wl_add_configs_for_visuals(_EGLDisplay *disp) /* No match for config. Try if we can blitImage convert to a visual */ c = dri2_wl_visual_idx_from_config(dri2_dpy, - dri2_dpy->driver_configs[i], - false); + dri2_dpy->driver_configs[i], false); if (c == -1) continue; @@ -2124,17 +2138,18 @@ dri2_wl_add_configs_for_visuals(_EGLDisplay *disp) * by our client gpu during PRIME blitImage conversion to a linear * wl_buffer, so add visual c as supported by the client renderer. */ - dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], - count + 1, EGL_WINDOW_BIT, NULL, - dri2_wl_visuals[c].rgba_shifts, - dri2_wl_visuals[c].rgba_sizes); + dri2_conf = dri2_add_config( + disp, dri2_dpy->driver_configs[i], count + 1, EGL_WINDOW_BIT, NULL, + dri2_wl_visuals[c].rgba_shifts, dri2_wl_visuals[c].rgba_sizes); if (dri2_conf) { if (dri2_conf->base.ConfigID == count + 1) count++; format_count[c]++; if (format_count[c] == 1) - _eglLog(_EGL_DEBUG, "Client format %s to server format %s via " - "PRIME blitImage.", dri2_wl_visuals[c].format_name, + _eglLog(_EGL_DEBUG, + "Client format %s to server format %s via " + "PRIME blitImage.", + dri2_wl_visuals[c].format_name, dri2_wl_visuals[s].format_name); } } @@ -2162,7 +2177,7 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) dri2_dpy->fd_render_gpu = -1; dri2_dpy->fd_display_gpu = -1; - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; if (dri2_wl_formats_init(&dri2_dpy->formats) < 0) goto cleanup; @@ -2182,27 +2197,28 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) if (dri2_dpy->wl_dpy_wrapper == NULL) goto cleanup; - wl_proxy_set_queue((struct wl_proxy *) dri2_dpy->wl_dpy_wrapper, + wl_proxy_set_queue((struct wl_proxy *)dri2_dpy->wl_dpy_wrapper, dri2_dpy->wl_queue); if (dri2_dpy->own_device) wl_display_dispatch_pending(dri2_dpy->wl_dpy); dri2_dpy->wl_registry = wl_display_get_registry(dri2_dpy->wl_dpy_wrapper); - wl_registry_add_listener(dri2_dpy->wl_registry, - ®istry_listener_drm, dri2_dpy); + wl_registry_add_listener(dri2_dpy->wl_registry, ®istry_listener_drm, + dri2_dpy); if (roundtrip(dri2_dpy) < 0) goto cleanup; /* Get default dma-buf feedback */ - if (dri2_dpy->wl_dmabuf && zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >= - ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) { + if (dri2_dpy->wl_dmabuf && + zwp_linux_dmabuf_v1_get_version(dri2_dpy->wl_dmabuf) >= + ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION) { dmabuf_feedback_format_table_init(&dri2_dpy->format_table); dri2_dpy->wl_dmabuf_feedback = zwp_linux_dmabuf_v1_get_default_feedback(dri2_dpy->wl_dmabuf); - zwp_linux_dmabuf_feedback_v1_add_listener(dri2_dpy->wl_dmabuf_feedback, - &dmabuf_feedback_listener, dri2_dpy); + zwp_linux_dmabuf_feedback_v1_add_listener( + dri2_dpy->wl_dmabuf_feedback, &dmabuf_feedback_listener, dri2_dpy); } if (roundtrip(dri2_dpy) < 0) @@ -2233,7 +2249,8 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) goto cleanup; } - loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, &dri2_dpy->fd_display_gpu); + loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, + &dri2_dpy->fd_display_gpu); dev = _eglAddDevice(dri2_dpy->fd_render_gpu, false); if (!dev) { @@ -2245,7 +2262,8 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) if (dri2_dpy->fd_render_gpu != dri2_dpy->fd_display_gpu) { free(dri2_dpy->device_name); - dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); + dri2_dpy->device_name = + loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu); if (!dri2_dpy->device_name) { _eglError(EGL_BAD_ALLOC, "wayland-egl: failed to get device name " "for requested GPU"); @@ -2257,7 +2275,8 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) * will return a render-node when the requested gpu is different * to the server, but also if the client asks for the same gpu than * the server by requesting its pci-id */ - dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER; + dri2_dpy->is_render_node = + drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER; dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu); if (dri2_dpy->driver_name == NULL) { @@ -2322,8 +2341,8 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) dri2_set_WL_bind_wayland_display(disp); /* When cannot convert EGLImage to wl_buffer when on a different gpu, * because the buffer of the EGLImage has likely a tiling mode the server - * gpu won't support. These is no way to check for now. Thus do not support the - * extension */ + * gpu won't support. These is no way to check for now. Thus do not support + * the extension */ if (dri2_dpy->fd_render_gpu == dri2_dpy->fd_display_gpu) disp->Extensions.WL_create_wayland_buffer_from_image = EGL_TRUE; @@ -2340,7 +2359,7 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp) return EGL_TRUE; - cleanup: +cleanup: dri2_display_destroy(disp); return EGL_FALSE; } @@ -2356,9 +2375,8 @@ dri2_wl_swrast_get_stride_for_format(int format, int w) } static EGLBoolean -dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface *dri2_surf, - int format, int w, int h, - void **data, int *size, +dri2_wl_swrast_allocate_buffer(struct dri2_egl_surface *dri2_surf, int format, + int w, int h, void **data, int *size, struct wl_buffer **buffer) { struct dri2_egl_display *dri2_dpy = @@ -2411,7 +2429,7 @@ swrast_update_buffers(struct dri2_egl_surface *dri2_surf) if (!zink) dri2_wl_release_buffers(dri2_surf); - dri2_surf->base.Width = dri2_surf->wl_win->width; + dri2_surf->base.Width = dri2_surf->wl_win->width; dri2_surf->base.Height = dri2_surf->wl_win->height; dri2_surf->dx = dri2_surf->wl_win->dx; dri2_surf->dy = dri2_surf->wl_win->dy; @@ -2439,22 +2457,19 @@ swrast_update_buffers(struct dri2_egl_surface *dri2_surf) if (!dri2_surf->back) { for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { if (!dri2_surf->color_buffers[i].locked) { - dri2_surf->back = &dri2_surf->color_buffers[i]; - if (zink) - continue; - if (!dri2_wl_swrast_allocate_buffer(dri2_surf, - dri2_surf->format, - dri2_surf->base.Width, - dri2_surf->base.Height, - &dri2_surf->back->data, - &dri2_surf->back->data_size, - &dri2_surf->back->wl_buffer)) { - _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer"); - return -1; - } - wl_buffer_add_listener(dri2_surf->back->wl_buffer, - &wl_buffer_listener, dri2_surf); - break; + dri2_surf->back = &dri2_surf->color_buffers[i]; + if (zink) + continue; + if (!dri2_wl_swrast_allocate_buffer( + dri2_surf, dri2_surf->format, dri2_surf->base.Width, + dri2_surf->base.Height, &dri2_surf->back->data, + &dri2_surf->back->data_size, &dri2_surf->back->wl_buffer)) { + _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer"); + return -1; + } + wl_buffer_add_listener(dri2_surf->back->wl_buffer, + &wl_buffer_listener, dri2_surf); + break; } } } @@ -2489,7 +2504,7 @@ swrast_update_buffers(struct dri2_egl_surface *dri2_surf) return 0; } -static void* +static void * dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface *dri2_surf) { /* if there has been a resize: */ @@ -2499,7 +2514,7 @@ dri2_wl_swrast_get_frontbuffer_data(struct dri2_egl_surface *dri2_surf) return dri2_surf->current->data; } -static void* +static void * dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface *dri2_surf) { assert(dri2_surf->back); @@ -2509,35 +2524,35 @@ dri2_wl_swrast_get_backbuffer_data(struct dri2_egl_surface *dri2_surf) static void dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface *dri2_surf) { - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); while (dri2_surf->throttle_callback != NULL) - if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, - dri2_surf->wl_queue) == -1) + if (wl_display_dispatch_queue(dri2_dpy->wl_dpy, dri2_surf->wl_queue) == + -1) return; if (dri2_surf->base.SwapInterval > 0) { dri2_surf->throttle_callback = wl_surface_frame(dri2_surf->wl_surface_wrapper); - wl_callback_add_listener(dri2_surf->throttle_callback, - &throttle_listener, dri2_surf); + wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener, + dri2_surf); } dri2_surf->current = dri2_surf->back; dri2_surf->back = NULL; wl_surface_attach(dri2_surf->wl_surface_wrapper, - dri2_surf->current->wl_buffer, - dri2_surf->dx, dri2_surf->dy); + dri2_surf->current->wl_buffer, dri2_surf->dx, + dri2_surf->dy); - dri2_surf->wl_win->attached_width = dri2_surf->base.Width; + dri2_surf->wl_win->attached_width = dri2_surf->base.Width; dri2_surf->wl_win->attached_height = dri2_surf->base.Height; /* reset resize growing parameters */ dri2_surf->dx = 0; dri2_surf->dy = 0; - wl_surface_damage(dri2_surf->wl_surface_wrapper, - 0, 0, INT32_MAX, INT32_MAX); + wl_surface_damage(dri2_surf->wl_surface_wrapper, 0, 0, INT32_MAX, INT32_MAX); wl_surface_commit(dri2_surf->wl_surface_wrapper); /* If we're not waiting for a frame callback then we'll at least throttle @@ -2546,21 +2561,20 @@ dri2_wl_swrast_commit_backbuffer(struct dri2_egl_surface *dri2_surf) * buffer */ if (dri2_surf->throttle_callback == NULL) { dri2_surf->throttle_callback = wl_display_sync(dri2_surf->wl_dpy_wrapper); - wl_callback_add_listener(dri2_surf->throttle_callback, - &throttle_listener, dri2_surf); + wl_callback_add_listener(dri2_surf->throttle_callback, &throttle_listener, + dri2_surf); } wl_display_flush(dri2_dpy->wl_dpy); } static void -dri2_wl_swrast_get_drawable_info(__DRIdrawable * draw, - int *x, int *y, int *w, int *h, - void *loaderPrivate) +dri2_wl_swrast_get_drawable_info(__DRIdrawable *draw, int *x, int *y, int *w, + int *h, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; - (void) swrast_update_buffers(dri2_surf); + (void)swrast_update_buffers(dri2_surf); *x = 0; *y = 0; *w = dri2_surf->base.Width; @@ -2568,14 +2582,14 @@ dri2_wl_swrast_get_drawable_info(__DRIdrawable * draw, } static void -dri2_wl_swrast_get_image(__DRIdrawable * read, - int x, int y, int w, int h, +dri2_wl_swrast_get_image(__DRIdrawable *read, int x, int y, int w, int h, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int copy_width = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, w); int x_offset = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, x); - int src_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, dri2_surf->base.Width); + int src_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, + dri2_surf->base.Width); int dst_stride = copy_width; char *src, *dst; @@ -2592,12 +2606,12 @@ dri2_wl_swrast_get_image(__DRIdrawable * read, src += y * src_stride; dst = data; - if (copy_width > src_stride-x_offset) - copy_width = src_stride-x_offset; - if (h > dri2_surf->base.Height-y) - h = dri2_surf->base.Height-y; + if (copy_width > src_stride - x_offset) + copy_width = src_stride - x_offset; + if (h > dri2_surf->base.Height - y) + h = dri2_surf->base.Height - y; - for (; h>0; h--) { + for (; h > 0; h--) { memcpy(dst, src, copy_width); src += src_stride; dst += dst_stride; @@ -2605,26 +2619,25 @@ dri2_wl_swrast_get_image(__DRIdrawable * read, } static void -dri2_wl_swrast_put_image2(__DRIdrawable * draw, int op, - int x, int y, int w, int h, int stride, - char *data, void *loaderPrivate) +dri2_wl_swrast_put_image2(__DRIdrawable *draw, int op, int x, int y, int w, + int h, int stride, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int copy_width = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, w); - int dst_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, dri2_surf->base.Width); + int dst_stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, + dri2_surf->base.Width); int x_offset = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, x); char *src, *dst; assert(copy_width <= stride); - (void) swrast_update_buffers(dri2_surf); + (void)swrast_update_buffers(dri2_surf); dst = dri2_wl_swrast_get_backbuffer_data(dri2_surf); /* partial copy, copy old content */ if (copy_width < dst_stride) - dri2_wl_swrast_get_image(draw, 0, 0, - dri2_surf->base.Width, dri2_surf->base.Height, - dst, loaderPrivate); + dri2_wl_swrast_get_image(draw, 0, 0, dri2_surf->base.Width, + dri2_surf->base.Height, dst, loaderPrivate); dst += x_offset; dst += y * dst_stride; @@ -2632,12 +2645,12 @@ dri2_wl_swrast_put_image2(__DRIdrawable * draw, int op, src = data; /* drivers expect we do these checks (and some rely on it) */ - if (copy_width > dst_stride-x_offset) - copy_width = dst_stride-x_offset; - if (h > dri2_surf->base.Height-y) - h = dri2_surf->base.Height-y; + if (copy_width > dst_stride - x_offset) + copy_width = dst_stride - x_offset; + if (h > dri2_surf->base.Height - y) + h = dri2_surf->base.Height - y; - for (; h>0; h--) { + for (; h > 0; h--) { memcpy(dst, src, copy_width); src += stride; dst += dst_stride; @@ -2646,16 +2659,14 @@ dri2_wl_swrast_put_image2(__DRIdrawable * draw, int op, } static void -dri2_wl_swrast_put_image(__DRIdrawable * draw, int op, - int x, int y, int w, int h, - char *data, void *loaderPrivate) +dri2_wl_swrast_put_image(__DRIdrawable *draw, int op, int x, int y, int w, + int h, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; int stride; stride = dri2_wl_swrast_get_stride_for_format(dri2_surf->format, w); - dri2_wl_swrast_put_image2(draw, op, x, y, w, h, - stride, data, loaderPrivate); + dri2_wl_swrast_put_image2(draw, op, x, y, w, h, stride, data, loaderPrivate); } static EGLBoolean @@ -2699,8 +2710,7 @@ registry_handle_global_swrast(void *data, struct wl_registry *registry, struct dri2_egl_display *dri2_dpy = data; if (strcmp(interface, wl_shm_interface.name) == 0) { - dri2_dpy->wl_shm = - wl_registry_bind(registry, name, &wl_shm_interface, 1); + dri2_dpy->wl_shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); wl_shm_add_listener(dri2_dpy->wl_shm, &shm_listener, dri2_dpy); } } @@ -2721,34 +2731,38 @@ static const struct dri2_egl_display_vtbl dri2_wl_swrast_display_vtbl = { }; static const __DRIswrastLoaderExtension swrast_loader_extension = { - .base = { __DRI_SWRAST_LOADER, 2 }, + .base = {__DRI_SWRAST_LOADER, 2}, .getDrawableInfo = dri2_wl_swrast_get_drawable_info, - .putImage = dri2_wl_swrast_put_image, - .getImage = dri2_wl_swrast_get_image, - .putImage2 = dri2_wl_swrast_put_image2, + .putImage = dri2_wl_swrast_put_image, + .getImage = dri2_wl_swrast_get_image, + .putImage2 = dri2_wl_swrast_put_image2, }; -static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkWaylandSurfaceCreateInfoKHR), ""); +static_assert(sizeof(struct kopper_vk_surface_create_storage) >= + sizeof(VkWaylandSurfaceCreateInfoKHR), + ""); static void kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *out) { - struct dri2_egl_surface *dri2_surf = _draw; - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); - VkWaylandSurfaceCreateInfoKHR *wlsci = (VkWaylandSurfaceCreateInfoKHR *)&out->bos; + struct dri2_egl_surface *dri2_surf = _draw; + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + VkWaylandSurfaceCreateInfoKHR *wlsci = + (VkWaylandSurfaceCreateInfoKHR *)&out->bos; - wlsci->sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; - wlsci->pNext = NULL; - wlsci->flags = 0; - wlsci->display = dri2_dpy->wl_dpy; - wlsci->surface = dri2_surf->wl_surface_wrapper; + wlsci->sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; + wlsci->pNext = NULL; + wlsci->flags = 0; + wlsci->display = dri2_dpy->wl_dpy; + wlsci->surface = dri2_surf->wl_surface_wrapper; } static const __DRIkopperLoaderExtension kopper_loader_extension = { - .base = { __DRI_KOPPER_LOADER, 1 }, + .base = {__DRI_KOPPER_LOADER, 1}, - .SetSurfaceCreateInfo = kopperSetSurfaceCreateInfo, + .SetSurfaceCreateInfo = kopperSetSurfaceCreateInfo, }; static const __DRIextension *swrast_loader_extensions[] = { &swrast_loader_extension.base, @@ -2768,7 +2782,7 @@ dri2_initialize_wayland_swrast(_EGLDisplay *disp) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); dri2_dpy->fd_render_gpu = -1; - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; if (dri2_wl_formats_init(&dri2_dpy->formats) < 0) goto cleanup; @@ -2796,21 +2810,22 @@ dri2_initialize_wayland_swrast(_EGLDisplay *disp) if (dri2_dpy->wl_dpy_wrapper == NULL) goto cleanup; - wl_proxy_set_queue((struct wl_proxy *) dri2_dpy->wl_dpy_wrapper, + wl_proxy_set_queue((struct wl_proxy *)dri2_dpy->wl_dpy_wrapper, dri2_dpy->wl_queue); if (dri2_dpy->own_device) wl_display_dispatch_pending(dri2_dpy->wl_dpy); dri2_dpy->wl_registry = wl_display_get_registry(dri2_dpy->wl_dpy_wrapper); - wl_registry_add_listener(dri2_dpy->wl_registry, - ®istry_listener_swrast, dri2_dpy); + wl_registry_add_listener(dri2_dpy->wl_registry, ®istry_listener_swrast, + dri2_dpy); if (roundtrip(dri2_dpy) < 0 || dri2_dpy->wl_shm == NULL) goto cleanup; - if (roundtrip(dri2_dpy) < 0 || !BITSET_TEST_RANGE(dri2_dpy->formats.formats_bitmap, - 0, dri2_dpy->formats.num_formats)) + if (roundtrip(dri2_dpy) < 0 || + !BITSET_TEST_RANGE(dri2_dpy->formats.formats_bitmap, 0, + dri2_dpy->formats.num_formats)) goto cleanup; dri2_dpy->driver_name = strdup(disp->Options.Zink ? "zink" : "swrast"); @@ -2841,7 +2856,7 @@ dri2_initialize_wayland_swrast(_EGLDisplay *disp) return EGL_TRUE; - cleanup: +cleanup: dri2_display_destroy(disp); return EGL_FALSE; } diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 8f1d01135f5..10a00380cab 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -25,15 +25,15 @@ * Kristian Høgsberg */ +#include +#include +#include +#include #include #include +#include #include #include -#include -#include -#include -#include -#include #include /* clang-format off */ #include @@ -43,15 +43,15 @@ #ifdef HAVE_LIBDRM #include #endif -#include -#include -#include "util/u_debug.h" -#include "util/macros.h" #include "util/bitscan.h" +#include "util/macros.h" +#include "util/u_debug.h" +#include +#include -#include "platform_x11.h" -#include "loader.h" #include "kopper_interface.h" +#include "loader.h" +#include "platform_x11.h" #ifdef HAVE_DRI3 #include "platform_x11_dri3.h" @@ -61,66 +61,68 @@ static EGLBoolean dri2_x11_swap_interval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval); static void -swrastCreateDrawable(struct dri2_egl_display * dri2_dpy, - struct dri2_egl_surface * dri2_surf) +swrastCreateDrawable(struct dri2_egl_display *dri2_dpy, + struct dri2_egl_surface *dri2_surf) { - uint32_t mask; - const uint32_t function = GXcopy; - uint32_t valgc[2]; + uint32_t mask; + const uint32_t function = GXcopy; + uint32_t valgc[2]; /* create GC's */ dri2_surf->gc = xcb_generate_id(dri2_dpy->conn); mask = XCB_GC_FUNCTION; - xcb_create_gc(dri2_dpy->conn, dri2_surf->gc, dri2_surf->drawable, mask, &function); + xcb_create_gc(dri2_dpy->conn, dri2_surf->gc, dri2_surf->drawable, mask, + &function); dri2_surf->swapgc = xcb_generate_id(dri2_dpy->conn); mask = XCB_GC_FUNCTION | XCB_GC_GRAPHICS_EXPOSURES; valgc[0] = function; valgc[1] = False; - xcb_create_gc(dri2_dpy->conn, dri2_surf->swapgc, dri2_surf->drawable, mask, valgc); + xcb_create_gc(dri2_dpy->conn, dri2_surf->swapgc, dri2_surf->drawable, mask, + valgc); switch (dri2_surf->depth) { - case 32: - case 30: - case 24: - dri2_surf->bytes_per_pixel = 4; - break; - case 16: - dri2_surf->bytes_per_pixel = 2; - break; - case 8: - dri2_surf->bytes_per_pixel = 1; - break; - case 0: - dri2_surf->bytes_per_pixel = 0; - break; - default: - _eglLog(_EGL_WARNING, "unsupported depth %d", dri2_surf->depth); + case 32: + case 30: + case 24: + dri2_surf->bytes_per_pixel = 4; + break; + case 16: + dri2_surf->bytes_per_pixel = 2; + break; + case 8: + dri2_surf->bytes_per_pixel = 1; + break; + case 0: + dri2_surf->bytes_per_pixel = 0; + break; + default: + _eglLog(_EGL_WARNING, "unsupported depth %d", dri2_surf->depth); } } static void -swrastDestroyDrawable(struct dri2_egl_display * dri2_dpy, - struct dri2_egl_surface * dri2_surf) +swrastDestroyDrawable(struct dri2_egl_display *dri2_dpy, + struct dri2_egl_surface *dri2_surf) { xcb_free_gc(dri2_dpy->conn, dri2_surf->gc); xcb_free_gc(dri2_dpy->conn, dri2_surf->swapgc); } static bool -x11_get_drawable_info(__DRIdrawable * draw, - int *x, int *y, int *w, int *h, +x11_get_drawable_info(__DRIdrawable *draw, int *x, int *y, int *w, int *h, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); xcb_get_geometry_cookie_t cookie; xcb_get_geometry_reply_t *reply; xcb_generic_error_t *error; bool ret; - cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); - reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); + cookie = xcb_get_geometry(dri2_dpy->conn, dri2_surf->drawable); + reply = xcb_get_geometry_reply(dri2_dpy->conn, cookie, &error); if (reply == NULL) return false; @@ -140,8 +142,7 @@ x11_get_drawable_info(__DRIdrawable * draw, } static void -swrastGetDrawableInfo(__DRIdrawable * draw, - int *x, int *y, int *w, int *h, +swrastGetDrawableInfo(__DRIdrawable *draw, int *x, int *y, int *w, int *h, void *loaderPrivate) { *x = *y = *w = *h = 0; @@ -149,12 +150,12 @@ swrastGetDrawableInfo(__DRIdrawable * draw, } static void -swrastPutImage(__DRIdrawable * draw, int op, - int x, int y, int w, int h, +swrastPutImage(__DRIdrawable *draw, int op, int x, int y, int w, int h, char *data, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); size_t hdr_len = sizeof(xcb_put_image_request_t); int stride_b = dri2_surf->bytes_per_pixel * w; size_t size = (hdr_len + stride_b * h) >> 2; @@ -174,9 +175,9 @@ swrastPutImage(__DRIdrawable * draw, int op, } if (size < max_req_len) { - cookie = xcb_put_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable, - gc, w, h, x, y, 0, dri2_surf->depth, - h * stride_b, (const uint8_t *)data); + cookie = xcb_put_image( + dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable, gc, w, + h, x, y, 0, dri2_surf->depth, h * stride_b, (const uint8_t *)data); xcb_discard_reply(dri2_dpy->conn, cookie.sequence); } else { int num_lines = ((max_req_len << 2) - hdr_len) / stride_b; @@ -184,9 +185,11 @@ swrastPutImage(__DRIdrawable * draw, int op, int y_todo = h; while (y_todo) { int this_lines = MIN2(num_lines, y_todo); - cookie = xcb_put_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable, - gc, w, this_lines, x, y_start, 0, dri2_surf->depth, - this_lines * stride_b, ((const uint8_t *)data + y_start * stride_b)); + cookie = + xcb_put_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, + dri2_surf->drawable, gc, w, this_lines, x, y_start, 0, + dri2_surf->depth, this_lines * stride_b, + ((const uint8_t *)data + y_start * stride_b)); xcb_discard_reply(dri2_dpy->conn, cookie.sequence); y_start += this_lines; y_todo -= this_lines; @@ -195,20 +198,20 @@ swrastPutImage(__DRIdrawable * draw, int op, } static void -swrastGetImage(__DRIdrawable * read, - int x, int y, int w, int h, - char *data, void *loaderPrivate) +swrastGetImage(__DRIdrawable *read, int x, int y, int w, int h, char *data, + void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); xcb_get_image_cookie_t cookie; xcb_get_image_reply_t *reply; xcb_generic_error_t *error; - cookie = xcb_get_image (dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, - dri2_surf->drawable, x, y, w, h, ~0); - reply = xcb_get_image_reply (dri2_dpy->conn, cookie, &error); + cookie = xcb_get_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, + dri2_surf->drawable, x, y, w, h, ~0); + reply = xcb_get_image_reply(dri2_dpy->conn, cookie, &error); if (reply == NULL) return; @@ -223,15 +226,14 @@ swrastGetImage(__DRIdrawable * read, free(reply); } - static xcb_screen_t * get_xcb_screen(xcb_screen_iterator_t iter, int screen) { - for (; iter.rem; --screen, xcb_screen_next(&iter)) - if (screen == 0) - return iter.data; + for (; iter.rem; --screen, xcb_screen_next(&iter)) + if (screen == 0) + return iter.data; - return NULL; + return NULL; } static xcb_visualtype_t * @@ -285,7 +287,7 @@ dri2_x11_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); return NULL; } - + if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, false, native_surface)) goto cleanup_surf; @@ -293,25 +295,25 @@ dri2_x11_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, dri2_surf->region = XCB_NONE; if (type == EGL_PBUFFER_BIT) { dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); - xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, - dri2_surf->drawable, dri2_dpy->screen->root, - dri2_surf->base.Width, dri2_surf->base.Height); + xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, dri2_surf->drawable, + dri2_dpy->screen->root, dri2_surf->base.Width, + dri2_surf->base.Height); } else { STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface)); - dri2_surf->drawable = (uintptr_t) native_surface; + dri2_surf->drawable = (uintptr_t)native_surface; } - config = dri2_get_dri_config(dri2_conf, type, - dri2_surf->base.GLColorspace); + config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace); if (!config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_pixmap; } if (type != EGL_PBUFFER_BIT) { - cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable); - reply = xcb_get_geometry_reply (dri2_dpy->conn, cookie, &error); + cookie = xcb_get_geometry(dri2_dpy->conn, dri2_surf->drawable); + reply = xcb_get_geometry_reply(dri2_dpy->conn, cookie, &error); if (error != NULL) { if (error->error_code == BadAlloc) _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); @@ -340,12 +342,13 @@ dri2_x11_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, xcb_void_cookie_t cookie; int conn_error; - cookie = xcb_dri2_create_drawable_checked(dri2_dpy->conn, - dri2_surf->drawable); + cookie = + xcb_dri2_create_drawable_checked(dri2_dpy->conn, dri2_surf->drawable); error = xcb_request_check(dri2_dpy->conn, cookie); conn_error = xcb_connection_has_error(dri2_dpy->conn); if (conn_error || error != NULL) { - if (type == EGL_PBUFFER_BIT || conn_error || error->error_code == BadAlloc) + if (type == EGL_PBUFFER_BIT || conn_error || + error->error_code == BadAlloc) _eglError(EGL_BAD_ALLOC, "xcb_dri2_create_drawable_checked"); else if (type == EGL_WINDOW_BIT) _eglError(EGL_BAD_NATIVE_WINDOW, @@ -368,12 +371,12 @@ dri2_x11_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, return &dri2_surf->base; - cleanup_dri_drawable: +cleanup_dri_drawable: dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); - cleanup_pixmap: +cleanup_pixmap: if (type == EGL_PBUFFER_BIT) xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); - cleanup_surf: +cleanup_surf: free(dri2_surf); return NULL; @@ -389,8 +392,8 @@ dri2_x11_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); _EGLSurface *surf; - surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, - native_window, attrib_list); + surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, native_window, + attrib_list); if (surf != NULL) { /* When we first create the DRI2 drawable, its swap interval on the * server side is 1. @@ -408,16 +411,16 @@ static _EGLSurface * dri2_x11_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list) { - return dri2_x11_create_surface(disp, EGL_PIXMAP_BIT, conf, - native_pixmap, attrib_list); + return dri2_x11_create_surface(disp, EGL_PIXMAP_BIT, conf, native_pixmap, + attrib_list); } static _EGLSurface * dri2_x11_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { - return dri2_x11_create_surface(disp, EGL_PBUFFER_BIT, conf, - NULL, attrib_list); + return dri2_x11_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, + attrib_list); } static EGLBoolean @@ -427,16 +430,16 @@ dri2_x11_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable); - + if (dri2_dpy->dri2) { - xcb_dri2_destroy_drawable (dri2_dpy->conn, dri2_surf->drawable); + xcb_dri2_destroy_drawable(dri2_dpy->conn, dri2_surf->drawable); } else { assert(dri2_dpy->swrast); swrastDestroyDrawable(dri2_dpy, dri2_surf); } if (surf->Type == EGL_PBUFFER_BIT) - xcb_free_pixmap (dri2_dpy->conn, dri2_surf->drawable); + xcb_free_pixmap(dri2_dpy->conn, dri2_surf->drawable); dri2_fini_surface(surf); free(surf); @@ -453,8 +456,8 @@ dri2_x11_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) * have. */ static EGLBoolean -dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, - EGLint attribute, EGLint *value) +dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint *value) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); @@ -525,10 +528,9 @@ dri2_x11_process_buffers(struct dri2_egl_surface *dri2_surf, } static __DRIbuffer * -dri2_x11_get_buffers(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2_x11_get_buffers(__DRIdrawable *driDrawable, int *width, int *height, + unsigned int *attachments, int count, int *out_count, + void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_display *dri2_dpy = @@ -537,15 +539,14 @@ dri2_x11_get_buffers(__DRIdrawable * driDrawable, xcb_dri2_get_buffers_reply_t *reply; xcb_dri2_get_buffers_cookie_t cookie; - (void) driDrawable; + (void)driDrawable; - cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, - dri2_surf->drawable, - count, count, attachments); - reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, cookie, NULL); + cookie = xcb_dri2_get_buffers_unchecked(dri2_dpy->conn, dri2_surf->drawable, + count, count, attachments); + reply = xcb_dri2_get_buffers_reply(dri2_dpy->conn, cookie, NULL); if (reply == NULL) return NULL; - buffers = xcb_dri2_get_buffers_buffers (reply); + buffers = xcb_dri2_get_buffers_buffers(reply); if (buffers == NULL) { free(reply); return NULL; @@ -562,10 +563,9 @@ dri2_x11_get_buffers(__DRIdrawable * driDrawable, } static __DRIbuffer * -dri2_x11_get_buffers_with_format(__DRIdrawable * driDrawable, - int *width, int *height, - unsigned int *attachments, int count, - int *out_count, void *loaderPrivate) +dri2_x11_get_buffers_with_format(__DRIdrawable *driDrawable, int *width, + int *height, unsigned int *attachments, + int count, int *out_count, void *loaderPrivate) { struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_display *dri2_dpy = @@ -575,20 +575,17 @@ dri2_x11_get_buffers_with_format(__DRIdrawable * driDrawable, xcb_dri2_get_buffers_with_format_cookie_t cookie; xcb_dri2_attach_format_t *format_attachments; - (void) driDrawable; + (void)driDrawable; - format_attachments = (xcb_dri2_attach_format_t *) attachments; - cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, - dri2_surf->drawable, - count, count, - format_attachments); + format_attachments = (xcb_dri2_attach_format_t *)attachments; + cookie = xcb_dri2_get_buffers_with_format_unchecked( + dri2_dpy->conn, dri2_surf->drawable, count, count, format_attachments); - reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, - cookie, NULL); + reply = xcb_dri2_get_buffers_with_format_reply(dri2_dpy->conn, cookie, NULL); if (reply == NULL) return NULL; - buffers = xcb_dri2_get_buffers_with_format_buffers (reply); + buffers = xcb_dri2_get_buffers_with_format_buffers(reply); dri2_surf->base.Width = *width = reply->width; dri2_surf->base.Height = *height = reply->height; *out_count = reply->count; @@ -600,9 +597,9 @@ dri2_x11_get_buffers_with_format(__DRIdrawable * driDrawable, } static void -dri2_x11_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) +dri2_x11_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) { - (void) driDrawable; + (void)driDrawable; /* FIXME: Does EGL support front buffer rendering at all? */ @@ -611,7 +608,7 @@ dri2_x11_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) dri2WaitGL(dri2_surf); #else - (void) loaderPrivate; + (void)loaderPrivate; #endif } @@ -622,8 +619,8 @@ dri2_x11_do_authenticate(struct dri2_egl_display *dri2_dpy, uint32_t id) xcb_dri2_authenticate_cookie_t authenticate_cookie; int ret = 0; - authenticate_cookie = - xcb_dri2_authenticate_unchecked(dri2_dpy->conn, dri2_dpy->screen->root, id); + authenticate_cookie = xcb_dri2_authenticate_unchecked( + dri2_dpy->conn, dri2_dpy->screen->root, id); authenticate = xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); @@ -667,8 +664,8 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) char *driver_name, *loader_driver_name, *device_name; const xcb_query_extension_reply_t *extension; - xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); - xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri2_id); + xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_xfixes_id); + xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_dri2_id); extension = xcb_get_extension_data(dri2_dpy->conn, &xcb_xfixes_id); if (!(extension && extension->present)) @@ -678,22 +675,19 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) if (!(extension && extension->present)) return EGL_FALSE; - xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, - XCB_XFIXES_MAJOR_VERSION, - XCB_XFIXES_MINOR_VERSION); + xfixes_query_cookie = xcb_xfixes_query_version( + dri2_dpy->conn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION); - dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, - XCB_DRI2_MAJOR_VERSION, - XCB_DRI2_MINOR_VERSION); + dri2_query_cookie = xcb_dri2_query_version( + dri2_dpy->conn, XCB_DRI2_MAJOR_VERSION, XCB_DRI2_MINOR_VERSION); - connect_cookie = xcb_dri2_connect_unchecked(dri2_dpy->conn, dri2_dpy->screen->root, - XCB_DRI2_DRIVER_TYPE_DRI); + connect_cookie = xcb_dri2_connect_unchecked( + dri2_dpy->conn, dri2_dpy->screen->root, XCB_DRI2_DRIVER_TYPE_DRI); - xfixes_query = - xcb_xfixes_query_version_reply (dri2_dpy->conn, - xfixes_query_cookie, &error); - if (xfixes_query == NULL || - error != NULL || xfixes_query->major_version < 2) { + xfixes_query = xcb_xfixes_query_version_reply(dri2_dpy->conn, + xfixes_query_cookie, &error); + if (xfixes_query == NULL || error != NULL || + xfixes_query->major_version < 2) { _eglLog(_EGL_WARNING, "DRI2: failed to query xfixes version"); free(error); free(xfixes_query); @@ -702,7 +696,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) free(xfixes_query); dri2_query = - xcb_dri2_query_version_reply (dri2_dpy->conn, dri2_query_cookie, &error); + xcb_dri2_query_version_reply(dri2_dpy->conn, dri2_query_cookie, &error); if (dri2_query == NULL || error != NULL) { _eglLog(_EGL_WARNING, "DRI2: failed to query version"); free(error); @@ -713,7 +707,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) dri2_dpy->dri2_minor = dri2_query->minor_version; free(dri2_query); - connect = xcb_dri2_connect_reply (dri2_dpy->conn, connect_cookie, NULL); + connect = xcb_dri2_connect_reply(dri2_dpy->conn, connect_cookie, NULL); if (connect == NULL || connect->driver_name_length + connect->device_name_length == 0) { _eglLog(_EGL_WARNING, "DRI2: failed to authenticate"); @@ -721,12 +715,12 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) return EGL_FALSE; } - device_name = xcb_dri2_connect_device_name (connect); + device_name = xcb_dri2_connect_device_name(connect); dri2_dpy->fd_render_gpu = loader_open_device(device_name); if (dri2_dpy->fd_render_gpu == -1) { - _eglLog(_EGL_WARNING, - "DRI2: could not open %s (%s)", device_name, strerror(errno)); + _eglLog(_EGL_WARNING, "DRI2: could not open %s (%s)", device_name, + strerror(errno)); free(connect); return EGL_FALSE; } @@ -737,7 +731,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) return EGL_FALSE; } - driver_name = xcb_dri2_connect_driver_name (connect); + driver_name = xcb_dri2_connect_driver_name(connect); /* If Mesa knows about the appropriate driver for this fd, then trust it. * Otherwise, default to the server's value. @@ -747,8 +741,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) dri2_dpy->driver_name = loader_driver_name; } else { dri2_dpy->driver_name = - strndup(driver_name, - xcb_dri2_connect_driver_name_length(connect)); + strndup(driver_name, xcb_dri2_connect_driver_name_length(connect)); } if (dri2_dpy->driver_name == NULL) { @@ -759,8 +752,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy) #ifdef HAVE_WAYLAND_PLATFORM dri2_dpy->device_name = - strndup(device_name, - xcb_dri2_connect_device_name_length(connect)); + strndup(device_name, xcb_dri2_connect_device_name_length(connect)); #endif free(connect); @@ -787,33 +779,34 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, d = xcb_screen_allowed_depths_iterator(dri2_dpy->screen); - surface_type = - EGL_WINDOW_BIT | - EGL_PIXMAP_BIT | - EGL_PBUFFER_BIT; + surface_type = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT; if (supports_preserved) surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; while (d.rem > 0) { - EGLBoolean class_added[6] = { 0, }; + EGLBoolean class_added[6] = { + 0, + }; visuals = xcb_depth_visuals(d.data); for (int i = 0; i < xcb_depth_visuals_length(d.data); i++) { - if (class_added[visuals[i]._class]) - continue; + if (class_added[visuals[i]._class]) + continue; - class_added[visuals[i]._class] = EGL_TRUE; + class_added[visuals[i]._class] = EGL_TRUE; - for (int j = 0; dri2_dpy->driver_configs[j]; j++) { + for (int j = 0; dri2_dpy->driver_configs[j]; j++) { struct dri2_egl_config *dri2_conf; const __DRIconfig *config = dri2_dpy->driver_configs[j]; const EGLint config_attrs[] = { - EGL_NATIVE_VISUAL_ID, visuals[i].visual_id, - EGL_NATIVE_VISUAL_TYPE, visuals[i]._class, - EGL_NONE, + EGL_NATIVE_VISUAL_ID, + visuals[i].visual_id, + EGL_NATIVE_VISUAL_TYPE, + visuals[i]._class, + EGL_NONE, }; int rgba_shifts[4] = { @@ -830,9 +823,9 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, 0, }; - dri2_conf = dri2_add_config(disp, config, config_count + 1, - surface_type, config_attrs, - rgba_shifts, rgba_sizes); + dri2_conf = + dri2_add_config(disp, config, config_count + 1, surface_type, + config_attrs, rgba_shifts, rgba_sizes); if (dri2_conf) if (dri2_conf->base.ConfigID == config_count + 1) config_count++; @@ -846,19 +839,19 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, * wants... especially on drivers that only have 32-bit RGBA * EGLConfigs! */ if (d.data->depth == 24 || d.data->depth == 30) { - unsigned int rgba_mask = ~(visuals[i].red_mask | - visuals[i].green_mask | - visuals[i].blue_mask); + unsigned int rgba_mask = + ~(visuals[i].red_mask | visuals[i].green_mask | + visuals[i].blue_mask); rgba_shifts[3] = ffs(rgba_mask) - 1; rgba_sizes[3] = util_bitcount(rgba_mask); - dri2_conf = dri2_add_config(disp, config, config_count + 1, - surface_type, config_attrs, - rgba_shifts, rgba_sizes); + dri2_conf = + dri2_add_config(disp, config, config_count + 1, surface_type, + config_attrs, rgba_shifts, rgba_sizes); if (dri2_conf) if (dri2_conf->base.ConfigID == config_count + 1) config_count++; } - } + } } xcb_depth_next(&d); @@ -873,8 +866,8 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, } static EGLBoolean -dri2_copy_region(_EGLDisplay *disp, - _EGLSurface *draw, xcb_xfixes_region_t region) +dri2_copy_region(_EGLDisplay *disp, _EGLSurface *draw, + xcb_xfixes_region_t region) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); @@ -893,19 +886,17 @@ dri2_copy_region(_EGLDisplay *disp, else render_attachment = XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT; - cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, - dri2_surf->drawable, - region, - XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, - render_attachment); + cookie = xcb_dri2_copy_region_unchecked( + dri2_dpy->conn, dri2_surf->drawable, region, + XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, render_attachment); free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); return EGL_TRUE; } static int64_t -dri2_x11_swap_buffers_msc(_EGLDisplay *disp, _EGLSurface *draw, - int64_t msc, int64_t divisor, int64_t remainder) +dri2_x11_swap_buffers_msc(_EGLDisplay *disp, _EGLSurface *draw, int64_t msc, + int64_t divisor, int64_t remainder) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); @@ -919,15 +910,15 @@ dri2_x11_swap_buffers_msc(_EGLDisplay *disp, _EGLSurface *draw, xcb_dri2_swap_buffers_reply_t *reply; int64_t swap_count = -1; - if (draw->SwapBehavior == EGL_BUFFER_PRESERVED || !dri2_dpy->swap_available) { + if (draw->SwapBehavior == EGL_BUFFER_PRESERVED || + !dri2_dpy->swap_available) { swap_count = dri2_copy_region(disp, draw, dri2_surf->region) ? 0 : -1; } else { dri2_flush_drawable_for_swapbuffers(disp, draw); - cookie = xcb_dri2_swap_buffers_unchecked(dri2_dpy->conn, - dri2_surf->drawable, msc_hi, - msc_lo, divisor_hi, divisor_lo, - remainder_hi, remainder_lo); + cookie = xcb_dri2_swap_buffers_unchecked( + dri2_dpy->conn, dri2_surf->drawable, msc_hi, msc_lo, divisor_hi, + divisor_lo, remainder_hi, remainder_lo); reply = xcb_dri2_swap_buffers_reply(dri2_dpy->conn, cookie, NULL); @@ -965,7 +956,8 @@ dri2_x11_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) * "The contents of ancillary buffers are always undefined * after calling eglSwapBuffers." */ - dri2_dpy->kopper->swapBuffers(dri2_surf->dri_drawable, __DRI2_FLUSH_INVALIDATE_ANCILLARY); + dri2_dpy->kopper->swapBuffers(dri2_surf->dri_drawable, + __DRI2_FLUSH_INVALIDATE_ANCILLARY); return EGL_TRUE; } else if (!dri2_dpy->flush) { /* aka the swrast path, which does the swap in the gallium driver. */ @@ -995,7 +987,8 @@ dri2_x11_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *draw, for (int i = 0; i < numRects; i++) { rectangles[i].x = rects[i * 4]; - rectangles[i].y = dri2_surf->base.Height - rects[i * 4 + 1] - rects[i * 4 + 3]; + rectangles[i].y = + dri2_surf->base.Height - rects[i * 4 + 1] - rects[i * 4 + 3]; rectangles[i].width = rects[i * 4 + 2]; rectangles[i].height = rects[i * 4 + 3]; } @@ -1009,10 +1002,10 @@ dri2_x11_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *draw, } static EGLBoolean -dri2_x11_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *draw, - EGLint x, EGLint y, EGLint width, EGLint height) +dri2_x11_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *draw, EGLint x, + EGLint y, EGLint width, EGLint height) { - const EGLint rect[4] = { x, y, width, height }; + const EGLint rect[4] = {x, y, width, height}; if (x < 0 || y < 0 || width < 0 || height < 0) _eglError(EGL_BAD_PARAMETER, "eglPostSubBufferNV"); @@ -1038,7 +1031,8 @@ dri2_x11_swap_interval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval) } static EGLBoolean -dri2_x11_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_target) +dri2_x11_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, + void *native_pixmap_target) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); @@ -1046,7 +1040,7 @@ dri2_x11_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_ xcb_pixmap_t target; STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_pixmap_target)); - target = (uintptr_t) native_pixmap_target; + target = (uintptr_t)native_pixmap_target; if (dri2_dpy->flush) dri2_dpy->flush->flush(dri2_surf->dri_drawable); @@ -1062,14 +1056,8 @@ dri2_x11_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_ gc = xcb_generate_id(dri2_dpy->conn); xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); - xcb_copy_area(dri2_dpy->conn, - dri2_surf->drawable, - target, - gc, - 0, 0, - 0, 0, - dri2_surf->base.Width, - dri2_surf->base.Height); + xcb_copy_area(dri2_dpy->conn, dri2_surf->drawable, target, gc, 0, 0, 0, 0, + dri2_surf->base.Width, dri2_surf->base.Height); xcb_free_gc(dri2_dpy->conn, gc); return EGL_TRUE; @@ -1098,7 +1086,7 @@ dri2_format_for_depth(struct dri2_egl_display *dri2_dpy, uint32_t depth) static _EGLImage * dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, - EGLClientBuffer buffer, const EGLint *attr_list) + EGLClientBuffer buffer, const EGLint *attr_list) { struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_image *dri2_img; @@ -1112,28 +1100,27 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, xcb_generic_error_t *error; int stride, format; - (void) ctx; + (void)ctx; - drawable = (xcb_drawable_t) (uintptr_t) buffer; - xcb_dri2_create_drawable (dri2_dpy->conn, drawable); + drawable = (xcb_drawable_t)(uintptr_t)buffer; + xcb_dri2_create_drawable(dri2_dpy->conn, drawable); attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; - buffers_cookie = - xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, - drawable, 1, 1, attachments); - geometry_cookie = xcb_get_geometry (dri2_dpy->conn, drawable); - buffers_reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, - buffers_cookie, NULL); + buffers_cookie = xcb_dri2_get_buffers_unchecked(dri2_dpy->conn, drawable, 1, + 1, attachments); + geometry_cookie = xcb_get_geometry(dri2_dpy->conn, drawable); + buffers_reply = + xcb_dri2_get_buffers_reply(dri2_dpy->conn, buffers_cookie, NULL); if (buffers_reply == NULL) - return NULL; + return NULL; - buffers = xcb_dri2_get_buffers_buffers (buffers_reply); + buffers = xcb_dri2_get_buffers_buffers(buffers_reply); if (buffers == NULL) { free(buffers_reply); return NULL; } - geometry_reply = xcb_get_geometry_reply (dri2_dpy->conn, - geometry_cookie, &error); + geometry_reply = + xcb_get_geometry_reply(dri2_dpy->conn, geometry_cookie, &error); if (geometry_reply == NULL || error != NULL) { _eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); free(error); @@ -1145,7 +1132,7 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, format = dri2_format_for_depth(dri2_dpy, geometry_reply->depth); if (format == __DRI_IMAGE_FORMAT_NONE) { _eglError(EGL_BAD_PARAMETER, - "dri2_create_image_khr: unsupported pixmap depth"); + "dri2_create_image_khr: unsupported pixmap depth"); free(buffers_reply); free(geometry_reply); return NULL; @@ -1162,14 +1149,9 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, _eglInitImage(&dri2_img->base, disp); stride = buffers[0].pitch / buffers[0].cpp; - dri2_img->dri_image = - dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu, - buffers_reply->width, - buffers_reply->height, - format, - buffers[0].name, - stride, - dri2_img); + dri2_img->dri_image = dri2_dpy->image->createImageFromName( + dri2_dpy->dri_screen_render_gpu, buffers_reply->width, + buffers_reply->height, format, buffers[0].name, stride, dri2_img); free(buffers_reply); free(geometry_reply); @@ -1205,21 +1187,20 @@ dri2_x11_get_sync_values(_EGLDisplay *display, _EGLSurface *surface, if (!reply) return _eglError(EGL_BAD_ACCESS, __func__); - *ust = ((EGLuint64KHR) reply->ust_hi << 32) | reply->ust_lo; - *msc = ((EGLuint64KHR) reply->msc_hi << 32) | reply->msc_lo; - *sbc = ((EGLuint64KHR) reply->sbc_hi << 32) | reply->sbc_lo; + *ust = ((EGLuint64KHR)reply->ust_hi << 32) | reply->ust_lo; + *msc = ((EGLuint64KHR)reply->msc_hi << 32) | reply->msc_lo; + *sbc = ((EGLuint64KHR)reply->sbc_hi << 32) | reply->sbc_lo; free(reply); return EGL_TRUE; } static int -box_intersection_area(int16_t a_x, int16_t a_y, - int16_t a_width, int16_t a_height, - int16_t b_x, int16_t b_y, +box_intersection_area(int16_t a_x, int16_t a_y, int16_t a_width, + int16_t a_height, int16_t b_x, int16_t b_y, int16_t b_width, int16_t b_height) { - int w = MIN2(a_x + a_width, b_x + b_width) - MAX2(a_x, b_x); + int w = MIN2(a_x + a_width, b_x + b_width) - MAX2(a_x, b_x); int h = MIN2(a_y + a_height, b_y + b_height) - MAX2(a_y, b_y); return (w < 0 || h < 0) ? 0 : w * h; @@ -1255,7 +1236,7 @@ dri2_x11_get_msc_rate(_EGLDisplay *display, _EGLSurface *surface, if (surface->Type != EGL_WINDOW_BIT) return EGL_TRUE; - xcb_window_t window = (uintptr_t) surface->NativeSurface; + xcb_window_t window = (uintptr_t)surface->NativeSurface; xcb_translate_coordinates_cookie_t cookie = xcb_translate_coordinates_unchecked(dri2_dpy->conn, window, @@ -1272,13 +1253,11 @@ dri2_x11_get_msc_rate(_EGLDisplay *display, _EGLSurface *surface, int area = 0; for (unsigned c = 0; c < dri2_dpy->screen_resources.num_crtcs; c++) { - struct loader_crtc_info *crtc = - &dri2_dpy->screen_resources.crtcs[c]; + struct loader_crtc_info *crtc = &dri2_dpy->screen_resources.crtcs[c]; - int c_area = box_intersection_area(reply->dst_x, reply->dst_y, - surface->Width, surface->Height, - crtc->x, crtc->y, - crtc->width, crtc->height); + int c_area = box_intersection_area( + reply->dst_x, reply->dst_y, surface->Width, surface->Height, crtc->x, + crtc->y, crtc->width, crtc->height); if (c_area > area) { *numerator = crtc->refresh_numerator; *denominator = crtc->refresh_denominator; @@ -1314,8 +1293,8 @@ dri2_kopper_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); _EGLSurface *surf; - surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, - native_window, attrib_list); + surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, native_window, + attrib_list); if (surf != NULL) { /* When we first create the DRI2 drawable, its swap interval on the * server side is 1. @@ -1397,36 +1376,39 @@ static const struct dri2_egl_display_vtbl dri2_x11_display_vtbl = { }; static const __DRIswrastLoaderExtension swrast_loader_extension = { - .base = { __DRI_SWRAST_LOADER, 1 }, + .base = {__DRI_SWRAST_LOADER, 1}, .getDrawableInfo = swrastGetDrawableInfo, - .putImage = swrastPutImage, - .getImage = swrastGetImage, + .putImage = swrastPutImage, + .getImage = swrastGetImage, }; -static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkXcbSurfaceCreateInfoKHR), ""); +static_assert(sizeof(struct kopper_vk_surface_create_storage) >= + sizeof(VkXcbSurfaceCreateInfoKHR), + ""); static void kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *ci) { - struct dri2_egl_surface *dri2_surf = _draw; - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); - VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&ci->bos; + struct dri2_egl_surface *dri2_surf = _draw; + struct dri2_egl_display *dri2_dpy = + dri2_egl_display(dri2_surf->base.Resource.Display); + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&ci->bos; - if (dri2_surf->base.Type != EGL_WINDOW_BIT) - return; - xcb->sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; - xcb->pNext = NULL; - xcb->flags = 0; - xcb->connection = dri2_dpy->conn; - xcb->window = dri2_surf->drawable; - ci->has_alpha = dri2_surf->depth == 32; + if (dri2_surf->base.Type != EGL_WINDOW_BIT) + return; + xcb->sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + xcb->pNext = NULL; + xcb->flags = 0; + xcb->connection = dri2_dpy->conn; + xcb->window = dri2_surf->drawable; + ci->has_alpha = dri2_surf->depth == 32; } static const __DRIkopperLoaderExtension kopper_loader_extension = { - .base = { __DRI_KOPPER_LOADER, 1 }, + .base = {__DRI_KOPPER_LOADER, 1}, - .SetSurfaceCreateInfo = kopperSetSurfaceCreateInfo, + .SetSurfaceCreateInfo = kopperSetSurfaceCreateInfo, }; static const __DRIextension *swrast_loader_extensions[] = { @@ -1454,14 +1436,13 @@ dri2_find_screen_for_display(const _EGLDisplay *disp, int fallback_screen) } static EGLBoolean -dri2_get_xcb_connection(_EGLDisplay *disp, - struct dri2_egl_display *dri2_dpy) +dri2_get_xcb_connection(_EGLDisplay *disp, struct dri2_egl_display *dri2_dpy) { xcb_screen_iterator_t s; int screen; const char *msg; - disp->DriverData = (void *) dri2_dpy; + disp->DriverData = (void *)dri2_dpy; if (disp->PlatformDisplay == NULL) { dri2_dpy->conn = xcb_connect(NULL, &screen); dri2_dpy->own_device = true; @@ -1516,7 +1497,7 @@ dri2_x11_setup_swap_interval(_EGLDisplay *disp) * interval. Unless we're kopper, for now. */ if (dri2_dpy->kopper) - arbitrary_max_interval = 1; + arbitrary_max_interval = 1; dri2_setup_swap_interval(disp, arbitrary_max_interval); } @@ -1577,7 +1558,7 @@ dri2_initialize_x11_swrast(_EGLDisplay *disp) disp->Extensions.EXT_buffer_age = EGL_TRUE; disp->Extensions.EXT_swap_buffers_with_damage = EGL_TRUE; - //dri2_set_WL_bind_wayland_display(disp); + // dri2_set_WL_bind_wayland_display(disp); } else { /* swrast */ disp->Extensions.ANGLE_sync_control_rate = EGL_TRUE; @@ -1596,7 +1577,7 @@ dri2_initialize_x11_swrast(_EGLDisplay *disp) return EGL_TRUE; - cleanup: +cleanup: dri2_display_destroy(disp); return EGL_FALSE; } @@ -1668,8 +1649,8 @@ dri2_initialize_x11_dri3(_EGLDisplay *disp) if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, false)) goto cleanup; - loader_init_screen_resources(&dri2_dpy->screen_resources, - dri2_dpy->conn, dri2_dpy->screen); + loader_init_screen_resources(&dri2_dpy->screen_resources, dri2_dpy->conn, + dri2_dpy->screen); dri2_dpy->loader_dri3_ext.core = dri2_dpy->core; dri2_dpy->loader_dri3_ext.image_driver = dri2_dpy->image_driver; @@ -1687,25 +1668,25 @@ dri2_initialize_x11_dri3(_EGLDisplay *disp) return EGL_TRUE; - cleanup: +cleanup: dri2_display_destroy(disp); return EGL_FALSE; } #endif static const __DRIdri2LoaderExtension dri2_loader_extension_old = { - .base = { __DRI_DRI2_LOADER, 2 }, + .base = {__DRI_DRI2_LOADER, 2}, - .getBuffers = dri2_x11_get_buffers, - .flushFrontBuffer = dri2_x11_flush_front_buffer, + .getBuffers = dri2_x11_get_buffers, + .flushFrontBuffer = dri2_x11_flush_front_buffer, .getBuffersWithFormat = NULL, }; static const __DRIdri2LoaderExtension dri2_loader_extension = { - .base = { __DRI_DRI2_LOADER, 3 }, + .base = {__DRI_DRI2_LOADER, 3}, - .getBuffers = dri2_x11_get_buffers, - .flushFrontBuffer = dri2_x11_flush_front_buffer, + .getBuffers = dri2_x11_get_buffers, + .flushFrontBuffer = dri2_x11_flush_front_buffer, .getBuffersWithFormat = dri2_x11_get_buffers_with_format, }; @@ -1792,7 +1773,7 @@ dri2_initialize_x11_dri2(_EGLDisplay *disp) return EGL_TRUE; - cleanup: +cleanup: dri2_display_destroy(disp); return EGL_FALSE; } diff --git a/src/egl/drivers/dri2/platform_x11_dri3.c b/src/egl/drivers/dri2/platform_x11_dri3.c index fcd083aaad0..9f636971025 100644 --- a/src/egl/drivers/dri2/platform_x11_dri3.c +++ b/src/egl/drivers/dri2/platform_x11_dri3.c @@ -20,15 +20,15 @@ * OF THIS SOFTWARE. */ +#include #include #include #include #include -#include -#include #include #include +#include #include #include @@ -41,14 +41,15 @@ #include "loader_dri3_helper.h" static struct dri3_egl_surface * -loader_drawable_to_egl_surface(struct loader_dri3_drawable *draw) { +loader_drawable_to_egl_surface(struct loader_dri3_drawable *draw) +{ size_t offset = offsetof(struct dri3_egl_surface, loader_drawable); - return (struct dri3_egl_surface *)(((void*) draw) - offset); + return (struct dri3_egl_surface *)(((void *)draw) - offset); } static void -egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw, - int width, int height) +egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw, int width, + int height) { struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw); @@ -84,7 +85,8 @@ egl_dri3_get_dri_screen(void) if (!ctx) return NULL; dri2_ctx = dri2_egl_context(ctx); - return dri2_egl_display(dri2_ctx->base.Resource.Display)->dri_screen_render_gpu; + return dri2_egl_display(dri2_ctx->base.Resource.Display) + ->dri_screen_render_gpu; } static void @@ -114,7 +116,7 @@ dri3_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) loader_dri3_drawable_fini(&dri3_surf->loader_drawable); if (surf->Type == EGL_PBUFFER_BIT) - xcb_free_pixmap (dri2_dpy->conn, drawable); + xcb_free_pixmap(dri2_dpy->conn, drawable); dri2_fini_surface(surf); free(surf); @@ -164,38 +166,35 @@ dri3_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, return NULL; } - if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, - attrib_list, false, native_surface)) + if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, attrib_list, + false, native_surface)) goto cleanup_surf; if (type == EGL_PBUFFER_BIT) { drawable = xcb_generate_id(dri2_dpy->conn); - xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, - drawable, dri2_dpy->screen->root, - dri3_surf->surf.base.Width, dri3_surf->surf.base.Height); + xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, drawable, + dri2_dpy->screen->root, dri3_surf->surf.base.Width, + dri3_surf->surf.base.Height); } else { STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface)); - drawable = (uintptr_t) native_surface; + drawable = (uintptr_t)native_surface; } - dri_config = dri2_get_dri_config(dri2_conf, type, - dri3_surf->surf.base.GLColorspace); + dri_config = + dri2_get_dri_config(dri2_conf, type, dri3_surf->surf.base.GLColorspace); if (!dri_config) { - _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + _eglError(EGL_BAD_MATCH, + "Unsupported surfacetype/colorspace configuration"); goto cleanup_pixmap; } - if (loader_dri3_drawable_init(dri2_dpy->conn, drawable, - egl_to_loader_dri3_drawable_type(type), - dri2_dpy->dri_screen_render_gpu, - dri2_dpy->dri_screen_display_gpu, - dri2_dpy->multibuffers_available, - true, - dri_config, - &dri2_dpy->loader_dri3_ext, - &egl_dri3_vtable, - &dri3_surf->loader_drawable)) { + if (loader_dri3_drawable_init( + dri2_dpy->conn, drawable, egl_to_loader_dri3_drawable_type(type), + dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_display_gpu, + dri2_dpy->multibuffers_available, true, dri_config, + &dri2_dpy->loader_dri3_ext, &egl_dri3_vtable, + &dri3_surf->loader_drawable)) { _eglError(EGL_BAD_ALLOC, "dri3_surface_create"); goto cleanup_pixmap; } @@ -211,10 +210,10 @@ dri3_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf, return &dri3_surf->surf.base; - cleanup_pixmap: +cleanup_pixmap: if (type == EGL_PBUFFER_BIT) xcb_free_pixmap(dri2_dpy->conn, drawable); - cleanup_surf: +cleanup_surf: free(dri3_surf); return NULL; @@ -249,8 +248,8 @@ dri3_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); _EGLSurface *surf; - surf = dri3_create_surface(disp, EGL_WINDOW_BIT, conf, - native_window, attrib_list); + surf = dri3_create_surface(disp, EGL_WINDOW_BIT, conf, native_window, + attrib_list); if (surf != NULL) dri3_set_swap_interval(disp, surf, dri2_dpy->default_swap_interval); @@ -261,28 +260,28 @@ static _EGLSurface * dri3_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list) { - return dri3_create_surface(disp, EGL_PIXMAP_BIT, conf, - native_pixmap, attrib_list); + return dri3_create_surface(disp, EGL_PIXMAP_BIT, conf, native_pixmap, + attrib_list); } static _EGLSurface * dri3_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { - return dri3_create_surface(disp, EGL_PBUFFER_BIT, conf, - NULL, attrib_list); + return dri3_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list); } static EGLBoolean dri3_get_sync_values(_EGLDisplay *display, _EGLSurface *surface, - EGLuint64KHR *ust, EGLuint64KHR *msc, - EGLuint64KHR *sbc) + EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surface); return loader_dri3_wait_for_msc(&dri3_surf->loader_drawable, 0, 0, 0, - (int64_t *) ust, (int64_t *) msc, - (int64_t *) sbc) ? EGL_TRUE : EGL_FALSE; + (int64_t *)ust, (int64_t *)msc, + (int64_t *)sbc) + ? EGL_TRUE + : EGL_FALSE; } static _EGLImage * @@ -293,13 +292,13 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, struct dri2_egl_image *dri2_img; xcb_drawable_t drawable; xcb_dri3_buffer_from_pixmap_cookie_t bp_cookie; - xcb_dri3_buffer_from_pixmap_reply_t *bp_reply; + xcb_dri3_buffer_from_pixmap_reply_t *bp_reply; unsigned int format; - drawable = (xcb_drawable_t) (uintptr_t) buffer; + drawable = (xcb_drawable_t)(uintptr_t)buffer; bp_cookie = xcb_dri3_buffer_from_pixmap(dri2_dpy->conn, drawable); - bp_reply = xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn, - bp_cookie, NULL); + bp_reply = + xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn, bp_cookie, NULL); if (!bp_reply) { _eglError(EGL_BAD_ALLOC, "xcb_dri3_buffer_from_pixmap"); return NULL; @@ -322,12 +321,9 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, _eglInitImage(&dri2_img->base, disp); - dri2_img->dri_image = loader_dri3_create_image(dri2_dpy->conn, - bp_reply, - format, - dri2_dpy->dri_screen_render_gpu, - dri2_dpy->image, - dri2_img); + dri2_img->dri_image = loader_dri3_create_image( + dri2_dpy->conn, bp_reply, format, dri2_dpy->dri_screen_render_gpu, + dri2_dpy->image, dri2_img); free(bp_reply); @@ -343,14 +339,14 @@ dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx, struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_image *dri2_img; xcb_dri3_buffers_from_pixmap_cookie_t bp_cookie; - xcb_dri3_buffers_from_pixmap_reply_t *bp_reply; + xcb_dri3_buffers_from_pixmap_reply_t *bp_reply; xcb_drawable_t drawable; unsigned int format; - drawable = (xcb_drawable_t) (uintptr_t) buffer; + drawable = (xcb_drawable_t)(uintptr_t)buffer; bp_cookie = xcb_dri3_buffers_from_pixmap(dri2_dpy->conn, drawable); - bp_reply = xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn, - bp_cookie, NULL); + bp_reply = + xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn, bp_cookie, NULL); if (!bp_reply) { _eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr"); @@ -374,12 +370,9 @@ dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx, _eglInitImage(&dri2_img->base, disp); - dri2_img->dri_image = loader_dri3_create_image_from_buffers(dri2_dpy->conn, - bp_reply, - format, - dri2_dpy->dri_screen_render_gpu, - dri2_dpy->image, - dri2_img); + dri2_img->dri_image = loader_dri3_create_image_from_buffers( + dri2_dpy->conn, bp_reply, format, dri2_dpy->dri_screen_render_gpu, + dri2_dpy->image, dri2_img); free(bp_reply); if (!dri2_img->dri_image) { @@ -421,21 +414,22 @@ static void dri3_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) { struct loader_dri3_drawable *draw = loaderPrivate; - (void) driDrawable; + (void)driDrawable; /* There does not seem to be any kind of consensus on whether we should * support front-buffer rendering or not: * http://lists.freedesktop.org/archives/mesa-dev/2013-June/040129.html */ if (draw->type == LOADER_DRI3_DRAWABLE_WINDOW) - _eglLog(_EGL_WARNING, "FIXME: egl/x11 doesn't support front buffer rendering."); + _eglLog(_EGL_WARNING, + "FIXME: egl/x11 doesn't support front buffer rendering."); } const __DRIimageLoaderExtension dri3_image_loader_extension = { - .base = { __DRI_IMAGE_LOADER, 1 }, + .base = {__DRI_IMAGE_LOADER, 1}, - .getBuffers = loader_dri3_get_buffers, - .flushFrontBuffer = dri3_flush_front_buffer, + .getBuffers = loader_dri3_get_buffers, + .flushFrontBuffer = dri3_flush_front_buffer, }; static EGLBoolean @@ -444,10 +438,9 @@ dri3_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw, { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(draw); - return loader_dri3_swap_buffers_msc(&dri3_surf->loader_drawable, - 0, 0, 0, 0, - rects, n_rects, - draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1; + return loader_dri3_swap_buffers_msc( + &dri3_surf->loader_drawable, 0, 0, 0, 0, rects, n_rects, + draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1; } static EGLBoolean @@ -457,13 +450,14 @@ dri3_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw) } static EGLBoolean -dri3_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_target) +dri3_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, + void *native_pixmap_target) { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf); xcb_pixmap_t target; STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_pixmap_target)); - target = (uintptr_t) native_pixmap_target; + target = (uintptr_t)native_pixmap_target; loader_dri3_copy_drawable(&dri3_surf->loader_drawable, target, dri3_surf->loader_drawable.drawable); @@ -480,8 +474,8 @@ dri3_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surf) } static EGLBoolean -dri3_query_surface(_EGLDisplay *disp, _EGLSurface *surf, - EGLint attribute, EGLint *value) +dri3_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint *value) { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf); @@ -533,15 +527,15 @@ struct dri2_egl_display_vtbl dri3_x11_display_vtbl = { }; /* Only request versions of these protocols which we actually support. */ -#define DRI3_SUPPORTED_MAJOR 1 +#define DRI3_SUPPORTED_MAJOR 1 #define PRESENT_SUPPORTED_MAJOR 1 #ifdef HAVE_DRI3_MODIFIERS -#define DRI3_SUPPORTED_MINOR 2 +#define DRI3_SUPPORTED_MINOR 2 #define PRESENT_SUPPORTED_MINOR 2 #else #define PRESENT_SUPPORTED_MINOR 0 -#define DRI3_SUPPORTED_MINOR 0 +#define DRI3_SUPPORTED_MINOR 0 #endif EGLBoolean @@ -556,9 +550,9 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) xcb_generic_error_t *error; const xcb_query_extension_reply_t *extension; - xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri3_id); - xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_present_id); - xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id); + xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_dri3_id); + xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_present_id); + xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_xfixes_id); extension = xcb_get_extension_data(dri2_dpy->conn, &xcb_dri3_id); if (!(extension && extension->present)) @@ -572,17 +566,14 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) if (!(extension && extension->present)) return EGL_FALSE; - dri3_query_cookie = xcb_dri3_query_version(dri2_dpy->conn, - DRI3_SUPPORTED_MAJOR, - DRI3_SUPPORTED_MINOR); + dri3_query_cookie = xcb_dri3_query_version( + dri2_dpy->conn, DRI3_SUPPORTED_MAJOR, DRI3_SUPPORTED_MINOR); - present_query_cookie = xcb_present_query_version(dri2_dpy->conn, - PRESENT_SUPPORTED_MAJOR, - PRESENT_SUPPORTED_MINOR); + present_query_cookie = xcb_present_query_version( + dri2_dpy->conn, PRESENT_SUPPORTED_MAJOR, PRESENT_SUPPORTED_MINOR); - xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, - XCB_XFIXES_MAJOR_VERSION, - XCB_XFIXES_MINOR_VERSION); + xfixes_query_cookie = xcb_xfixes_query_version( + dri2_dpy->conn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION); dri3_query = xcb_dri3_query_version_reply(dri2_dpy->conn, dri3_query_cookie, &error); @@ -597,9 +588,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) dri2_dpy->dri3_minor_version = dri3_query->minor_version; free(dri3_query); - present_query = - xcb_present_query_version_reply(dri2_dpy->conn, - present_query_cookie, &error); + present_query = xcb_present_query_version_reply( + dri2_dpy->conn, present_query_cookie, &error); if (present_query == NULL || error != NULL) { _eglLog(_EGL_WARNING, "DRI3: failed to query Present version"); free(present_query); @@ -611,9 +601,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) dri2_dpy->present_minor_version = present_query->minor_version; free(present_query); - xfixes_query = - xcb_xfixes_query_version_reply(dri2_dpy->conn, - xfixes_query_cookie, &error); + xfixes_query = xcb_xfixes_query_version_reply(dri2_dpy->conn, + xfixes_query_cookie, &error); if (xfixes_query == NULL || error != NULL || xfixes_query->major_version < 2) { _eglLog(_EGL_WARNING, "DRI3: failed to query xfixes version"); @@ -623,7 +612,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) } free(xfixes_query); - dri2_dpy->fd_render_gpu = loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0); + dri2_dpy->fd_render_gpu = + loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0); if (dri2_dpy->fd_render_gpu < 0) { int conn_error = xcb_connection_has_error(dri2_dpy->conn); _eglLog(_EGL_WARNING, "DRI3: Screen seems not DRI3 capable"); @@ -634,7 +624,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) return EGL_FALSE; } - loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, &dri2_dpy->fd_display_gpu); + loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, + &dri2_dpy->fd_display_gpu); dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu); if (!dri2_dpy->driver_name) { @@ -647,7 +638,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) /* Only try to get a render device name since dri3 doesn't provide a * mechanism for authenticating client opened device node fds. If this * fails then don't advertise the extension. */ - dri2_dpy->device_name = drmGetRenderDeviceNameFromFd(dri2_dpy->fd_render_gpu); + dri2_dpy->device_name = + drmGetRenderDeviceNameFromFd(dri2_dpy->fd_render_gpu); #endif return EGL_TRUE; diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp index d6215ef2445..e76cb927b5b 100644 --- a/src/egl/drivers/haiku/egl_haiku.cpp +++ b/src/egl/drivers/haiku/egl_haiku.cpp @@ -22,8 +22,8 @@ * DEALINGS IN THE SOFTWARE. */ -#include #include +#include #include #include @@ -31,20 +31,20 @@ #include "eglconfig.h" #include "eglcontext.h" +#include "eglcurrent.h" #include "egldevice.h" #include "egldisplay.h" #include "egldriver.h" -#include "eglcurrent.h" +#include "eglimage.h" #include "egllog.h" #include "eglsurface.h" -#include "eglimage.h" #include "egltypedefs.h" -#include -#include "util/u_atomic.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "state_tracker/st_context.h" +#include "util/u_atomic.h" +#include #include "hgl_context.h" #include "hgl_sw_winsys.h" @@ -53,261 +53,260 @@ extern "C" { #include "target-helpers/inline_sw_helper.h" } -#define BGL_RGB 0 -#define BGL_INDEX 1 -#define BGL_SINGLE 0 -#define BGL_DOUBLE 2 -#define BGL_DIRECT 0 -#define BGL_INDIRECT 4 -#define BGL_ACCUM 8 -#define BGL_ALPHA 16 -#define BGL_DEPTH 32 -#define BGL_OVERLAY 64 -#define BGL_UNDERLAY 128 -#define BGL_STENCIL 512 -#define BGL_SHARE_CONTEXT 1024 - +#define BGL_RGB 0 +#define BGL_INDEX 1 +#define BGL_SINGLE 0 +#define BGL_DOUBLE 2 +#define BGL_DIRECT 0 +#define BGL_INDIRECT 4 +#define BGL_ACCUM 8 +#define BGL_ALPHA 16 +#define BGL_DEPTH 32 +#define BGL_OVERLAY 64 +#define BGL_UNDERLAY 128 +#define BGL_STENCIL 512 +#define BGL_SHARE_CONTEXT 1024 #ifdef DEBUG -# define TRACE(x...) printf("egl_haiku: " x) -# define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__) +#define TRACE(x...) printf("egl_haiku: " x) +#define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__) #else -# define TRACE(x...) -# define CALLED() +#define TRACE(x...) +#define CALLED() #endif #define ERROR(x...) printf("egl_haiku: " x) - _EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl) - struct haiku_egl_display { - int ref_count; - struct hgl_display *disp; + int ref_count; + struct hgl_display *disp; }; struct haiku_egl_config { - _EGLConfig base; + _EGLConfig base; }; struct haiku_egl_context { - _EGLContext base; - struct hgl_context *ctx; + _EGLContext base; + struct hgl_context *ctx; }; struct haiku_egl_surface { - _EGLSurface base; - struct hgl_buffer *fb; - struct pipe_fence_handle *throttle_fence; + _EGLSurface base; + struct hgl_buffer *fb; + struct pipe_fence_handle *throttle_fence; }; - // #pragma mark EGLSurface // Called via eglCreateWindowSurface(), drv->CreateWindowSurface(). static _EGLSurface * -haiku_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list) +haiku_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, + void *native_window, const EGLint *attrib_list) { - printf("haiku_create_window_surface\n"); - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + printf("haiku_create_window_surface\n"); + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); - struct haiku_egl_surface *wgl_surf = (struct haiku_egl_surface*)calloc(1, sizeof(*wgl_surf)); - if (!wgl_surf) - return NULL; + struct haiku_egl_surface *wgl_surf = + (struct haiku_egl_surface *)calloc(1, sizeof(*wgl_surf)); + if (!wgl_surf) + return NULL; - if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf, attrib_list, NULL)) { - free(wgl_surf); - return NULL; - } + if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf, + attrib_list, NULL)) { + free(wgl_surf); + return NULL; + } - struct st_visual visual; - hgl_get_st_visual(&visual, BGL_DOUBLE|BGL_DEPTH); + struct st_visual visual; + hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH); - wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, native_window); - if (!wgl_surf->fb) { - free(wgl_surf); - return NULL; - } + wgl_surf->fb = + hgl_create_st_framebuffer(hgl_dpy->disp, &visual, native_window); + if (!wgl_surf->fb) { + free(wgl_surf); + return NULL; + } - return &wgl_surf->base; + return &wgl_surf->base; } - static _EGLSurface * -haiku_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list) +haiku_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, + void *native_pixmap, const EGLint *attrib_list) { - printf("haiku_create_pixmap_surface\n"); - return NULL; + printf("haiku_create_pixmap_surface\n"); + return NULL; } - static _EGLSurface * -haiku_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) +haiku_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, + const EGLint *attrib_list) { - printf("haiku_create_pbuffer_surface\n"); - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + printf("haiku_create_pbuffer_surface\n"); + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); - struct haiku_egl_surface *wgl_surf = (struct haiku_egl_surface*)calloc(1, sizeof(*wgl_surf)); - if (!wgl_surf) - return NULL; + struct haiku_egl_surface *wgl_surf = + (struct haiku_egl_surface *)calloc(1, sizeof(*wgl_surf)); + if (!wgl_surf) + return NULL; - if (!_eglInitSurface(&wgl_surf->base, disp, EGL_PBUFFER_BIT, conf, attrib_list, NULL)) { - free(wgl_surf); - return NULL; - } + if (!_eglInitSurface(&wgl_surf->base, disp, EGL_PBUFFER_BIT, conf, + attrib_list, NULL)) { + free(wgl_surf); + return NULL; + } + struct st_visual visual; + hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH); - struct st_visual visual; - hgl_get_st_visual(&visual, BGL_DOUBLE|BGL_DEPTH); + wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, NULL); + if (!wgl_surf->fb) { + free(wgl_surf); + return NULL; + } - wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, NULL); - if (!wgl_surf->fb) { - free(wgl_surf); - return NULL; - } + wgl_surf->fb->newWidth = wgl_surf->base.Width; + wgl_surf->fb->newHeight = wgl_surf->base.Height; + p_atomic_inc(&wgl_surf->fb->base.stamp); - wgl_surf->fb->newWidth = wgl_surf->base.Width; - wgl_surf->fb->newHeight = wgl_surf->base.Height; - p_atomic_inc(&wgl_surf->fb->base.stamp); - - return &wgl_surf->base; + return &wgl_surf->base; } - static EGLBoolean haiku_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) { - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); - if (_eglPutSurface(surf)) { - struct haiku_egl_surface *hgl_surf = haiku_egl_surface(surf); - struct pipe_screen* screen = hgl_dpy->disp->fscreen->screen; - screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL); - hgl_destroy_st_framebuffer(hgl_surf->fb); - free(surf); - } - return EGL_TRUE; + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + if (_eglPutSurface(surf)) { + struct haiku_egl_surface *hgl_surf = haiku_egl_surface(surf); + struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen; + screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL); + hgl_destroy_st_framebuffer(hgl_surf->fb); + free(surf); + } + return EGL_TRUE; } static void update_size(struct hgl_buffer *buffer) { - uint32_t newWidth, newHeight; - ((BitmapHook*)buffer->winsysContext)->GetSize(newWidth, newHeight); - if (buffer->newWidth != newWidth || buffer->newHeight != newHeight) { - buffer->newWidth = newWidth; - buffer->newHeight = newHeight; - p_atomic_inc(&buffer->base.stamp); - } + uint32_t newWidth, newHeight; + ((BitmapHook *)buffer->winsysContext)->GetSize(newWidth, newHeight); + if (buffer->newWidth != newWidth || buffer->newHeight != newHeight) { + buffer->newWidth = newWidth; + buffer->newHeight = newHeight; + p_atomic_inc(&buffer->base.stamp); + } } static EGLBoolean haiku_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf) { - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); - struct haiku_egl_surface* hgl_surf = haiku_egl_surface(surf); - struct haiku_egl_context* hgl_ctx = haiku_egl_context(surf->CurrentContext); - if (hgl_ctx == NULL) - return EGL_FALSE; + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + struct haiku_egl_surface *hgl_surf = haiku_egl_surface(surf); + struct haiku_egl_context *hgl_ctx = haiku_egl_context(surf->CurrentContext); + if (hgl_ctx == NULL) + return EGL_FALSE; - struct st_context *st = hgl_ctx->ctx->st; - struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen; + struct st_context *st = hgl_ctx->ctx->st; + struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen; - struct hgl_buffer* buffer = hgl_surf->fb; - auto &frontBuffer = buffer->textures[ST_ATTACHMENT_FRONT_LEFT]; - auto &backBuffer = buffer->textures[ST_ATTACHMENT_BACK_LEFT]; + struct hgl_buffer *buffer = hgl_surf->fb; + auto &frontBuffer = buffer->textures[ST_ATTACHMENT_FRONT_LEFT]; + auto &backBuffer = buffer->textures[ST_ATTACHMENT_BACK_LEFT]; - // Inform ST of a flush if double buffering is used - if (backBuffer != NULL) - st->pipe->flush_resource(st->pipe, backBuffer); + // Inform ST of a flush if double buffering is used + if (backBuffer != NULL) + st->pipe->flush_resource(st->pipe, backBuffer); - _mesa_glthread_finish(st->ctx); + _mesa_glthread_finish(st->ctx); - struct pipe_fence_handle *new_fence = NULL; - st_context_flush(st, ST_FLUSH_FRONT, &new_fence, NULL, NULL); - if (hgl_surf->throttle_fence) { - screen->fence_finish(screen, NULL, hgl_surf->throttle_fence, OS_TIMEOUT_INFINITE); - screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL); - } - hgl_surf->throttle_fence = new_fence; + struct pipe_fence_handle *new_fence = NULL; + st_context_flush(st, ST_FLUSH_FRONT, &new_fence, NULL, NULL); + if (hgl_surf->throttle_fence) { + screen->fence_finish(screen, NULL, hgl_surf->throttle_fence, + OS_TIMEOUT_INFINITE); + screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL); + } + hgl_surf->throttle_fence = new_fence; - // flush back buffer and swap buffers if double buffering is used - if (backBuffer != NULL) { - screen->flush_frontbuffer(screen, st->pipe, backBuffer, 0, 0, buffer->winsysContext, NULL); - std::swap(frontBuffer, backBuffer); - p_atomic_inc(&buffer->base.stamp); - } + // flush back buffer and swap buffers if double buffering is used + if (backBuffer != NULL) { + screen->flush_frontbuffer(screen, st->pipe, backBuffer, 0, 0, + buffer->winsysContext, NULL); + std::swap(frontBuffer, backBuffer); + p_atomic_inc(&buffer->base.stamp); + } - // XXX: right front / back if BGL_STEREO? + // XXX: right front / back if BGL_STEREO? - update_size(buffer); + update_size(buffer); - return EGL_TRUE; + return EGL_TRUE; } - // #pragma mark EGLDisplay static EGLBoolean haiku_add_configs_for_visuals(_EGLDisplay *disp) { - CALLED(); + CALLED(); - struct haiku_egl_config* conf; - conf = (struct haiku_egl_config*) calloc(1, sizeof (*conf)); - if (!conf) - return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals"); + struct haiku_egl_config *conf; + conf = (struct haiku_egl_config *)calloc(1, sizeof(*conf)); + if (!conf) + return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals"); - _eglInitConfig(&conf->base, disp, 1); - TRACE("Config inited\n"); + _eglInitConfig(&conf->base, disp, 1); + TRACE("Config inited\n"); - conf->base.RedSize = 8; - conf->base.BlueSize = 8; - conf->base.GreenSize = 8; - conf->base.LuminanceSize = 0; - conf->base.AlphaSize = 8; - conf->base.ColorBufferType = EGL_RGB_BUFFER; - conf->base.BufferSize = conf->base.RedSize - + conf->base.GreenSize - + conf->base.BlueSize - + conf->base.AlphaSize; - conf->base.ConfigCaveat = EGL_NONE; - conf->base.ConfigID = 1; - conf->base.BindToTextureRGB = EGL_FALSE; - conf->base.BindToTextureRGBA = EGL_FALSE; - conf->base.StencilSize = 0; - conf->base.TransparentType = EGL_NONE; - conf->base.NativeRenderable = EGL_TRUE; // Let's say yes - conf->base.NativeVisualID = 0; // No visual - conf->base.NativeVisualType = EGL_NONE; // No visual - conf->base.RenderableType = 0x8; - conf->base.SampleBuffers = 0; // TODO: How to get the right value ? - conf->base.Samples = conf->base.SampleBuffers == 0 ? 0 : 0; - conf->base.DepthSize = 24; // TODO: How to get the right value ? - conf->base.Level = 0; - conf->base.MaxPbufferWidth = _EGL_MAX_PBUFFER_WIDTH; - conf->base.MaxPbufferHeight = _EGL_MAX_PBUFFER_HEIGHT; - conf->base.MaxPbufferPixels = 0; // TODO: How to get the right value ? - conf->base.SurfaceType = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT; + conf->base.RedSize = 8; + conf->base.BlueSize = 8; + conf->base.GreenSize = 8; + conf->base.LuminanceSize = 0; + conf->base.AlphaSize = 8; + conf->base.ColorBufferType = EGL_RGB_BUFFER; + conf->base.BufferSize = conf->base.RedSize + conf->base.GreenSize + + conf->base.BlueSize + conf->base.AlphaSize; + conf->base.ConfigCaveat = EGL_NONE; + conf->base.ConfigID = 1; + conf->base.BindToTextureRGB = EGL_FALSE; + conf->base.BindToTextureRGBA = EGL_FALSE; + conf->base.StencilSize = 0; + conf->base.TransparentType = EGL_NONE; + conf->base.NativeRenderable = EGL_TRUE; // Let's say yes + conf->base.NativeVisualID = 0; // No visual + conf->base.NativeVisualType = EGL_NONE; // No visual + conf->base.RenderableType = 0x8; + conf->base.SampleBuffers = 0; // TODO: How to get the right value ? + conf->base.Samples = conf->base.SampleBuffers == 0 ? 0 : 0; + conf->base.DepthSize = 24; // TODO: How to get the right value ? + conf->base.Level = 0; + conf->base.MaxPbufferWidth = _EGL_MAX_PBUFFER_WIDTH; + conf->base.MaxPbufferHeight = _EGL_MAX_PBUFFER_HEIGHT; + conf->base.MaxPbufferPixels = 0; // TODO: How to get the right value ? + conf->base.SurfaceType = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT; - TRACE("Config configuated\n"); - if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { - _eglLog(_EGL_DEBUG, "Haiku: failed to validate config"); - goto cleanup; - } - TRACE("Validated config\n"); + TRACE("Config configuated\n"); + if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { + _eglLog(_EGL_DEBUG, "Haiku: failed to validate config"); + goto cleanup; + } + TRACE("Validated config\n"); - _eglLinkConfig(&conf->base); - if (!_eglGetArraySize(disp->Configs)) { - _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); - goto cleanup; - } - TRACE("Config successful\n"); + _eglLinkConfig(&conf->base); + if (!_eglGetArraySize(disp->Configs)) { + _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); + goto cleanup; + } + TRACE("Config successful\n"); - return EGL_TRUE; + return EGL_TRUE; cleanup: - free(conf); - return EGL_FALSE; + free(conf); + return EGL_FALSE; } static void @@ -316,209 +315,212 @@ haiku_display_destroy(_EGLDisplay *disp) if (!disp) return; - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); assert(hgl_dpy->ref_count > 0); if (!p_atomic_dec_zero(&hgl_dpy->ref_count)) return; - struct pipe_screen* screen = hgl_dpy->disp->fscreen->screen; - hgl_destroy_display(hgl_dpy->disp); hgl_dpy->disp = NULL; - screen->destroy(screen); // destroy will deallocate object + struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen; + hgl_destroy_display(hgl_dpy->disp); + hgl_dpy->disp = NULL; + screen->destroy(screen); // destroy will deallocate object - free(hgl_dpy); + free(hgl_dpy); } static EGLBoolean haiku_initialize_impl(_EGLDisplay *disp, void *platformDisplay) { - struct haiku_egl_display *hgl_dpy; - const char* err; + struct haiku_egl_display *hgl_dpy; + const char *err; - hgl_dpy = (struct haiku_egl_display*)calloc(1, sizeof(struct haiku_egl_display)); - if (!hgl_dpy) - return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + hgl_dpy = + (struct haiku_egl_display *)calloc(1, sizeof(struct haiku_egl_display)); + if (!hgl_dpy) + return _eglError(EGL_BAD_ALLOC, "eglInitialize"); - hgl_dpy->ref_count = 1; - disp->DriverData = (void *)hgl_dpy; + hgl_dpy->ref_count = 1; + disp->DriverData = (void *)hgl_dpy; - struct sw_winsys* winsys = hgl_create_sw_winsys(); - struct pipe_screen* screen = sw_screen_create(winsys); - hgl_dpy->disp = hgl_create_display(screen); + struct sw_winsys *winsys = hgl_create_sw_winsys(); + struct pipe_screen *screen = sw_screen_create(winsys); + hgl_dpy->disp = hgl_create_display(screen); - disp->ClientAPIs = 0; - if (_eglIsApiValid(EGL_OPENGL_API)) - disp->ClientAPIs |= EGL_OPENGL_BIT; - if (_eglIsApiValid(EGL_OPENGL_ES_API)) - disp->ClientAPIs |= EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR; + disp->ClientAPIs = 0; + if (_eglIsApiValid(EGL_OPENGL_API)) + disp->ClientAPIs |= EGL_OPENGL_BIT; + if (_eglIsApiValid(EGL_OPENGL_ES_API)) + disp->ClientAPIs |= + EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR; - disp->Extensions.KHR_no_config_context = EGL_TRUE; - disp->Extensions.KHR_surfaceless_context = EGL_TRUE; - disp->Extensions.MESA_query_driver = EGL_TRUE; + disp->Extensions.KHR_no_config_context = EGL_TRUE; + disp->Extensions.KHR_surfaceless_context = EGL_TRUE; + disp->Extensions.MESA_query_driver = EGL_TRUE; - /* Report back to EGL the bitmask of priorities supported */ - disp->Extensions.IMG_context_priority = - hgl_dpy->disp->fscreen->screen->get_param(hgl_dpy->disp->fscreen->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK); + /* Report back to EGL the bitmask of priorities supported */ + disp->Extensions.IMG_context_priority = + hgl_dpy->disp->fscreen->screen->get_param(hgl_dpy->disp->fscreen->screen, + PIPE_CAP_CONTEXT_PRIORITY_MASK); - disp->Extensions.EXT_pixel_format_float = EGL_TRUE; + disp->Extensions.EXT_pixel_format_float = EGL_TRUE; - if (hgl_dpy->disp->fscreen->screen->is_format_supported(hgl_dpy->disp->fscreen->screen, - PIPE_FORMAT_B8G8R8A8_SRGB, - PIPE_TEXTURE_2D, 0, 0, - PIPE_BIND_RENDER_TARGET)) - disp->Extensions.KHR_gl_colorspace = EGL_TRUE; + if (hgl_dpy->disp->fscreen->screen->is_format_supported( + hgl_dpy->disp->fscreen->screen, PIPE_FORMAT_B8G8R8A8_SRGB, + PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_RENDER_TARGET)) + disp->Extensions.KHR_gl_colorspace = EGL_TRUE; - disp->Extensions.KHR_create_context = EGL_TRUE; - disp->Extensions.KHR_reusable_sync = EGL_TRUE; + disp->Extensions.KHR_create_context = EGL_TRUE; + disp->Extensions.KHR_reusable_sync = EGL_TRUE; - haiku_add_configs_for_visuals(disp); + haiku_add_configs_for_visuals(disp); - return EGL_TRUE; + return EGL_TRUE; cleanup: - haiku_display_destroy(disp); - return _eglError(EGL_NOT_INITIALIZED, err); + haiku_display_destroy(disp); + return _eglError(EGL_NOT_INITIALIZED, err); } - static EGLBoolean haiku_initialize(_EGLDisplay *disp) { - EGLBoolean ret = EGL_FALSE; - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + EGLBoolean ret = EGL_FALSE; + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); - if (hgl_dpy) { - hgl_dpy->ref_count++; - return EGL_TRUE; - } + if (hgl_dpy) { + hgl_dpy->ref_count++; + return EGL_TRUE; + } - switch (disp->Platform) { - case _EGL_PLATFORM_SURFACELESS: - case _EGL_PLATFORM_HAIKU: - ret = haiku_initialize_impl(disp, NULL); - break; - case _EGL_PLATFORM_DEVICE: - ret = haiku_initialize_impl(disp, disp->PlatformDisplay); - break; - default: - unreachable("Callers ensure we cannot get here."); - return EGL_FALSE; - } + switch (disp->Platform) { + case _EGL_PLATFORM_SURFACELESS: + case _EGL_PLATFORM_HAIKU: + ret = haiku_initialize_impl(disp, NULL); + break; + case _EGL_PLATFORM_DEVICE: + ret = haiku_initialize_impl(disp, disp->PlatformDisplay); + break; + default: + unreachable("Callers ensure we cannot get here."); + return EGL_FALSE; + } - if (!ret) - return EGL_FALSE; + if (!ret) + return EGL_FALSE; - hgl_dpy = haiku_egl_display(disp); + hgl_dpy = haiku_egl_display(disp); - return EGL_TRUE; + return EGL_TRUE; } - static EGLBoolean haiku_terminate(_EGLDisplay *disp) { - haiku_display_destroy(disp); - return EGL_TRUE; + haiku_display_destroy(disp); + return EGL_TRUE; } - // #pragma mark EGLContext -static _EGLContext* +static _EGLContext * haiku_create_context(_EGLDisplay *disp, _EGLConfig *conf, - _EGLContext *share_list, const EGLint *attrib_list) + _EGLContext *share_list, const EGLint *attrib_list) { - CALLED(); + CALLED(); - struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); + struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); - struct st_visual visual; - hgl_get_st_visual(&visual, BGL_DOUBLE|BGL_DEPTH); + struct st_visual visual; + hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH); - struct haiku_egl_context* context = (struct haiku_egl_context*) calloc(1, sizeof (*context)); - if (!context) { - _eglError(EGL_BAD_ALLOC, "haiku_create_context"); - return NULL; - } + struct haiku_egl_context *context = + (struct haiku_egl_context *)calloc(1, sizeof(*context)); + if (!context) { + _eglError(EGL_BAD_ALLOC, "haiku_create_context"); + return NULL; + } - if (!_eglInitContext(&context->base, disp, conf, share_list, attrib_list)) - goto cleanup; + if (!_eglInitContext(&context->base, disp, conf, share_list, attrib_list)) + goto cleanup; - context->ctx = hgl_create_context(hgl_dpy->disp, &visual, share_list == NULL ? NULL : haiku_egl_context(share_list)->ctx->st); - if (context->ctx == NULL) - goto cleanup; + context->ctx = hgl_create_context( + hgl_dpy->disp, &visual, + share_list == NULL ? NULL : haiku_egl_context(share_list)->ctx->st); + if (context->ctx == NULL) + goto cleanup; - return &context->base; + return &context->base; cleanup: - free(context); - return NULL; + free(context); + return NULL; } - static EGLBoolean -haiku_destroy_context(_EGLDisplay *disp, _EGLContext* ctx) +haiku_destroy_context(_EGLDisplay *disp, _EGLContext *ctx) { - if (_eglPutContext(ctx)) { - struct haiku_egl_context* hgl_ctx = haiku_egl_context(ctx); - hgl_destroy_context(hgl_ctx->ctx); - free(ctx); - ctx = NULL; - } - return EGL_TRUE; + if (_eglPutContext(ctx)) { + struct haiku_egl_context *hgl_ctx = haiku_egl_context(ctx); + hgl_destroy_context(hgl_ctx->ctx); + free(ctx); + ctx = NULL; + } + return EGL_TRUE; } - static EGLBoolean -haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf, _EGLContext *ctx) +haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf, + _EGLContext *ctx) { - CALLED(); + CALLED(); - struct haiku_egl_context* hgl_ctx = haiku_egl_context(ctx); - struct haiku_egl_surface* hgl_dsurf = haiku_egl_surface(dsurf); - struct haiku_egl_surface* hgl_rsurf = haiku_egl_surface(rsurf); - _EGLContext *old_ctx; - _EGLSurface *old_dsurf, *old_rsurf; + struct haiku_egl_context *hgl_ctx = haiku_egl_context(ctx); + struct haiku_egl_surface *hgl_dsurf = haiku_egl_surface(dsurf); + struct haiku_egl_surface *hgl_rsurf = haiku_egl_surface(rsurf); + _EGLContext *old_ctx; + _EGLSurface *old_dsurf, *old_rsurf; - if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) - return EGL_FALSE; + if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) + return EGL_FALSE; - if (old_ctx == ctx && old_dsurf == dsurf && old_rsurf == rsurf) { - _eglPutSurface(old_dsurf); - _eglPutSurface(old_rsurf); - _eglPutContext(old_ctx); - return EGL_TRUE; - } + if (old_ctx == ctx && old_dsurf == dsurf && old_rsurf == rsurf) { + _eglPutSurface(old_dsurf); + _eglPutSurface(old_rsurf); + _eglPutContext(old_ctx); + return EGL_TRUE; + } - if (ctx == NULL) { - st_api_make_current(NULL, NULL, NULL); - } else { - if (dsurf != NULL && dsurf != old_dsurf) - update_size(hgl_dsurf->fb); + if (ctx == NULL) { + st_api_make_current(NULL, NULL, NULL); + } else { + if (dsurf != NULL && dsurf != old_dsurf) + update_size(hgl_dsurf->fb); - st_api_make_current(hgl_ctx->ctx->st, - hgl_dsurf == NULL ? NULL : &hgl_dsurf->fb->base, - hgl_rsurf == NULL ? NULL : &hgl_rsurf->fb->base); - } + st_api_make_current(hgl_ctx->ctx->st, + hgl_dsurf == NULL ? NULL : &hgl_dsurf->fb->base, + hgl_rsurf == NULL ? NULL : &hgl_rsurf->fb->base); + } - if (old_dsurf != NULL) haiku_destroy_surface(disp, old_dsurf); - if (old_rsurf != NULL) haiku_destroy_surface(disp, old_rsurf); - if (old_ctx != NULL) haiku_destroy_context(disp, old_ctx); + if (old_dsurf != NULL) + haiku_destroy_surface(disp, old_dsurf); + if (old_rsurf != NULL) + haiku_destroy_surface(disp, old_rsurf); + if (old_ctx != NULL) + haiku_destroy_context(disp, old_ctx); - return EGL_TRUE; + return EGL_TRUE; } - -extern "C" -const _EGLDriver _eglDriver = { - .Initialize = haiku_initialize, - .Terminate = haiku_terminate, - .CreateContext = haiku_create_context, - .DestroyContext = haiku_destroy_context, - .MakeCurrent = haiku_make_current, - .CreateWindowSurface = haiku_create_window_surface, - .CreatePixmapSurface = haiku_create_pixmap_surface, - .CreatePbufferSurface = haiku_create_pbuffer_surface, - .DestroySurface = haiku_destroy_surface, - .SwapBuffers = haiku_swap_buffers, +extern "C" const _EGLDriver _eglDriver = { + .Initialize = haiku_initialize, + .Terminate = haiku_terminate, + .CreateContext = haiku_create_context, + .DestroyContext = haiku_destroy_context, + .MakeCurrent = haiku_make_current, + .CreateWindowSurface = haiku_create_window_surface, + .CreatePixmapSurface = haiku_create_pixmap_surface, + .CreatePbufferSurface = haiku_create_pbuffer_surface, + .DestroySurface = haiku_destroy_surface, + .SwapBuffers = haiku_swap_buffers, }; diff --git a/src/egl/drivers/wgl/egl_wgl.c b/src/egl/drivers/wgl/egl_wgl.c index 17c8357d351..498496417c2 100644 --- a/src/egl/drivers/wgl/egl_wgl.c +++ b/src/egl/drivers/wgl/egl_wgl.c @@ -23,30 +23,30 @@ #include "state_tracker/st_context.h" +#include +#include #include #include -#include -#include #include #include "egl_wgl.h" -#include -#include #include +#include +#include #include #include +#include #include -#include #include +#include #include #include -#include -#include #include "util/u_call_once.h" +#include #include @@ -63,7 +63,8 @@ wgl_match_config(const _EGLConfig *conf, const _EGLConfig *criteria) } static struct wgl_egl_config * -wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config, int id, EGLint surface_type) +wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config, + int id, EGLint surface_type) { struct wgl_egl_config *conf; _EGLConfig base; @@ -134,7 +135,7 @@ wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config, base.ConfigID = EGL_DONT_CARE; base.SurfaceType = EGL_DONT_CARE; num_configs = _eglFilterArray(disp->Configs, (void **)&matching_config, 1, - (_EGLArrayForEach)wgl_match_config, &base); + (_EGLArrayForEach)wgl_match_config, &base); if (num_configs == 1) { conf = (struct wgl_egl_config *)matching_config; @@ -144,8 +145,7 @@ wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config, else /* a similar config type is already added (unlikely) => discard */ return NULL; - } - else if (num_configs == 0) { + } else if (num_configs == 0) { conf = calloc(1, sizeof(*conf)); if (conf == NULL) return NULL; @@ -157,8 +157,7 @@ wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config, conf->base.ConfigID = config_id; _eglLinkConfig(&conf->base); - } - else { + } else { unreachable("duplicates should not be possible"); return NULL; } @@ -178,8 +177,8 @@ wgl_add_configs(_EGLDisplay *disp) // and there's no further filtering needed per-visual for (unsigned i = 1; stw_pixelformat_get_info(i) != NULL; i++) { - struct wgl_egl_config *wgl_conf = wgl_add_config(disp, stw_pixelformat_get_info(i), - config_count + 1, surface_type); + struct wgl_egl_config *wgl_conf = wgl_add_config( + disp, stw_pixelformat_get_info(i), config_count + 1, surface_type); if (wgl_conf) { if (wgl_conf->base.ConfigID == config_count + 1) @@ -200,14 +199,16 @@ wgl_display_destroy(_EGLDisplay *disp) } static int -wgl_egl_st_get_param(struct pipe_frontend_screen *fscreen, enum st_manager_param param) +wgl_egl_st_get_param(struct pipe_frontend_screen *fscreen, + enum st_manager_param param) { /* no-op */ return 0; } static bool -wgl_get_egl_image(struct pipe_frontend_screen *fscreen, void *image, struct st_egl_image *out) +wgl_get_egl_image(struct pipe_frontend_screen *fscreen, void *image, + struct st_egl_image *out) { struct wgl_egl_image *wgl_img = (struct wgl_egl_image *)image; stw_translate_image(wgl_img->img, out); @@ -234,7 +235,7 @@ static EGLBoolean wgl_initialize_impl(_EGLDisplay *disp, HDC hdc) { struct wgl_egl_display *wgl_dpy; - const char* err; + const char *err; wgl_dpy = calloc(1, sizeof(*wgl_dpy)); if (!wgl_dpy) @@ -260,22 +261,22 @@ wgl_initialize_impl(_EGLDisplay *disp, HDC hdc) if (_eglIsApiValid(EGL_OPENGL_API)) disp->ClientAPIs |= EGL_OPENGL_BIT; if (_eglIsApiValid(EGL_OPENGL_ES_API)) - disp->ClientAPIs |= EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR; + disp->ClientAPIs |= + EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR; disp->Extensions.KHR_no_config_context = EGL_TRUE; disp->Extensions.KHR_surfaceless_context = EGL_TRUE; disp->Extensions.MESA_query_driver = EGL_TRUE; /* Report back to EGL the bitmask of priorities supported */ - disp->Extensions.IMG_context_priority = - wgl_dpy->screen->get_param(wgl_dpy->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK); + disp->Extensions.IMG_context_priority = wgl_dpy->screen->get_param( + wgl_dpy->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK); disp->Extensions.EXT_pixel_format_float = EGL_TRUE; - if (wgl_dpy->screen->is_format_supported(wgl_dpy->screen, - PIPE_FORMAT_B8G8R8A8_SRGB, - PIPE_TEXTURE_2D, 0, 0, - PIPE_BIND_RENDER_TARGET)) + if (wgl_dpy->screen->is_format_supported( + wgl_dpy->screen, PIPE_FORMAT_B8G8R8A8_SRGB, PIPE_TEXTURE_2D, 0, 0, + PIPE_BIND_RENDER_TARGET)) disp->Extensions.KHR_gl_colorspace = EGL_TRUE; disp->Extensions.KHR_create_context = EGL_TRUE; @@ -388,14 +389,13 @@ wgl_terminate(_EGLDisplay *disp) * Called via eglCreateContext(), drv->CreateContext(). */ static _EGLContext * -wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, - _EGLContext *share_list, const EGLint *attrib_list) +wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, _EGLContext *share_list, + const EGLint *attrib_list) { struct wgl_egl_context *wgl_ctx; struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp); struct wgl_egl_context *wgl_ctx_shared = wgl_egl_context(share_list); - struct stw_context *shared = - wgl_ctx_shared ? wgl_ctx_shared->ctx : NULL; + struct stw_context *shared = wgl_ctx_shared ? wgl_ctx_shared->ctx : NULL; struct wgl_egl_config *wgl_config = wgl_egl_config(conf); const struct stw_pixelformat_info *stw_config; @@ -414,13 +414,13 @@ wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, profile_mask = WGL_CONTEXT_ES_PROFILE_BIT_EXT; break; case EGL_OPENGL_API: - if ((wgl_ctx->base.ClientMajorVersion >= 4 - || (wgl_ctx->base.ClientMajorVersion == 3 - && wgl_ctx->base.ClientMinorVersion >= 2)) - && wgl_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) + if ((wgl_ctx->base.ClientMajorVersion >= 4 || + (wgl_ctx->base.ClientMajorVersion == 3 && + wgl_ctx->base.ClientMinorVersion >= 2)) && + wgl_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) profile_mask = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; else if (wgl_ctx->base.ClientMajorVersion == 3 && - wgl_ctx->base.ClientMinorVersion == 1) + wgl_ctx->base.ClientMinorVersion == 1) profile_mask = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; else profile_mask = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; @@ -443,8 +443,7 @@ wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, stw_config = wgl_config->stw_config[1]; else stw_config = wgl_config->stw_config[0]; - } - else + } else stw_config = NULL; unsigned flags = 0; @@ -455,14 +454,10 @@ wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, unsigned resetStrategy = WGL_NO_RESET_NOTIFICATION_ARB; if (wgl_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION) resetStrategy = WGL_LOSE_CONTEXT_ON_RESET_ARB; - wgl_ctx->ctx = stw_create_context_attribs(disp->PlatformDisplay, 0, shared, - &wgl_dpy->base, - wgl_ctx->base.ClientMajorVersion, - wgl_ctx->base.ClientMinorVersion, - flags, - profile_mask, - stw_config, - resetStrategy); + wgl_ctx->ctx = stw_create_context_attribs( + disp->PlatformDisplay, 0, shared, &wgl_dpy->base, + wgl_ctx->base.ClientMajorVersion, wgl_ctx->base.ClientMinorVersion, flags, + profile_mask, stw_config, resetStrategy); if (!wgl_ctx->ctx) goto cleanup; @@ -520,8 +515,8 @@ wgl_gl_flush() static void (*glFlush)(void); static util_once_flag once = UTIL_ONCE_FLAG_INIT; - util_call_once_data(&once, - (util_call_once_data_func)wgl_gl_flush_get, &glFlush); + util_call_once_data(&once, (util_call_once_data_func)wgl_gl_flush_get, + &glFlush); /* if glFlush is not available things are horribly broken */ if (!glFlush) { @@ -536,8 +531,8 @@ wgl_gl_flush() * Called via eglMakeCurrent(), drv->MakeCurrent(). */ static EGLBoolean -wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, - _EGLSurface *rsurf, _EGLContext *ctx) +wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf, + _EGLContext *ctx) { struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp); struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); @@ -581,10 +576,10 @@ wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, egl_error = EGL_BAD_MATCH; /* undo the previous _eglBindContext */ - _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf); - assert(&wgl_ctx->base == ctx && - tmp_dsurf == dsurf && - tmp_rsurf == rsurf); + _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, + &tmp_rsurf); + assert(&wgl_ctx->base == ctx && tmp_dsurf == dsurf && + tmp_rsurf == rsurf); _eglPutSurface(dsurf); _eglPutSurface(rsurf); @@ -613,11 +608,10 @@ wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _eglBindContext(ctx, dsurf, rsurf, &tmp_ctx, &tmp_dsurf, &tmp_rsurf); assert(tmp_ctx == old_ctx && tmp_dsurf == old_dsurf && - tmp_rsurf == old_rsurf); + tmp_rsurf == old_rsurf); _eglLog(_EGL_WARNING, "wgl: failed to rebind the previous context"); - } - else { + } else { /* wgl_dpy->core->bindContext succeeded, so take a reference on the * wgl_dpy. This prevents wgl_dpy from being reinitialized when a * EGLDisplay is terminated and then initialized again while a @@ -641,7 +635,7 @@ wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, return EGL_TRUE; } -static _EGLSurface* +static _EGLSurface * wgl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list) { @@ -652,14 +646,17 @@ wgl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, if (!wgl_surf) return NULL; - if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf, attrib_list, native_window)) { + if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf, + attrib_list, native_window)) { free(wgl_surf); return NULL; } - const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1] ? - wgl_conf->stw_config[1] : wgl_conf->stw_config[0]; - wgl_surf->fb = stw_framebuffer_create(native_window, stw_conf, STW_FRAMEBUFFER_EGL_WINDOW, &wgl_dpy->base); + const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1] + ? wgl_conf->stw_config[1] + : wgl_conf->stw_config[0]; + wgl_surf->fb = stw_framebuffer_create( + native_window, stw_conf, STW_FRAMEBUFFER_EGL_WINDOW, &wgl_dpy->base); if (!wgl_surf->fb) { free(wgl_surf); return NULL; @@ -671,7 +668,7 @@ wgl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, return &wgl_surf->base; } -static _EGLSurface* +static _EGLSurface * wgl_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list) { @@ -682,14 +679,17 @@ wgl_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, if (!wgl_surf) return NULL; - if (!_eglInitSurface(&wgl_surf->base, disp, EGL_PBUFFER_BIT, conf, attrib_list, NULL)) { + if (!_eglInitSurface(&wgl_surf->base, disp, EGL_PBUFFER_BIT, conf, + attrib_list, NULL)) { free(wgl_surf); return NULL; } - const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1] ? - wgl_conf->stw_config[1] : wgl_conf->stw_config[0]; - wgl_surf->fb = stw_pbuffer_create(stw_conf, wgl_surf->base.Width, wgl_surf->base.Height, &wgl_dpy->base); + const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1] + ? wgl_conf->stw_config[1] + : wgl_conf->stw_config[0]; + wgl_surf->fb = stw_pbuffer_create(stw_conf, wgl_surf->base.Width, + wgl_surf->base.Height, &wgl_dpy->base); if (!wgl_surf->fb) { free(wgl_surf); return NULL; @@ -702,8 +702,8 @@ wgl_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, } static EGLBoolean -wgl_query_surface(_EGLDisplay *disp, _EGLSurface *surf, - EGLint attribute, EGLint *value) +wgl_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint *value) { struct wgl_egl_surface *wgl_surf = wgl_egl_surface(surf); RECT client_rect; @@ -733,7 +733,8 @@ wgl_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) if (!_eglBindTexImage(disp, surf, buffer)) return EGL_FALSE; - struct pipe_resource *pres = stw_get_framebuffer_resource(wgl_surf->fb->drawable, ST_ATTACHMENT_FRONT_LEFT); + struct pipe_resource *pres = stw_get_framebuffer_resource( + wgl_surf->fb->drawable, ST_ATTACHMENT_FRONT_LEFT); enum pipe_format format = pres->format; switch (surf->TextureFormat) { @@ -771,8 +772,7 @@ wgl_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) assert(!"Unexpected texture target in wgl_bind_tex_image()"); } - st_context_teximage(wgl_ctx->ctx->st, GL_TEXTURE_2D, 0, format, pres, - false); + st_context_teximage(wgl_ctx->ctx->st, GL_TEXTURE_2D, 0, format, pres, false); return EGL_TRUE; } @@ -803,7 +803,8 @@ wgl_wait_client(_EGLDisplay *disp, _EGLContext *ctx) { struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); struct pipe_fence_handle *fence = NULL; - st_context_flush(wgl_ctx->ctx->st, ST_FLUSH_END_OF_FRAME | ST_FLUSH_WAIT, &fence, NULL, NULL); + st_context_flush(wgl_ctx->ctx->st, ST_FLUSH_END_OF_FRAME | ST_FLUSH_WAIT, + &fence, NULL, NULL); return EGL_TRUE; } @@ -839,13 +840,12 @@ egl_error_from_stw_image_error(enum stw_image_error err) static _EGLImage * wgl_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, - EGLenum target, - EGLClientBuffer buffer, - const EGLint *attr_list) + EGLenum target, EGLClientBuffer buffer, + const EGLint *attr_list) { struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); struct wgl_egl_image *wgl_img; - GLuint texture = (GLuint) (uintptr_t) buffer; + GLuint texture = (GLuint)(uintptr_t)buffer; _EGLImageAttribs attrs; GLuint depth; GLenum gl_target; @@ -890,12 +890,8 @@ wgl_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, _eglInitImage(&wgl_img->base, disp); - wgl_img->img = stw_create_image_from_texture(wgl_ctx->ctx, - gl_target, - texture, - depth, - attrs.GLTextureLevel, - &error); + wgl_img->img = stw_create_image_from_texture( + wgl_ctx->ctx, gl_target, texture, depth, attrs.GLTextureLevel, &error); assert(!!wgl_img->img == (error == STW_IMAGE_ERROR_SUCCESS)); if (!wgl_img->img) { @@ -908,12 +904,12 @@ wgl_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, static _EGLImage * wgl_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, - EGLClientBuffer buffer, - const EGLint *attr_list) + EGLClientBuffer buffer, + const EGLint *attr_list) { struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); struct wgl_egl_image *wgl_img; - GLuint renderbuffer = (GLuint) (uintptr_t) buffer; + GLuint renderbuffer = (GLuint)(uintptr_t)buffer; enum stw_image_error error; if (renderbuffer == 0) { @@ -929,7 +925,8 @@ wgl_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, _eglInitImage(&wgl_img->base, disp); - wgl_img->img = stw_create_image_from_renderbuffer(wgl_ctx->ctx, renderbuffer, &error); + wgl_img->img = + stw_create_image_from_renderbuffer(wgl_ctx->ctx, renderbuffer, &error); assert(!!wgl_img->img == (error == STW_IMAGE_ERROR_SUCCESS)); if (!wgl_img->img) { @@ -943,7 +940,7 @@ wgl_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx, static _EGLImage * wgl_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target, - EGLClientBuffer buffer, const EGLint *attr_list) + EGLClientBuffer buffer, const EGLint *attr_list) { switch (target) { case EGL_GL_TEXTURE_2D_KHR: @@ -973,7 +970,8 @@ wgl_destroy_image_khr(_EGLDisplay *disp, _EGLImage *img) } static _EGLSync * -wgl_create_sync_khr(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list) +wgl_create_sync_khr(_EGLDisplay *disp, EGLenum type, + const EGLAttrib *attrib_list) { _EGLContext *ctx = _eglGetCurrentContext(); @@ -1017,7 +1015,8 @@ wgl_create_sync_khr(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_lis } static void -wgl_egl_unref_sync(struct wgl_egl_display *wgl_dpy, struct wgl_egl_sync *wgl_sync) +wgl_egl_unref_sync(struct wgl_egl_display *wgl_dpy, + struct wgl_egl_sync *wgl_sync) { if (InterlockedDecrement((volatile LONG *)&wgl_sync->refcount) > 0) return; @@ -1039,7 +1038,8 @@ wgl_destroy_sync_khr(_EGLDisplay *disp, _EGLSync *sync) } static EGLint -wgl_client_wait_sync_khr(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, EGLTime timeout) +wgl_client_wait_sync_khr(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, + EGLTime timeout) { _EGLContext *ctx = _eglGetCurrentContext(); struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp); @@ -1053,7 +1053,8 @@ wgl_client_wait_sync_khr(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, EGLTim switch (sync->Type) { case EGL_SYNC_FENCE_KHR: - if (wgl_dpy->screen->fence_finish(wgl_dpy->screen, NULL, wgl_sync->fence, timeout)) + if (wgl_dpy->screen->fence_finish(wgl_dpy->screen, NULL, wgl_sync->fence, + timeout)) wgl_sync->base.SyncStatus = EGL_SIGNALED_KHR; else ret = EGL_TIMEOUT_EXPIRED_KHR; @@ -1066,7 +1067,9 @@ wgl_client_wait_sync_khr(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, EGLTim wgl_gl_flush(); } - DWORD wait_milliseconds = (timeout == EGL_FOREVER_KHR) ? INFINITE : (DWORD)(timeout / 1000000ull); + DWORD wait_milliseconds = (timeout == EGL_FOREVER_KHR) + ? INFINITE + : (DWORD)(timeout / 1000000ull); DWORD wait_ret = WaitForSingleObject(wgl_sync->event, wait_milliseconds); switch (wait_ret) { case WAIT_OBJECT_0: @@ -1082,10 +1085,10 @@ wgl_client_wait_sync_khr(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, EGLTim break; } break; - } - wgl_egl_unref_sync(wgl_dpy, wgl_sync); + } + wgl_egl_unref_sync(wgl_dpy, wgl_sync); - return ret; + return ret; } static EGLint @@ -1159,8 +1162,8 @@ wgl_interop_export_object(_EGLDisplay *disp, _EGLContext *ctx, } static int -wgl_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, - unsigned count, struct mesa_glinterop_export_in *objects, +wgl_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, unsigned count, + struct mesa_glinterop_export_in *objects, GLsync *sync) { struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); @@ -1196,4 +1199,3 @@ struct _egl_driver _eglDriver = { .GLInteropExportObject = wgl_interop_export_object, .GLInteropFlushObjects = wgl_interop_flush_objects, }; - diff --git a/src/egl/drivers/wgl/egl_wgl.h b/src/egl/drivers/wgl/egl_wgl.h index e5ba680b757..d77304a3d1e 100644 --- a/src/egl/drivers/wgl/egl_wgl.h +++ b/src/egl/drivers/wgl/egl_wgl.h @@ -23,49 +23,43 @@ #pragma once -#include -#include #include +#include +#include #include #include -#include #include +#include -struct wgl_egl_display -{ +struct wgl_egl_display { struct pipe_frontend_screen base; _EGLDisplay *parent; int ref_count; struct pipe_screen *screen; }; -struct wgl_egl_config -{ - _EGLConfig base; +struct wgl_egl_config { + _EGLConfig base; const struct stw_pixelformat_info *stw_config[2]; }; -struct wgl_egl_context -{ +struct wgl_egl_context { _EGLContext base; struct stw_context *ctx; }; -struct wgl_egl_surface -{ +struct wgl_egl_surface { _EGLSurface base; struct stw_framebuffer *fb; }; -struct wgl_egl_image -{ +struct wgl_egl_image { _EGLImage base; struct stw_image *img; }; -struct wgl_egl_sync -{ +struct wgl_egl_sync { _EGLSync base; int refcount; struct pipe_fence_handle *fence; diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 8830b4073d4..ea8a011467e 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -27,7 +27,6 @@ * **************************************************************************/ - /** * Public EGL API entrypoints * @@ -82,7 +81,6 @@ * */ - #ifdef USE_LIBGLVND #define EGLAPI #undef PUBLIC @@ -95,23 +93,23 @@ #include #include "c11/threads.h" #include "mapi/glapi/glapi.h" -#include "util/u_debug.h" #include "util/macros.h" #include "util/perf/cpu_trace.h" +#include "util/u_debug.h" -#include "egldefines.h" -#include "eglglobals.h" -#include "eglcontext.h" -#include "egldisplay.h" -#include "egltypedefs.h" -#include "eglcurrent.h" -#include "egldevice.h" -#include "egldriver.h" -#include "eglsurface.h" #include "eglconfig.h" +#include "eglcontext.h" +#include "eglcurrent.h" +#include "egldefines.h" +#include "egldevice.h" +#include "egldisplay.h" +#include "egldriver.h" +#include "eglglobals.h" #include "eglimage.h" -#include "eglsync.h" #include "egllog.h" +#include "eglsurface.h" +#include "eglsync.h" +#include "egltypedefs.h" #include "GL/mesa_glinterop.h" @@ -120,51 +118,48 @@ * * These macros will unlock the display and record the error code. */ -#define RETURN_EGL_ERROR(disp, err, ret) \ - do { \ - if (disp) \ - _eglUnlockDisplay(disp); \ - /* EGL error codes are non-zero */ \ - if (err) \ - _eglError(err, __func__); \ - return ret; \ +#define RETURN_EGL_ERROR(disp, err, ret) \ + do { \ + if (disp) \ + _eglUnlockDisplay(disp); \ + /* EGL error codes are non-zero */ \ + if (err) \ + _eglError(err, __func__); \ + return ret; \ } while (0) -#define RETURN_EGL_SUCCESS(disp, ret) \ - RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret) +#define RETURN_EGL_SUCCESS(disp, ret) RETURN_EGL_ERROR(disp, EGL_SUCCESS, ret) /* record EGL_SUCCESS only when ret evaluates to true */ -#define RETURN_EGL_EVAL(disp, ret) \ +#define RETURN_EGL_EVAL(disp, ret) \ RETURN_EGL_ERROR(disp, (ret) ? EGL_SUCCESS : 0, ret) - /* * A bunch of macros and checks to simplify error checking. */ -#define _EGL_CHECK_DISPLAY(disp, ret) \ - do { \ - if (!_eglCheckDisplay(disp, __func__)) \ - RETURN_EGL_ERROR(disp, 0, ret); \ +#define _EGL_CHECK_DISPLAY(disp, ret) \ + do { \ + if (!_eglCheckDisplay(disp, __func__)) \ + RETURN_EGL_ERROR(disp, 0, ret); \ } while (0) -#define _EGL_CHECK_OBJECT(disp, type, obj, ret) \ - do { \ - if (!_eglCheck ## type(disp, obj, __func__)) \ - RETURN_EGL_ERROR(disp, 0, ret); \ +#define _EGL_CHECK_OBJECT(disp, type, obj, ret) \ + do { \ + if (!_eglCheck##type(disp, obj, __func__)) \ + RETURN_EGL_ERROR(disp, 0, ret); \ } while (0) -#define _EGL_CHECK_SURFACE(disp, surf, ret) \ +#define _EGL_CHECK_SURFACE(disp, surf, ret) \ _EGL_CHECK_OBJECT(disp, Surface, surf, ret) -#define _EGL_CHECK_CONTEXT(disp, context, ret) \ +#define _EGL_CHECK_CONTEXT(disp, context, ret) \ _EGL_CHECK_OBJECT(disp, Context, context, ret) -#define _EGL_CHECK_CONFIG(disp, conf, ret) \ +#define _EGL_CHECK_CONFIG(disp, conf, ret) \ _EGL_CHECK_OBJECT(disp, Config, conf, ret) -#define _EGL_CHECK_SYNC(disp, s, ret) \ - _EGL_CHECK_OBJECT(disp, Sync, s, ret) +#define _EGL_CHECK_SYNC(disp, s, ret) _EGL_CHECK_OBJECT(disp, Sync, s, ret) static _EGLResource ** _egl_relax_begin(_EGLDisplay *disp, _EGLResource **rs, unsigned rs_count) @@ -191,21 +186,19 @@ _egl_relax_end(_EGLDisplay *disp, _EGLResource **rs, unsigned rs_count) * a reference to a list of _EGLResource's until the lock is re-acquired, * protecting the resources from destruction while the BDL is dropped. */ -#define egl_relax(disp, ...) \ - for (_EGLResource *__rs[] = {NULL /* for vs2019 */, __VA_ARGS__}, \ - **__rsp = _egl_relax_begin(disp, __rs, ARRAY_SIZE(__rs)); \ - __rsp; \ - __rsp = _egl_relax_end(disp, __rs, ARRAY_SIZE(__rs))) +#define egl_relax(disp, ...) \ + for (_EGLResource * __rs[] = {NULL /* for vs2019 */, __VA_ARGS__}, \ + **__rsp = \ + _egl_relax_begin(disp, __rs, ARRAY_SIZE(__rs)); \ + __rsp; __rsp = _egl_relax_end(disp, __rs, ARRAY_SIZE(__rs))) extern const _EGLDriver _eglDriver; - struct _egl_entrypoint { const char *name; _EGLProc function; }; - static inline bool _eglCheckDisplay(_EGLDisplay *disp, const char *msg) { @@ -220,7 +213,6 @@ _eglCheckDisplay(_EGLDisplay *disp, const char *msg) return true; } - static inline bool _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) { @@ -233,7 +225,6 @@ _eglCheckSurface(_EGLDisplay *disp, _EGLSurface *surf, const char *msg) return true; } - static inline bool _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) { @@ -246,7 +237,6 @@ _eglCheckContext(_EGLDisplay *disp, _EGLContext *context, const char *msg) return true; } - static inline bool _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) { @@ -259,7 +249,6 @@ _eglCheckConfig(_EGLDisplay *disp, _EGLConfig *conf, const char *msg) return true; } - static inline bool _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg) { @@ -272,7 +261,6 @@ _eglCheckSync(_EGLDisplay *disp, _EGLSync *s, const char *msg) return true; } - /** * Lookup a handle to find the linked display. * Return NULL if the handle has no corresponding linked display. @@ -284,7 +272,7 @@ _eglLookupDisplay(EGLDisplay dpy) _EGLDisplay *cur = _eglGlobal.DisplayList; while (cur) { - if (cur == (_EGLDisplay *) dpy) + if (cur == (_EGLDisplay *)dpy) break; cur = cur->Next; } @@ -293,7 +281,6 @@ _eglLookupDisplay(EGLDisplay dpy) return cur; } - /** * Lookup and lock a display. */ @@ -334,7 +321,8 @@ _eglUnlockDisplay(_EGLDisplay *disp) } static void -_eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EGLResource *object) +_eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, + _EGLResource *object) { _EGLThreadInfo *thr = _eglGetCurrentThread(); thr->CurrentFuncName = funcName; @@ -348,11 +336,11 @@ _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EG thr->CurrentObjectLabel = object->Label; } -#define _EGL_FUNC_START(disp, objectType, object) \ - do { \ - MESA_TRACE_FUNC(); \ - _eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object); \ - } while(0) +#define _EGL_FUNC_START(disp, objectType, object) \ + do { \ + MESA_TRACE_FUNC(); \ + _eglSetFuncName(__func__, disp, objectType, (_EGLResource *)object); \ + } while (0) /** * Convert an attribute list from EGLint[] to EGLAttrib[]. @@ -367,7 +355,7 @@ _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list) EGLAttrib *attrib_list; if (int_list) { - while (int_list[2*len] != EGL_NONE) + while (int_list[2 * len] != EGL_NONE) ++len; } @@ -376,25 +364,24 @@ _eglConvertIntsToAttribs(const EGLint *int_list, EGLAttrib **out_attrib_list) return EGL_SUCCESS; } - if (2*len + 1 > SIZE_MAX / sizeof(EGLAttrib)) + if (2 * len + 1 > SIZE_MAX / sizeof(EGLAttrib)) return EGL_BAD_ALLOC; - attrib_list = malloc((2*len + 1) * sizeof(EGLAttrib)); + attrib_list = malloc((2 * len + 1) * sizeof(EGLAttrib)); if (!attrib_list) return EGL_BAD_ALLOC; for (size_t i = 0; i < len; ++i) { - attrib_list[2*i + 0] = int_list[2*i + 0]; - attrib_list[2*i + 1] = int_list[2*i + 1]; + attrib_list[2 * i + 0] = int_list[2 * i + 0]; + attrib_list[2 * i + 1] = int_list[2 * i + 1]; } - attrib_list[2*len] = EGL_NONE; + attrib_list[2 * len] = EGL_NONE; *out_attrib_list = attrib_list; return EGL_SUCCESS; } - static EGLint * _eglConvertAttribsToInt(const EGLAttrib *attr_list) { @@ -413,7 +400,6 @@ _eglConvertAttribsToInt(const EGLAttrib *attr_list) return int_attribs; } - /** * This is typically the first EGL function that an application calls. * It associates a private _EGLDisplay object to the native display. @@ -428,8 +414,8 @@ eglGetDisplay(EGLNativeDisplayType nativeDisplay) util_perfetto_init(); _EGL_FUNC_START(NULL, EGL_OBJECT_THREAD_KHR, NULL); - STATIC_ASSERT(sizeof(void*) == sizeof(nativeDisplay)); - native_display_ptr = (void*) nativeDisplay; + STATIC_ASSERT(sizeof(void *) == sizeof(nativeDisplay)); + native_display_ptr = (void *)nativeDisplay; plat = _eglGetNativePlatform(native_display_ptr); disp = _eglFindDisplay(plat, native_display_ptr, NULL); @@ -445,24 +431,24 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display, switch (platform) { #ifdef HAVE_X11_PLATFORM case EGL_PLATFORM_X11_EXT: - disp = _eglGetX11Display((Display*) native_display, attrib_list); + disp = _eglGetX11Display((Display *)native_display, attrib_list); break; #endif #ifdef HAVE_XCB_PLATFORM case EGL_PLATFORM_XCB_EXT: - disp = _eglGetXcbDisplay((xcb_connection_t*) native_display, attrib_list); + disp = _eglGetXcbDisplay((xcb_connection_t *)native_display, attrib_list); break; #endif #ifdef HAVE_DRM_PLATFORM case EGL_PLATFORM_GBM_MESA: - disp = _eglGetGbmDisplay((struct gbm_device*) native_display, - attrib_list); + disp = + _eglGetGbmDisplay((struct gbm_device *)native_display, attrib_list); break; #endif #ifdef HAVE_WAYLAND_PLATFORM case EGL_PLATFORM_WAYLAND_EXT: - disp = _eglGetWaylandDisplay((struct wl_display*) native_display, - attrib_list); + disp = _eglGetWaylandDisplay((struct wl_display *)native_display, + attrib_list); break; #endif case EGL_PLATFORM_SURFACELESS_MESA: @@ -525,12 +511,11 @@ _eglAppendExtension(char **str, const char *ext) s[len] = '\0'; *str += len; - } - else { + } else { len++; } - return (EGLint) len; + return (EGLint)len; } /** @@ -540,12 +525,12 @@ _eglAppendExtension(char **str, const char *ext) static void _eglCreateExtensionsString(_EGLDisplay *disp) { -#define _EGL_CHECK_EXTENSION(ext) \ - do { \ - if (disp->Extensions.ext) { \ - _eglAppendExtension(&exts, "EGL_" #ext); \ - assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ - } \ +#define _EGL_CHECK_EXTENSION(ext) \ + do { \ + if (disp->Extensions.ext) { \ + _eglAppendExtension(&exts, "EGL_" #ext); \ + assert(exts <= disp->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \ + } \ } while (0) char *exts = disp->ExtensionsString; @@ -620,15 +605,15 @@ _eglCreateExtensionsString(_EGLDisplay *disp) static void _eglCreateAPIsString(_EGLDisplay *disp) { -#define addstr(str) \ - { \ - const size_t old_len = strlen(disp->ClientAPIsString); \ - const size_t add_len = sizeof(str); \ - const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \ - if (old_len + add_len <= max_len) \ - strcat(disp->ClientAPIsString, str " "); \ - else \ - assert(!"disp->ClientAPIsString is not large enough"); \ +#define addstr(str) \ + { \ + const size_t old_len = strlen(disp->ClientAPIsString); \ + const size_t add_len = sizeof(str); \ + const size_t max_len = sizeof(disp->ClientAPIsString) - 1; \ + if (old_len + add_len <= max_len) \ + strcat(disp->ClientAPIsString, str " "); \ + else \ + assert(!"disp->ClientAPIsString is not large enough"); \ } if (disp->ClientAPIs & EGL_OPENGL_BIT) @@ -651,10 +636,8 @@ _eglComputeVersion(_EGLDisplay *disp) { disp->Version = 14; - if (disp->Extensions.KHR_fence_sync && - disp->Extensions.KHR_cl_event2 && - disp->Extensions.KHR_wait_sync && - disp->Extensions.KHR_image_base && + if (disp->Extensions.KHR_fence_sync && disp->Extensions.KHR_cl_event2 && + disp->Extensions.KHR_wait_sync && disp->Extensions.KHR_image_base && disp->Extensions.KHR_gl_texture_2D_image && disp->Extensions.KHR_gl_texture_3D_image && disp->Extensions.KHR_gl_texture_cubemap_image && @@ -666,7 +649,7 @@ _eglComputeVersion(_EGLDisplay *disp) disp->Extensions.KHR_surfaceless_context) disp->Version = 15; - /* For Android P and below limit the EGL version to 1.4 */ + /* For Android P and below limit the EGL version to 1.4 */ #if defined(ANDROID) && ANDROID_API_LEVEL <= 28 disp->Version = 14; #endif @@ -691,7 +674,8 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) disp->Options.ForceSoftware = debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false); if (disp->Options.ForceSoftware) - _eglLog(_EGL_DEBUG, "Found 'LIBGL_ALWAYS_SOFTWARE' set, will use a CPU renderer"); + _eglLog(_EGL_DEBUG, + "Found 'LIBGL_ALWAYS_SOFTWARE' set, will use a CPU renderer"); const char *env = getenv("MESA_LOADER_DRIVER_OVERRIDE"); disp->Options.Zink = env && !strcmp(env, "zink"); @@ -745,8 +729,8 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) _eglComputeVersion(disp); _eglCreateExtensionsString(disp); _eglCreateAPIsString(disp); - snprintf(disp->VersionString, sizeof(disp->VersionString), - "%d.%d", disp->Version / 10, disp->Version % 10); + snprintf(disp->VersionString, sizeof(disp->VersionString), "%d.%d", + disp->Version / 10, disp->Version % 10); } /* Update applications version of major and minor if not NULL */ @@ -758,7 +742,6 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) RETURN_EGL_SUCCESS(disp, EGL_TRUE); } - PUBLIC EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy) { @@ -786,8 +769,7 @@ eglTerminate(EGLDisplay dpy) RETURN_EGL_SUCCESS(NULL, EGL_TRUE); } - -PUBLIC const char * EGLAPIENTRY +PUBLIC const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name) { _EGLDisplay *disp; @@ -816,10 +798,9 @@ eglQueryString(EGLDisplay dpy, EGLint name) } } - PUBLIC EGLBoolean EGLAPIENTRY -eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, - EGLint config_size, EGLint *num_config) +eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, + EGLint *num_config) { _EGLDisplay *disp = _eglLockDisplay(dpy); EGLBoolean ret; @@ -836,7 +817,6 @@ eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) @@ -851,16 +831,14 @@ eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, if (!num_config) RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); - ret = _eglChooseConfig(disp, attrib_list, configs, - config_size, num_config); + ret = _eglChooseConfig(disp, attrib_list, configs, config_size, num_config); RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY -eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, - EGLint attribute, EGLint *value) +eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, + EGLint *value) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLConfig *conf = _eglLookupConfig(config, disp); @@ -875,7 +853,6 @@ eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) @@ -915,7 +892,6 @@ eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { @@ -932,10 +908,8 @@ eglDestroyContext(EGLDisplay dpy, EGLContext ctx) RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY -eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, - EGLContext ctx) +eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLContext *context = _eglLookupContext(ctx, disp); @@ -987,21 +961,20 @@ eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, * EGL_PROTECTED_CONTENT_EXT attributes of draw is EGL_FALSE, an * EGL_BAD_ACCESS error is generated. */ - if (read_surf && read_surf->ProtectedContent && - draw_surf && !draw_surf->ProtectedContent) + if (read_surf && read_surf->ProtectedContent && draw_surf && + !draw_surf->ProtectedContent) RETURN_EGL_ERROR(disp, EGL_BAD_ACCESS, EGL_FALSE); - egl_relax (disp, &draw_surf->Resource, &read_surf->Resource, &context->Resource) { + egl_relax (disp, &draw_surf->Resource, &read_surf->Resource, + &context->Resource) { ret = disp->Driver->MakeCurrent(disp, draw_surf, read_surf, context); } RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY -eglQueryContext(EGLDisplay dpy, EGLContext ctx, - EGLint attribute, EGLint *value) +eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLContext *context = _eglLookupContext(ctx, disp); @@ -1016,7 +989,6 @@ eglQueryContext(EGLDisplay dpy, EGLContext ctx, RETURN_EGL_EVAL(disp, ret); } - /* In EGL specs 1.4 and 1.5, at the end of sections 3.5.1 and 3.5.4, it says * that if native_surface was already used to create a window or pixmap, we * can't create a new one. This is what this function checks for. @@ -1030,7 +1002,7 @@ _eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface) list = disp->ResourceLists[_EGL_RESOURCE_SURFACE]; while (list) { - _EGLSurface *surf = (_EGLSurface *) list; + _EGLSurface *surf = (_EGLSurface *)list; list = list->Next; @@ -1044,7 +1016,6 @@ _eglNativeSurfaceAlreadyUsed(_EGLDisplay *disp, void *native_surface) return false; } - static EGLSurface _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, void *native_window, const EGLint *attrib_list) @@ -1053,7 +1024,6 @@ _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, _EGLSurface *surf = NULL; EGLSurface ret; - if (native_window == NULL) RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); @@ -1083,14 +1053,14 @@ _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config, RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); egl_relax (disp) { - surf = disp->Driver->CreateWindowSurface(disp, conf, native_window, attrib_list); + surf = disp->Driver->CreateWindowSurface(disp, conf, native_window, + attrib_list); } ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType window, const EGLint *attrib_list) @@ -1098,8 +1068,8 @@ eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL); - STATIC_ASSERT(sizeof(void*) == sizeof(window)); - return _eglCreateWindowSurfaceCommon(disp, config, (void*) window, + STATIC_ASSERT(sizeof(void *) == sizeof(window)); + return _eglCreateWindowSurfaceCommon(disp, config, (void *)window, attrib_list); } @@ -1115,7 +1085,7 @@ _fixupNativeWindow(_EGLDisplay *disp, void *native_window) * `Window*`. Convert `Window*` to `Window` because that's what * dri2_x11_create_window_surface() expects. */ - return (void *)(* (Window*) native_window); + return (void *)(*(Window *)native_window); } #endif #ifdef HAVE_XCB_PLATFORM @@ -1124,7 +1094,7 @@ _fixupNativeWindow(_EGLDisplay *disp, void *native_window) * (i.e., uint32_t *) to xcb_window_t. We have to do an intermediate cast * to uintptr_t, since uint32_t may be smaller than a pointer. */ - return (void *)(uintptr_t) (* (uint32_t*) native_window); + return (void *)(uintptr_t)(*(uint32_t *)native_window); } #endif return native_window; @@ -1144,7 +1114,6 @@ eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, attrib_list); } - PUBLIC EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void *native_window, @@ -1161,8 +1130,8 @@ eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); native_window = _fixupNativeWindow(disp, native_window); - surface = _eglCreateWindowSurfaceCommon(disp, config, native_window, - int_attribs); + surface = + _eglCreateWindowSurfaceCommon(disp, config, native_window, int_attribs); free(int_attribs); return surface; } @@ -1179,7 +1148,7 @@ _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap) * dri2_x11_create_pixmap_surface() expects. */ if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) - return (void *)(* (Pixmap*) native_pixmap); + return (void *)(*(Pixmap *)native_pixmap); #endif #ifdef HAVE_XCB_PLATFORM if (disp && disp->Platform == _EGL_PLATFORM_XCB && native_pixmap != NULL) { @@ -1187,7 +1156,7 @@ _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap) * (i.e., uint32_t *) to xcb_pixmap_t. We have to do an intermediate cast * to uintptr_t, since uint32_t may be smaller than a pointer. */ - return (void *)(uintptr_t) (* (uint32_t*) native_pixmap); + return (void *)(uintptr_t)(*(uint32_t *)native_pixmap); } #endif return native_pixmap; @@ -1228,14 +1197,14 @@ _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config, RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); egl_relax (disp) { - surf = disp->Driver->CreatePixmapSurface(disp, conf, native_pixmap, attrib_list); + surf = disp->Driver->CreatePixmapSurface(disp, conf, native_pixmap, + attrib_list); } ret = (surf) ? _eglLinkSurface(surf) : EGL_NO_SURFACE; RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) @@ -1243,8 +1212,8 @@ eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL); - STATIC_ASSERT(sizeof(void*) == sizeof(pixmap)); - return _eglCreatePixmapSurfaceCommon(disp, config, (void*) pixmap, + STATIC_ASSERT(sizeof(void *) == sizeof(pixmap)); + return _eglCreatePixmapSurfaceCommon(disp, config, (void *)pixmap, attrib_list); } @@ -1261,7 +1230,6 @@ eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, attrib_list); } - PUBLIC EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void *native_pixmap, @@ -1278,13 +1246,12 @@ eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); native_pixmap = _fixupNativePixmap(disp, native_pixmap); - surface = _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, - int_attribs); + surface = + _eglCreatePixmapSurfaceCommon(disp, config, native_pixmap, int_attribs); free(int_attribs); return surface; } - PUBLIC EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) @@ -1308,7 +1275,6 @@ eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { @@ -1327,8 +1293,8 @@ eglDestroySurface(EGLDisplay dpy, EGLSurface surface) } PUBLIC EGLBoolean EGLAPIENTRY -eglQuerySurface(EGLDisplay dpy, EGLSurface surface, - EGLint attribute, EGLint *value) +eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, + EGLint *value) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); @@ -1346,8 +1312,8 @@ eglQuerySurface(EGLDisplay dpy, EGLSurface surface, } PUBLIC EGLBoolean EGLAPIENTRY -eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, - EGLint attribute, EGLint value) +eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, + EGLint value) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); @@ -1361,7 +1327,6 @@ eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { @@ -1379,7 +1344,6 @@ eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { @@ -1397,7 +1361,6 @@ eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval) { @@ -1419,8 +1382,7 @@ eglSwapInterval(EGLDisplay dpy, EGLint interval) if (surf->Type != EGL_WINDOW_BIT) RETURN_EGL_EVAL(disp, EGL_TRUE); - interval = CLAMP(interval, - surf->Config->MinSwapInterval, + interval = CLAMP(interval, surf->Config->MinSwapInterval, surf->Config->MaxSwapInterval); if (surf->SwapInterval != interval && disp->Driver->SwapInterval) { @@ -1437,7 +1399,6 @@ eglSwapInterval(EGLDisplay dpy, EGLint interval) RETURN_EGL_EVAL(disp, ret); } - PUBLIC EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { @@ -1449,12 +1410,11 @@ eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf); _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); - /* surface must be bound to current context in EGL 1.4 */ - #ifndef _EGL_BUILT_IN_DRIVER_HAIKU - if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || - surf != ctx->DrawSurface) +/* surface must be bound to current context in EGL 1.4 */ +#ifndef _EGL_BUILT_IN_DRIVER_HAIKU + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || surf != ctx->DrawSurface) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); - #endif +#endif if (surf->Type != EGL_WINDOW_BIT) RETURN_EGL_EVAL(disp, EGL_TRUE); @@ -1484,7 +1444,6 @@ eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) RETURN_EGL_EVAL(disp, ret); } - static EGLBoolean _eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf, const EGLint *rects, EGLint n_rects) @@ -1495,8 +1454,7 @@ _eglSwapBuffersWithDamageCommon(_EGLDisplay *disp, _EGLSurface *surf, _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); /* surface must be bound to current context in EGL 1.4 */ - if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || - surf != ctx->DrawSurface) + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || surf != ctx->DrawSurface) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); if (surf->Type != EGL_WINDOW_BIT) @@ -1546,8 +1504,8 @@ eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, */ static void -_eglSetDamageRegionKHRClampRects(_EGLSurface* surf, - EGLint *rects, EGLint n_rects) +_eglSetDamageRegionKHRClampRects(_EGLSurface *surf, EGLint *rects, + EGLint n_rects) { EGLint i; EGLint surf_height = surf->Height; @@ -1568,8 +1526,8 @@ _eglSetDamageRegionKHRClampRects(_EGLSurface* surf, } static EGLBoolean EGLAPIENTRY -eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, - EGLint *rects, EGLint n_rects) +eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, EGLint *rects, + EGLint n_rects) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); @@ -1579,8 +1537,7 @@ eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || - surf->Type != EGL_WINDOW_BIT || - ctx->DrawSurface != surf || + surf->Type != EGL_WINDOW_BIT || ctx->DrawSurface != surf || surf->SwapBehavior != EGL_BUFFER_DESTROYED) RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE); @@ -1610,8 +1567,8 @@ eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) void *native_pixmap_ptr; _EGL_FUNC_START(disp, EGL_OBJECT_SURFACE_KHR, surf); - STATIC_ASSERT(sizeof(void*) == sizeof(target)); - native_pixmap_ptr = (void*) target; + STATIC_ASSERT(sizeof(void *) == sizeof(target)); + native_pixmap_ptr = (void *)target; _EGL_CHECK_SURFACE(disp, surf, EGL_FALSE); if (surf->ProtectedContent) @@ -1624,7 +1581,6 @@ eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) RETURN_EGL_EVAL(disp, ret); } - static EGLBoolean _eglWaitClientCommon(void) { @@ -1662,12 +1618,12 @@ eglWaitClient(void) PUBLIC EGLBoolean EGLAPIENTRY eglWaitGL(void) { - /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to eglWaitClient. */ + /* Since we only support OpenGL and GLES, eglWaitGL is equivalent to + * eglWaitClient. */ _EGL_FUNC_START(NULL, EGL_OBJECT_CONTEXT_KHR, _eglGetCurrentContext()); return _eglWaitClientCommon(); } - PUBLIC EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) { @@ -1708,7 +1664,6 @@ eglGetCurrentDisplay(void) RETURN_EGL_SUCCESS(NULL, ret); } - PUBLIC EGLContext EGLAPIENTRY eglGetCurrentContext(void) { @@ -1720,7 +1675,6 @@ eglGetCurrentContext(void) RETURN_EGL_SUCCESS(NULL, ret); } - PUBLIC EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { @@ -1752,7 +1706,6 @@ eglGetCurrentSurface(EGLint readdraw) RETURN_EGL_ERROR(NULL, err, ret); } - PUBLIC EGLint EGLAPIENTRY eglGetError(void) { @@ -1762,7 +1715,6 @@ eglGetError(void) return e; } - /** ** EGL 1.2 **/ @@ -1795,7 +1747,6 @@ eglBindAPI(EGLenum api) RETURN_EGL_SUCCESS(NULL, EGL_TRUE); } - /** * Return the last value set with eglBindAPI(). */ @@ -1811,7 +1762,6 @@ eglQueryAPI(void) RETURN_EGL_SUCCESS(NULL, ret); } - PUBLIC EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, @@ -1828,7 +1778,6 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, RETURN_EGL_ERROR(disp, EGL_BAD_ALLOC, EGL_NO_SURFACE); } - PUBLIC EGLBoolean EGLAPIENTRY eglReleaseThread(void) { @@ -1842,7 +1791,7 @@ eglReleaseThread(void) _EGLDisplay *disp = ctx->Resource.Display; u_rwlock_rdlock(&disp->TerminateLock); - (void) disp->Driver->MakeCurrent(disp, NULL, NULL, NULL); + (void)disp->Driver->MakeCurrent(disp, NULL, NULL, NULL); u_rwlock_rdunlock(&disp->TerminateLock); } @@ -1851,7 +1800,6 @@ eglReleaseThread(void) RETURN_EGL_SUCCESS(NULL, EGL_TRUE); } - static EGLImage _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list) @@ -1872,7 +1820,8 @@ _eglCreateImageCommon(_EGLDisplay *disp, EGLContext ctx, EGLenum target, RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); egl_relax (disp, &context->Resource) { - img = disp->Driver->CreateImageKHR(disp, context, target, buffer, attr_list); + img = + disp->Driver->CreateImageKHR(disp, context, target, buffer, attr_list); } ret = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; @@ -1889,7 +1838,6 @@ eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, return _eglCreateImageCommon(disp, ctx, target, buffer, attr_list); } - PUBLIC EGLImage EGLAPIENTRY eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attr_list) @@ -1909,7 +1857,6 @@ eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, return image; } - static EGLBoolean _eglDestroyImageCommon(_EGLDisplay *disp, _EGLImage *img) { @@ -1945,11 +1892,9 @@ eglDestroyImageKHR(EGLDisplay dpy, EGLImage image) return _eglDestroyImageCommon(disp, img); } - static EGLSync _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list, - EGLBoolean orig_is_EGLAttrib, - EGLenum invalid_type_error) + EGLBoolean orig_is_EGLAttrib, EGLenum invalid_type_error) { _EGLContext *ctx = _eglGetCurrentContext(); _EGLSync *sync = NULL; @@ -2011,7 +1956,6 @@ _eglCreateSync(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list, RETURN_EGL_EVAL(disp, ret); } - static EGLSync EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list) { @@ -2023,15 +1967,14 @@ eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list) EGLint err; if (sizeof(int_list[0]) == sizeof(attrib_list[0])) { - attrib_list = (EGLAttrib *) int_list; + attrib_list = (EGLAttrib *)int_list; } else { err = _eglConvertIntsToAttribs(int_list, &attrib_list); if (err != EGL_SUCCESS) RETURN_EGL_ERROR(disp, err, EGL_NO_SYNC); } - sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE, - EGL_BAD_ATTRIBUTE); + sync = _eglCreateSync(disp, type, attrib_list, EGL_FALSE, EGL_BAD_ATTRIBUTE); if (sizeof(int_list[0]) != sizeof(attrib_list[0])) free(attrib_list); @@ -2040,27 +1983,22 @@ eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *int_list) return sync; } - static EGLSync EGLAPIENTRY eglCreateSync64KHR(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL); - return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, - EGL_BAD_ATTRIBUTE); + return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, EGL_BAD_ATTRIBUTE); } - PUBLIC EGLSync EGLAPIENTRY eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGL_FUNC_START(disp, EGL_OBJECT_DISPLAY_KHR, NULL); - return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, - EGL_BAD_PARAMETER); + return _eglCreateSync(disp, type, attrib_list, EGL_TRUE, EGL_BAD_PARAMETER); } - static EGLBoolean _eglDestroySync(_EGLDisplay *disp, _EGLSync *s) { @@ -2098,10 +2036,9 @@ eglDestroySyncKHR(EGLDisplay dpy, EGLSync sync) return _eglDestroySync(disp, s); } - static EGLint -_eglClientWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, - EGLint flags, EGLTime timeout) +_eglClientWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags, + EGLTime timeout) { EGLint ret = EGL_FALSE; @@ -2121,8 +2058,7 @@ _eglClientWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, } PUBLIC EGLint EGLAPIENTRY -eglClientWaitSync(EGLDisplay dpy, EGLSync sync, - EGLint flags, EGLTime timeout) +eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSync *s = _eglLookupSync(sync, disp); @@ -2131,8 +2067,8 @@ eglClientWaitSync(EGLDisplay dpy, EGLSync sync, } static EGLint EGLAPIENTRY -eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync, - EGLint flags, EGLTime timeout) +eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags, + EGLTime timeout) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSync *s = _eglLookupSync(sync, disp); @@ -2140,7 +2076,6 @@ eglClientWaitSyncKHR(EGLDisplay dpy, EGLSync sync, return _eglClientWaitSyncCommon(disp, s, flags, timeout); } - static EGLint _eglWaitSyncCommon(_EGLDisplay *disp, _EGLSync *s, EGLint flags) { @@ -2173,7 +2108,6 @@ eglWaitSyncKHR(EGLDisplay dpy, EGLSync sync, EGLint flags) return _eglWaitSyncCommon(disp, s, flags); } - PUBLIC EGLBoolean EGLAPIENTRY eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags) { @@ -2187,7 +2121,6 @@ eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags) return _eglWaitSyncCommon(disp, s, flags); } - static EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode) { @@ -2207,9 +2140,9 @@ eglSignalSyncKHR(EGLDisplay dpy, EGLSync sync, EGLenum mode) RETURN_EGL_EVAL(disp, ret); } - static EGLBoolean -_eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAttrib *value) +_eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, + EGLAttrib *value) { EGLBoolean ret; @@ -2224,7 +2157,8 @@ _eglGetSyncAttribCommon(_EGLDisplay *disp, _EGLSync *s, EGLint attribute, EGLAtt } PUBLIC EGLBoolean EGLAPIENTRY -eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value) +eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, + EGLAttrib *value) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSync *s = _eglLookupSync(sync, disp); @@ -2236,9 +2170,9 @@ eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *valu return _eglGetSyncAttribCommon(disp, s, attribute, value); } - static EGLBoolean EGLAPIENTRY -eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value) +eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, + EGLint *value) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSync *s = _eglLookupSync(sync, disp); @@ -2291,8 +2225,8 @@ eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSync sync) } static EGLBoolean EGLAPIENTRY -eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, - EGLint numRects, const EGLint *rects) +eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, EGLint numRects, + const EGLint *rects) { _EGLContext *ctx = _eglGetCurrentContext(); _EGLDisplay *disp = _eglLockDisplay(dpy); @@ -2307,8 +2241,7 @@ eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, RETURN_EGL_EVAL(disp, EGL_FALSE); /* surface must be bound to current context in EGL 1.4 */ - if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || - surf != ctx->DrawSurface) + if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT || surf != ctx->DrawSurface) RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE); egl_relax (disp, &surf->Resource) { @@ -2318,7 +2251,6 @@ eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, RETURN_EGL_EVAL(disp, ret); } - static EGLImage EGLAPIENTRY eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list) { @@ -2339,8 +2271,8 @@ eglCreateDRMImageMESA(EGLDisplay dpy, const EGLint *attr_list) } static EGLBoolean EGLAPIENTRY -eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image, - EGLint *name, EGLint *handle, EGLint *stride) +eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image, EGLint *name, + EGLint *handle, EGLint *stride) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLImage *img = _eglLookupImage(image, disp); @@ -2361,7 +2293,6 @@ eglExportDRMImageMESA(EGLDisplay dpy, EGLImage image, RETURN_EGL_EVAL(disp, ret); } - struct wl_display; static EGLBoolean EGLAPIENTRY @@ -2428,8 +2359,7 @@ eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer, RETURN_EGL_EVAL(disp, ret); } - -static struct wl_buffer * EGLAPIENTRY +static struct wl_buffer *EGLAPIENTRY eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image) { _EGLDisplay *disp = _eglLockDisplay(dpy); @@ -2453,8 +2383,8 @@ eglCreateWaylandBufferFromImageWL(EGLDisplay dpy, EGLImage image) } static EGLBoolean EGLAPIENTRY -eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, - EGLint x, EGLint y, EGLint width, EGLint height) +eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, + EGLint width, EGLint height) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); @@ -2475,9 +2405,8 @@ eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface, } static EGLBoolean EGLAPIENTRY -eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface, - EGLuint64KHR *ust, EGLuint64KHR *msc, - EGLuint64KHR *sbc) +eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface, EGLuint64KHR *ust, + EGLuint64KHR *msc, EGLuint64KHR *sbc) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); @@ -2500,8 +2429,8 @@ eglGetSyncValuesCHROMIUM(EGLDisplay dpy, EGLSurface surface, } static EGLBoolean EGLAPIENTRY -eglGetMscRateANGLE(EGLDisplay dpy, EGLSurface surface, - EGLint *numerator, EGLint *denominator) +eglGetMscRateANGLE(EGLDisplay dpy, EGLSurface surface, EGLint *numerator, + EGLint *denominator) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLSurface *surf = _eglLookupSurface(surface, disp); @@ -2522,9 +2451,8 @@ eglGetMscRateANGLE(EGLDisplay dpy, EGLSurface surface, } static EGLBoolean EGLAPIENTRY -eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image, - EGLint *fourcc, EGLint *nplanes, - EGLuint64KHR *modifiers) +eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image, EGLint *fourcc, + EGLint *nplanes, EGLuint64KHR *modifiers) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLImage *img = _eglLookupImage(image, disp); @@ -2539,15 +2467,16 @@ eglExportDMABUFImageQueryMESA(EGLDisplay dpy, EGLImage image, RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); egl_relax (disp, &img->Resource) { - ret = disp->Driver->ExportDMABUFImageQueryMESA(disp, img, fourcc, nplanes, modifiers); + ret = disp->Driver->ExportDMABUFImageQueryMESA(disp, img, fourcc, nplanes, + modifiers); } RETURN_EGL_EVAL(disp, ret); } static EGLBoolean EGLAPIENTRY -eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image, - int *fds, EGLint *strides, EGLint *offsets) +eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image, int *fds, + EGLint *strides, EGLint *offsets) { _EGLDisplay *disp = _eglLockDisplay(dpy); _EGLImage *img = _eglLookupImage(image, disp); @@ -2562,7 +2491,8 @@ eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImage image, RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE); egl_relax (disp, &img->Resource) { - ret = disp->Driver->ExportDMABUFImageMESA(disp, img, fds, strides, offsets); + ret = + disp->Driver->ExportDMABUFImageMESA(disp, img, fds, strides, offsets); } RETURN_EGL_EVAL(disp, ret); @@ -2580,8 +2510,8 @@ eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, if (objectType == EGL_OBJECT_THREAD_KHR) { _EGLThreadInfo *t = _eglGetCurrentThread(); - t->Label = label; - return EGL_SUCCESS; + t->Label = label; + return EGL_SUCCESS; } disp = _eglLockDisplay(dpy); @@ -2589,7 +2519,7 @@ eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, RETURN_EGL_ERROR(disp, EGL_BAD_DISPLAY, EGL_BAD_DISPLAY); if (objectType == EGL_OBJECT_DISPLAY_KHR) { - if (dpy != (EGLDisplay) object) + if (dpy != (EGLDisplay)object) RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); disp->Label = label; @@ -2597,25 +2527,25 @@ eglLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, } switch (objectType) { - case EGL_OBJECT_CONTEXT_KHR: - type = _EGL_RESOURCE_CONTEXT; - break; - case EGL_OBJECT_SURFACE_KHR: - type = _EGL_RESOURCE_SURFACE; - break; - case EGL_OBJECT_IMAGE_KHR: - type = _EGL_RESOURCE_IMAGE; - break; - case EGL_OBJECT_SYNC_KHR: - type = _EGL_RESOURCE_SYNC; - break; - case EGL_OBJECT_STREAM_KHR: - default: - RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); + case EGL_OBJECT_CONTEXT_KHR: + type = _EGL_RESOURCE_CONTEXT; + break; + case EGL_OBJECT_SURFACE_KHR: + type = _EGL_RESOURCE_SURFACE; + break; + case EGL_OBJECT_IMAGE_KHR: + type = _EGL_RESOURCE_IMAGE; + break; + case EGL_OBJECT_SYNC_KHR: + type = _EGL_RESOURCE_SYNC; + break; + case EGL_OBJECT_STREAM_KHR: + default: + RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_BAD_PARAMETER); } if (_eglCheckResource(object, type, disp)) { - _EGLResource *res = (_EGLResource *) object; + _EGLResource *res = (_EGLResource *)object; res->Label = label; RETURN_EGL_EVAL(disp, EGL_SUCCESS); @@ -2654,7 +2584,8 @@ eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback, // debug callback, and return the error code. simple_mtx_unlock(_eglGlobal.Mutex); _eglDebugReport(EGL_BAD_ATTRIBUTE, NULL, EGL_DEBUG_MSG_ERROR_KHR, - "Invalid attribute 0x%04lx", (unsigned long) attrib_list[i]); + "Invalid attribute 0x%04lx", + (unsigned long)attrib_list[i]); return EGL_BAD_ATTRIBUTE; } } @@ -2665,7 +2596,8 @@ eglDebugMessageControlKHR(EGLDEBUGPROCKHR callback, _eglGlobal.debugTypesEnabled = newEnabled; } else { _eglGlobal.debugCallback = NULL; - _eglGlobal.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR; + _eglGlobal.debugTypesEnabled = + _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR; } simple_mtx_unlock(_eglGlobal.Mutex); @@ -2690,12 +2622,12 @@ eglQueryDebugKHR(EGLint attribute, EGLAttrib *value) *value = EGL_FALSE; break; case EGL_DEBUG_CALLBACK_KHR: - *value = (EGLAttrib) _eglGlobal.debugCallback; + *value = (EGLAttrib)_eglGlobal.debugCallback; break; default: simple_mtx_unlock(_eglGlobal.Mutex); _eglDebugReport(EGL_BAD_ATTRIBUTE, NULL, EGL_DEBUG_MSG_ERROR_KHR, - "Invalid attribute 0x%04lx", (unsigned long) attribute); + "Invalid attribute 0x%04lx", (unsigned long)attribute); return EGL_FALSE; } @@ -2712,18 +2644,19 @@ _eglFunctionCompare(const void *key, const void *elem) } static EGLBoolean EGLAPIENTRY -eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats, - EGLint *formats, EGLint *num_formats) +eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats, EGLint *formats, + EGLint *num_formats) { _EGLDisplay *disp = _eglLockDisplay(dpy); - EGLBoolean ret = EGL_FALSE; + EGLBoolean ret = EGL_FALSE; _EGL_FUNC_START(NULL, EGL_NONE, NULL); _EGL_CHECK_DISPLAY(disp, EGL_FALSE); egl_relax (disp) { - ret = disp->Driver->QueryDmaBufFormatsEXT(disp, max_formats, formats, num_formats); + ret = disp->Driver->QueryDmaBufFormatsEXT(disp, max_formats, formats, + num_formats); } RETURN_EGL_EVAL(disp, ret); @@ -2742,8 +2675,8 @@ eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers, _EGL_CHECK_DISPLAY(disp, EGL_FALSE); egl_relax (disp) { - ret = disp->Driver->QueryDmaBufModifiersEXT(disp, format, max_modifiers, modifiers, - external_only, num_modifiers); + ret = disp->Driver->QueryDmaBufModifiersEXT( + disp, format, max_modifiers, modifiers, external_only, num_modifiers); } RETURN_EGL_EVAL(disp, ret); @@ -2773,9 +2706,7 @@ eglSetBlobCacheFuncsANDROID(EGLDisplay *dpy, EGLSetBlobFuncANDROID set, } static EGLBoolean EGLAPIENTRY -eglQueryDeviceAttribEXT(EGLDeviceEXT device, - EGLint attribute, - EGLAttrib *value) +eglQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib *value) { _EGLDevice *dev = _eglLookupDevice(device); EGLBoolean ret; @@ -2788,9 +2719,8 @@ eglQueryDeviceAttribEXT(EGLDeviceEXT device, RETURN_EGL_EVAL(NULL, ret); } -static const char * EGLAPIENTRY -eglQueryDeviceStringEXT(EGLDeviceEXT device, - EGLint name) +static const char *EGLAPIENTRY +eglQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name) { _EGLDevice *dev = _eglLookupDevice(device); @@ -2802,22 +2732,18 @@ eglQueryDeviceStringEXT(EGLDeviceEXT device, } static EGLBoolean EGLAPIENTRY -eglQueryDevicesEXT(EGLint max_devices, - EGLDeviceEXT *devices, +eglQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices) { EGLBoolean ret; _EGL_FUNC_START(NULL, EGL_NONE, NULL); - ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **) devices, - num_devices); + ret = _eglQueryDevicesEXT(max_devices, (_EGLDevice **)devices, num_devices); RETURN_EGL_EVAL(NULL, ret); } static EGLBoolean EGLAPIENTRY -eglQueryDisplayAttribEXT(EGLDisplay dpy, - EGLint attribute, - EGLAttrib *value) +eglQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib *value) { _EGLDisplay *disp = _eglLockDisplay(dpy); @@ -2826,7 +2752,7 @@ eglQueryDisplayAttribEXT(EGLDisplay dpy, switch (attribute) { case EGL_DEVICE_EXT: - *value = (EGLAttrib) disp->Device; + *value = (EGLAttrib)disp->Device; break; default: RETURN_EGL_ERROR(disp, EGL_BAD_ATTRIBUTE, EGL_FALSE); @@ -2834,41 +2760,41 @@ eglQueryDisplayAttribEXT(EGLDisplay dpy, RETURN_EGL_SUCCESS(disp, EGL_TRUE); } -static char * EGLAPIENTRY +static char *EGLAPIENTRY eglGetDisplayDriverConfig(EGLDisplay dpy) { - _EGLDisplay *disp = _eglLockDisplay(dpy); - char *ret; + _EGLDisplay *disp = _eglLockDisplay(dpy); + char *ret; - _EGL_FUNC_START(disp, EGL_NONE, NULL); - _EGL_CHECK_DISPLAY(disp, NULL); + _EGL_FUNC_START(disp, EGL_NONE, NULL); + _EGL_CHECK_DISPLAY(disp, NULL); - assert(disp->Extensions.MESA_query_driver); + assert(disp->Extensions.MESA_query_driver); - ret = disp->Driver->QueryDriverConfig(disp); - RETURN_EGL_EVAL(disp, ret); + ret = disp->Driver->QueryDriverConfig(disp); + RETURN_EGL_EVAL(disp, ret); } -static const char * EGLAPIENTRY +static const char *EGLAPIENTRY eglGetDisplayDriverName(EGLDisplay dpy) { - _EGLDisplay *disp = _eglLockDisplay(dpy); - const char *ret; + _EGLDisplay *disp = _eglLockDisplay(dpy); + const char *ret; - _EGL_FUNC_START(disp, EGL_NONE, NULL); - _EGL_CHECK_DISPLAY(disp, NULL); + _EGL_FUNC_START(disp, EGL_NONE, NULL); + _EGL_CHECK_DISPLAY(disp, NULL); - assert(disp->Extensions.MESA_query_driver); + assert(disp->Extensions.MESA_query_driver); - ret = disp->Driver->QueryDriverName(disp); - RETURN_EGL_EVAL(disp, ret); + ret = disp->Driver->QueryDriverName(disp); + RETURN_EGL_EVAL(disp, ret); } PUBLIC __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname) { static const struct _egl_entrypoint egl_functions[] = { -#define EGL_ENTRYPOINT(f) { .name = #f, .function = (_EGLProc) f }, +#define EGL_ENTRYPOINT(f) {.name = #f, .function = (_EGLProc)f}, #include "eglentrypoint.h" #undef EGL_ENTRYPOINT }; @@ -2881,10 +2807,8 @@ eglGetProcAddress(const char *procname) if (strncmp(procname, "egl", 3) == 0) { const struct _egl_entrypoint *entrypoint = - bsearch(procname, - egl_functions, ARRAY_SIZE(egl_functions), - sizeof(egl_functions[0]), - _eglFunctionCompare); + bsearch(procname, egl_functions, ARRAY_SIZE(egl_functions), + sizeof(egl_functions[0]), _eglFunctionCompare); if (entrypoint) ret = entrypoint->function; } @@ -2896,8 +2820,8 @@ eglGetProcAddress(const char *procname) } static int -_eglLockDisplayInterop(EGLDisplay dpy, EGLContext context, - _EGLDisplay **disp, _EGLContext **ctx) +_eglLockDisplayInterop(EGLDisplay dpy, EGLContext context, _EGLDisplay **disp, + _EGLContext **ctx) { *disp = _eglLockDisplay(dpy); @@ -2960,8 +2884,8 @@ MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context, } PUBLIC int -MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context, - unsigned count, struct mesa_glinterop_export_in *objects, +MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context, unsigned count, + struct mesa_glinterop_export_in *objects, GLsync *sync) { _EGLDisplay *disp; @@ -2973,7 +2897,8 @@ MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context, return ret; if (disp->Driver->GLInteropFlushObjects) - ret = disp->Driver->GLInteropFlushObjects(disp, ctx, count, objects, sync); + ret = + disp->Driver->GLInteropFlushObjects(disp, ctx, count, objects, sync); else ret = MESA_GLINTEROP_UNSUPPORTED; diff --git a/src/egl/main/eglarray.c b/src/egl/main/eglarray.c index ba6cb3e6a4e..e360d943dec 100644 --- a/src/egl/main/eglarray.c +++ b/src/egl/main/eglarray.c @@ -25,14 +25,12 @@ * **************************************************************************/ - #include #include #include -#include "egllog.h" #include "eglarray.h" - +#include "egllog.h" /** * Grow the size of the array. @@ -49,8 +47,8 @@ _eglGrowArray(_EGLArray *array) elems = realloc(array->Elements, new_size * sizeof(array->Elements[0])); if (!elems) { - _eglLog(_EGL_DEBUG, "failed to grow %s array to %d", - array->Name, new_size); + _eglLog(_EGL_DEBUG, "failed to grow %s array to %d", array->Name, + new_size); return EGL_FALSE; } @@ -60,7 +58,6 @@ _eglGrowArray(_EGLArray *array) return EGL_TRUE; } - /** * Create an array. */ @@ -82,7 +79,6 @@ _eglCreateArray(const char *name, EGLint init_size) return array; } - /** * Destroy an array, optionally free the data. */ @@ -98,7 +94,6 @@ _eglDestroyArray(_EGLArray *array, void (*free_cb)(void *)) free(array); } - /** * Append a element to an array. */ @@ -111,7 +106,6 @@ _eglAppendArray(_EGLArray *array, void *elem) array->Elements[array->Size++] = elem; } - /** * Erase an element from an array. */ @@ -122,12 +116,11 @@ _eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *)) free_cb(array->Elements[i]); if (i < array->Size - 1) { memmove(&array->Elements[i], &array->Elements[i + 1], - (array->Size - i - 1) * sizeof(array->Elements[0])); + (array->Size - i - 1) * sizeof(array->Elements[0])); } array->Size--; } - /** * Find in an array for the given element. */ @@ -145,7 +138,6 @@ _eglFindArray(_EGLArray *array, void *elem) return NULL; } - /** * Filter an array and return the number of filtered elements. */ @@ -172,7 +164,6 @@ _eglFilterArray(_EGLArray *array, void **data, EGLint size, return count; } - /** * Flatten an array by converting array elements into another form and store * them in a buffer. @@ -195,8 +186,7 @@ _eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size, if (count > size) count = size; for (i = 0; i < count; i++) - flatten(array->Elements[i], - (void *) ((char *) buffer + elem_size * i)); + flatten(array->Elements[i], (void *)((char *)buffer + elem_size * i)); } return count; diff --git a/src/egl/main/eglarray.h b/src/egl/main/eglarray.h index af728088034..87b8f0a9b11 100644 --- a/src/egl/main/eglarray.h +++ b/src/egl/main/eglarray.h @@ -25,20 +25,17 @@ * **************************************************************************/ - #ifndef EGLARRAY_INCLUDED #define EGLARRAY_INCLUDED #include "egltypedefs.h" - #ifdef __cplusplus extern "C" { #endif typedef EGLBoolean (*_EGLArrayForEach)(void *elem, void *foreach_data); - struct _egl_array { const char *Name; EGLint MaxSize; @@ -47,44 +44,35 @@ struct _egl_array { EGLint Size; }; - extern _EGLArray * _eglCreateArray(const char *name, EGLint init_size); - extern void _eglDestroyArray(_EGLArray *array, void (*free_cb)(void *)); - extern void _eglAppendArray(_EGLArray *array, void *elem); - extern void _eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *)); - void * _eglFindArray(_EGLArray *array, void *elem); - extern EGLint _eglFilterArray(_EGLArray *array, void **data, EGLint size, _EGLArrayForEach filter, void *filter_data); - EGLint _eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size, _EGLArrayForEach flatten); - static inline EGLint _eglGetArraySize(_EGLArray *array) { return (array) ? array->Size : 0; } - #ifdef __cplusplus } #endif diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index 1f181b90a51..9281ccd347f 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -27,26 +27,21 @@ * **************************************************************************/ - /** * EGL Configuration (pixel format) functions. */ - +#include #include #include -#include #include "util/macros.h" #include "eglconfig.h" #include "eglconfigdebug.h" -#include "egldisplay.h" #include "eglcurrent.h" +#include "egldisplay.h" #include "egllog.h" - - - /** * Init the given _EGLconfig to default values. * \param id the configuration's ID. @@ -71,7 +66,6 @@ _eglInitConfig(_EGLConfig *conf, _EGLDisplay *disp, EGLint id) conf->ComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; } - /** * Link a config to its display and return the handle of the link. * The handle can be passed to client directly. @@ -90,15 +84,14 @@ _eglLinkConfig(_EGLConfig *conf) if (!disp->Configs) { disp->Configs = _eglCreateArray("Config", 16); if (!disp->Configs) - return (EGLConfig) NULL; + return (EGLConfig)NULL; } - _eglAppendArray(disp->Configs, (void *) conf); + _eglAppendArray(disp->Configs, (void *)conf); - return (EGLConfig) conf; + return (EGLConfig)conf; } - /** * Lookup a handle to find the linked config. * Return NULL if the handle has no corresponding linked config. @@ -111,20 +104,19 @@ _eglLookupConfig(EGLConfig config, _EGLDisplay *disp) if (!disp) return NULL; - conf = (_EGLConfig *) _eglFindArray(disp->Configs, (void *) config); + conf = (_EGLConfig *)_eglFindArray(disp->Configs, (void *)config); if (conf) assert(conf->Display == disp); return conf; } - enum type { ATTRIB_TYPE_INTEGER, ATTRIB_TYPE_BOOLEAN, ATTRIB_TYPE_BITMASK, ATTRIB_TYPE_ENUM, - ATTRIB_TYPE_PSEUDO, /* non-queryable */ + ATTRIB_TYPE_PSEUDO, /* non-queryable */ ATTRIB_TYPE_PLATFORM, /* platform-dependent */ }; @@ -136,15 +128,13 @@ enum criterion { ATTRIB_CRITERION_IGNORE }; - /* EGL spec Table 3.1 and 3.4 */ static const struct { EGLint attr; enum type type; enum criterion criterion; EGLint default_value; -} _eglValidationTable[] = -{ +} _eglValidationTable[] = { /* clang-format off */ /* core */ { EGL_BUFFER_SIZE, ATTRIB_TYPE_INTEGER, @@ -262,7 +252,6 @@ static const struct { /* clang-format on */ }; - /** * Return true if a config is valid. When for_matching is true, * EGL_DONT_CARE is accepted as a valid attribute value, and checks @@ -336,11 +325,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) case ATTRIB_TYPE_BITMASK: switch (attr) { case EGL_SURFACE_TYPE: - mask = EGL_PBUFFER_BIT | - EGL_PIXMAP_BIT | - EGL_WINDOW_BIT | - EGL_VG_COLORSPACE_LINEAR_BIT | - EGL_VG_ALPHA_FORMAT_PRE_BIT | + mask = EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT | + EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT | EGL_MULTISAMPLE_RESOLVE_BOX_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT; if (disp->Extensions.KHR_mutable_render_buffer) @@ -348,11 +334,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) break; case EGL_RENDERABLE_TYPE: case EGL_CONFORMANT: - mask = EGL_OPENGL_ES_BIT | - EGL_OPENVG_BIT | - EGL_OPENGL_ES2_BIT | - EGL_OPENGL_ES3_BIT_KHR | - EGL_OPENGL_BIT; + mask = EGL_OPENGL_ES_BIT | EGL_OPENVG_BIT | EGL_OPENGL_ES2_BIT | + EGL_OPENGL_ES3_BIT_KHR | EGL_OPENGL_BIT; break; default: unreachable("check _eglValidationTable[]"); @@ -380,8 +363,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) valid = EGL_TRUE; } if (!valid) { - _eglLog(_EGL_DEBUG, - "attribute 0x%04x has an invalid value 0x%x", attr, val); + _eglLog(_EGL_DEBUG, "attribute 0x%04x has an invalid value 0x%x", attr, + val); break; } } @@ -396,8 +379,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) case EGL_RGB_BUFFER: if (conf->LuminanceSize) valid = EGL_FALSE; - if (conf->RedSize + conf->GreenSize + - conf->BlueSize + conf->AlphaSize != conf->BufferSize) + if (conf->RedSize + conf->GreenSize + conf->BlueSize + conf->AlphaSize != + conf->BufferSize) valid = EGL_FALSE; break; case EGL_LUMINANCE_BUFFER: @@ -428,14 +411,14 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching) valid = EGL_FALSE; } if (!valid) { - _eglLog(_EGL_DEBUG, "conflicting surface type and native visual/texture binding"); + _eglLog(_EGL_DEBUG, + "conflicting surface type and native visual/texture binding"); return EGL_FALSE; } return valid; } - /** * Return true if a config matches the criteria. This and * _eglParseConfigAttribList together implement the algorithm @@ -489,8 +472,9 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria) break; #endif _eglLog(_EGL_DEBUG, - "the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)", - val, attr, cmp); + "the value (0x%x) of attribute 0x%04x did not meet the " + "criteria (0x%x)", + val, attr, cmp); break; } } @@ -552,8 +536,7 @@ _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp, return EGL_FALSE; /* EGL_LEVEL and EGL_MATCH_NATIVE_PIXMAP cannot be EGL_DONT_CARE */ - if (conf->Level == EGL_DONT_CARE || - conf->MatchNativePixmap == EGL_DONT_CARE) + if (conf->Level == EGL_DONT_CARE || conf->MatchNativePixmap == EGL_DONT_CARE) return EGL_FALSE; /* ignore other attributes when EGL_CONFIG_ID is given */ @@ -563,8 +546,7 @@ _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp, if (attr != EGL_CONFIG_ID) _eglSetConfigKey(conf, attr, EGL_DONT_CARE); } - } - else { + } else { if (!(conf->SurfaceType & EGL_WINDOW_BIT)) conf->NativeVisualType = EGL_DONT_CARE; @@ -578,7 +560,6 @@ _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp, return EGL_TRUE; } - /** * Decide the ordering of conf1 and conf2, under the given criteria. * When compare_id is true, this implements the algorithm described @@ -597,12 +578,8 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, const _EGLConfig *criteria, EGLBoolean compare_id) { const EGLint compare_attribs[] = { - EGL_BUFFER_SIZE, - EGL_SAMPLE_BUFFERS, - EGL_SAMPLES, - EGL_DEPTH_SIZE, - EGL_STENCIL_SIZE, - EGL_ALPHA_MASK_SIZE, + EGL_BUFFER_SIZE, EGL_SAMPLE_BUFFERS, EGL_SAMPLES, + EGL_DEPTH_SIZE, EGL_STENCIL_SIZE, EGL_ALPHA_MASK_SIZE, }; EGLint val1, val2; EGLint i; @@ -638,8 +615,7 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, val1 += conf1->BlueSize; val2 += conf2->BlueSize; } - } - else { + } else { if (criteria->LuminanceSize > 0) { val1 += conf1->LuminanceSize; val2 += conf2->LuminanceSize; @@ -649,8 +625,7 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, val1 += conf1->AlphaSize; val2 += conf2->AlphaSize; } - } - else { + } else { /* assume the default criteria, which gives no specific ordering */ val1 = val2 = 0; } @@ -671,16 +646,14 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, return (compare_id) ? (conf1->ConfigID - conf2->ConfigID) : 0; } - -static inline -void _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2) +static inline void +_eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2) { const _EGLConfig *tmp = *conf1; *conf1 = *conf2; *conf2 = tmp; } - /** * Quick sort an array of configs. This differs from the standard * qsort() in that the compare function accepts an additional @@ -710,8 +683,7 @@ _eglSortConfigs(const _EGLConfig **configs, EGLint count, _eglSwapConfigs(&configs[i], &configs[j]); i++; j--; - } - else if (i == j) { + } else if (i == j) { i++; j--; break; @@ -723,14 +695,13 @@ _eglSortConfigs(const _EGLConfig **configs, EGLint count, _eglSortConfigs(configs + i, count - i, compare, priv_data); } - /** * A helper function for implementing eglChooseConfig. See _eglFilterArray and * _eglSortConfigs for the meanings of match and compare. */ EGLBoolean -_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, - EGLint config_size, EGLint *num_configs, +_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, EGLint config_size, + EGLint *num_configs, EGLBoolean (*match)(const _EGLConfig *, void *), EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, void *), @@ -740,8 +711,7 @@ _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, EGLint i, count; /* get the number of matched configs */ - count = _eglFilterArray(array, NULL, 0, - (_EGLArrayForEach) match, priv_data); + count = _eglFilterArray(array, NULL, 0, (_EGLArrayForEach)match, priv_data); if (!count) { *num_configs = count; return EGL_TRUE; @@ -752,13 +722,13 @@ _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); /* get the matched configs */ - _eglFilterArray(array, (void **) configList, count, - (_EGLArrayForEach) match, priv_data); + _eglFilterArray(array, (void **)configList, count, (_EGLArrayForEach)match, + priv_data); /* perform sorting of configs */ if (configs && count) { - _eglSortConfigs((const _EGLConfig **) configList, count, - compare, priv_data); + _eglSortConfigs((const _EGLConfig **)configList, count, compare, + priv_data); count = MIN2(count, config_size); for (i = 0; i < count; i++) configs[i] = _eglGetConfigHandle(configList[i]); @@ -771,23 +741,20 @@ _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, return EGL_TRUE; } - static EGLBoolean _eglFallbackMatch(const _EGLConfig *conf, void *priv_data) { - return _eglMatchConfig(conf, (const _EGLConfig *) priv_data); + return _eglMatchConfig(conf, (const _EGLConfig *)priv_data); } - static EGLint _eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2, void *priv_data) { - return _eglCompareConfigs(conf1, conf2, - (const _EGLConfig *) priv_data, EGL_TRUE); + return _eglCompareConfigs(conf1, conf2, (const _EGLConfig *)priv_data, + EGL_TRUE); } - /** * Typical fallback routine for eglChooseConfig */ @@ -801,10 +768,9 @@ _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, if (!_eglParseConfigAttribList(&criteria, disp, attrib_list)) return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); - result = _eglFilterConfigArray(disp->Configs, - configs, config_size, num_configs, - _eglFallbackMatch, _eglFallbackCompare, - (void *) &criteria); + result = _eglFilterConfigArray(disp->Configs, configs, config_size, + num_configs, _eglFallbackMatch, + _eglFallbackCompare, (void *)&criteria); if (result && (_eglGetLogLevel() == _EGL_DEBUG)) eglPrintConfigDebug(disp, configs, *num_configs, EGL_TRUE); @@ -812,7 +778,6 @@ _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, return result; } - /** * Fallback for eglGetConfigAttrib. */ @@ -839,12 +804,11 @@ _eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf, return EGL_TRUE; } - static EGLBoolean _eglFlattenConfig(void *elem, void *buffer) { - _EGLConfig *conf = (_EGLConfig *) elem; - EGLConfig *handle = (EGLConfig *) buffer; + _EGLConfig *conf = (_EGLConfig *)elem; + EGLConfig *handle = (EGLConfig *)buffer; *handle = _eglGetConfigHandle(conf); return EGL_TRUE; } @@ -853,11 +817,12 @@ _eglFlattenConfig(void *elem, void *buffer) * Fallback for eglGetConfigs. */ EGLBoolean -_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, - EGLint config_size, EGLint *num_config) +_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, + EGLint *num_config) { - *num_config = _eglFlattenArray(disp->Configs, (void *) configs, - sizeof(configs[0]), config_size, _eglFlattenConfig); + *num_config = + _eglFlattenArray(disp->Configs, (void *)configs, sizeof(configs[0]), + config_size, _eglFlattenConfig); if (_eglGetLogLevel() == _EGL_DEBUG) eglPrintConfigDebug(disp, configs, *num_config, EGL_FALSE); diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h index e712d7b5f1d..e7caea20bbc 100644 --- a/src/egl/main/eglconfig.h +++ b/src/egl/main/eglconfig.h @@ -27,25 +27,21 @@ * **************************************************************************/ - #ifndef EGLCONFIG_INCLUDED #define EGLCONFIG_INCLUDED - #include #include #include "egltypedefs.h" - #ifdef __cplusplus extern "C" { #endif /* update _eglValidationTable and _eglOffsetOfConfig before updating this * struct */ -struct _egl_config -{ +struct _egl_config { _EGLDisplay *Display; /* core */ @@ -90,7 +86,6 @@ struct _egl_config EGLint ComponentType; }; - /** * Map an EGL attribute enum to the offset of the member in _EGLConfig. */ @@ -98,53 +93,54 @@ static inline EGLint _eglOffsetOfConfig(EGLint attr) { switch (attr) { -#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb) - /* core */ - ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize); - ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize); - ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize); - ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize); - ATTRIB_MAP(EGL_RED_SIZE, RedSize); - ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize); - ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize); - ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat); - ATTRIB_MAP(EGL_CONFIG_ID, ConfigID); - ATTRIB_MAP(EGL_LEVEL, Level); - ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight); - ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels); - ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth); - ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable); - ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID); - ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType); - ATTRIB_MAP(EGL_SAMPLES, Samples); - ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers); - ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType); - ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType); - ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue); - ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue); - ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue); - ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB); - ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA); - ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval); - ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval); - ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize); - ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize); - ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType); - ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType); - ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap); - ATTRIB_MAP(EGL_CONFORMANT, Conformant); - /* extensions */ - ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK); - ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid); - ATTRIB_MAP(EGL_RECORDABLE_ANDROID, RecordableAndroid); - ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT, ComponentType); +#define ATTRIB_MAP(attr, memb) \ + case attr: \ + return offsetof(_EGLConfig, memb) + /* core */ + ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize); + ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize); + ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize); + ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize); + ATTRIB_MAP(EGL_RED_SIZE, RedSize); + ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize); + ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize); + ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat); + ATTRIB_MAP(EGL_CONFIG_ID, ConfigID); + ATTRIB_MAP(EGL_LEVEL, Level); + ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight); + ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels); + ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth); + ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable); + ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID); + ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType); + ATTRIB_MAP(EGL_SAMPLES, Samples); + ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers); + ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType); + ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType); + ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue); + ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue); + ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue); + ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB); + ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA); + ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval); + ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval); + ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize); + ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize); + ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType); + ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType); + ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap); + ATTRIB_MAP(EGL_CONFORMANT, Conformant); + /* extensions */ + ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK); + ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid); + ATTRIB_MAP(EGL_RECORDABLE_ANDROID, RecordableAndroid); + ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT, ComponentType); #undef ATTRIB_MAP default: return -1; } } - /** * Update a config for a given key. * @@ -157,10 +153,9 @@ _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val) { EGLint offset = _eglOffsetOfConfig(key); assert(offset >= 0); - *((EGLint *) ((char *) conf + offset)) = val; + *((EGLint *)((char *)conf + offset)) = val; } - /** * Return the value for a given key. */ @@ -169,70 +164,60 @@ _eglGetConfigKey(const _EGLConfig *conf, EGLint key) { EGLint offset = _eglOffsetOfConfig(key); assert(offset >= 0); - return *((EGLint *) ((char *) conf + offset)); + return *((EGLint *)((char *)conf + offset)); } - extern void _eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id); - extern EGLConfig _eglLinkConfig(_EGLConfig *conf); - extern _EGLConfig * _eglLookupConfig(EGLConfig config, _EGLDisplay *disp); - /** * Return the handle of a linked config. */ static inline EGLConfig _eglGetConfigHandle(_EGLConfig *conf) { - return (EGLConfig) conf; + return (EGLConfig)conf; } - extern EGLBoolean _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching); - extern EGLBoolean _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria); - extern EGLBoolean _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp, const EGLint *attrib_list); - extern EGLint _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, const _EGLConfig *criteria, EGLBoolean compare_id); - extern EGLBoolean -_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, - EGLint config_size, EGLint *num_configs, +_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, EGLint config_size, + EGLint *num_configs, EGLBoolean (*match)(const _EGLConfig *, void *), EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, void *), void *filter_data); +extern EGLBoolean +_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, EGLint *num_config); extern EGLBoolean -_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); - +_eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf, + EGLint attribute, EGLint *value); extern EGLBoolean -_eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf, EGLint attribute, EGLint *value); - - -extern EGLBoolean -_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config); - +_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, + EGLint *num_config); #ifdef __cplusplus } diff --git a/src/egl/main/eglconfigdebug.c b/src/egl/main/eglconfigdebug.c index 92c0e13e673..7cca37605fd 100644 --- a/src/egl/main/eglconfigdebug.c +++ b/src/egl/main/eglconfigdebug.c @@ -23,18 +23,18 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include +#include #include #include -#include -#include +#include "util/macros.h" #include "eglarray.h" #include "eglconfig.h" #include "eglconfigdebug.h" #include "egldisplay.h" #include "egllog.h" #include "egltypedefs.h" -#include "util/macros.h" /* Max debug message length */ #define CONFIG_DEBUG_MSG_MAX 1000 @@ -43,7 +43,7 @@ * These are X visual types, so if you're running eglinfo under * something not X, they probably don't make sense. */ -static const char *const vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" }; +static const char *const vnames[] = {"SG", "GS", "SC", "PC", "TC", "DC"}; static void _printHeaderFormat(void) @@ -99,7 +99,7 @@ _strnAppend(char *const buf, const int bufSize, const char *fmt, ...) assert(maxAllowed >= 0); va_start(args, fmt); - (void) vsnprintf(&buf[bufLen], maxAllowed, fmt, args); + (void)vsnprintf(&buf[bufLen], maxAllowed, fmt, args); va_end(args); } @@ -136,10 +136,10 @@ _eglPrintConfig(_EGLConfig *const conf, const int chosenIndex) _strnAppend(printMsg, sizeof(printMsg), "0x%03x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%08x%2s ", - conf->ConfigID, conf->BufferSize, conf->Level, - conf->RedSize, conf->GreenSize, conf->BlueSize, conf->AlphaSize, - conf->DepthSize, conf->StencilSize, - conf->Samples, conf->SampleBuffers, conf->NativeVisualID, + conf->ConfigID, conf->BufferSize, conf->Level, conf->RedSize, + conf->GreenSize, conf->BlueSize, conf->AlphaSize, + conf->DepthSize, conf->StencilSize, conf->Samples, + conf->SampleBuffers, conf->NativeVisualID, vtype < 6 ? vnames[vtype] : "--"); bindRgb = conf->BindToTextureRGB; @@ -149,20 +149,22 @@ _eglPrintConfig(_EGLConfig *const conf, const int chosenIndex) _strnAppend(printMsg, sizeof(printMsg), "%c %c %c %c %c %c %c %15s", (conf->ConfigCaveat != EGL_NONE) ? 'y' : ' ', - (bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ', + (bindRgba) ? 'a' + : (bindRgb) ? 'y' + : ' ', (renderable & EGL_OPENGL_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_ES3_BIT) ? 'y' : ' ', - (renderable & EGL_OPENVG_BIT) ? 'y' : ' ', - surfString); + (renderable & EGL_OPENVG_BIT) ? 'y' : ' ', surfString); _eglLog(_EGL_DEBUG, printMsg); } -void eglPrintConfigDebug(const _EGLDisplay *const disp, - const EGLConfig *const configs, - const EGLint numConfigs, const EGLBoolean printChosen) +void +eglPrintConfigDebug(const _EGLDisplay *const disp, + const EGLConfig *const configs, const EGLint numConfigs, + const EGLBoolean printChosen) { EGLint numConfigsToPrint; _EGLConfig **configsToPrint; @@ -178,11 +180,11 @@ void eglPrintConfigDebug(const _EGLDisplay *const disp, * configs are printed, and the "chosen" configs are marked. */ if (printChosen) { - configsToPrint = (_EGLConfig **) disp->Configs->Elements; + configsToPrint = (_EGLConfig **)disp->Configs->Elements; numConfigsToPrint = disp->Configs->Size; - chosenConfigs = (_EGLConfig **) configs; + chosenConfigs = (_EGLConfig **)configs; } else { - configsToPrint = (_EGLConfig **) configs; + configsToPrint = (_EGLConfig **)configs; numConfigsToPrint = numConfigs; chosenConfigs = NULL; } diff --git a/src/egl/main/eglconfigdebug.h b/src/egl/main/eglconfigdebug.h index 929e5c4fb12..d8763008780 100644 --- a/src/egl/main/eglconfigdebug.h +++ b/src/egl/main/eglconfigdebug.h @@ -36,9 +36,10 @@ extern "C" { /** * Print the list of configs and the associated attributes. */ -void eglPrintConfigDebug(const _EGLDisplay *const disp, - const EGLConfig *const configs, - EGLint numConfigs, EGLBoolean printChosen); +void +eglPrintConfigDebug(const _EGLDisplay *const disp, + const EGLConfig *const configs, EGLint numConfigs, + EGLBoolean printChosen); #ifdef __cplusplus } diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c index 2d51ba0dcf4..5f6f9ada708 100644 --- a/src/egl/main/eglcontext.c +++ b/src/egl/main/eglcontext.c @@ -27,18 +27,16 @@ * **************************************************************************/ - +#include "eglcontext.h" #include #include #include -#include "eglconfig.h" -#include "eglcontext.h" -#include "egldisplay.h" -#include "eglcurrent.h" -#include "eglsurface.h" -#include "egllog.h" #include "util/macros.h" - +#include "eglconfig.h" +#include "eglcurrent.h" +#include "egldisplay.h" +#include "egllog.h" +#include "eglsurface.h" /** * Return the API bit (one of EGL_xxx_BIT) of the context. @@ -77,7 +75,6 @@ _eglGetContextAPIBit(_EGLContext *ctx) return bit; } - /** * Parse the list of context attributes and return the proper error code. */ @@ -119,9 +116,10 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * generate an error." */ if ((api != EGL_OPENGL_ES_API && - (!disp->Extensions.KHR_create_context || api != EGL_OPENGL_API))) { - err = EGL_BAD_ATTRIBUTE; - break; + (!disp->Extensions.KHR_create_context || + api != EGL_OPENGL_API))) { + err = EGL_BAD_ATTRIBUTE; + break; } ctx->ClientMajorVersion = val; @@ -179,11 +177,11 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * forward-compatible context for OpenGL versions less than 3.0 * will generate an error." * - * Note: since the forward-compatible flag can be set more than one way, - * the OpenGL version check is performed once, below. + * Note: since the forward-compatible flag can be set more than one + * way, the OpenGL version check is performed once, below. */ if ((val & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) && - api != EGL_OPENGL_API) { + api != EGL_OPENGL_API) { err = EGL_BAD_ATTRIBUTE; break; } @@ -258,9 +256,9 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * "This attribute is supported only for OpenGL and OpenGL ES * contexts." */ - if (!(disp->Extensions.KHR_create_context && api == EGL_OPENGL_API) - && !(disp->Version >= 15 && (api == EGL_OPENGL_API || - api == EGL_OPENGL_ES_API))) { + if (!(disp->Extensions.KHR_create_context && api == EGL_OPENGL_API) && + !(disp->Version >= 15 && + (api == EGL_OPENGL_API || api == EGL_OPENGL_ES_API))) { err = EGL_BAD_ATTRIBUTE; break; } @@ -275,8 +273,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * meaningful for OpenGL ES contexts, and specifying it for other * types of contexts will generate an EGL_BAD_ATTRIBUTE error." */ - if (!disp->Extensions.EXT_create_context_robustness - || api != EGL_OPENGL_ES_API) { + if (!disp->Extensions.EXT_create_context_robustness || + api != EGL_OPENGL_ES_API) { err = EGL_BAD_ATTRIBUTE; break; } @@ -335,7 +333,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * OpenGL ES 2.0+ */ if (((api != EGL_OPENGL_API && api != EGL_OPENGL_ES_API) || - ctx->ClientMajorVersion < 2) && val == EGL_TRUE) { + ctx->ClientMajorVersion < 2) && + val == EGL_TRUE) { err = EGL_BAD_ATTRIBUTE; break; } @@ -437,8 +436,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * Since the value is ignored, only validate the setting if the version * is >= 3.2. */ - if (ctx->ClientMajorVersion >= 4 - || (ctx->ClientMajorVersion == 3 && ctx->ClientMinorVersion >= 2)) { + if (ctx->ClientMajorVersion >= 4 || + (ctx->ClientMajorVersion == 3 && ctx->ClientMinorVersion >= 2)) { switch (ctx->Profile) { case EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR: case EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR: @@ -450,11 +449,11 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, * "* If an OpenGL context is requested, the requested version * is greater than 3.2, and the value for attribute * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has - * any bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR - * and EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has - * more than one of these bits set; or if the implementation does - * not support the requested profile, then an EGL_BAD_MATCH error - * is generated." + * any bits set other than + * EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and + * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than + * one of these bits set; or if the implementation does not support + * the requested profile, then an EGL_BAD_MATCH error is generated." */ err = EGL_BAD_MATCH; break; @@ -486,14 +485,14 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, switch (ctx->ClientMajorVersion) { case 1: - if (ctx->ClientMinorVersion > 5 - || (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) + if (ctx->ClientMinorVersion > 5 || + (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) err = EGL_BAD_MATCH; break; case 2: - if (ctx->ClientMinorVersion > 1 - || (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) + if (ctx->ClientMinorVersion > 1 || + (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) err = EGL_BAD_MATCH; break; @@ -563,24 +562,24 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp, /* The EGL_KHR_create_context_no_error spec says: * - * "BAD_MATCH is generated if the EGL_CONTEXT_OPENGL_NO_ERROR_KHR is TRUE at - * the same time as a debug or robustness context is specified." + * "BAD_MATCH is generated if the EGL_CONTEXT_OPENGL_NO_ERROR_KHR is TRUE + * at the same time as a debug or robustness context is specified." */ - if (ctx->NoError && (ctx->Flags & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR || - ctx->Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) { + if (ctx->NoError && + (ctx->Flags & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR || + ctx->Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) { err = EGL_BAD_MATCH; } - if ((ctx->Flags & ~(EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR - | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR - | EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) != 0) { + if ((ctx->Flags & ~(EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | + EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR | + EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) != 0) { err = EGL_BAD_ATTRIBUTE; } return err; } - /** * Initialize the given _EGLContext object to defaults and/or the values * in the attrib_list. @@ -624,7 +623,7 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *conf, api_bit = _eglGetContextAPIBit(ctx); if (!(ctx->Config->RenderableType & api_bit)) { _eglLog(_EGL_DEBUG, "context api is 0x%x while config supports 0x%x", - api_bit, ctx->Config->RenderableType); + api_bit, ctx->Config->RenderableType); err = EGL_BAD_CONFIG; } } @@ -640,9 +639,10 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *conf, * generated." */ if (share_list && share_list->ResetNotificationStrategy != - ctx->ResetNotificationStrategy) { - return _eglError(EGL_BAD_MATCH, - "eglCreateContext() share list notification strategy mismatch"); + ctx->ResetNotificationStrategy) { + return _eglError( + EGL_BAD_MATCH, + "eglCreateContext() share list notification strategy mismatch"); } /* The EGL_KHR_create_context_no_error spec says: @@ -659,7 +659,6 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *conf, return EGL_TRUE; } - static EGLint _eglQueryContextRenderBuffer(_EGLContext *ctx) { @@ -702,7 +701,6 @@ _eglQueryContextRenderBuffer(_EGLContext *ctx) } } - EGLBoolean _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value) { @@ -746,7 +744,6 @@ _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value) return EGL_TRUE; } - /** * Bind the context to the thread and return the previous context. * @@ -770,7 +767,6 @@ _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t) return oldCtx; } - /** * Return true if the given context and surfaces can be made current. */ @@ -788,8 +784,8 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read) } disp = ctx->Resource.Display; - if (!disp->Extensions.KHR_surfaceless_context - && (draw == NULL || read == NULL)) + if (!disp->Extensions.KHR_surfaceless_context && + (draw == NULL || read == NULL)) return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); /* @@ -830,7 +826,6 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read) return EGL_TRUE; } - /** * Bind the context to the current thread and given surfaces. Return the * previous bound context and surfaces. The caller should unreference the @@ -842,8 +837,8 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read) */ EGLBoolean _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, - _EGLContext **old_ctx, - _EGLSurface **old_draw, _EGLSurface **old_read) + _EGLContext **old_ctx, _EGLSurface **old_draw, + _EGLSurface **old_read) { _EGLThreadInfo *t = _eglGetCurrentThread(); _EGLContext *prev_ctx; @@ -872,8 +867,7 @@ _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, prev_ctx->DrawSurface = NULL; prev_ctx->ReadSurface = NULL; - } - else { + } else { prev_draw = prev_read = NULL; } diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h index acfef4fe7c0..dd690765323 100644 --- a/src/egl/main/eglcontext.h +++ b/src/egl/main/eglcontext.h @@ -27,13 +27,11 @@ * **************************************************************************/ - #ifndef EGLCONTEXT_INCLUDED #define EGLCONTEXT_INCLUDED -#include "egltypedefs.h" #include "egldisplay.h" - +#include "egltypedefs.h" #ifdef __cplusplus extern "C" { @@ -42,8 +40,7 @@ extern "C" { /** * "Base" class for device driver contexts. */ -struct _egl_context -{ +struct _egl_context { /* A context is a display resource */ _EGLResource Resource; @@ -66,25 +63,21 @@ struct _egl_context EGLBoolean Protected; /* EGL_EXT_protected_content */ }; - extern EGLBoolean -_eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, - _EGLConfig *config, _EGLContext *share_list, const EGLint *attrib_list); - +_eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *config, + _EGLContext *share_list, const EGLint *attrib_list); extern EGLBoolean _eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value); - extern EGLBoolean _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, - _EGLContext **old_ctx, - _EGLSurface **old_draw, _EGLSurface **old_read); + _EGLContext **old_ctx, _EGLSurface **old_draw, + _EGLSurface **old_read); extern _EGLContext * _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t); - /** * Increment reference count for the context. */ @@ -96,7 +89,6 @@ _eglGetContext(_EGLContext *ctx) return ctx; } - /** * Decrement reference count for the context. */ @@ -106,7 +98,6 @@ _eglPutContext(_EGLContext *ctx) return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE; } - /** * Link a context to its display and return the handle of the link. * The handle can be passed to client directly. @@ -115,10 +106,9 @@ static inline EGLContext _eglLinkContext(_EGLContext *ctx) { _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); - return (EGLContext) ctx; + return (EGLContext)ctx; } - /** * Unlink a linked context from its display. * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. @@ -129,7 +119,6 @@ _eglUnlinkContext(_EGLContext *ctx) _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); } - /** * Lookup a handle to find the linked context. * Return NULL if the handle has no corresponding linked context. @@ -137,25 +126,22 @@ _eglUnlinkContext(_EGLContext *ctx) static inline _EGLContext * _eglLookupContext(EGLContext context, _EGLDisplay *disp) { - _EGLContext *ctx = (_EGLContext *) context; - if (!disp || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, disp)) + _EGLContext *ctx = (_EGLContext *)context; + if (!disp || !_eglCheckResource((void *)ctx, _EGL_RESOURCE_CONTEXT, disp)) ctx = NULL; return ctx; } - /** * Return the handle of a linked context, or EGL_NO_CONTEXT. */ static inline EGLContext _eglGetContextHandle(_EGLContext *ctx) { - _EGLResource *res = (_EGLResource *) ctx; - return (res && _eglIsResourceLinked(res)) ? - (EGLContext) ctx : EGL_NO_CONTEXT; + _EGLResource *res = (_EGLResource *)ctx; + return (res && _eglIsResourceLinked(res)) ? (EGLContext)ctx : EGL_NO_CONTEXT; } - #ifdef __cplusplus } #endif diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c index a1f28713b6c..6707897971e 100644 --- a/src/egl/main/eglcurrent.c +++ b/src/egl/main/eglcurrent.c @@ -25,19 +25,18 @@ * **************************************************************************/ - +#include #include #include #include -#include #include "c11/threads.h" -#include "util/u_thread.h" #include "util/u_string.h" +#include "util/u_thread.h" -#include "egllog.h" #include "eglcurrent.h" #include "eglglobals.h" +#include "egllog.h" static __THREAD_INITIAL_EXEC _EGLThreadInfo _egl_TLS = { .inited = false, @@ -51,7 +50,6 @@ _eglInitThreadInfo(_EGLThreadInfo *t) t->CurrentAPI = EGL_OPENGL_ES_API; } - /** * Return the calling thread's thread info. * If the calling thread never calls this function before, or if its thread @@ -69,7 +67,6 @@ _eglGetCurrentThread(void) return current; } - /** * Destroy the calling thread's thread info. */ @@ -80,7 +77,6 @@ _eglDestroyCurrentThread(void) t->inited = false; } - /** * Return the currently bound context of the current API, or NULL. */ @@ -91,7 +87,6 @@ _eglGetCurrentContext(void) return t->CurrentContext; } - /** * Record EGL error code and return EGL_FALSE. */ @@ -172,8 +167,8 @@ _eglError(EGLint errCode, const char *msg) } void -_eglDebugReport(EGLenum error, const char *funcName, - EGLint type, const char *message, ...) +_eglDebugReport(EGLenum error, const char *funcName, EGLint type, + const char *message, ...) { _EGLThreadInfo *thr = _eglGetCurrentThread(); EGLDEBUGPROCKHR callback = NULL; diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h index 89f47a23c5e..c4d4041d713 100644 --- a/src/egl/main/eglcurrent.h +++ b/src/egl/main/eglcurrent.h @@ -25,7 +25,6 @@ * **************************************************************************/ - #ifndef EGLCURRENT_INCLUDED #define EGLCURRENT_INCLUDED @@ -33,24 +32,18 @@ #include "egltypedefs.h" - #ifdef __cplusplus extern "C" { #endif -#define _EGL_API_ALL_BITS \ - (EGL_OPENGL_ES_BIT | \ - EGL_OPENVG_BIT | \ - EGL_OPENGL_ES2_BIT | \ - EGL_OPENGL_ES3_BIT_KHR | \ - EGL_OPENGL_BIT) - +#define _EGL_API_ALL_BITS \ + (EGL_OPENGL_ES_BIT | EGL_OPENVG_BIT | EGL_OPENGL_ES2_BIT | \ + EGL_OPENGL_ES3_BIT_KHR | EGL_OPENGL_BIT) /** * Per-thread info */ -struct _egl_thread_info -{ +struct _egl_thread_info { bool inited; EGLint LastError; _EGLContext *CurrentContext; @@ -65,7 +58,6 @@ struct _egl_thread_info EGLLabelKHR CurrentObjectLabel; }; - /** * Return true if a client API enum is recognized. */ @@ -80,25 +72,21 @@ _eglIsApiValid(EGLenum api) #endif } - extern _EGLThreadInfo * _eglGetCurrentThread(void); - extern void _eglDestroyCurrentThread(void); - extern _EGLContext * _eglGetCurrentContext(void); - extern EGLBoolean _eglError(EGLint errCode, const char *msg); extern void -_eglDebugReport(EGLenum error, const char *funcName, - EGLint type, const char *message, ...); +_eglDebugReport(EGLenum error, const char *funcName, EGLint type, + const char *message, ...); #ifdef __cplusplus } diff --git a/src/egl/main/egldefines.h b/src/egl/main/egldefines.h index c925e0ca553..d8f7dfa2dc9 100644 --- a/src/egl/main/egldefines.h +++ b/src/egl/main/egldefines.h @@ -25,12 +25,10 @@ * **************************************************************************/ - /** * Internal EGL defines */ - #ifndef EGLDEFINES_INCLUDED #define EGLDEFINES_INCLUDED @@ -43,7 +41,7 @@ extern "C" { /* Hardcoded, conservative default for EGL_LARGEST_PBUFFER, * this is used to implement EGL_LARGEST_PBUFFER. */ -#define _EGL_MAX_PBUFFER_WIDTH 4096 +#define _EGL_MAX_PBUFFER_WIDTH 4096 #define _EGL_MAX_PBUFFER_HEIGHT 4096 #define _EGL_VENDOR_STRING "Mesa Project" diff --git a/src/egl/main/egldevice.c b/src/egl/main/egldevice.c index c6402ed666d..38ab12be4ac 100644 --- a/src/egl/main/egldevice.c +++ b/src/egl/main/egldevice.c @@ -33,11 +33,10 @@ #include "eglcurrent.h" #include "egldevice.h" -#include "egllog.h" #include "eglglobals.h" +#include "egllog.h" #include "egltypedefs.h" - struct _egl_device { _EGLDevice *Next; @@ -89,7 +88,7 @@ _eglCheckDeviceHandle(EGLDeviceEXT device) simple_mtx_lock(_eglGlobal.Mutex); cur = _eglGlobal.DeviceList; while (cur) { - if (cur == (_EGLDevice *) device) + if (cur == (_EGLDevice *)device) break; cur = cur->Next; } @@ -113,8 +112,8 @@ _eglAddDRMDevice(drmDevicePtr device, _EGLDevice **out_dev) { _EGLDevice *dev; - if ((device->available_nodes & (1 << DRM_NODE_PRIMARY | - 1 << DRM_NODE_RENDER)) == 0) + if ((device->available_nodes & + (1 << DRM_NODE_PRIMARY | 1 << DRM_NODE_RENDER)) == 0) return -1; dev = _eglGlobal.DeviceList; @@ -189,7 +188,8 @@ _eglAddDevice(int fd, bool software) if (_eglAddDRMDevice(device, &dev) != 0) drmFreeDevice(&device); #else - _eglLog(_EGL_FATAL, "Driver bug: Built without libdrm, yet looking for HW device"); + _eglLog(_EGL_FATAL, + "Driver bug: Built without libdrm, yet looking for HW device"); dev = NULL; #endif @@ -215,8 +215,7 @@ _eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext) } EGLBoolean -_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, - EGLAttrib *value) +_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, EGLAttrib *value) { switch (attribute) { default: @@ -304,8 +303,7 @@ _eglRefreshDeviceList(void) } EGLBoolean -_eglQueryDevicesEXT(EGLint max_devices, - _EGLDevice **devices, +_eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices, EGLint *num_devices) { _EGLDevice *dev, *devs, *swrast; diff --git a/src/egl/main/egldevice.h b/src/egl/main/egldevice.h index 9a103e19ff2..5998ae665d1 100644 --- a/src/egl/main/egldevice.h +++ b/src/egl/main/egldevice.h @@ -25,11 +25,9 @@ * **************************************************************************/ - #ifndef EGLDEVICE_INCLUDED #define EGLDEVICE_INCLUDED - #include #include #include "egltypedefs.h" @@ -49,7 +47,7 @@ _eglCheckDeviceHandle(EGLDeviceEXT device); static inline _EGLDevice * _eglLookupDevice(EGLDeviceEXT device) { - _EGLDevice *dev = (_EGLDevice *) device; + _EGLDevice *dev = (_EGLDevice *)device; if (!_eglCheckDeviceHandle(device)) dev = NULL; return dev; @@ -70,8 +68,7 @@ EGLBoolean _eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext); EGLBoolean -_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, - EGLAttrib *value); +_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, EGLAttrib *value); const char * _eglQueryDeviceStringEXT(_EGLDevice *dev, EGLint name); diff --git a/src/egl/main/egldispatchstubs.c b/src/egl/main/egldispatchstubs.c index ee9c8f5f68d..694902f4b53 100644 --- a/src/egl/main/egldispatchstubs.c +++ b/src/egl/main/egldispatchstubs.c @@ -28,8 +28,8 @@ #include "egldispatchstubs.h" #include "g_egldispatchstubs.h" -#include #include +#include #include "eglcurrent.h" @@ -38,101 +38,110 @@ static const __EGLapiExports *exports; const int __EGL_DISPATCH_FUNC_COUNT = __EGL_DISPATCH_COUNT; int __EGL_DISPATCH_FUNC_INDICES[__EGL_DISPATCH_COUNT + 1]; -static int Compare(const void *l, const void *r) +static int +Compare(const void *l, const void *r) { - const char *s = *(const char **)r; - return strcmp(l, s); + const char *s = *(const char **)r; + return strcmp(l, s); } -static int FindProcIndex(const char *name) +static int +FindProcIndex(const char *name) { - const char **match = bsearch(name, __EGL_DISPATCH_FUNC_NAMES, - __EGL_DISPATCH_COUNT, sizeof(const char *), Compare); + const char **match = + bsearch(name, __EGL_DISPATCH_FUNC_NAMES, __EGL_DISPATCH_COUNT, + sizeof(const char *), Compare); - if (match == NULL) - return __EGL_DISPATCH_COUNT; + if (match == NULL) + return __EGL_DISPATCH_COUNT; - return match - __EGL_DISPATCH_FUNC_NAMES; + return match - __EGL_DISPATCH_FUNC_NAMES; } -void __eglInitDispatchStubs(const __EGLapiExports *exportsTable) +void +__eglInitDispatchStubs(const __EGLapiExports *exportsTable) { - int i; - exports = exportsTable; - for (i=0; i<__EGL_DISPATCH_FUNC_COUNT; i++) { - __EGL_DISPATCH_FUNC_INDICES[i] = -1; - } + int i; + exports = exportsTable; + for (i = 0; i < __EGL_DISPATCH_FUNC_COUNT; i++) { + __EGL_DISPATCH_FUNC_INDICES[i] = -1; + } } -void __eglSetDispatchIndex(const char *name, int dispatchIndex) +void +__eglSetDispatchIndex(const char *name, int dispatchIndex) { - int index = FindProcIndex(name); - __EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex; + int index = FindProcIndex(name); + __EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex; } -void *__eglDispatchFindDispatchFunction(const char *name) +void * +__eglDispatchFindDispatchFunction(const char *name) { - int index = FindProcIndex(name); - return (void *) __EGL_DISPATCH_FUNCS[index]; + int index = FindProcIndex(name); + return (void *)__EGL_DISPATCH_FUNCS[index]; } -static __eglMustCastToProperFunctionPointerType FetchVendorFunc(__EGLvendorInfo *vendor, - int index, EGLint errorCode) +static __eglMustCastToProperFunctionPointerType +FetchVendorFunc(__EGLvendorInfo *vendor, int index, EGLint errorCode) { - __eglMustCastToProperFunctionPointerType func = NULL; + __eglMustCastToProperFunctionPointerType func = NULL; - if (vendor != NULL) { - func = exports->fetchDispatchEntry(vendor, __EGL_DISPATCH_FUNC_INDICES[index]); - } - if (func == NULL) { - if (errorCode != EGL_SUCCESS) { - // Since we have no vendor, the follow-up eglGetError() call will - // end up using the GLVND error code. Set it here. - if (vendor == NULL) { - exports->setEGLError(errorCode); - } - _eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]); - } - return NULL; - } + if (vendor != NULL) { + func = exports->fetchDispatchEntry(vendor, + __EGL_DISPATCH_FUNC_INDICES[index]); + } + if (func == NULL) { + if (errorCode != EGL_SUCCESS) { + // Since we have no vendor, the follow-up eglGetError() call will + // end up using the GLVND error code. Set it here. + if (vendor == NULL) { + exports->setEGLError(errorCode); + } + _eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]); + } + return NULL; + } - if (!exports->setLastVendor(vendor)) { - // Don't bother trying to set an error code in libglvnd. If - // setLastVendor failed, then setEGLError would also fail. - _eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]); - return NULL; - } + if (!exports->setLastVendor(vendor)) { + // Don't bother trying to set an error code in libglvnd. If + // setLastVendor failed, then setEGLError would also fail. + _eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]); + return NULL; + } - return func; + return func; } -__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index) +__eglMustCastToProperFunctionPointerType +__eglDispatchFetchByCurrent(int index) { - __EGLvendorInfo *vendor; + __EGLvendorInfo *vendor; - // Note: This is only used for the eglWait* functions. For those, if - // there's no current context, then they're supposed to do nothing but - // return success. - exports->threadInit(); - vendor = exports->getCurrentVendor(); - return FetchVendorFunc(vendor, index, EGL_SUCCESS); + // Note: This is only used for the eglWait* functions. For those, if + // there's no current context, then they're supposed to do nothing but + // return success. + exports->threadInit(); + vendor = exports->getCurrentVendor(); + return FetchVendorFunc(vendor, index, EGL_SUCCESS); } -__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index) +__eglMustCastToProperFunctionPointerType +__eglDispatchFetchByDisplay(EGLDisplay dpy, int index) { - __EGLvendorInfo *vendor; + __EGLvendorInfo *vendor; - exports->threadInit(); - vendor = exports->getVendorFromDisplay(dpy); - return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY); + exports->threadInit(); + vendor = exports->getVendorFromDisplay(dpy); + return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY); } -__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dev, int index) +__eglMustCastToProperFunctionPointerType +__eglDispatchFetchByDevice(EGLDeviceEXT dev, int index) { - __EGLvendorInfo *vendor; + __EGLvendorInfo *vendor; - exports->threadInit(); - vendor = exports->getVendorFromDevice(dev); - return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT); + exports->threadInit(); + vendor = exports->getVendorFromDevice(dev); + return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT); } - diff --git a/src/egl/main/egldispatchstubs.h b/src/egl/main/egldispatchstubs.h index fec1e63bb88..bd59f0ba1f2 100644 --- a/src/egl/main/egldispatchstubs.h +++ b/src/egl/main/egldispatchstubs.h @@ -32,22 +32,28 @@ // These variables are all generated along with the dispatch stubs. extern const int __EGL_DISPATCH_FUNC_COUNT; -extern const char * const __EGL_DISPATCH_FUNC_NAMES[]; +extern const char *const __EGL_DISPATCH_FUNC_NAMES[]; extern int __EGL_DISPATCH_FUNC_INDICES[]; extern const __eglMustCastToProperFunctionPointerType __EGL_DISPATCH_FUNCS[]; -void __eglInitDispatchStubs(const __EGLapiExports *exportsTable); -void __eglSetDispatchIndex(const char *name, int index); +void +__eglInitDispatchStubs(const __EGLapiExports *exportsTable); +void +__eglSetDispatchIndex(const char *name, int index); /** * Returns the dispatch function for the given name, or \c NULL if the function * isn't supported. */ -void *__eglDispatchFindDispatchFunction(const char *name); +void * +__eglDispatchFindDispatchFunction(const char *name); // Helper functions used by the generated stubs. -__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index); -__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dpy, int index); -__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index); +__eglMustCastToProperFunctionPointerType +__eglDispatchFetchByDisplay(EGLDisplay dpy, int index); +__eglMustCastToProperFunctionPointerType +__eglDispatchFetchByDevice(EGLDeviceEXT dpy, int index); +__eglMustCastToProperFunctionPointerType +__eglDispatchFetchByCurrent(int index); #endif // EGLDISPATCHSTUBS_H diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index cf54cd05bcb..dd36a91e0d7 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -27,7 +27,6 @@ * **************************************************************************/ - /** * Functions related to EGLDisplay. */ @@ -48,13 +47,13 @@ #include "eglcontext.h" #include "eglcurrent.h" -#include "eglsurface.h" #include "egldevice.h" #include "egldisplay.h" #include "egldriver.h" #include "eglglobals.h" -#include "egllog.h" #include "eglimage.h" +#include "egllog.h" +#include "eglsurface.h" #include "eglsync.h" /* Includes for _eglNativePlatformDetectNativeDisplay */ @@ -68,7 +67,6 @@ #include #endif - /** * Map build-system platform names to platform types. */ @@ -76,18 +74,17 @@ static const struct { _EGLPlatformType platform; const char *name; } egl_platforms[] = { - { _EGL_PLATFORM_X11, "x11" }, - { _EGL_PLATFORM_XCB, "xcb" }, - { _EGL_PLATFORM_WAYLAND, "wayland" }, - { _EGL_PLATFORM_DRM, "drm" }, - { _EGL_PLATFORM_ANDROID, "android" }, - { _EGL_PLATFORM_HAIKU, "haiku" }, - { _EGL_PLATFORM_SURFACELESS, "surfaceless" }, - { _EGL_PLATFORM_DEVICE, "device" }, - { _EGL_PLATFORM_WINDOWS, "windows" }, + {_EGL_PLATFORM_X11, "x11"}, + {_EGL_PLATFORM_XCB, "xcb"}, + {_EGL_PLATFORM_WAYLAND, "wayland"}, + {_EGL_PLATFORM_DRM, "drm"}, + {_EGL_PLATFORM_ANDROID, "android"}, + {_EGL_PLATFORM_HAIKU, "haiku"}, + {_EGL_PLATFORM_SURFACELESS, "surfaceless"}, + {_EGL_PLATFORM_DEVICE, "device"}, + {_EGL_PLATFORM_WINDOWS, "windows"}, }; - /** * Return the native platform by parsing EGL_PLATFORM. */ @@ -121,7 +118,6 @@ _eglGetNativePlatformFromEnv(void) return plat; } - /** * Try detecting native platform with the help of native display characteristics. */ @@ -138,7 +134,7 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay) #if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM) if (_eglPointerIsDereferenceable(nativeDisplay)) { - void *first_pointer = *(void **) nativeDisplay; + void *first_pointer = *(void **)nativeDisplay; #ifdef HAVE_WAYLAND_PLATFORM /* wl_display is a wl_proxy, which is a wl_object. @@ -158,7 +154,6 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay) return _EGL_INVALID_PLATFORM; } - /** * Return the native platform. It is the platform of the EGL native types. */ @@ -184,7 +179,6 @@ _eglGetNativePlatform(void *nativeDisplay) return detected_platform; } - /** * Finish display management. */ @@ -209,7 +203,6 @@ _eglFiniDisplay(void) } } - /* The fcntl() code in _eglGetDeviceDisplay() ensures that valid fd >= 3, * and invalid one is 0. */ @@ -304,7 +297,6 @@ out: return disp; } - /** * Destroy the contexts and surfaces that are linked to the display. */ @@ -318,7 +310,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display) list = display->ResourceLists[_EGL_RESOURCE_CONTEXT]; while (list) { - _EGLContext *ctx = (_EGLContext *) list; + _EGLContext *ctx = (_EGLContext *)list; list = list->Next; _eglUnlinkContext(ctx); @@ -328,7 +320,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display) list = display->ResourceLists[_EGL_RESOURCE_SURFACE]; while (list) { - _EGLSurface *surf = (_EGLSurface *) list; + _EGLSurface *surf = (_EGLSurface *)list; list = list->Next; _eglUnlinkSurface(surf); @@ -338,7 +330,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display) list = display->ResourceLists[_EGL_RESOURCE_IMAGE]; while (list) { - _EGLImage *image = (_EGLImage *) list; + _EGLImage *image = (_EGLImage *)list; list = list->Next; _eglUnlinkImage(image); @@ -348,7 +340,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display) list = display->ResourceLists[_EGL_RESOURCE_SYNC]; while (list) { - _EGLSync *sync = (_EGLSync *) list; + _EGLSync *sync = (_EGLSync *)list; list = list->Next; _eglUnlinkSync(sync); @@ -357,7 +349,6 @@ _eglReleaseDisplayResources(_EGLDisplay *display) assert(!display->ResourceLists[_EGL_RESOURCE_SYNC]); } - /** * Free all the data hanging of an _EGLDisplay object, but not * the object itself. @@ -373,7 +364,6 @@ _eglCleanupDisplay(_EGLDisplay *disp) /* XXX incomplete */ } - /** * Return EGL_TRUE if the given resource is valid. That is, the display does * own the resource. @@ -382,14 +372,14 @@ EGLBoolean _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp) { _EGLResource *list = disp->ResourceLists[type]; - + simple_mtx_assert_locked(&disp->Mutex); if (!res) return EGL_FALSE; while (list) { - if (res == (void *) list) { + if (res == (void *)list) { assert(list->Display == disp); break; } @@ -399,7 +389,6 @@ _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp) return (list != NULL); } - /** * Initialize a display resource. The size of the subclass object is * specified. @@ -415,7 +404,6 @@ _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp) res->RefCount = 1; } - /** * Increment reference count for the resource. */ @@ -426,7 +414,6 @@ _eglGetResource(_EGLResource *res) p_atomic_inc(&res->RefCount); } - /** * Decrement reference count for the resource. */ @@ -437,7 +424,6 @@ _eglPutResource(_EGLResource *res) return p_atomic_dec_zero(&res->RefCount); } - /** * Link a resource to its display. */ @@ -453,7 +439,6 @@ _eglLinkResource(_EGLResource *res, _EGLResourceType type) _eglGetResource(res); } - /** * Unlink a linked resource from its display. */ @@ -473,8 +458,7 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type) } assert(prev); prev->Next = res->Next; - } - else { + } else { res->Display->ResourceLists[type] = res->Next; } @@ -487,9 +471,8 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type) } #ifdef HAVE_X11_PLATFORM -_EGLDisplay* -_eglGetX11Display(Display *native_display, - const EGLAttrib *attrib_list) +_EGLDisplay * +_eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list) { /* EGL_EXT_platform_x11 recognizes exactly one attribute, * EGL_PLATFORM_X11_SCREEN_EXT, which is optional. @@ -507,7 +490,7 @@ _eglGetX11Display(Display *native_display, #endif /* HAVE_X11_PLATFORM */ #ifdef HAVE_XCB_PLATFORM -_EGLDisplay* +_EGLDisplay * _eglGetXcbDisplay(xcb_connection_t *native_display, const EGLAttrib *attrib_list) { @@ -528,7 +511,7 @@ _eglGetXcbDisplay(xcb_connection_t *native_display, #endif /* HAVE_XCB_PLATFORM */ #ifdef HAVE_DRM_PLATFORM -_EGLDisplay* +_EGLDisplay * _eglGetGbmDisplay(struct gbm_device *native_display, const EGLAttrib *attrib_list) { @@ -543,7 +526,7 @@ _eglGetGbmDisplay(struct gbm_device *native_display, #endif /* HAVE_DRM_PLATFORM */ #ifdef HAVE_WAYLAND_PLATFORM -_EGLDisplay* +_EGLDisplay * _eglGetWaylandDisplay(struct wl_display *native_display, const EGLAttrib *attrib_list) { @@ -557,9 +540,8 @@ _eglGetWaylandDisplay(struct wl_display *native_display, } #endif /* HAVE_WAYLAND_PLATFORM */ -_EGLDisplay* -_eglGetSurfacelessDisplay(void *native_display, - const EGLAttrib *attrib_list) +_EGLDisplay * +_eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list) { /* This platform has no native display. */ if (native_display != NULL) { @@ -578,9 +560,8 @@ _eglGetSurfacelessDisplay(void *native_display, } #ifdef HAVE_ANDROID_PLATFORM -_EGLDisplay* -_eglGetAndroidDisplay(void *native_display, - const EGLAttrib *attrib_list) +_EGLDisplay * +_eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list) { /* This platform recognizes no display attributes. */ @@ -589,14 +570,12 @@ _eglGetAndroidDisplay(void *native_display, return NULL; } - return _eglFindDisplay(_EGL_PLATFORM_ANDROID, native_display, - attrib_list); + return _eglFindDisplay(_EGL_PLATFORM_ANDROID, native_display, attrib_list); } #endif /* HAVE_ANDROID_PLATFORM */ -_EGLDisplay* -_eglGetDeviceDisplay(void *native_display, - const EGLAttrib *attrib_list) +_EGLDisplay * +_eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list) { _EGLDevice *dev; _EGLDisplay *display; @@ -623,7 +602,7 @@ _eglGetDeviceDisplay(void *native_display, return NULL; } - fd = (int) value; + fd = (int)value; } } diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 4c340c8b0bd..ac4b05b30dd 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -27,16 +27,15 @@ * **************************************************************************/ - #ifndef EGLDISPLAY_INCLUDED #define EGLDISPLAY_INCLUDED -#include "util/simple_mtx.h" #include "util/rwlock.h" +#include "util/simple_mtx.h" -#include "egltypedefs.h" -#include "egldefines.h" #include "eglarray.h" +#include "egldefines.h" +#include "egltypedefs.h" #ifdef HAVE_X11_PLATFORM #include @@ -62,7 +61,6 @@ enum _egl_platform_type { }; typedef enum _egl_platform_type _EGLPlatformType; - enum _egl_resource_type { _EGL_RESOURCE_CONTEXT, _EGL_RESOURCE_SURFACE, @@ -74,12 +72,10 @@ enum _egl_resource_type { /* this cannot and need not go into egltypedefs.h */ typedef enum _egl_resource_type _EGLResourceType; - /** * A resource of a display. */ -struct _egl_resource -{ +struct _egl_resource { /* which display the resource belongs to */ _EGLDisplay *Display; EGLBoolean IsLinked; @@ -91,12 +87,10 @@ struct _egl_resource _EGLResource *Next; }; - /** * Optional EGL extensions info. */ -struct _egl_extensions -{ +struct _egl_extensions { /* Please keep these sorted alphabetically. */ EGLBoolean ANDROID_blob_cache; EGLBoolean ANDROID_framebuffer_target; @@ -120,9 +114,9 @@ struct _egl_extensions EGLBoolean EXT_swap_buffers_with_damage; unsigned int IMG_context_priority; -#define __EGL_CONTEXT_PRIORITY_LOW_BIT 0 -#define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1 -#define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2 +#define __EGL_CONTEXT_PRIORITY_LOW_BIT 0 +#define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1 +#define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2 EGLBoolean KHR_cl_event2; EGLBoolean KHR_config_attribs; @@ -159,8 +153,7 @@ struct _egl_extensions EGLBoolean WL_create_wayland_buffer_from_image; }; -struct _egl_display -{ +struct _egl_display { /* used to link displays */ _EGLDisplay *Next; @@ -195,9 +188,9 @@ struct _egl_display _EGLPlatformType Platform; /**< The type of the platform display */ void *PlatformDisplay; /**< A pointer to the platform display */ - _EGLDevice *Device; /**< Device backing the display */ - const _EGLDriver *Driver; /**< Matched driver of the display */ - EGLBoolean Initialized; /**< True if the display is initialized */ + _EGLDevice *Device; /**< Device backing the display */ + const _EGLDriver *Driver; /**< Matched driver of the display */ + EGLBoolean Initialized; /**< True if the display is initialized */ /* options that affect how the driver initializes the display */ struct { @@ -230,69 +223,54 @@ struct _egl_display EGLGetBlobFuncANDROID BlobCacheGet; }; - extern _EGLDisplay * _eglLockDisplay(EGLDisplay dpy); - extern void _eglUnlockDisplay(_EGLDisplay *disp); - extern _EGLPlatformType _eglGetNativePlatform(void *nativeDisplay); - extern void _eglFiniDisplay(void); - extern _EGLDisplay * _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr); - extern void _eglReleaseDisplayResources(_EGLDisplay *disp); - extern void _eglCleanupDisplay(_EGLDisplay *disp); - extern EGLBoolean _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp); - /** * Return the handle of a linked display, or EGL_NO_DISPLAY. */ static inline EGLDisplay _eglGetDisplayHandle(_EGLDisplay *disp) { - return (EGLDisplay) ((disp) ? disp : EGL_NO_DISPLAY); + return (EGLDisplay)((disp) ? disp : EGL_NO_DISPLAY); } - extern void _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp); - extern void _eglGetResource(_EGLResource *res); - extern EGLBoolean _eglPutResource(_EGLResource *res); - extern void _eglLinkResource(_EGLResource *res, _EGLResourceType type); - extern void _eglUnlinkResource(_EGLResource *res, _EGLResourceType type); - /** * Return true if the resource is linked. */ @@ -316,20 +294,21 @@ _eglNumAttribs(const EGLAttrib *attribs) } #ifdef HAVE_X11_PLATFORM -_EGLDisplay* +_EGLDisplay * _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list); #endif #ifdef HAVE_XCB_PLATFORM typedef struct xcb_connection_t xcb_connection_t; -_EGLDisplay* -_eglGetXcbDisplay(xcb_connection_t *native_display, const EGLAttrib *attrib_list); +_EGLDisplay * +_eglGetXcbDisplay(xcb_connection_t *native_display, + const EGLAttrib *attrib_list); #endif #ifdef HAVE_DRM_PLATFORM struct gbm_device; -_EGLDisplay* +_EGLDisplay * _eglGetGbmDisplay(struct gbm_device *native_display, const EGLAttrib *attrib_list); #endif @@ -337,24 +316,21 @@ _eglGetGbmDisplay(struct gbm_device *native_display, #ifdef HAVE_WAYLAND_PLATFORM struct wl_display; -_EGLDisplay* +_EGLDisplay * _eglGetWaylandDisplay(struct wl_display *native_display, const EGLAttrib *attrib_list); #endif -_EGLDisplay* -_eglGetSurfacelessDisplay(void *native_display, - const EGLAttrib *attrib_list); +_EGLDisplay * +_eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list); #ifdef HAVE_ANDROID_PLATFORM -_EGLDisplay* -_eglGetAndroidDisplay(void *native_display, - const EGLAttrib *attrib_list); +_EGLDisplay * +_eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list); #endif -_EGLDisplay* -_eglGetDeviceDisplay(void *native_display, - const EGLAttrib *attrib_list); +_EGLDisplay * +_eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list); #ifdef __cplusplus } diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 6a1b2e1dd29..6bea4fb3d6b 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -27,15 +27,12 @@ * **************************************************************************/ - #ifndef EGLDRIVER_INCLUDED #define EGLDRIVER_INCLUDED - -#include "egltypedefs.h" #include #include - +#include "egltypedefs.h" #ifdef __cplusplus extern "C" { @@ -47,10 +44,11 @@ extern "C" { * Note that this macro defines a function and should not be ended with a * semicolon when used. */ -#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \ - static inline struct drvtype *drvtype(const egltype *obj) \ - { return (struct drvtype *) code; } - +#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \ + static inline struct drvtype *drvtype(const egltype *obj) \ + { \ + return (struct drvtype *)code; \ + } /** * Define the driver typecast functions for _EGLDisplay, @@ -59,12 +57,12 @@ extern "C" { * Note that this macro defines several functions and should not be ended with * a semicolon when used. */ -#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \ - /* note that this is not a direct cast */ \ - _EGL_DRIVER_TYPECAST(drvname ## _display, _EGLDisplay, obj->DriverData) \ - _EGL_DRIVER_TYPECAST(drvname ## _context, _EGLContext, obj) \ - _EGL_DRIVER_TYPECAST(drvname ## _surface, _EGLSurface, obj) \ - _EGL_DRIVER_TYPECAST(drvname ## _config, _EGLConfig, obj) +#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \ + /* note that this is not a direct cast */ \ + _EGL_DRIVER_TYPECAST(drvname##_display, _EGLDisplay, obj->DriverData) \ + _EGL_DRIVER_TYPECAST(drvname##_context, _EGLContext, obj) \ + _EGL_DRIVER_TYPECAST(drvname##_surface, _EGLSurface, obj) \ + _EGL_DRIVER_TYPECAST(drvname##_config, _EGLConfig, obj) /** * A generic function ptr type @@ -80,28 +78,29 @@ typedef struct __GLsync *GLsync; /** * The API dispatcher jumps through these functions */ -struct _egl_driver -{ +struct _egl_driver { /* driver funcs */ EGLBoolean (*Initialize)(_EGLDisplay *disp); EGLBoolean (*Terminate)(_EGLDisplay *disp); /* context funcs */ _EGLContext *(*CreateContext)(_EGLDisplay *disp, _EGLConfig *config, - _EGLContext *share_list, const EGLint *attrib_list); + _EGLContext *share_list, + const EGLint *attrib_list); EGLBoolean (*DestroyContext)(_EGLDisplay *disp, _EGLContext *ctx); /* this is the only function (other than Initialize) that may be called * with an uninitialized display */ - EGLBoolean (*MakeCurrent)(_EGLDisplay *disp, - _EGLSurface *draw, _EGLSurface *read, - _EGLContext *ctx); + EGLBoolean (*MakeCurrent)(_EGLDisplay *disp, _EGLSurface *draw, + _EGLSurface *read, _EGLContext *ctx); /* surface funcs */ _EGLSurface *(*CreateWindowSurface)(_EGLDisplay *disp, _EGLConfig *config, - void *native_window, const EGLint *attrib_list); + void *native_window, + const EGLint *attrib_list); _EGLSurface *(*CreatePixmapSurface)(_EGLDisplay *disp, _EGLConfig *config, - void *native_pixmap, const EGLint *attrib_list); + void *native_pixmap, + const EGLint *attrib_list); _EGLSurface *(*CreatePbufferSurface)(_EGLDisplay *disp, _EGLConfig *config, const EGLint *attrib_list); EGLBoolean (*DestroySurface)(_EGLDisplay *disp, _EGLSurface *surface); @@ -135,8 +134,8 @@ struct _egl_driver _EGLSync *(*CreateSyncKHR)(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list); EGLBoolean (*DestroySyncKHR)(_EGLDisplay *disp, _EGLSync *sync); - EGLint (*ClientWaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, - EGLint flags, EGLTime timeout); + EGLint (*ClientWaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, + EGLTime timeout); EGLint (*WaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync); /* for EGL_KHR_reusable_sync */ EGLBoolean (*SignalSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLenum mode); @@ -155,21 +154,27 @@ struct _egl_driver EGLint *stride); /* for EGL_WL_bind_wayland_display */ - EGLBoolean (*BindWaylandDisplayWL)(_EGLDisplay *disp, struct wl_display *display); - EGLBoolean (*UnbindWaylandDisplayWL)(_EGLDisplay *disp, struct wl_display *display); - EGLBoolean (*QueryWaylandBufferWL)(_EGLDisplay *displ, struct wl_resource *buffer, + EGLBoolean (*BindWaylandDisplayWL)(_EGLDisplay *disp, + struct wl_display *display); + EGLBoolean (*UnbindWaylandDisplayWL)(_EGLDisplay *disp, + struct wl_display *display); + EGLBoolean (*QueryWaylandBufferWL)(_EGLDisplay *displ, + struct wl_resource *buffer, EGLint attribute, EGLint *value); /* for EGL_WL_create_wayland_buffer_from_image */ - struct wl_buffer *(*CreateWaylandBufferFromImageWL)(_EGLDisplay *disp, _EGLImage *img); + struct wl_buffer *(*CreateWaylandBufferFromImageWL)(_EGLDisplay *disp, + _EGLImage *img); /* for EGL_EXT_swap_buffers_with_damage */ - EGLBoolean (*SwapBuffersWithDamageEXT)(_EGLDisplay *disp, _EGLSurface *surface, + EGLBoolean (*SwapBuffersWithDamageEXT)(_EGLDisplay *disp, + _EGLSurface *surface, const EGLint *rects, EGLint n_rects); /* for EGL_NV_post_sub_buffer */ EGLBoolean (*PostSubBufferNV)(_EGLDisplay *disp, _EGLSurface *surface, - EGLint x, EGLint y, EGLint width, EGLint height); + EGLint x, EGLint y, EGLint width, + EGLint height); /* for EGL_EXT_buffer_age/EGL_KHR_partial_update */ EGLint (*QueryBufferAge)(_EGLDisplay *disp, _EGLSurface *surface); @@ -201,15 +206,16 @@ struct _egl_driver struct mesa_glinterop_export_in *in, struct mesa_glinterop_export_out *out); int (*GLInteropFlushObjects)(_EGLDisplay *disp, _EGLContext *ctx, - unsigned count, struct mesa_glinterop_export_in *in, + unsigned count, + struct mesa_glinterop_export_in *in, GLsync *sync); /* for EGL_EXT_image_dma_buf_import_modifiers */ - EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp, - EGLint max_formats, EGLint *formats, - EGLint *num_formats); + EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp, EGLint max_formats, + EGLint *formats, EGLint *num_formats); EGLBoolean (*QueryDmaBufModifiersEXT)(_EGLDisplay *disp, EGLint format, - EGLint max_modifiers, EGLuint64KHR *modifiers, + EGLint max_modifiers, + EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers); @@ -219,10 +225,8 @@ struct _egl_driver EGLGetBlobFuncANDROID get); }; - #ifdef __cplusplus } #endif - #endif /* EGLDRIVER_INCLUDED */ diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index fefbb37807c..3d12e6d5eae 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -27,16 +27,15 @@ * **************************************************************************/ - -#include -#include -#include #include +#include +#include +#include #include "util/simple_mtx.h" -#include "eglglobals.h" #include "egldevice.h" #include "egldisplay.h" +#include "eglglobals.h" #include "util/macros.h" #include "util/os_misc.h" @@ -46,69 +45,67 @@ #include #endif - static simple_mtx_t _eglGlobalMutex = SIMPLE_MTX_INITIALIZER; -struct _egl_global _eglGlobal = -{ +struct _egl_global _eglGlobal = { .Mutex = &_eglGlobalMutex, .DisplayList = NULL, .DeviceList = &_eglSoftwareDevice, .NumAtExitCalls = 2, - .AtExitCalls = { - /* default AtExitCalls, called in reverse order */ - _eglFiniDevice, /* always called last */ - _eglFiniDisplay, - }, + .AtExitCalls = + { + /* default AtExitCalls, called in reverse order */ + _eglFiniDevice, /* always called last */ + _eglFiniDisplay, + }, #if USE_LIBGLVND .ClientOnlyExtensionString = #else .ClientExtensionString = #endif - "EGL_EXT_client_extensions" + "EGL_EXT_client_extensions" #if !DETECT_OS_WINDOWS - " EGL_EXT_device_base" - " EGL_EXT_device_enumeration" - " EGL_EXT_device_query" + " EGL_EXT_device_base" + " EGL_EXT_device_enumeration" + " EGL_EXT_device_query" #endif - " EGL_EXT_platform_base" - " EGL_KHR_client_get_all_proc_addresses" - " EGL_KHR_debug" + " EGL_EXT_platform_base" + " EGL_KHR_client_get_all_proc_addresses" + " EGL_KHR_debug" #if USE_LIBGLVND , .PlatformExtensionString = #else - " " + " " #endif #if !DETECT_OS_WINDOWS - "EGL_EXT_platform_device" + "EGL_EXT_platform_device" #endif #ifdef HAVE_WAYLAND_PLATFORM - " EGL_EXT_platform_wayland" - " EGL_KHR_platform_wayland" + " EGL_EXT_platform_wayland" + " EGL_KHR_platform_wayland" #endif #ifdef HAVE_X11_PLATFORM - " EGL_EXT_platform_x11" - " EGL_KHR_platform_x11" + " EGL_EXT_platform_x11" + " EGL_KHR_platform_x11" #endif #ifdef HAVE_XCB_PLATFORM - " EGL_EXT_platform_xcb" + " EGL_EXT_platform_xcb" #endif #ifdef HAVE_DRM_PLATFORM - " EGL_MESA_platform_gbm" - " EGL_KHR_platform_gbm" + " EGL_MESA_platform_gbm" + " EGL_KHR_platform_gbm" #endif - " EGL_MESA_platform_surfaceless" - "", + " EGL_MESA_platform_surfaceless" + "", .debugCallback = NULL, .debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR, }; - static void _eglAtExit(void) { @@ -117,7 +114,6 @@ _eglAtExit(void) _eglGlobal.AtExitCalls[i](); } - void _eglAddAtExitCall(void (*func)(void)) { @@ -141,7 +137,7 @@ _eglAddAtExitCall(void (*func)(void)) EGLBoolean _eglPointerIsDereferenceable(void *p) { - uintptr_t addr = (uintptr_t) p; + uintptr_t addr = (uintptr_t)p; uint64_t page_size = 0; os_get_page_size(&page_size); #ifdef HAVE_MINCORE @@ -156,7 +152,7 @@ _eglPointerIsDereferenceable(void *p) /* mincore expects &valid to be unsigned char* on Linux but char* on BSD: * we cast pointers to void, to fix type mismatch warnings in all systems */ - if (mincore((void *) addr, page_size, (void*)&valid) < 0) { + if (mincore((void *)addr, page_size, (void *)&valid) < 0) { return EGL_FALSE; } diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h index c3f421c0c33..9cf8d582d9e 100644 --- a/src/egl/main/eglglobals.h +++ b/src/egl/main/eglglobals.h @@ -27,7 +27,6 @@ * **************************************************************************/ - #ifndef EGLGLOBALS_INCLUDED #define EGLGLOBALS_INCLUDED @@ -36,19 +35,17 @@ #include "egltypedefs.h" -enum -{ - _EGL_DEBUG_BIT_CRITICAL = 0x1, - _EGL_DEBUG_BIT_ERROR = 0x2, - _EGL_DEBUG_BIT_WARN = 0x4, - _EGL_DEBUG_BIT_INFO = 0x8, +enum { + _EGL_DEBUG_BIT_CRITICAL = 0x1, + _EGL_DEBUG_BIT_ERROR = 0x2, + _EGL_DEBUG_BIT_WARN = 0x4, + _EGL_DEBUG_BIT_INFO = 0x8, }; /** * Global library data */ -struct _egl_global -{ +struct _egl_global { simple_mtx_t *Mutex; /* the list of all displays */ @@ -75,14 +72,13 @@ struct _egl_global unsigned int debugTypesEnabled; }; - extern struct _egl_global _eglGlobal; - extern void _eglAddAtExitCall(void (*func)(void)); -static inline unsigned int DebugBitFromType(EGLenum type) +static inline unsigned int +DebugBitFromType(EGLenum type) { assert(type >= EGL_DEBUG_MSG_CRITICAL_KHR && type <= EGL_DEBUG_MSG_INFO_KHR); return (1 << (type - EGL_DEBUG_MSG_CRITICAL_KHR)); diff --git a/src/egl/main/eglglvnd.c b/src/egl/main/eglglvnd.c index 8e8e52db8cc..b9bec229246 100644 --- a/src/egl/main/eglglvnd.c +++ b/src/egl/main/eglglvnd.c @@ -25,8 +25,8 @@ * Kyle Brenneman */ -#include #include +#include #include @@ -36,7 +36,7 @@ static const __EGLapiExports *__eglGLVNDApiExports = NULL; -static const char * EGLAPIENTRY +static const char *EGLAPIENTRY __eglGLVNDQueryString(EGLDisplay dpy, EGLenum name) { // For client extensions, return the list of non-platform extensions. The @@ -59,12 +59,12 @@ __eglGLVNDGetVendorString(int name) static EGLDisplay __eglGLVNDGetPlatformDisplay(EGLenum platform, void *native_display, - const EGLAttrib *attrib_list) + const EGLAttrib *attrib_list) { if (platform == EGL_NONE) { - assert(native_display == (void *) EGL_DEFAULT_DISPLAY); + assert(native_display == (void *)EGL_DEFAULT_DISPLAY); assert(attrib_list == NULL); - return eglGetDisplay((EGLNativeDisplayType) native_display); + return eglGetDisplay((EGLNativeDisplayType)native_display); } else { return eglGetPlatformDisplay(platform, native_display, attrib_list); } @@ -74,14 +74,14 @@ static void * __eglGLVNDGetProcAddress(const char *procName) { if (strcmp(procName, "eglQueryString") == 0) - return (void *) __eglGLVNDQueryString; + return (void *)__eglGLVNDQueryString; - return (void *) eglGetProcAddress(procName); + return (void *)eglGetProcAddress(procName); } PUBLIC EGLAPI EGLBoolean __egl_Main(uint32_t version, const __EGLapiExports *exports, - __EGLvendorInfo *vendor, __EGLapiImports *imports) + __EGLvendorInfo *vendor, __EGLapiImports *imports) { if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) != EGL_VENDOR_ABI_MAJOR_VERSION) @@ -99,4 +99,3 @@ __egl_Main(uint32_t version, const __EGLapiExports *exports, return EGL_TRUE; } - diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c index 997855f48c0..a66384412bd 100644 --- a/src/egl/main/eglimage.c +++ b/src/egl/main/eglimage.c @@ -26,7 +26,6 @@ * **************************************************************************/ - #include #include @@ -214,8 +213,8 @@ _eglParseEXTImageDmaBufImportAttribs(_EGLImageAttribs *attrs, _EGLDisplay *disp, static EGLint _eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs *attrs, - _EGLDisplay *disp, - EGLint attr, EGLint val) + _EGLDisplay *disp, EGLint attr, + EGLint val) { if (!disp->Extensions.EXT_image_dma_buf_import_modifiers) return EGL_BAD_PARAMETER; @@ -316,7 +315,8 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp, if (err == EGL_BAD_ATTRIBUTE) return _eglError(err, __func__); - err = _eglParseEXTImageDmaBufImportModifiersAttribs(attrs, disp, attr, val); + err = + _eglParseEXTImageDmaBufImportModifiersAttribs(attrs, disp, attr, val); if (err == EGL_SUCCESS) continue; diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h index 02ad3b8ef10..a1595404aa5 100644 --- a/src/egl/main/eglimage.h +++ b/src/egl/main/eglimage.h @@ -26,28 +26,24 @@ * **************************************************************************/ - #ifndef EGLIMAGE_INCLUDED #define EGLIMAGE_INCLUDED -#include "egltypedefs.h" #include "egldisplay.h" - +#include "egltypedefs.h" #ifdef __cplusplus extern "C" { #endif -struct _egl_image_attrib_int -{ +struct _egl_image_attrib_int { EGLint Value; EGLBoolean IsPresent; }; #define DMA_BUF_MAX_PLANES 4 -struct _egl_image_attribs -{ +struct _egl_image_attribs { /* EGL_KHR_image_base */ EGLBoolean ImagePreserved; @@ -85,25 +81,21 @@ struct _egl_image_attribs /** * "Base" class for device driver images. */ -struct _egl_image -{ +struct _egl_image { /* An image is a display resource */ _EGLResource Resource; }; - EGLBoolean _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp, const EGLint *attrib_list); - static inline void _eglInitImage(_EGLImage *img, _EGLDisplay *disp) { _eglInitResource(&img->Resource, sizeof(*img), disp); } - /** * Increment reference count for the image. */ @@ -115,7 +107,6 @@ _eglGetImage(_EGLImage *img) return img; } - /** * Decrement reference count for the image. */ @@ -125,7 +116,6 @@ _eglPutImage(_EGLImage *img) return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE; } - /** * Link an image to its display and return the handle of the link. * The handle can be passed to client directly. @@ -134,10 +124,9 @@ static inline EGLImage _eglLinkImage(_EGLImage *img) { _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE); - return (EGLImage) img; + return (EGLImage)img; } - /** * Unlink a linked image from its display. * Accessing an unlinked image should generate EGL_BAD_PARAMETER error. @@ -148,7 +137,6 @@ _eglUnlinkImage(_EGLImage *img) _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE); } - /** * Lookup a handle to find the linked image. * Return NULL if the handle has no corresponding linked image. @@ -156,25 +144,22 @@ _eglUnlinkImage(_EGLImage *img) static inline _EGLImage * _eglLookupImage(EGLImage image, _EGLDisplay *disp) { - _EGLImage *img = (_EGLImage *) image; - if (!disp || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, disp)) + _EGLImage *img = (_EGLImage *)image; + if (!disp || !_eglCheckResource((void *)img, _EGL_RESOURCE_IMAGE, disp)) img = NULL; return img; } - /** * Return the handle of a linked image, or EGL_NO_IMAGE_KHR. */ static inline EGLImage _eglGetImageHandle(_EGLImage *img) { - _EGLResource *res = (_EGLResource *) img; - return (res && _eglIsResourceLinked(res)) ? - (EGLImage) img : EGL_NO_IMAGE_KHR; + _EGLResource *res = (_EGLResource *)img; + return (res && _eglIsResourceLinked(res)) ? (EGLImage)img : EGL_NO_IMAGE_KHR; } - #ifdef __cplusplus } #endif diff --git a/src/egl/main/egllog.c b/src/egl/main/egllog.c index 655e139f4af..678bb75d5bf 100644 --- a/src/egl/main/egllog.c +++ b/src/egl/main/egllog.c @@ -27,14 +27,12 @@ * **************************************************************************/ - /** * Logging facility for debug/info messages. * _EGL_FATAL messages are printed to stderr * The EGL_LOG_LEVEL var controls the output of other warning/info/debug msgs. */ - #include #include #include @@ -56,10 +54,9 @@ #endif /* HAVE_ANDROID_PLATFORM */ -#define MAXSTRING 1000 +#define MAXSTRING 1000 #define FALLBACK_LOG_LEVEL _EGL_WARNING - static struct { simple_mtx_t mutex; @@ -73,12 +70,11 @@ static struct { static const char *level_strings[] = { [_EGL_FATAL] = "fatal", - [_EGL_WARNING] = "warning", + [_EGL_WARNING] = "warning", [_EGL_INFO] = "info", [_EGL_DEBUG] = "debug", }; - /** * The default logger. It prints the message to stderr. */ @@ -88,7 +84,7 @@ _eglDefaultLogger(EGLint level, const char *msg) #ifdef HAVE_ANDROID_PLATFORM static const int egl2alog[] = { [_EGL_FATAL] = ANDROID_LOG_ERROR, - [_EGL_WARNING] = ANDROID_LOG_WARN, + [_EGL_WARNING] = ANDROID_LOG_WARN, [_EGL_INFO] = ANDROID_LOG_INFO, [_EGL_DEBUG] = ANDROID_LOG_DEBUG, }; @@ -98,7 +94,6 @@ _eglDefaultLogger(EGLint level, const char *msg) #endif /* HAVE_ANDROID_PLATFORM */ } - /** * Initialize the logging facility. */ @@ -143,7 +138,6 @@ _eglGetLogLevel(void) return logging.level; } - /** * Log a message with message logger. * \param level one of _EGL_FATAL, _EGL_WARNING, _EGL_INFO, _EGL_DEBUG. diff --git a/src/egl/main/egllog.h b/src/egl/main/egllog.h index a1cf9770ed8..09633124eda 100644 --- a/src/egl/main/egllog.h +++ b/src/egl/main/egllog.h @@ -26,32 +26,26 @@ * **************************************************************************/ - #ifndef EGLLOG_INCLUDED #define EGLLOG_INCLUDED - #include "egltypedefs.h" - #ifdef __cplusplus extern "C" { #endif -#define _EGL_FATAL 0 /* unrecoverable error */ -#define _EGL_WARNING 1 /* recoverable error/problem */ -#define _EGL_INFO 2 /* just useful info */ -#define _EGL_DEBUG 3 /* useful info for debugging */ - +#define _EGL_FATAL 0 /* unrecoverable error */ +#define _EGL_WARNING 1 /* recoverable error/problem */ +#define _EGL_INFO 2 /* just useful info */ +#define _EGL_DEBUG 3 /* useful info for debugging */ extern EGLint _eglGetLogLevel(void); - extern void _eglLog(EGLint level, const char *fmtStr, ...); - #ifdef __cplusplus } #endif diff --git a/src/egl/main/eglsurface.c b/src/egl/main/eglsurface.c index fe2315da91c..45407cdf427 100644 --- a/src/egl/main/eglsurface.c +++ b/src/egl/main/eglsurface.c @@ -27,23 +27,21 @@ * **************************************************************************/ - /** * Surface-related functions. */ - +#include "eglsurface.h" #include #include #include +#include "eglconfig.h" +#include "eglcontext.h" +#include "eglcurrent.h" #include "egldefines.h" #include "egldisplay.h" #include "egldriver.h" -#include "eglcontext.h" -#include "eglconfig.h" -#include "eglcurrent.h" #include "egllog.h" -#include "eglsurface.h" #include "util/macros.h" @@ -232,8 +230,7 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list) surf->PresentOpaque = val; break; case EGL_POST_SUB_BUFFER_SUPPORTED_NV: - if (!disp->Extensions.NV_post_sub_buffer || - type != EGL_WINDOW_BIT) { + if (!disp->Extensions.NV_post_sub_buffer || type != EGL_WINDOW_BIT) { err = EGL_BAD_ATTRIBUTE; break; } @@ -338,9 +335,12 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list) } if (err == EGL_SUCCESS && type == EGL_PBUFFER_BIT) { - if ((surf->TextureTarget == EGL_NO_TEXTURE && surf->TextureFormat != EGL_NO_TEXTURE) || - (surf->TextureFormat == EGL_NO_TEXTURE && surf->TextureTarget != EGL_NO_TEXTURE)) { - attr = surf->TextureTarget == EGL_NO_TEXTURE ? EGL_TEXTURE_TARGET : EGL_TEXTURE_FORMAT; + if ((surf->TextureTarget == EGL_NO_TEXTURE && + surf->TextureFormat != EGL_NO_TEXTURE) || + (surf->TextureFormat == EGL_NO_TEXTURE && + surf->TextureTarget != EGL_NO_TEXTURE)) { + attr = surf->TextureTarget == EGL_NO_TEXTURE ? EGL_TEXTURE_TARGET + : EGL_TEXTURE_FORMAT; err = EGL_BAD_MATCH; } } @@ -351,7 +351,6 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list) return err; } - /** * Do error check on parameters and initialize the given _EGLSurface object. * \return EGL_TRUE if no errors, EGL_FALSE otherwise. @@ -453,10 +452,9 @@ _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, return EGL_TRUE; } - EGLBoolean -_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface, - EGLint attribute, EGLint *value) +_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface, EGLint attribute, + EGLint *value) { switch (attribute) { case EGL_WIDTH: @@ -627,19 +625,17 @@ _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface, return EGL_TRUE; } - /** * Default fallback routine - drivers might override this. */ EGLBoolean -_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surface, - EGLint attribute, EGLint value) +_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surface, EGLint attribute, + EGLint value) { EGLint confval; EGLint err = EGL_SUCCESS; - EGLint all_es_bits = EGL_OPENGL_ES_BIT | - EGL_OPENGL_ES2_BIT | - EGL_OPENGL_ES3_BIT_KHR; + EGLint all_es_bits = + EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR; switch (attribute) { case EGL_MIPMAP_LEVEL: @@ -755,7 +751,6 @@ _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surface, return EGL_TRUE; } - EGLBoolean _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surface, EGLint buffer) { @@ -797,8 +792,7 @@ _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) if (surf == EGL_NO_SURFACE) return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); - if (!surf->BoundToTexture) - { + if (!surf->BoundToTexture) { /* Not an error, simply nothing to do */ return EGL_TRUE; } @@ -823,8 +817,7 @@ _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer) EGLBoolean _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf) { - return surf->Type == EGL_WINDOW_BIT && - surf->Config && + return surf->Type == EGL_WINDOW_BIT && surf->Config && (surf->Config->SurfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR); } diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h index 752b1b41e23..2f960aaf8d5 100644 --- a/src/egl/main/eglsurface.h +++ b/src/egl/main/eglsurface.h @@ -27,26 +27,22 @@ * **************************************************************************/ - #ifndef EGLSURFACE_INCLUDED #define EGLSURFACE_INCLUDED -#include "egltypedefs.h" #include "egldisplay.h" - +#include "egltypedefs.h" #ifdef __cplusplus extern "C" { #endif -struct _egl_xy -{ +struct _egl_xy { EGLint x; EGLint y; }; -struct _egl_hdr_metadata -{ +struct _egl_hdr_metadata { struct _egl_xy display_primary_r; struct _egl_xy display_primary_g; struct _egl_xy display_primary_b; @@ -60,8 +56,7 @@ struct _egl_hdr_metadata /** * "Base" class for device driver surfaces. */ -struct _egl_surface -{ +struct _egl_surface { /* A surface is a display resource */ _EGLResource Resource; @@ -176,20 +171,18 @@ struct _egl_surface void *NativeSurface; }; - extern EGLBoolean _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, _EGLConfig *config, const EGLint *attrib_list, void *native_surface); +extern EGLBoolean +_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint *value); extern EGLBoolean -_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value); - - -extern EGLBoolean -_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value); - +_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, + EGLint value); extern EGLBoolean _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); @@ -197,7 +190,6 @@ _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); extern EGLBoolean _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); - extern EGLBoolean _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf); @@ -215,7 +207,6 @@ _eglGetSurface(_EGLSurface *surf) return surf; } - /** * Decrement reference count for the surface. */ @@ -225,7 +216,6 @@ _eglPutSurface(_EGLSurface *surf) return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; } - /** * Link a surface to its display and return the handle of the link. * The handle can be passed to client directly. @@ -234,10 +224,9 @@ static inline EGLSurface _eglLinkSurface(_EGLSurface *surf) { _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); - return (EGLSurface) surf; + return (EGLSurface)surf; } - /** * Unlink a linked surface from its display. * Accessing an unlinked surface should generate EGL_BAD_SURFACE error. @@ -248,7 +237,6 @@ _eglUnlinkSurface(_EGLSurface *surf) _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); } - /** * Lookup a handle to find the linked surface. * Return NULL if the handle has no corresponding linked surface. @@ -256,25 +244,23 @@ _eglUnlinkSurface(_EGLSurface *surf) static inline _EGLSurface * _eglLookupSurface(EGLSurface surface, _EGLDisplay *disp) { - _EGLSurface *surf = (_EGLSurface *) surface; - if (!disp || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, disp)) + _EGLSurface *surf = (_EGLSurface *)surface; + if (!disp || !_eglCheckResource((void *)surf, _EGL_RESOURCE_SURFACE, disp)) surf = NULL; return surf; } - /** * Return the handle of a linked surface, or EGL_NO_SURFACE. */ static inline EGLSurface _eglGetSurfaceHandle(_EGLSurface *surf) { - _EGLResource *res = (_EGLResource *) surf; - return (res && _eglIsResourceLinked(res)) ? - (EGLSurface) surf : EGL_NO_SURFACE; + _EGLResource *res = (_EGLResource *)surf; + return (res && _eglIsResourceLinked(res)) ? (EGLSurface)surf + : EGL_NO_SURFACE; } - #ifdef __cplusplus } #endif diff --git a/src/egl/main/eglsync.c b/src/egl/main/eglsync.c index ccad83bb241..554077650bc 100644 --- a/src/egl/main/eglsync.c +++ b/src/egl/main/eglsync.c @@ -25,15 +25,13 @@ * **************************************************************************/ - #include #include -#include "eglsync.h" #include "eglcurrent.h" #include "egldriver.h" #include "egllog.h" - +#include "eglsync.h" /** * Parse the list of sync attributes and return the proper error code. @@ -81,7 +79,6 @@ _eglParseSyncAttribList(_EGLSync *sync, const EGLAttrib *attrib_list) return EGL_SUCCESS; } - EGLBoolean _eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list) @@ -118,10 +115,9 @@ _eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, return EGL_TRUE; } - EGLBoolean -_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, - EGLint attribute, EGLAttrib *value) +_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, EGLint attribute, + EGLAttrib *value) { switch (attribute) { case EGL_SYNC_TYPE_KHR: diff --git a/src/egl/main/eglsync.h b/src/egl/main/eglsync.h index b2f1ee5f3f5..d76446cd0b9 100644 --- a/src/egl/main/eglsync.h +++ b/src/egl/main/eglsync.h @@ -25,20 +25,16 @@ * **************************************************************************/ - #ifndef EGLSYNC_INCLUDED #define EGLSYNC_INCLUDED - -#include "egltypedefs.h" #include "egldisplay.h" - +#include "egltypedefs.h" /** * "Base" class for device driver syncs. */ -struct _egl_sync -{ +struct _egl_sync { /* A sync is a display resource */ _EGLResource Resource; @@ -49,16 +45,13 @@ struct _egl_sync EGLint SyncFd; }; - extern EGLBoolean _eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_list); - extern EGLBoolean -_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, - EGLint attribute, EGLAttrib *value); - +_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, EGLint attribute, + EGLAttrib *value); /** * Increment reference count for the sync. @@ -71,7 +64,6 @@ _eglGetSync(_EGLSync *sync) return sync; } - /** * Decrement reference count for the sync. */ @@ -81,7 +73,6 @@ _eglPutSync(_EGLSync *sync) return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE; } - /** * Link a sync to its display and return the handle of the link. * The handle can be passed to client directly. @@ -90,10 +81,9 @@ static inline EGLSync _eglLinkSync(_EGLSync *sync) { _eglLinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); - return (EGLSync) sync; + return (EGLSync)sync; } - /** * Unlink a linked sync from its display. */ @@ -103,7 +93,6 @@ _eglUnlinkSync(_EGLSync *sync) _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); } - /** * Lookup a handle to find the linked sync. * Return NULL if the handle has no corresponding linked sync. @@ -111,23 +100,20 @@ _eglUnlinkSync(_EGLSync *sync) static inline _EGLSync * _eglLookupSync(EGLSync handle, _EGLDisplay *disp) { - _EGLSync *sync = (_EGLSync *) handle; - if (!disp || !_eglCheckResource((void *) sync, _EGL_RESOURCE_SYNC, disp)) + _EGLSync *sync = (_EGLSync *)handle; + if (!disp || !_eglCheckResource((void *)sync, _EGL_RESOURCE_SYNC, disp)) sync = NULL; return sync; } - /** * Return the handle of a linked sync, or EGL_NO_SYNC_KHR. */ static inline EGLSync _eglGetSyncHandle(_EGLSync *sync) { - _EGLResource *res = (_EGLResource *) sync; - return (res && _eglIsResourceLinked(res)) ? - (EGLSync) sync : EGL_NO_SYNC_KHR; + _EGLResource *res = (_EGLResource *)sync; + return (res && _eglIsResourceLinked(res)) ? (EGLSync)sync : EGL_NO_SYNC_KHR; } - #endif /* EGLSYNC_INCLUDED */ diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h index 5d2ea58a59b..11d0fe8e248 100644 --- a/src/egl/main/egltypedefs.h +++ b/src/egl/main/egltypedefs.h @@ -27,14 +27,13 @@ * **************************************************************************/ - #ifndef EGLTYPEDEFS_INCLUDED #define EGLTYPEDEFS_INCLUDED #include #include -#include #include +#include #ifdef __cplusplus extern "C" { @@ -70,7 +69,6 @@ typedef struct _egl_sync _EGLSync; typedef struct _egl_thread_info _EGLThreadInfo; - #ifdef __cplusplus } #endif diff --git a/src/egl/wayland/wayland-drm/wayland-drm.c b/src/egl/wayland/wayland-drm/wayland-drm.c index 4b15657c288..45380ecb09e 100644 --- a/src/egl/wayland/wayland-drm/wayland-drm.c +++ b/src/egl/wayland/wayland-drm/wayland-drm.c @@ -27,238 +27,224 @@ * Benjamin Franzke */ +#include #include #include #include -#include #include -#include -#include "wayland-drm.h" #include "wayland-drm-server-protocol.h" +#include "wayland-drm.h" +#include -#define MIN(x,y) (((x)<(y))?(x):(y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) static void destroy_buffer(struct wl_resource *resource) { - struct wl_drm_buffer *buffer = wl_resource_get_user_data(resource); - struct wl_drm *drm = buffer->drm; + struct wl_drm_buffer *buffer = wl_resource_get_user_data(resource); + struct wl_drm *drm = buffer->drm; - drm->callbacks.release_buffer(drm->user_data, buffer); - free(buffer); + drm->callbacks.release_buffer(drm->user_data, buffer); + free(buffer); } static void buffer_destroy(struct wl_client *client, struct wl_resource *resource) { - wl_resource_destroy(resource); + wl_resource_destroy(resource); } static void create_buffer(struct wl_client *client, struct wl_resource *resource, - uint32_t id, uint32_t name, int fd, - int32_t width, int32_t height, - uint32_t format, - int32_t offset0, int32_t stride0, - int32_t offset1, int32_t stride1, - int32_t offset2, int32_t stride2) + uint32_t id, uint32_t name, int fd, int32_t width, int32_t height, + uint32_t format, int32_t offset0, int32_t stride0, + int32_t offset1, int32_t stride1, int32_t offset2, + int32_t stride2) { - struct wl_drm *drm = wl_resource_get_user_data(resource); - struct wl_drm_buffer *buffer; + struct wl_drm *drm = wl_resource_get_user_data(resource); + struct wl_drm_buffer *buffer; - buffer = calloc(1, sizeof *buffer); - if (buffer == NULL) { - wl_resource_post_no_memory(resource); - return; - } + buffer = calloc(1, sizeof *buffer); + if (buffer == NULL) { + wl_resource_post_no_memory(resource); + return; + } - buffer->drm = drm; - buffer->width = width; - buffer->height = height; - buffer->format = format; - buffer->offset[0] = offset0; - buffer->stride[0] = stride0; - buffer->offset[1] = offset1; - buffer->stride[1] = stride1; - buffer->offset[2] = offset2; - buffer->stride[2] = stride2; + buffer->drm = drm; + buffer->width = width; + buffer->height = height; + buffer->format = format; + buffer->offset[0] = offset0; + buffer->stride[0] = stride0; + buffer->offset[1] = offset1; + buffer->stride[1] = stride1; + buffer->offset[2] = offset2; + buffer->stride[2] = stride2; - drm->callbacks.reference_buffer(drm->user_data, name, fd, buffer); - if (buffer->driver_buffer == NULL) { - wl_resource_post_error(resource, - WL_DRM_ERROR_INVALID_NAME, - "invalid name"); - return; - } + drm->callbacks.reference_buffer(drm->user_data, name, fd, buffer); + if (buffer->driver_buffer == NULL) { + wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME, + "invalid name"); + return; + } - buffer->resource = - wl_resource_create(client, &wl_buffer_interface, 1, id); - if (!buffer->resource) { - wl_resource_post_no_memory(resource); - free(buffer); - return; - } + buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id); + if (!buffer->resource) { + wl_resource_post_no_memory(resource); + free(buffer); + return; + } - wl_resource_set_implementation(buffer->resource, - (void (**)(void)) &drm->buffer_interface, - buffer, destroy_buffer); + wl_resource_set_implementation(buffer->resource, + (void (**)(void)) & drm->buffer_interface, + buffer, destroy_buffer); } static void drm_create_buffer(struct wl_client *client, struct wl_resource *resource, - uint32_t id, uint32_t name, int32_t width, int32_t height, - uint32_t stride, uint32_t format) + uint32_t id, uint32_t name, int32_t width, int32_t height, + uint32_t stride, uint32_t format) { - switch (format) { - case WL_DRM_FORMAT_ABGR2101010: - case WL_DRM_FORMAT_XBGR2101010: - case WL_DRM_FORMAT_ARGB2101010: - case WL_DRM_FORMAT_XRGB2101010: - case WL_DRM_FORMAT_ARGB8888: - case WL_DRM_FORMAT_XRGB8888: - case WL_DRM_FORMAT_YUYV: - case WL_DRM_FORMAT_RGB565: - break; - default: - wl_resource_post_error(resource, - WL_DRM_ERROR_INVALID_FORMAT, - "invalid format"); - return; - } + switch (format) { + case WL_DRM_FORMAT_ABGR2101010: + case WL_DRM_FORMAT_XBGR2101010: + case WL_DRM_FORMAT_ARGB2101010: + case WL_DRM_FORMAT_XRGB2101010: + case WL_DRM_FORMAT_ARGB8888: + case WL_DRM_FORMAT_XRGB8888: + case WL_DRM_FORMAT_YUYV: + case WL_DRM_FORMAT_RGB565: + break; + default: + wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, + "invalid format"); + return; + } - create_buffer(client, resource, id, - name, -1, width, height, format, 0, stride, 0, 0, 0, 0); + create_buffer(client, resource, id, name, -1, width, height, format, 0, + stride, 0, 0, 0, 0); } static void -drm_create_planar_buffer(struct wl_client *client, - struct wl_resource *resource, - uint32_t id, uint32_t name, - int32_t width, int32_t height, uint32_t format, - int32_t offset0, int32_t stride0, - int32_t offset1, int32_t stride1, +drm_create_planar_buffer(struct wl_client *client, struct wl_resource *resource, + uint32_t id, uint32_t name, int32_t width, + int32_t height, uint32_t format, int32_t offset0, + int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2) { - switch (format) { - case WL_DRM_FORMAT_YUV410: - case WL_DRM_FORMAT_YUV411: - case WL_DRM_FORMAT_YUV420: - case WL_DRM_FORMAT_YUV422: - case WL_DRM_FORMAT_YUV444: - case WL_DRM_FORMAT_NV12: - case WL_DRM_FORMAT_NV16: - break; - default: - wl_resource_post_error(resource, - WL_DRM_ERROR_INVALID_FORMAT, - "invalid format"); - return; - } + switch (format) { + case WL_DRM_FORMAT_YUV410: + case WL_DRM_FORMAT_YUV411: + case WL_DRM_FORMAT_YUV420: + case WL_DRM_FORMAT_YUV422: + case WL_DRM_FORMAT_YUV444: + case WL_DRM_FORMAT_NV12: + case WL_DRM_FORMAT_NV16: + break; + default: + wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, + "invalid format"); + return; + } - create_buffer(client, resource, id, name, -1, width, height, format, - offset0, stride0, offset1, stride1, offset2, stride2); + create_buffer(client, resource, id, name, -1, width, height, format, offset0, + stride0, offset1, stride1, offset2, stride2); } static void -drm_create_prime_buffer(struct wl_client *client, - struct wl_resource *resource, - uint32_t id, int fd, - int32_t width, int32_t height, uint32_t format, - int32_t offset0, int32_t stride0, - int32_t offset1, int32_t stride1, - int32_t offset2, int32_t stride2) +drm_create_prime_buffer(struct wl_client *client, struct wl_resource *resource, + uint32_t id, int fd, int32_t width, int32_t height, + uint32_t format, int32_t offset0, int32_t stride0, + int32_t offset1, int32_t stride1, int32_t offset2, + int32_t stride2) { - create_buffer(client, resource, id, 0, fd, width, height, format, - offset0, stride0, offset1, stride1, offset2, stride2); - close(fd); + create_buffer(client, resource, id, 0, fd, width, height, format, offset0, + stride0, offset1, stride1, offset2, stride2); + close(fd); } static void -drm_authenticate(struct wl_client *client, - struct wl_resource *resource, uint32_t id) +drm_authenticate(struct wl_client *client, struct wl_resource *resource, + uint32_t id) { - struct wl_drm *drm = wl_resource_get_user_data(resource); + struct wl_drm *drm = wl_resource_get_user_data(resource); - if (!drm->callbacks.authenticate || - drm->callbacks.authenticate(drm->user_data, id) < 0) - wl_resource_post_error(resource, - WL_DRM_ERROR_AUTHENTICATE_FAIL, - "authenticate failed"); - else - wl_resource_post_event(resource, WL_DRM_AUTHENTICATED); + if (!drm->callbacks.authenticate || + drm->callbacks.authenticate(drm->user_data, id) < 0) + wl_resource_post_error(resource, WL_DRM_ERROR_AUTHENTICATE_FAIL, + "authenticate failed"); + else + wl_resource_post_event(resource, WL_DRM_AUTHENTICATED); } static const struct wl_drm_interface drm_interface = { - drm_authenticate, - drm_create_buffer, - drm_create_planar_buffer, - drm_create_prime_buffer, + drm_authenticate, + drm_create_buffer, + drm_create_planar_buffer, + drm_create_prime_buffer, }; static void bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id) { - struct wl_drm *drm = data; - struct wl_resource *resource; - uint32_t capabilities; + struct wl_drm *drm = data; + struct wl_resource *resource; + uint32_t capabilities; - resource = wl_resource_create(client, &wl_drm_interface, - MIN(version, 2), id); - if (!resource) { - wl_client_post_no_memory(client); - return; - } + resource = + wl_resource_create(client, &wl_drm_interface, MIN(version, 2), id); + if (!resource) { + wl_client_post_no_memory(client); + return; + } - wl_resource_set_implementation(resource, &drm_interface, data, NULL); + wl_resource_set_implementation(resource, &drm_interface, data, NULL); - wl_resource_post_event(resource, WL_DRM_DEVICE, drm->device_name); + wl_resource_post_event(resource, WL_DRM_DEVICE, drm->device_name); - if (drm->callbacks.is_format_supported(drm->user_data, - WL_DRM_FORMAT_ARGB2101010)) { - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_ARGB2101010); - } + if (drm->callbacks.is_format_supported(drm->user_data, + WL_DRM_FORMAT_ARGB2101010)) { + wl_resource_post_event(resource, WL_DRM_FORMAT, + WL_DRM_FORMAT_ARGB2101010); + } - if (drm->callbacks.is_format_supported(drm->user_data, - WL_DRM_FORMAT_XRGB2101010)) { - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_XRGB2101010); - } + if (drm->callbacks.is_format_supported(drm->user_data, + WL_DRM_FORMAT_XRGB2101010)) { + wl_resource_post_event(resource, WL_DRM_FORMAT, + WL_DRM_FORMAT_XRGB2101010); + } - if (drm->callbacks.is_format_supported(drm->user_data, - WL_DRM_FORMAT_ABGR2101010)) { - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_ABGR2101010); - } + if (drm->callbacks.is_format_supported(drm->user_data, + WL_DRM_FORMAT_ABGR2101010)) { + wl_resource_post_event(resource, WL_DRM_FORMAT, + WL_DRM_FORMAT_ABGR2101010); + } - if (drm->callbacks.is_format_supported(drm->user_data, - WL_DRM_FORMAT_XBGR2101010)) { - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_XBGR2101010); - } + if (drm->callbacks.is_format_supported(drm->user_data, + WL_DRM_FORMAT_XBGR2101010)) { + wl_resource_post_event(resource, WL_DRM_FORMAT, + WL_DRM_FORMAT_XBGR2101010); + } - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_ARGB8888); - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_XRGB8888); - wl_resource_post_event(resource, WL_DRM_FORMAT, - WL_DRM_FORMAT_RGB565); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV410); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV411); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV420); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV422); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV444); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV16); - wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUYV); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_ARGB8888); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_XRGB8888); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_RGB565); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV410); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV411); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV420); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV422); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV444); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV16); + wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUYV); - capabilities = 0; - if (drm->flags & WAYLAND_DRM_PRIME) - capabilities |= WL_DRM_CAPABILITY_PRIME; + capabilities = 0; + if (drm->flags & WAYLAND_DRM_PRIME) + capabilities |= WL_DRM_CAPABILITY_PRIME; - if (version >= 2) - wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities); + if (version >= 2) + wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities); } struct wl_drm * @@ -266,33 +252,32 @@ wayland_drm_init(struct wl_display *display, char *device_name, const struct wayland_drm_callbacks *callbacks, void *user_data, uint32_t flags) { - struct wl_drm *drm; + struct wl_drm *drm; - drm = malloc(sizeof *drm); - if (!drm) - return NULL; + drm = malloc(sizeof *drm); + if (!drm) + return NULL; - drm->display = display; - drm->device_name = strdup(device_name); - drm->callbacks = *callbacks; - drm->user_data = user_data; - drm->flags = flags; + drm->display = display; + drm->device_name = strdup(device_name); + drm->callbacks = *callbacks; + drm->user_data = user_data; + drm->flags = flags; - drm->buffer_interface.destroy = buffer_destroy; + drm->buffer_interface.destroy = buffer_destroy; - drm->wl_drm_global = - wl_global_create(display, &wl_drm_interface, 2, - drm, bind_drm); + drm->wl_drm_global = + wl_global_create(display, &wl_drm_interface, 2, drm, bind_drm); - return drm; + return drm; } void wayland_drm_uninit(struct wl_drm *drm) { - free(drm->device_name); + free(drm->device_name); - wl_global_destroy(drm->wl_drm_global); + wl_global_destroy(drm->wl_drm_global); - free(drm); + free(drm); } diff --git a/src/egl/wayland/wayland-drm/wayland-drm.h b/src/egl/wayland/wayland-drm/wayland-drm.h index 8b7fd3b0b64..8f3522e9bcb 100644 --- a/src/egl/wayland/wayland-drm/wayland-drm.h +++ b/src/egl/wayland/wayland-drm/wayland-drm.h @@ -8,39 +8,38 @@ struct wl_resource; struct wl_drm_buffer; struct wayland_drm_callbacks { - int (*authenticate)(void *user_data, uint32_t id); + int (*authenticate)(void *user_data, uint32_t id); - void (*reference_buffer)(void *user_data, uint32_t name, int fd, - struct wl_drm_buffer *buffer); + void (*reference_buffer)(void *user_data, uint32_t name, int fd, + struct wl_drm_buffer *buffer); - void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer); + void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer); - bool (*is_format_supported)(void *user_data, uint32_t format); + bool (*is_format_supported)(void *user_data, uint32_t format); }; - struct wl_drm { - struct wl_display *display; - struct wl_global *wl_drm_global; + struct wl_display *display; + struct wl_global *wl_drm_global; - void *user_data; - char *device_name; - uint32_t flags; + void *user_data; + char *device_name; + uint32_t flags; - struct wayland_drm_callbacks callbacks; + struct wayland_drm_callbacks callbacks; - struct wl_buffer_interface buffer_interface; + struct wl_buffer_interface buffer_interface; }; struct wl_drm_buffer { - struct wl_resource *resource; - struct wl_drm *drm; - int32_t width, height; - uint32_t format; - const void *driver_format; - int32_t offset[3]; - int32_t stride[3]; - void *driver_buffer; + struct wl_resource *resource; + struct wl_drm *drm; + int32_t width, height; + uint32_t format; + const void *driver_format; + int32_t offset[3]; + int32_t stride[3]; + void *driver_buffer; }; enum { WAYLAND_DRM_PRIME = 0x01 }; @@ -48,19 +47,19 @@ enum { WAYLAND_DRM_PRIME = 0x01 }; static inline struct wl_drm_buffer * wayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource) { - if (resource == NULL) - return NULL; + if (resource == NULL) + return NULL; - if (wl_resource_instance_of(resource, &wl_buffer_interface, - &drm->buffer_interface)) - return wl_resource_get_user_data(resource); - else - return NULL; + if (wl_resource_instance_of(resource, &wl_buffer_interface, + &drm->buffer_interface)) + return wl_resource_get_user_data(resource); + else + return NULL; } struct wl_drm * wayland_drm_init(struct wl_display *display, char *device_name, - const struct wayland_drm_callbacks *callbacks, void *user_data, + const struct wayland_drm_callbacks *callbacks, void *user_data, uint32_t flags); void