egl: re-format using clang-format

No manual changes here, this is simply running
$ ninja -C build/ clang-format

Signed-off-by: Eric Engestrom <eric@igalia.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23398>
This commit is contained in:
Eric Engestrom 2023-06-01 14:54:56 +01:00 committed by Marge Bot
parent f30081e586
commit e85983d772
47 changed files with 3102 additions and 3451 deletions

File diff suppressed because it is too large Load diff

View file

@ -32,11 +32,11 @@
#include <stdint.h> #include <stdint.h>
#ifdef HAVE_X11_PLATFORM #ifdef HAVE_X11_PLATFORM
#include <xcb/xcb.h> #include <X11/Xlib-xcb.h>
#include <xcb/dri2.h> #include <xcb/dri2.h>
#include <xcb/randr.h> #include <xcb/randr.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h> #include <xcb/xfixes.h>
#include <X11/Xlib-xcb.h>
#include "loader_dri_helper.h" #include "loader_dri_helper.h"
#ifdef HAVE_DRI3 #ifdef HAVE_DRI3
@ -82,18 +82,18 @@ struct zwp_linux_dmabuf_feedback_v1;
#include "eglconfig.h" #include "eglconfig.h"
#include "eglcontext.h" #include "eglcontext.h"
#include "eglcurrent.h"
#include "egldevice.h" #include "egldevice.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "eglcurrent.h" #include "eglimage.h"
#include "egllog.h" #include "egllog.h"
#include "eglsurface.h" #include "eglsurface.h"
#include "eglimage.h"
#include "eglsync.h" #include "eglsync.h"
#include "util/u_vector.h"
#include "util/u_dynarray.h"
#include "util/bitset.h" #include "util/bitset.h"
#include "util/u_dynarray.h"
#include "util/u_vector.h"
struct wl_buffer; struct wl_buffer;
@ -131,7 +131,8 @@ struct dri2_egl_display_vtbl {
EGLBoolean (*swap_buffers)(_EGLDisplay *disp, _EGLSurface *surf); EGLBoolean (*swap_buffers)(_EGLDisplay *disp, _EGLSurface *surf);
/* optional - falls back to .swap_buffers */ /* 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); const EGLint *rects, EGLint n_rects);
/* optional */ /* optional */
@ -139,9 +140,8 @@ struct dri2_egl_display_vtbl {
EGLint numRects, const EGLint *rects); EGLint numRects, const EGLint *rects);
/* optional */ /* optional */
EGLBoolean (*post_sub_buffer)(_EGLDisplay *disp, _EGLSurface *surf, EGLBoolean (*post_sub_buffer)(_EGLDisplay *disp, _EGLSurface *surf, EGLint x,
EGLint x, EGLint y, EGLint y, EGLint width, EGLint height);
EGLint width, EGLint height);
/* optional */ /* optional */
EGLBoolean (*copy_buffers)(_EGLDisplay *disp, _EGLSurface *surf, EGLBoolean (*copy_buffers)(_EGLDisplay *disp, _EGLSurface *surf,
@ -215,8 +215,7 @@ struct dmabuf_feedback {
}; };
#endif #endif
struct dri2_egl_display struct dri2_egl_display {
{
const struct dri2_egl_display_vtbl *vtbl; const struct dri2_egl_display_vtbl *vtbl;
mtx_t lock; mtx_t lock;
@ -224,11 +223,11 @@ struct dri2_egl_display
int dri2_major; int dri2_major;
int dri2_minor; int dri2_minor;
__DRIscreen *dri_screen_render_gpu; __DRIscreen *dri_screen_render_gpu;
/* dri_screen_display_gpu holds display GPU in case of prime gpu offloading else /* dri_screen_display_gpu holds display GPU in case of prime gpu offloading
* dri_screen_render_gpu and dri_screen_display_gpu is same. * else dri_screen_render_gpu and dri_screen_display_gpu is same. In case of
* In case of prime gpu offloading, if display and render driver names are different * 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 * (potentially not compatible), dri_screen_display_gpu will be NULL but
* will still hold fd for display driver. * fd_display_gpu will still hold fd for display driver.
*/ */
__DRIscreen *dri_screen_display_gpu; __DRIscreen *dri_screen_display_gpu;
bool own_dri_screen; bool own_dri_screen;
@ -319,14 +318,12 @@ struct dri2_egl_display
bool is_render_node; bool is_render_node;
}; };
struct dri2_egl_context struct dri2_egl_context {
{
_EGLContext base; _EGLContext base;
__DRIcontext *dri_context; __DRIcontext *dri_context;
}; };
struct dri2_egl_surface struct dri2_egl_surface {
{
_EGLSurface base; _EGLSurface base;
__DRIdrawable *dri_drawable; __DRIdrawable *dri_drawable;
__DRIbuffer buffers[5]; __DRIbuffer buffers[5];
@ -418,14 +415,12 @@ struct dri2_egl_surface
char *swrast_device_buffer; char *swrast_device_buffer;
}; };
struct dri2_egl_config struct dri2_egl_config {
{
_EGLConfig base; _EGLConfig base;
const __DRIconfig *dri_config[2][2]; const __DRIconfig *dri_config[2][2];
}; };
struct dri2_egl_image struct dri2_egl_image {
{
_EGLImage base; _EGLImage base;
__DRIimage *dri_image; __DRIimage *dri_image;
}; };
@ -455,7 +450,8 @@ dri2_egl_display_lock(_EGLDisplay *disp)
} }
static inline EGLBoolean 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); mtx_unlock(&dri2_dpy->lock);
return _eglError(err, msg); return _eglError(err, msg);
@ -507,8 +503,7 @@ dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
void void
dri2_get_render_type_float(const __DRIcoreExtension *core, dri2_get_render_type_float(const __DRIcoreExtension *core,
const __DRIconfig *config, const __DRIconfig *config, bool *is_float);
bool *is_float);
unsigned int unsigned int
dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy, 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"); return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
} }
static inline void 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 static inline unsigned int
dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth) 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"); return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built");
} }
static inline void static inline void
dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {} dri2_teardown_drm(struct dri2_egl_display *dri2_dpy)
{
}
#endif #endif
#ifdef HAVE_WAYLAND_PLATFORM #ifdef HAVE_WAYLAND_PLATFORM
@ -584,7 +583,9 @@ dri2_initialize_wayland(_EGLDisplay *disp)
return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built"); return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built");
} }
static inline void static inline void
dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {} dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy)
{
}
#endif #endif
#ifdef HAVE_ANDROID_PLATFORM #ifdef HAVE_ANDROID_PLATFORM
@ -604,10 +605,13 @@ dri2_initialize_surfaceless(_EGLDisplay *disp);
EGLBoolean EGLBoolean
dri2_initialize_device(_EGLDisplay *disp); dri2_initialize_device(_EGLDisplay *disp);
static inline void static inline void
dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ } dri2_teardown_device(struct dri2_egl_display *dri2_dpy)
{ /* noop */
}
void void
dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw, dri2_flush_drawable_for_swapbuffers_flags(
_EGLDisplay *disp, _EGLSurface *draw,
enum __DRI2throttleReason throttle_reason); enum __DRI2throttleReason throttle_reason);
void void
dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw); dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
@ -659,8 +663,7 @@ dri2_fini_surface(_EGLSurface *surf);
EGLBoolean EGLBoolean
dri2_create_drawable(struct dri2_egl_display *dri2_dpy, dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
const __DRIconfig *config, const __DRIconfig *config,
struct dri2_egl_surface *dri2_surf, struct dri2_egl_surface *dri2_surf, void *loaderPrivate);
void *loaderPrivate);
static inline uint64_t static inline uint64_t
combine_u32_into_u64(uint32_t hi, uint32_t lo) combine_u32_into_u64(uint32_t hi, uint32_t lo)

View file

@ -27,29 +27,29 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include <cutils/properties.h>
#include <errno.h>
#include <dirent.h> #include <dirent.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <xf86drm.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <xf86drm.h>
#include <cutils/properties.h>
#include <drm-uapi/drm_fourcc.h>
#include <sync/sync.h> #include <sync/sync.h>
#include <sys/types.h> #include <sys/types.h>
#include <drm-uapi/drm_fourcc.h>
#include "util/compiler.h" #include "util/compiler.h"
#include "util/os_file.h"
#include "util/libsync.h" #include "util/libsync.h"
#include "util/os_file.h"
#include "loader.h"
#include "egl_dri2.h" #include "egl_dri2.h"
#include "loader.h"
#include "platform_android.h" #include "platform_android.h"
#ifdef HAVE_DRM_GRALLOC #ifdef HAVE_DRM_GRALLOC
#include <gralloc_drm_handle.h>
#include "gralloc_drm.h" #include "gralloc_drm.h"
#include <gralloc_drm_handle.h>
#endif /* HAVE_DRM_GRALLOC */ #endif /* HAVE_DRM_GRALLOC */
#define ALIGN(val, align) (((val) + (align)-1) & ~((align)-1)) #define ALIGN(val, align) (((val) + (align)-1) & ~((align)-1))
@ -121,7 +121,8 @@ get_format_bpp(int native)
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
/* /*
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. * 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_RGBX_8888:
case HAL_PIXEL_FORMAT_BGRA_8888: case HAL_PIXEL_FORMAT_BGRA_8888:
@ -140,20 +141,28 @@ get_format_bpp(int native)
} }
/* createImageFromFds requires fourcc format */ /* createImageFromFds requires fourcc format */
static int get_fourcc(int native) static int
get_fourcc(int native)
{ {
switch (native) { switch (native) {
case HAL_PIXEL_FORMAT_RGB_565: return DRM_FORMAT_RGB565; case HAL_PIXEL_FORMAT_RGB_565:
case HAL_PIXEL_FORMAT_BGRA_8888: return DRM_FORMAT_ARGB8888; return DRM_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_RGBA_8888: return DRM_FORMAT_ABGR8888; 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: case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
/* /*
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. * 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_RGBX_8888:
case HAL_PIXEL_FORMAT_RGBA_FP16: return DRM_FORMAT_ABGR16161616F; return DRM_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_RGBA_1010102: return DRM_FORMAT_ABGR2101010; case HAL_PIXEL_FORMAT_RGBA_FP16:
return DRM_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102:
return DRM_FORMAT_ABGR2101010;
default: default:
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", native); _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)); memset(&ycbcr, 0, sizeof(ycbcr));
ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, 0, 0, 0,
0, 0, 0, 0, 0, &ycbcr); 0, 0, &ycbcr);
if (ret) { if (ret) {
/* HACK: See native_window_buffer_get_buffer_info() and /* HACK: See native_window_buffer_get_buffer_info() and
* https://issuetracker.google.com/32077885.*/ * 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. */ * 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); drm_fourcc = get_fourcc_yuv(buf->format, chroma_order, ycbcr.chroma_step);
if (drm_fourcc == -1) { if (drm_fourcc == -1) {
_eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = %d", _eglLog(_EGL_WARNING,
buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb", ycbcr.chroma_step); "unsupported YUV format, native = %x, chroma_order = %s, "
"chroma_step = %d",
buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb",
ycbcr.chroma_step);
return -EINVAL; return -EINVAL;
} }
@ -355,7 +367,8 @@ native_window_buffer_get_buffer_info(struct dri2_egl_display *dri2_dpy,
* offsets and strides. If we have this, we can skip straight to * offsets and strides. If we have this, we can skip straight to
* createImageFromDmaBufs2() and avoid all the guessing and recalculations. * createImageFromDmaBufs2() and avoid all the guessing and recalculations.
* This also gives us the modifier and plane offsets/strides for multiplanar * 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"; static const char cros_gralloc_module_name[] = "CrOS Gralloc";
@ -383,8 +396,8 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy,
if (strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) == 0 && if (strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) == 0 &&
dri2_dpy->gralloc->perform && dri2_dpy->gralloc->perform &&
dri2_dpy->gralloc->perform(dri2_dpy->gralloc, dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
CROS_GRALLOC_DRM_GET_BUFFER_INFO, CROS_GRALLOC_DRM_GET_BUFFER_INFO, buf->handle,
buf->handle, &info) == 0) { &info) == 0) {
*out_buf_info = (struct buffer_info){ *out_buf_info = (struct buffer_info){
.width = buf->width, .width = buf->width,
.height = buf->height, .height = buf->height,
@ -411,8 +424,7 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy,
static __DRIimage * static __DRIimage *
droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy, droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy,
struct buffer_info *buf_info, struct buffer_info *buf_info, void *priv)
void *priv)
{ {
unsigned error; 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->drm_fourcc, buf_info->modifier, buf_info->fds,
buf_info->num_planes, buf_info->pitches, buf_info->offsets, buf_info->num_planes, buf_info->pitches, buf_info->offsets,
buf_info->yuv_color_space, buf_info->sample_range, buf_info->yuv_color_space, buf_info->sample_range,
buf_info->horizontal_siting, buf_info->vertical_siting, &error, buf_info->horizontal_siting, buf_info->vertical_siting, &error, priv);
priv);
} }
return dri2_dpy->image->createImageFromDmaBufs( return dri2_dpy->image->createImageFromDmaBufs(
@ -536,7 +547,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
} }
static EGLBoolean 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); 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); _eglLog(_EGL_DEBUG, "%s: mode=%d", __func__, mode);
if (ANativeWindow_setSharedBufferMode(window, mode)) { if (ANativeWindow_setSharedBufferMode(window, mode)) {
_eglLog(_EGL_WARNING, "failed ANativeWindow_setSharedBufferMode" _eglLog(_EGL_WARNING,
"(window=%p, mode=%d)", window, mode); "failed ANativeWindow_setSharedBufferMode"
"(window=%p, mode=%d)",
window, mode);
return false; return false;
} }
@ -616,7 +630,8 @@ droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode)
return true; return true;
#else #else
_eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__, __LINE__); _eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__,
__LINE__);
return false; return false;
#endif #endif
} }
@ -639,8 +654,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
dri2_surf->in_fence_fd = -1; dri2_surf->in_fence_fd = -1;
if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, true,
true, native_window)) native_window))
goto cleanup_surface; goto cleanup_surface;
if (type == EGL_WINDOW_BIT) { if (type == EGL_WINDOW_BIT) {
@ -667,8 +682,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
/* Required buffer caching slots. */ /* Required buffer caching slots. */
buffer_count = min_undequeued_buffers + 2; buffer_count = min_undequeued_buffers + 2;
dri2_surf->color_buffers = calloc(buffer_count, dri2_surf->color_buffers =
sizeof(*dri2_surf->color_buffers)); calloc(buffer_count, sizeof(*dri2_surf->color_buffers));
if (!dri2_surf->color_buffers) { if (!dri2_surf->color_buffers) {
_eglError(EGL_BAD_ALLOC, "droid_create_surface"); _eglError(EGL_BAD_ALLOC, "droid_create_surface");
goto cleanup_surface; goto cleanup_surface;
@ -676,8 +691,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
dri2_surf->color_buffers_count = buffer_count; dri2_surf->color_buffers_count = buffer_count;
if (format != dri2_conf->base.NativeVisualID) { if (format != dri2_conf->base.NativeVisualID) {
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", _eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", format,
format, dri2_conf->base.NativeVisualID); dri2_conf->base.NativeVisualID);
} }
ANativeWindow_query(window, ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, 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, config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
dri2_surf->base.GLColorspace);
if (!config) { if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); _eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surface; goto cleanup_surface;
} }
@ -728,16 +743,15 @@ static _EGLSurface *
droid_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, droid_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_window, const EGLint *attrib_list) void *native_window, const EGLint *attrib_list)
{ {
return droid_create_surface(disp, EGL_WINDOW_BIT, conf, return droid_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
native_window, attrib_list); attrib_list);
} }
static _EGLSurface * static _EGLSurface *
droid_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, droid_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list) const EGLint *attrib_list)
{ {
return droid_create_surface(disp, EGL_PBUFFER_BIT, conf, return droid_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list);
NULL, attrib_list);
} }
static EGLBoolean static EGLBoolean
@ -756,13 +770,15 @@ droid_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
} }
if (dri2_surf->dri_image_back) { 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_dpy->image->destroyImage(dri2_surf->dri_image_back);
dri2_surf->dri_image_back = NULL; dri2_surf->dri_image_back = NULL;
} }
if (dri2_surf->dri_image_front) { 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_dpy->image->destroyImage(dri2_surf->dri_image_front);
dri2_surf->dri_image_front = NULL; 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. * and mesa doesn't have the implementation of this case.
* Add warning message, but not treat it as error. * 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) { } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
dri2_surf->dri_image_front = dri2_surf->dri_image_front = dri2_dpy->image->createImage(
dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Width, dri2_surf->base.Height, format, 0, NULL);
dri2_surf->base.Height,
format,
0,
NULL);
if (!dri2_surf->dri_image_front) { if (!dri2_surf->dri_image_front) {
_eglLog(_EGL_WARNING, "dri2_image_front allocation failed"); _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
return -1; 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); handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
} else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) { } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
/* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically, /* The EGL 1.5 spec states that pbuffers are single-buffered.
* the spec states that they have a back buffer but no front buffer, in * Specifically, the spec states that they have a back buffer but no front
* contrast to pixmaps, which have a front buffer but no back buffer. * 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 * Single-buffered surfaces with no front buffer confuse Mesa; so we
* from the spec, following the precedent of Mesa's EGL X11 platform. The * deviate from the spec, following the precedent of Mesa's EGL X11
* X11 platform correctly assigns pbuffers to single-buffered configs, but * platform. The X11 platform correctly assigns pbuffers to
* assigns the pbuffer a front buffer instead of a back buffer. * 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 * 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 * behavior instead of trying to fix (and hence potentially breaking) the
* world. * 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; return 0;
@ -899,12 +917,9 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
* return error when the allocation for supported buffer failed. * return error when the allocation for supported buffer failed.
*/ */
static int static int
droid_image_get_buffers(__DRIdrawable *driDrawable, droid_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
unsigned int format, uint32_t *stamp, void *loaderPrivate,
uint32_t *stamp, uint32_t buffer_mask, struct __DRIimageList *images)
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *images)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; 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 * for which there is no pending change to the EGL_RENDER_BUFFER
* attribute, eglSwapBuffers has no effect. * attribute, eglSwapBuffers has no effect.
*/ */
if (has_mutable_rb && if (has_mutable_rb && draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER &&
draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER &&
draw->ActiveRenderBuffer == EGL_SINGLE_BUFFER) { draw->ActiveRenderBuffer == EGL_SINGLE_BUFFER) {
_eglLog(_EGL_DEBUG, "%s: remain in shared buffer mode", __func__); _eglLog(_EGL_DEBUG, "%s: remain in shared buffer mode", __func__);
return EGL_TRUE; return EGL_TRUE;
@ -997,7 +1011,8 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
if (dri2_surf->back) if (dri2_surf->back)
dri2_surf->back->age = 1; 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 /* 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 * example, if the user has called no GL rendering commands since the
@ -1014,8 +1029,8 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
if (has_mutable_rb && if (has_mutable_rb &&
draw->ActiveRenderBuffer != draw->RequestedRenderBuffer) { draw->ActiveRenderBuffer != draw->RequestedRenderBuffer) {
bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER); bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER);
_eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", _eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", __func__,
__func__, mode); mode);
if (!droid_set_shared_buffer_mode(disp, draw, mode)) if (!droid_set_shared_buffer_mode(disp, draw, mode))
return EGL_FALSE; return EGL_FALSE;
@ -1026,20 +1041,28 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
} }
#ifdef HAVE_DRM_GRALLOC #ifdef HAVE_DRM_GRALLOC
static int get_format(int format) static int
get_format(int format)
{ {
switch (format) { switch (format) {
case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FORMAT_ARGB8888; case HAL_PIXEL_FORMAT_BGRA_8888:
case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FORMAT_RGB565; return __DRI_IMAGE_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FORMAT_ABGR8888; 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: case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
/* /*
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack. * 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_RGBX_8888:
case HAL_PIXEL_FORMAT_RGBA_FP16: return __DRI_IMAGE_FORMAT_ABGR16161616F; return __DRI_IMAGE_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_RGBA_1010102: return __DRI_IMAGE_FORMAT_ABGR2101010; case HAL_PIXEL_FORMAT_RGBA_FP16:
return __DRI_IMAGE_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102:
return __DRI_IMAGE_FORMAT_ABGR2101010;
default: default:
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format); _eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
} }
@ -1047,8 +1070,7 @@ static int get_format(int format)
} }
static __DRIimage * static __DRIimage *
droid_create_image_from_name(_EGLDisplay *disp, droid_create_image_from_name(_EGLDisplay *disp, struct ANativeWindowBuffer *buf,
struct ANativeWindowBuffer *buf,
void *priv) void *priv)
{ {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
@ -1065,20 +1087,15 @@ droid_create_image_from_name(_EGLDisplay *disp,
if (format == -1) if (format == -1)
return NULL; return NULL;
return return dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu, buf->width, buf->height, format,
buf->width, name, buf->stride, priv);
buf->height,
format,
name,
buf->stride,
priv);
} }
#endif /* HAVE_DRM_GRALLOC */ #endif /* HAVE_DRM_GRALLOC */
static EGLBoolean static EGLBoolean
droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf, droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint attribute, EGLint *value) EGLint *value)
{ {
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
switch (attribute) { switch (attribute) {
@ -1103,8 +1120,7 @@ droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf,
} }
static _EGLImage * static _EGLImage *
dri2_create_image_android_native_buffer(_EGLDisplay *disp, dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
_EGLContext *ctx,
struct ANativeWindowBuffer *buf) struct ANativeWindowBuffer *buf)
{ {
if (ctx != NULL) { if (ctx != NULL) {
@ -1113,7 +1129,8 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp,
* * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not * * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not
* EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated. * 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_NATIVE_BUFFER_ANDROID, the context must be "
"EGL_NO_CONTEXT"); "EGL_NO_CONTEXT");
return NULL; return NULL;
@ -1149,8 +1166,8 @@ droid_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target,
{ {
switch (target) { switch (target) {
case EGL_NATIVE_BUFFER_ANDROID: case EGL_NATIVE_BUFFER_ANDROID:
return dri2_create_image_android_native_buffer(disp, ctx, return dri2_create_image_android_native_buffer(
(struct ANativeWindowBuffer *) buffer); disp, ctx, (struct ANativeWindowBuffer *)buffer);
default: default:
return dri2_create_image_khr(disp, ctx, target, buffer, attr_list); return dri2_create_image_khr(disp, ctx, target, buffer, attr_list);
} }
@ -1195,8 +1212,8 @@ droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
case __DRI_BUFFER_ACCUM: case __DRI_BUFFER_ACCUM:
case __DRI_BUFFER_DEPTH_STENCIL: case __DRI_BUFFER_DEPTH_STENCIL:
case __DRI_BUFFER_HIZ: case __DRI_BUFFER_HIZ:
local = dri2_egl_surface_alloc_local_buffer(dri2_surf, local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
attachments[i], attachments[i + 1]); attachments[i + 1]);
if (local) { if (local) {
*buf = *local; *buf = *local;
@ -1218,9 +1235,8 @@ droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
} }
static __DRIbuffer * static __DRIbuffer *
droid_get_buffers_with_format(__DRIdrawable * driDrawable, droid_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
int *width, int *height, int *height, unsigned int *attachments, int count,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate) int *out_count, void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
@ -1228,7 +1244,8 @@ droid_get_buffers_with_format(__DRIdrawable * driDrawable,
if (update_buffers(dri2_surf) < 0) if (update_buffers(dri2_surf) < 0)
return NULL; 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) if (width)
*width = dri2_surf->base.Width; *width = dri2_surf->base.Width;
@ -1312,17 +1329,20 @@ droid_add_configs_for_visuals(_EGLDisplay *disp)
const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT; const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
const EGLint config_attrs[] = { const EGLint config_attrs[] = {
EGL_NATIVE_VISUAL_ID, visuals[i].format, EGL_NATIVE_VISUAL_ID,
EGL_NATIVE_VISUAL_TYPE, visuals[i].format, visuals[i].format,
EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE, EGL_NATIVE_VISUAL_TYPE,
EGL_RECORDABLE_ANDROID, EGL_TRUE, visuals[i].format,
EGL_FRAMEBUFFER_TARGET_ANDROID,
EGL_TRUE,
EGL_RECORDABLE_ANDROID,
EGL_TRUE,
EGL_NONE, EGL_NONE,
}; };
struct dri2_egl_config *dri2_conf = struct dri2_egl_config *dri2_conf = dri2_add_config(
dri2_add_config(disp, dri2_dpy->driver_configs[j], disp, dri2_dpy->driver_configs[j], config_count + 1, surface_type,
config_count + 1, surface_type, config_attrs, config_attrs, visuals[i].rgba_shifts, visuals[i].rgba_sizes);
visuals[i].rgba_shifts, visuals[i].rgba_sizes);
if (dri2_conf) { if (dri2_conf) {
if (dri2_conf->base.ConfigID == config_count + 1) if (dri2_conf->base.ConfigID == config_count + 1)
config_count++; config_count++;
@ -1451,7 +1471,8 @@ droid_display_shared_buffer(__DRIdrawable *driDrawable, int fence_fd,
handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back); handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
} }
static const __DRImutableRenderBufferLoaderExtension droid_mutable_render_buffer_extension = { static const __DRImutableRenderBufferLoaderExtension
droid_mutable_render_buffer_extension = {
.base = {__DRI_MUTABLE_RENDER_BUFFER_LOADER, 1}, .base = {__DRI_MUTABLE_RENDER_BUFFER_LOADER, 1},
.displaySharedBuffer = droid_display_shared_buffer, .displaySharedBuffer = droid_display_shared_buffer,
}; };
@ -1567,8 +1588,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
if (dri2_dpy->gralloc->perform) if (dri2_dpy->gralloc->perform)
err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc, err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
GRALLOC_MODULE_PERFORM_GET_DRM_FD, GRALLOC_MODULE_PERFORM_GET_DRM_FD, &fd);
&fd);
if (err || fd < 0) { if (err || fd < 0) {
_eglLog(_EGL_WARNING, "fail to get drm fd"); _eglLog(_EGL_WARNING, "fail to get drm fd");
return EGL_FALSE; return EGL_FALSE;
@ -1616,8 +1636,8 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
dri2_dpy->fd_render_gpu = loader_open_device(device->nodes[node_type]); dri2_dpy->fd_render_gpu = loader_open_device(device->nodes[node_type]);
if (dri2_dpy->fd_render_gpu < 0) { if (dri2_dpy->fd_render_gpu < 0) {
_eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", __func__,
__func__, device->nodes[node_type]); device->nodes[node_type]);
continue; continue;
} }

View file

@ -63,24 +63,21 @@ ANativeWindow_getFormat(struct ANativeWindow *window)
static inline int static inline int
ANativeWindow_dequeueBuffer(struct ANativeWindow *window, ANativeWindow_dequeueBuffer(struct ANativeWindow *window,
struct ANativeWindowBuffer **buffer, struct ANativeWindowBuffer **buffer, int *fenceFd)
int *fenceFd)
{ {
return window->dequeueBuffer(window, buffer, fenceFd); return window->dequeueBuffer(window, buffer, fenceFd);
} }
static inline int static inline int
ANativeWindow_queueBuffer(struct ANativeWindow *window, ANativeWindow_queueBuffer(struct ANativeWindow *window,
struct ANativeWindowBuffer *buffer, struct ANativeWindowBuffer *buffer, int fenceFd)
int fenceFd)
{ {
return window->queueBuffer(window, buffer, fenceFd); return window->queueBuffer(window, buffer, fenceFd);
} }
static inline int static inline int
ANativeWindow_cancelBuffer(struct ANativeWindow *window, ANativeWindow_cancelBuffer(struct ANativeWindow *window,
struct ANativeWindowBuffer *buffer, struct ANativeWindowBuffer *buffer, int fenceFd)
int fenceFd)
{ {
return window->cancelBuffer(window, buffer, fenceFd); return window->cancelBuffer(window, buffer, fenceFd);
} }
@ -106,8 +103,7 @@ ANativeWindow_setSwapInterval(struct ANativeWindow *window, int interval)
static inline int static inline int
ANativeWindow_query(const struct ANativeWindow *window, ANativeWindow_query(const struct ANativeWindow *window,
enum ANativeWindowQuery what, enum ANativeWindowQuery what, int *value)
int *value)
{ {
switch (what) { switch (what) {
case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS: case ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS:
@ -149,7 +145,8 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
#else #else
static inline int static inline int
mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
struct buffer_info *out_buf_info) { struct buffer_info *out_buf_info)
{
return -ENOTSUP; return -ENOTSUP;
} }
#endif /* USE_IMAPPER4_METADATA_API */ #endif /* USE_IMAPPER4_METADATA_API */

View file

@ -25,13 +25,13 @@
#include "platform_android.h" #include "platform_android.h"
#include <system/window.h>
#include <aidl/android/hardware/graphics/common/ChromaSiting.h> #include <aidl/android/hardware/graphics/common/ChromaSiting.h>
#include <aidl/android/hardware/graphics/common/Dataspace.h> #include <aidl/android/hardware/graphics/common/Dataspace.h>
#include <aidl/android/hardware/graphics/common/ExtendableType.h> #include <aidl/android/hardware/graphics/common/ExtendableType.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponent.h> #include <aidl/android/hardware/graphics/common/PlaneLayoutComponent.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h> #include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <gralloctypes/Gralloc4.h> #include <gralloctypes/Gralloc4.h>
#include <system/window.h>
using aidl::android::hardware::graphics::common::ChromaSiting; using aidl::android::hardware::graphics::common::ChromaSiting;
using aidl::android::hardware::graphics::common::Dataspace; using aidl::android::hardware::graphics::common::Dataspace;
@ -39,11 +39,11 @@ using aidl::android::hardware::graphics::common::ExtendableType;
using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayout;
using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; 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::common::V1_2::BufferUsage;
using android::hardware::graphics::mapper::V4_0::Error; using android::hardware::graphics::mapper::V4_0::Error;
using android::hardware::graphics::mapper::V4_0::IMapper; using android::hardware::graphics::mapper::V4_0::IMapper;
using android::hardware::hidl_handle;
using android::hardware::hidl_vec;
using MetadataType = using MetadataType =
android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;
@ -67,13 +67,13 @@ GetMetadata(android::sp<IMapper> mapper, const native_handle_t *buffer,
return error; return error;
} }
std::optional<std::vector<PlaneLayout>> GetPlaneLayouts( std::optional<std::vector<PlaneLayout>>
android::sp<IMapper> mapper, const native_handle_t *buffer) GetPlaneLayouts(android::sp<IMapper> mapper, const native_handle_t *buffer)
{ {
hidl_vec<uint8_t> encoded_layouts; hidl_vec<uint8_t> encoded_layouts;
Error error = GetMetadata(mapper, buffer, Error error =
android::gralloc4::MetadataType_PlaneLayouts, GetMetadata(mapper, buffer, android::gralloc4::MetadataType_PlaneLayouts,
&encoded_layouts); &encoded_layouts);
if (error != Error::NONE) if (error != Error::NONE)
@ -81,7 +81,8 @@ std::optional<std::vector<PlaneLayout>> GetPlaneLayouts(
std::vector<PlaneLayout> plane_layouts; std::vector<PlaneLayout> plane_layouts;
auto status = android::gralloc4::decodePlaneLayouts(encoded_layouts, &plane_layouts); auto status =
android::gralloc4::decodePlaneLayouts(encoded_layouts, &plane_layouts);
if (status != android::OK) if (status != android::OK)
return std::nullopt; return std::nullopt;
@ -89,8 +90,7 @@ std::optional<std::vector<PlaneLayout>> GetPlaneLayouts(
return plane_layouts; return plane_layouts;
} }
extern "C" extern "C" {
{
int int
mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf, 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; buf_info.height = buf->height;
hidl_vec<uint8_t> encoded_format; hidl_vec<uint8_t> 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) if (err != Error::NONE)
return -EINVAL; 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) if (status != android::OK)
return -EINVAL; return -EINVAL;
hidl_vec<uint8_t> encoded_modifier; hidl_vec<uint8_t> 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) if (err != Error::NONE)
return -EINVAL; return -EINVAL;
status = android::gralloc4::decodePixelFormatModifier(encoded_modifier, &buf_info.modifier); status = android::gralloc4::decodePixelFormatModifier(encoded_modifier,
&buf_info.modifier);
if (status != android::OK) if (status != android::OK)
return -EINVAL; return -EINVAL;
@ -137,21 +143,26 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
bool per_plane_unique_fd = buf->handle->numFds == buf_info.num_planes; bool per_plane_unique_fd = buf->handle->numFds == buf_info.num_planes;
for (uint32_t i = 0; i < layouts.size(); i++) { 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.pitches[i] = layouts[i].strideInBytes;
buf_info.offsets[i] = layouts[i].offsetInBytes; buf_info.offsets[i] = layouts[i].offsetInBytes;
} }
/* optional attributes */ /* optional attributes */
hidl_vec<uint8_t> encoded_chroma_siting; hidl_vec<uint8_t> 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) { if (err == Error::NONE) {
ExtendableType chroma_siting_ext; 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) if (status != android::OK)
return -EINVAL; return -EINVAL;
ChromaSiting chroma_siting = android::gralloc4::getStandardChromaSitingValue(chroma_siting_ext); ChromaSiting chroma_siting =
android::gralloc4::getStandardChromaSitingValue(chroma_siting_ext);
switch (chroma_siting) { switch (chroma_siting) {
case ChromaSiting::SITED_INTERSTITIAL: case ChromaSiting::SITED_INTERSTITIAL:
buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0_5; buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0_5;
@ -167,14 +178,18 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
} }
hidl_vec<uint8_t> encoded_dataspace; hidl_vec<uint8_t> 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) { if (err == Error::NONE) {
Dataspace dataspace; Dataspace dataspace;
status = android::gralloc4::decodeDataspace(encoded_dataspace, &dataspace); status =
android::gralloc4::decodeDataspace(encoded_dataspace, &dataspace);
if (status != android::OK) if (status != android::OK)
return -EINVAL; return -EINVAL;
Dataspace standard = (Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK); Dataspace standard =
(Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK);
switch (standard) { switch (standard) {
case Dataspace::STANDARD_BT709: case Dataspace::STANDARD_BT709:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC709; buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC709;
@ -193,7 +208,8 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
break; break;
} }
Dataspace range = (Dataspace)((int)dataspace & (uint32_t)Dataspace::RANGE_MASK); Dataspace range =
(Dataspace)((int)dataspace & (uint32_t)Dataspace::RANGE_MASK);
switch (range) { switch (range) {
case Dataspace::RANGE_FULL: case Dataspace::RANGE_FULL:
buf_info.sample_range = __DRI_YUV_FULL_RANGE; buf_info.sample_range = __DRI_YUV_FULL_RANGE;

View file

@ -30,31 +30,27 @@
#include <xf86drm.h> #include <xf86drm.h>
#endif #endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "egl_dri2.h"
#include "loader.h"
#include "kopper_interface.h"
#include "util/u_debug.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, device_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( return dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Width, dri2_surf->base.Height, dri2_surf->visual, 0, NULL);
dri2_surf->base.Height,
dri2_surf->visual,
0,
NULL);
} }
static void static void
@ -73,12 +69,9 @@ device_free_images(struct dri2_egl_surface *dri2_surf)
} }
static int static int
device_image_get_buffers(__DRIdrawable *driDrawable, device_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
unsigned int format, uint32_t *stamp, void *loaderPrivate,
uint32_t *stamp, uint32_t buffer_mask, struct __DRIimageList *buffers)
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *buffers)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct dri2_egl_display *dri2_dpy = struct dri2_egl_display *dri2_dpy =
@ -105,8 +98,7 @@ device_image_get_buffers(__DRIdrawable *driDrawable,
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) { if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
if (!dri2_surf->front) if (!dri2_surf->front)
dri2_surf->front = dri2_surf->front = device_alloc_image(dri2_dpy, dri2_surf);
device_alloc_image(dri2_dpy, dri2_surf);
buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT; buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
buffers->front = dri2_surf->front; buffers->front = dri2_surf->front;
@ -138,11 +130,11 @@ dri2_device_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
false, NULL)) false, NULL))
goto cleanup_surface; goto cleanup_surface;
config = dri2_get_dri_config(dri2_conf, type, config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
dri2_surf->base.GLColorspace);
if (!config) { if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); _eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surface; goto cleanup_surface;
} }
@ -253,24 +245,24 @@ device_get_fd(_EGLDisplay *disp, _EGLDevice *dev)
if (dev != _eglAddDevice(fd, false)) if (dev != _eglAddDevice(fd, false))
return -1; return -1;
/* kms_swrast only work with primary node. It used to work with render node in /* kms_swrast only work with primary node. It used to work with render
* the past because some downstream kernel carry a patch to enable dumb bo * node in the past because some downstream kernel carry a patch to enable
* ioctl on render nodes. * dumb bo ioctl on render nodes.
*/ */
char *node = kms_swrast ? drmGetPrimaryDeviceNameFromFd(fd) : char *node = kms_swrast ? drmGetPrimaryDeviceNameFromFd(fd)
drmGetRenderDeviceNameFromFd(fd); : drmGetRenderDeviceNameFromFd(fd);
/* Don't close the internal fd, get render node one based on it. */ /* Don't close the internal fd, get render node one based on it. */
fd = loader_open_device(node); fd = loader_open_device(node);
free(node); free(node);
return fd; return fd;
} }
const char *node = _eglQueryDeviceStringEXT(dev, kms_swrast ? const char *node = _eglQueryDeviceStringEXT(
EGL_DRM_DEVICE_FILE_EXT : dev, kms_swrast ? EGL_DRM_DEVICE_FILE_EXT : EGL_DRM_RENDER_NODE_FILE_EXT);
EGL_DRM_RENDER_NODE_FILE_EXT);
return loader_open_device(node); return loader_open_device(node);
#else #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; return -1;
#endif #endif
} }
@ -279,7 +271,8 @@ static bool
device_probe_device(_EGLDisplay *disp) device_probe_device(_EGLDisplay *disp)
{ {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(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) if (request_software)
_eglLog(_EGL_WARNING, "Not allowed to force software rendering when " _eglLog(_EGL_WARNING, "Not allowed to force software rendering when "
@ -320,7 +313,6 @@ err_name:
close(dri2_dpy->fd_render_gpu); close(dri2_dpy->fd_render_gpu);
dri2_dpy->fd_render_gpu = dri2_dpy->fd_display_gpu = -1; dri2_dpy->fd_render_gpu = dri2_dpy->fd_display_gpu = -1;
return false; return false;
} }
static bool static bool
@ -371,7 +363,8 @@ dri2_initialize_device(_EGLDisplay *disp)
if (!device_probe_device_sw(disp)) if (!device_probe_device_sw(disp))
goto cleanup; goto cleanup;
} else { } 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; return EGL_FALSE;
} }
@ -387,7 +380,8 @@ dri2_initialize_device(_EGLDisplay *disp)
dri2_setup_screen(disp); dri2_setup_screen(disp);
#ifdef HAVE_WAYLAND_PLATFORM #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 #endif
dri2_set_WL_bind_wayland_display(disp); dri2_set_WL_bind_wayland_display(disp);

View file

@ -25,16 +25,16 @@
* Kristian Høgsberg <krh@bitplanet.net> * Kristian Høgsberg <krh@bitplanet.net>
*/ */
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xf86drm.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <xf86drm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "util/os_file.h" #include "util/os_file.h"
@ -162,7 +162,8 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
dri2_surf->base.GLColorspace); dri2_surf->base.GLColorspace);
if (!config) { if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); _eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surf; goto cleanup_surf;
} }
@ -245,23 +246,17 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
return -1; return -1;
if (dri2_surf->back->bo == NULL) { if (dri2_surf->back->bo == NULL) {
if (surf->base.v0.modifiers) if (surf->base.v0.modifiers)
dri2_surf->back->bo = gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base, dri2_surf->back->bo = gbm_bo_create_with_modifiers(
surf->base.v0.width, &dri2_dpy->gbm_dri->base, surf->base.v0.width, surf->base.v0.height,
surf->base.v0.height, surf->base.v0.format, surf->base.v0.modifiers, surf->base.v0.count);
surf->base.v0.format,
surf->base.v0.modifiers,
surf->base.v0.count);
else { else {
unsigned flags = surf->base.v0.flags; unsigned flags = surf->base.v0.flags;
if (dri2_surf->base.ProtectedContent) if (dri2_surf->base.ProtectedContent)
flags |= GBM_BO_USE_PROTECTED; flags |= GBM_BO_USE_PROTECTED;
dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base, dri2_surf->back->bo =
surf->base.v0.width, gbm_bo_create(&dri2_dpy->gbm_dri->base, surf->base.v0.width,
surf->base.v0.height, surf->base.v0.height, surf->base.v0.format, flags);
surf->base.v0.format,
flags);
} }
} }
if (dri2_surf->back->bo == NULL) if (dri2_surf->back->bo == NULL)
return -1; return -1;
@ -282,11 +277,9 @@ get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
} }
if (dri2_surf->current->bo == NULL) if (dri2_surf->current->bo == NULL)
dri2_surf->current->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base, dri2_surf->current->bo = gbm_bo_create(
surf->base.v0.width, &dri2_dpy->gbm_dri->base, surf->base.v0.width, surf->base.v0.height,
surf->base.v0.height, surf->base.v0.format, surf->base.v0.flags);
surf->base.v0.format,
surf->base.v0.flags);
if (dri2_surf->current->bo == NULL) if (dri2_surf->current->bo == NULL)
return -1; return -1;
@ -314,10 +307,9 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
} }
static __DRIbuffer * static __DRIbuffer *
dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
int *width, int *height, int *height, unsigned int *attachments,
unsigned int *attachments, int count, int count, int *out_count, void *loaderPrivate)
int *out_count, void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
int i, j; int i, j;
@ -360,10 +352,9 @@ dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,
} }
static __DRIbuffer * static __DRIbuffer *
dri2_drm_get_buffers(__DRIdrawable * driDrawable, dri2_drm_get_buffers(__DRIdrawable *driDrawable, int *width, int *height,
int *width, int *height, unsigned int *attachments, int count, int *out_count,
unsigned int *attachments, int count, void *loaderPrivate)
int *out_count, void *loaderPrivate)
{ {
unsigned int *attachments_with_format; unsigned int *attachments_with_format;
__DRIbuffer *buffer; __DRIbuffer *buffer;
@ -380,9 +371,7 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable,
attachments_with_format[2 * i + 1] = format; attachments_with_format[2 * i + 1] = format;
} }
buffer = buffer = dri2_drm_get_buffers_with_format(driDrawable, width, height,
dri2_drm_get_buffers_with_format(driDrawable,
width, height,
attachments_with_format, count, attachments_with_format, count,
out_count, loaderPrivate); out_count, loaderPrivate);
@ -392,12 +381,9 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable,
} }
static int static int
dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
unsigned int format, uint32_t *stamp, void *loaderPrivate,
uint32_t *stamp, uint32_t buffer_mask, struct __DRIimageList *buffers)
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *buffers)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct gbm_dri_bo *bo; struct gbm_dri_bo *bo;
@ -466,7 +452,8 @@ dri2_drm_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surface)
static _EGLImage * static _EGLImage *
dri2_drm_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, 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 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);
@ -511,15 +498,8 @@ dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id)
} }
static void static void
swrast_put_image2(__DRIdrawable *driDrawable, swrast_put_image2(__DRIdrawable *driDrawable, int op, int x, int y, int width,
int op, int height, int stride, char *data, void *loaderPrivate)
int x,
int y,
int width,
int height,
int stride,
char *data,
void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
int internal_stride; int internal_stride;
@ -528,8 +508,7 @@ swrast_put_image2(__DRIdrawable *driDrawable,
int x_bytes, width_bytes; int x_bytes, width_bytes;
char *src, *dst; char *src, *dst;
if (op != __DRI_SWRAST_IMAGE_OP_DRAW && if (op != __DRI_SWRAST_IMAGE_OP_DRAW && op != __DRI_SWRAST_IMAGE_OP_SWAP)
op != __DRI_SWRAST_IMAGE_OP_SWAP)
return; return;
if (get_swrast_front_bo(dri2_surf) < 0) if (get_swrast_front_bo(dri2_surf) < 0)
@ -562,13 +541,8 @@ swrast_put_image2(__DRIdrawable *driDrawable,
} }
static void static void
swrast_get_image(__DRIdrawable *driDrawable, swrast_get_image(__DRIdrawable *driDrawable, int x, int y, int width,
int x, int height, char *data, void *loaderPrivate)
int y,
int width,
int height,
char *data,
void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
int internal_stride, stride; int internal_stride, stride;
@ -643,12 +617,14 @@ drm_add_configs_for_visuals(_EGLDisplay *disp)
continue; continue;
const EGLint attr_list[] = { const EGLint attr_list[] = {
EGL_NATIVE_VISUAL_ID, visuals[j].gbm_format, EGL_NATIVE_VISUAL_ID,
visuals[j].gbm_format,
EGL_NONE, EGL_NONE,
}; };
dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], dri2_conf =
config_count + 1, EGL_WINDOW_BIT, attr_list, NULL, NULL); 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) {
if (dri2_conf->base.ConfigID == config_count + 1) if (dri2_conf->base.ConfigID == config_count + 1)
config_count++; config_count++;
@ -731,7 +707,8 @@ dri2_initialize_drm(_EGLDisplay *disp)
disp->Device = dev; disp->Device = dev;
dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->driver_name); 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 /* render nodes cannot use Gem names, and thus do not support
* the __DRI_DRI2_LOADER extension */ * 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->get_buffers = dri2_drm_get_buffers;
dri2_dpy->gbm_dri->flush_front_buffer = dri2_drm_flush_front_buffer; 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->image_get_buffers = dri2_drm_image_get_buffers;
dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2; dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2;
dri2_dpy->gbm_dri->swrast_get_image = swrast_get_image; 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; disp->Extensions.EXT_buffer_age = EGL_TRUE;
#ifdef HAVE_WAYLAND_PLATFORM #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 #endif
dri2_set_WL_bind_wayland_display(disp); dri2_set_WL_bind_wayland_display(disp);

View file

@ -23,31 +23,27 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xf86drm.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <xf86drm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "egl_dri2.h" #include "egl_dri2.h"
#include "loader.h"
#include "kopper_interface.h" #include "kopper_interface.h"
#include "loader.h"
static __DRIimage * static __DRIimage *
surfaceless_alloc_image(struct dri2_egl_display *dri2_dpy, 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( return dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Width, dri2_surf->base.Height, dri2_surf->visual, 0, NULL);
dri2_surf->base.Height,
dri2_surf->visual,
0,
NULL);
} }
static void static void
@ -66,10 +62,8 @@ surfaceless_free_images(struct dri2_egl_surface *dri2_surf)
} }
static int static int
surfaceless_image_get_buffers(__DRIdrawable *driDrawable, surfaceless_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
unsigned int format, uint32_t *stamp, void *loaderPrivate,
uint32_t *stamp,
void *loaderPrivate,
uint32_t buffer_mask, uint32_t buffer_mask,
struct __DRIimageList *buffers) struct __DRIimageList *buffers)
{ {
@ -98,8 +92,7 @@ surfaceless_image_get_buffers(__DRIdrawable *driDrawable,
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) { if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
if (!dri2_surf->front) if (!dri2_surf->front)
dri2_surf->front = dri2_surf->front = surfaceless_alloc_image(dri2_dpy, dri2_surf);
surfaceless_alloc_image(dri2_dpy, dri2_surf);
buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT; buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
buffers->front = dri2_surf->front; buffers->front = dri2_surf->front;
@ -131,11 +124,11 @@ dri2_surfaceless_create_surface(_EGLDisplay *disp, EGLint type,
false, NULL)) false, NULL))
goto cleanup_surface; goto cleanup_surface;
config = dri2_get_dri_config(dri2_conf, type, config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
dri2_surf->base.GLColorspace);
if (!config) { if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); _eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surface; goto cleanup_surface;
} }
@ -214,21 +207,15 @@ static const __DRIimageLoaderExtension image_loader_extension = {
}; };
static const __DRIextension *image_loader_extensions[] = { static const __DRIextension *image_loader_extensions[] = {
&image_loader_extension.base, &image_loader_extension.base, &image_lookup_extension.base,
&image_lookup_extension.base, &use_invalidate.base, &background_callable_extension.base,
&use_invalidate.base, &kopper_loader_extension.base, NULL,
&background_callable_extension.base,
&kopper_loader_extension.base,
NULL,
}; };
static const __DRIextension *swrast_loader_extensions[] = { static const __DRIextension *swrast_loader_extensions[] = {
&swrast_pbuffer_loader_extension.base, &swrast_pbuffer_loader_extension.base, &image_loader_extension.base,
&image_loader_extension.base, &image_lookup_extension.base, &use_invalidate.base,
&image_lookup_extension.base, &kopper_loader_extension.base, NULL,
&use_invalidate.base,
&kopper_loader_extension.base,
NULL,
}; };
static bool static bool
@ -268,8 +255,7 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
* are unavailable since 6c5ab, and kms_swrast is more * are unavailable since 6c5ab, and kms_swrast is more
* feature complete than swrast. * feature complete than swrast.
*/ */
if (driver_name && if (driver_name && (strcmp(driver_name, "vgem") == 0 ||
(strcmp(driver_name, "vgem") == 0 ||
strcmp(driver_name, "virtio_gpu") == 0)) strcmp(driver_name, "virtio_gpu") == 0))
dri2_dpy->driver_name = strdup("kms_swrast"); dri2_dpy->driver_name = strdup("kms_swrast");
free(driver_name); free(driver_name);
@ -365,7 +351,8 @@ dri2_initialize_surfaceless(_EGLDisplay *disp)
dri2_setup_screen(disp); dri2_setup_screen(disp);
#ifdef HAVE_WAYLAND_PLATFORM #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 #endif
dri2_set_WL_bind_wayland_display(disp); dri2_set_WL_bind_wayland_display(disp);

File diff suppressed because it is too large Load diff

View file

@ -25,15 +25,15 @@
* Kristian Høgsberg <krh@bitplanet.net> * Kristian Høgsberg <krh@bitplanet.net>
*/ */
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <limits.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
/* clang-format off */ /* clang-format off */
#include <xcb/xcb.h> #include <xcb/xcb.h>
@ -43,15 +43,15 @@
#ifdef HAVE_LIBDRM #ifdef HAVE_LIBDRM
#include <xf86drm.h> #include <xf86drm.h>
#endif #endif
#include <sys/types.h>
#include <sys/stat.h>
#include "util/u_debug.h"
#include "util/macros.h"
#include "util/bitscan.h" #include "util/bitscan.h"
#include "util/macros.h"
#include "util/u_debug.h"
#include <sys/stat.h>
#include <sys/types.h>
#include "platform_x11.h"
#include "loader.h"
#include "kopper_interface.h" #include "kopper_interface.h"
#include "loader.h"
#include "platform_x11.h"
#ifdef HAVE_DRI3 #ifdef HAVE_DRI3
#include "platform_x11_dri3.h" #include "platform_x11_dri3.h"
@ -71,13 +71,15 @@ swrastCreateDrawable(struct dri2_egl_display * dri2_dpy,
/* create GC's */ /* create GC's */
dri2_surf->gc = xcb_generate_id(dri2_dpy->conn); dri2_surf->gc = xcb_generate_id(dri2_dpy->conn);
mask = XCB_GC_FUNCTION; 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); dri2_surf->swapgc = xcb_generate_id(dri2_dpy->conn);
mask = XCB_GC_FUNCTION | XCB_GC_GRAPHICS_EXPOSURES; mask = XCB_GC_FUNCTION | XCB_GC_GRAPHICS_EXPOSURES;
valgc[0] = function; valgc[0] = function;
valgc[1] = False; 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) { switch (dri2_surf->depth) {
case 32: case 32:
case 30: case 30:
@ -107,12 +109,12 @@ swrastDestroyDrawable(struct dri2_egl_display * dri2_dpy,
} }
static bool static bool
x11_get_drawable_info(__DRIdrawable * draw, x11_get_drawable_info(__DRIdrawable *draw, int *x, int *y, int *w, int *h,
int *x, int *y, int *w, int *h,
void *loaderPrivate) void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = 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_cookie_t cookie;
xcb_get_geometry_reply_t *reply; xcb_get_geometry_reply_t *reply;
@ -140,8 +142,7 @@ x11_get_drawable_info(__DRIdrawable * draw,
} }
static void static void
swrastGetDrawableInfo(__DRIdrawable * draw, swrastGetDrawableInfo(__DRIdrawable *draw, int *x, int *y, int *w, int *h,
int *x, int *y, int *w, int *h,
void *loaderPrivate) void *loaderPrivate)
{ {
*x = *y = *w = *h = 0; *x = *y = *w = *h = 0;
@ -149,12 +150,12 @@ swrastGetDrawableInfo(__DRIdrawable * draw,
} }
static void static void
swrastPutImage(__DRIdrawable * draw, int op, swrastPutImage(__DRIdrawable *draw, int op, int x, int y, int w, int h,
int x, int y, int w, int h,
char *data, void *loaderPrivate) char *data, void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = 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); size_t hdr_len = sizeof(xcb_put_image_request_t);
int stride_b = dri2_surf->bytes_per_pixel * w; int stride_b = dri2_surf->bytes_per_pixel * w;
size_t size = (hdr_len + stride_b * h) >> 2; size_t size = (hdr_len + stride_b * h) >> 2;
@ -174,9 +175,9 @@ swrastPutImage(__DRIdrawable * draw, int op,
} }
if (size < max_req_len) { if (size < max_req_len) {
cookie = xcb_put_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable, cookie = xcb_put_image(
gc, w, h, x, y, 0, dri2_surf->depth, dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable, gc, w,
h * stride_b, (const uint8_t *)data); h, x, y, 0, dri2_surf->depth, h * stride_b, (const uint8_t *)data);
xcb_discard_reply(dri2_dpy->conn, cookie.sequence); xcb_discard_reply(dri2_dpy->conn, cookie.sequence);
} else { } else {
int num_lines = ((max_req_len << 2) - hdr_len) / stride_b; int num_lines = ((max_req_len << 2) - hdr_len) / stride_b;
@ -184,9 +185,11 @@ swrastPutImage(__DRIdrawable * draw, int op,
int y_todo = h; int y_todo = h;
while (y_todo) { while (y_todo) {
int this_lines = MIN2(num_lines, 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, cookie =
gc, w, this_lines, x, y_start, 0, dri2_surf->depth, xcb_put_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP,
this_lines * stride_b, ((const uint8_t *)data + y_start * stride_b)); 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); xcb_discard_reply(dri2_dpy->conn, cookie.sequence);
y_start += this_lines; y_start += this_lines;
y_todo -= this_lines; y_todo -= this_lines;
@ -195,12 +198,12 @@ swrastPutImage(__DRIdrawable * draw, int op,
} }
static void static void
swrastGetImage(__DRIdrawable * read, swrastGetImage(__DRIdrawable *read, int x, int y, int w, int h, char *data,
int x, int y, int w, int h, void *loaderPrivate)
char *data, void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = 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_cookie_t cookie;
xcb_get_image_reply_t *reply; xcb_get_image_reply_t *reply;
@ -223,7 +226,6 @@ swrastGetImage(__DRIdrawable * read,
free(reply); free(reply);
} }
static xcb_screen_t * static xcb_screen_t *
get_xcb_screen(xcb_screen_iterator_t iter, int screen) get_xcb_screen(xcb_screen_iterator_t iter, int screen)
{ {
@ -293,19 +295,19 @@ dri2_x11_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
dri2_surf->region = XCB_NONE; dri2_surf->region = XCB_NONE;
if (type == EGL_PBUFFER_BIT) { if (type == EGL_PBUFFER_BIT) {
dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn); dri2_surf->drawable = xcb_generate_id(dri2_dpy->conn);
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, dri2_surf->drawable,
dri2_surf->drawable, dri2_dpy->screen->root, dri2_dpy->screen->root, dri2_surf->base.Width,
dri2_surf->base.Width, dri2_surf->base.Height); dri2_surf->base.Height);
} else { } else {
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface)); 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, config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
dri2_surf->base.GLColorspace);
if (!config) { if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); _eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_pixmap; goto cleanup_pixmap;
} }
@ -340,12 +342,13 @@ dri2_x11_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
xcb_void_cookie_t cookie; xcb_void_cookie_t cookie;
int conn_error; int conn_error;
cookie = xcb_dri2_create_drawable_checked(dri2_dpy->conn, cookie =
dri2_surf->drawable); xcb_dri2_create_drawable_checked(dri2_dpy->conn, dri2_surf->drawable);
error = xcb_request_check(dri2_dpy->conn, cookie); error = xcb_request_check(dri2_dpy->conn, cookie);
conn_error = xcb_connection_has_error(dri2_dpy->conn); conn_error = xcb_connection_has_error(dri2_dpy->conn);
if (conn_error || error != NULL) { 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"); _eglError(EGL_BAD_ALLOC, "xcb_dri2_create_drawable_checked");
else if (type == EGL_WINDOW_BIT) else if (type == EGL_WINDOW_BIT)
_eglError(EGL_BAD_NATIVE_WINDOW, _eglError(EGL_BAD_NATIVE_WINDOW,
@ -389,8 +392,8 @@ dri2_x11_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
_EGLSurface *surf; _EGLSurface *surf;
surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
native_window, attrib_list); attrib_list);
if (surf != NULL) { if (surf != NULL) {
/* When we first create the DRI2 drawable, its swap interval on the /* When we first create the DRI2 drawable, its swap interval on the
* server side is 1. * server side is 1.
@ -408,16 +411,16 @@ static _EGLSurface *
dri2_x11_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, dri2_x11_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_pixmap, const EGLint *attrib_list) void *native_pixmap, const EGLint *attrib_list)
{ {
return dri2_x11_create_surface(disp, EGL_PIXMAP_BIT, conf, return dri2_x11_create_surface(disp, EGL_PIXMAP_BIT, conf, native_pixmap,
native_pixmap, attrib_list); attrib_list);
} }
static _EGLSurface * static _EGLSurface *
dri2_x11_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, dri2_x11_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list) const EGLint *attrib_list)
{ {
return dri2_x11_create_surface(disp, EGL_PBUFFER_BIT, conf, return dri2_x11_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL,
NULL, attrib_list); attrib_list);
} }
static EGLBoolean static EGLBoolean
@ -453,8 +456,8 @@ dri2_x11_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
* have. * have.
*/ */
static EGLBoolean static EGLBoolean
dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, dri2_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint attribute, EGLint *value) EGLint *value)
{ {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); 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 * static __DRIbuffer *
dri2_x11_get_buffers(__DRIdrawable * driDrawable, dri2_x11_get_buffers(__DRIdrawable *driDrawable, int *width, int *height,
int *width, int *height, unsigned int *attachments, int count, int *out_count,
unsigned int *attachments, int count, void *loaderPrivate)
int *out_count, void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct dri2_egl_display *dri2_dpy = struct dri2_egl_display *dri2_dpy =
@ -539,8 +541,7 @@ dri2_x11_get_buffers(__DRIdrawable * driDrawable,
(void)driDrawable; (void)driDrawable;
cookie = xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, cookie = xcb_dri2_get_buffers_unchecked(dri2_dpy->conn, dri2_surf->drawable,
dri2_surf->drawable,
count, count, attachments); count, count, attachments);
reply = xcb_dri2_get_buffers_reply(dri2_dpy->conn, cookie, NULL); reply = xcb_dri2_get_buffers_reply(dri2_dpy->conn, cookie, NULL);
if (reply == NULL) if (reply == NULL)
@ -562,10 +563,9 @@ dri2_x11_get_buffers(__DRIdrawable * driDrawable,
} }
static __DRIbuffer * static __DRIbuffer *
dri2_x11_get_buffers_with_format(__DRIdrawable * driDrawable, dri2_x11_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
int *width, int *height, int *height, unsigned int *attachments,
unsigned int *attachments, int count, int count, int *out_count, void *loaderPrivate)
int *out_count, void *loaderPrivate)
{ {
struct dri2_egl_surface *dri2_surf = loaderPrivate; struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct dri2_egl_display *dri2_dpy = struct dri2_egl_display *dri2_dpy =
@ -578,13 +578,10 @@ dri2_x11_get_buffers_with_format(__DRIdrawable * driDrawable,
(void)driDrawable; (void)driDrawable;
format_attachments = (xcb_dri2_attach_format_t *)attachments; format_attachments = (xcb_dri2_attach_format_t *)attachments;
cookie = xcb_dri2_get_buffers_with_format_unchecked (dri2_dpy->conn, cookie = xcb_dri2_get_buffers_with_format_unchecked(
dri2_surf->drawable, dri2_dpy->conn, dri2_surf->drawable, count, count, format_attachments);
count, count,
format_attachments);
reply = xcb_dri2_get_buffers_with_format_reply (dri2_dpy->conn, reply = xcb_dri2_get_buffers_with_format_reply(dri2_dpy->conn, cookie, NULL);
cookie, NULL);
if (reply == NULL) if (reply == NULL)
return NULL; return NULL;
@ -622,8 +619,8 @@ dri2_x11_do_authenticate(struct dri2_egl_display *dri2_dpy, uint32_t id)
xcb_dri2_authenticate_cookie_t authenticate_cookie; xcb_dri2_authenticate_cookie_t authenticate_cookie;
int ret = 0; int ret = 0;
authenticate_cookie = authenticate_cookie = xcb_dri2_authenticate_unchecked(
xcb_dri2_authenticate_unchecked(dri2_dpy->conn, dri2_dpy->screen->root, id); dri2_dpy->conn, dri2_dpy->screen->root, id);
authenticate = authenticate =
xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL); xcb_dri2_authenticate_reply(dri2_dpy->conn, authenticate_cookie, NULL);
@ -678,22 +675,19 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
if (!(extension && extension->present)) if (!(extension && extension->present))
return EGL_FALSE; return EGL_FALSE;
xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, xfixes_query_cookie = xcb_xfixes_query_version(
XCB_XFIXES_MAJOR_VERSION, dri2_dpy->conn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
XCB_XFIXES_MINOR_VERSION);
dri2_query_cookie = xcb_dri2_query_version (dri2_dpy->conn, dri2_query_cookie = xcb_dri2_query_version(
XCB_DRI2_MAJOR_VERSION, dri2_dpy->conn, XCB_DRI2_MAJOR_VERSION, XCB_DRI2_MINOR_VERSION);
XCB_DRI2_MINOR_VERSION);
connect_cookie = xcb_dri2_connect_unchecked(dri2_dpy->conn, dri2_dpy->screen->root, connect_cookie = xcb_dri2_connect_unchecked(
XCB_DRI2_DRIVER_TYPE_DRI); dri2_dpy->conn, dri2_dpy->screen->root, XCB_DRI2_DRIVER_TYPE_DRI);
xfixes_query = xfixes_query = xcb_xfixes_query_version_reply(dri2_dpy->conn,
xcb_xfixes_query_version_reply (dri2_dpy->conn,
xfixes_query_cookie, &error); xfixes_query_cookie, &error);
if (xfixes_query == NULL || if (xfixes_query == NULL || error != NULL ||
error != NULL || xfixes_query->major_version < 2) { xfixes_query->major_version < 2) {
_eglLog(_EGL_WARNING, "DRI2: failed to query xfixes version"); _eglLog(_EGL_WARNING, "DRI2: failed to query xfixes version");
free(error); free(error);
free(xfixes_query); free(xfixes_query);
@ -725,8 +719,8 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
dri2_dpy->fd_render_gpu = loader_open_device(device_name); dri2_dpy->fd_render_gpu = loader_open_device(device_name);
if (dri2_dpy->fd_render_gpu == -1) { if (dri2_dpy->fd_render_gpu == -1) {
_eglLog(_EGL_WARNING, _eglLog(_EGL_WARNING, "DRI2: could not open %s (%s)", device_name,
"DRI2: could not open %s (%s)", device_name, strerror(errno)); strerror(errno));
free(connect); free(connect);
return EGL_FALSE; return EGL_FALSE;
} }
@ -747,8 +741,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
dri2_dpy->driver_name = loader_driver_name; dri2_dpy->driver_name = loader_driver_name;
} else { } else {
dri2_dpy->driver_name = dri2_dpy->driver_name =
strndup(driver_name, strndup(driver_name, xcb_dri2_connect_driver_name_length(connect));
xcb_dri2_connect_driver_name_length(connect));
} }
if (dri2_dpy->driver_name == NULL) { if (dri2_dpy->driver_name == NULL) {
@ -759,8 +752,7 @@ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
#ifdef HAVE_WAYLAND_PLATFORM #ifdef HAVE_WAYLAND_PLATFORM
dri2_dpy->device_name = dri2_dpy->device_name =
strndup(device_name, strndup(device_name, xcb_dri2_connect_device_name_length(connect));
xcb_dri2_connect_device_name_length(connect));
#endif #endif
free(connect); free(connect);
@ -787,16 +779,15 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
d = xcb_screen_allowed_depths_iterator(dri2_dpy->screen); d = xcb_screen_allowed_depths_iterator(dri2_dpy->screen);
surface_type = surface_type = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT;
EGL_WINDOW_BIT |
EGL_PIXMAP_BIT |
EGL_PBUFFER_BIT;
if (supports_preserved) if (supports_preserved)
surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT; surface_type |= EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
while (d.rem > 0) { while (d.rem > 0) {
EGLBoolean class_added[6] = { 0, }; EGLBoolean class_added[6] = {
0,
};
visuals = xcb_depth_visuals(d.data); visuals = xcb_depth_visuals(d.data);
@ -811,8 +802,10 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
const __DRIconfig *config = dri2_dpy->driver_configs[j]; const __DRIconfig *config = dri2_dpy->driver_configs[j];
const EGLint config_attrs[] = { const EGLint config_attrs[] = {
EGL_NATIVE_VISUAL_ID, visuals[i].visual_id, EGL_NATIVE_VISUAL_ID,
EGL_NATIVE_VISUAL_TYPE, visuals[i]._class, visuals[i].visual_id,
EGL_NATIVE_VISUAL_TYPE,
visuals[i]._class,
EGL_NONE, EGL_NONE,
}; };
@ -830,9 +823,9 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
0, 0,
}; };
dri2_conf = dri2_add_config(disp, config, config_count + 1, dri2_conf =
surface_type, config_attrs, dri2_add_config(disp, config, config_count + 1, surface_type,
rgba_shifts, rgba_sizes); config_attrs, rgba_shifts, rgba_sizes);
if (dri2_conf) if (dri2_conf)
if (dri2_conf->base.ConfigID == config_count + 1) if (dri2_conf->base.ConfigID == config_count + 1)
config_count++; config_count++;
@ -846,14 +839,14 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
* wants... especially on drivers that only have 32-bit RGBA * wants... especially on drivers that only have 32-bit RGBA
* EGLConfigs! */ * EGLConfigs! */
if (d.data->depth == 24 || d.data->depth == 30) { if (d.data->depth == 24 || d.data->depth == 30) {
unsigned int rgba_mask = ~(visuals[i].red_mask | unsigned int rgba_mask =
visuals[i].green_mask | ~(visuals[i].red_mask | visuals[i].green_mask |
visuals[i].blue_mask); visuals[i].blue_mask);
rgba_shifts[3] = ffs(rgba_mask) - 1; rgba_shifts[3] = ffs(rgba_mask) - 1;
rgba_sizes[3] = util_bitcount(rgba_mask); rgba_sizes[3] = util_bitcount(rgba_mask);
dri2_conf = dri2_add_config(disp, config, config_count + 1, dri2_conf =
surface_type, config_attrs, dri2_add_config(disp, config, config_count + 1, surface_type,
rgba_shifts, rgba_sizes); config_attrs, rgba_shifts, rgba_sizes);
if (dri2_conf) if (dri2_conf)
if (dri2_conf->base.ConfigID == config_count + 1) if (dri2_conf->base.ConfigID == config_count + 1)
config_count++; config_count++;
@ -873,8 +866,8 @@ dri2_x11_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
} }
static EGLBoolean static EGLBoolean
dri2_copy_region(_EGLDisplay *disp, dri2_copy_region(_EGLDisplay *disp, _EGLSurface *draw,
_EGLSurface *draw, xcb_xfixes_region_t region) xcb_xfixes_region_t region)
{ {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
@ -893,19 +886,17 @@ dri2_copy_region(_EGLDisplay *disp,
else else
render_attachment = XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT; render_attachment = XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT;
cookie = xcb_dri2_copy_region_unchecked(dri2_dpy->conn, cookie = xcb_dri2_copy_region_unchecked(
dri2_surf->drawable, dri2_dpy->conn, dri2_surf->drawable, region,
region, XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT, render_attachment);
XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
render_attachment);
free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL)); free(xcb_dri2_copy_region_reply(dri2_dpy->conn, cookie, NULL));
return EGL_TRUE; return EGL_TRUE;
} }
static int64_t static int64_t
dri2_x11_swap_buffers_msc(_EGLDisplay *disp, _EGLSurface *draw, dri2_x11_swap_buffers_msc(_EGLDisplay *disp, _EGLSurface *draw, int64_t msc,
int64_t msc, int64_t divisor, int64_t remainder) int64_t divisor, int64_t remainder)
{ {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); 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; xcb_dri2_swap_buffers_reply_t *reply;
int64_t swap_count = -1; 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; swap_count = dri2_copy_region(disp, draw, dri2_surf->region) ? 0 : -1;
} else { } else {
dri2_flush_drawable_for_swapbuffers(disp, draw); dri2_flush_drawable_for_swapbuffers(disp, draw);
cookie = xcb_dri2_swap_buffers_unchecked(dri2_dpy->conn, cookie = xcb_dri2_swap_buffers_unchecked(
dri2_surf->drawable, msc_hi, dri2_dpy->conn, dri2_surf->drawable, msc_hi, msc_lo, divisor_hi,
msc_lo, divisor_hi, divisor_lo, divisor_lo, remainder_hi, remainder_lo);
remainder_hi, remainder_lo);
reply = xcb_dri2_swap_buffers_reply(dri2_dpy->conn, cookie, NULL); 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 * "The contents of ancillary buffers are always undefined
* after calling eglSwapBuffers." * 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; return EGL_TRUE;
} else if (!dri2_dpy->flush) { } else if (!dri2_dpy->flush) {
/* aka the swrast path, which does the swap in the gallium driver. */ /* 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++) { for (int i = 0; i < numRects; i++) {
rectangles[i].x = rects[i * 4]; 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].width = rects[i * 4 + 2];
rectangles[i].height = rects[i * 4 + 3]; rectangles[i].height = rects[i * 4 + 3];
} }
@ -1009,8 +1002,8 @@ dri2_x11_swap_buffers_region(_EGLDisplay *disp, _EGLSurface *draw,
} }
static EGLBoolean static EGLBoolean
dri2_x11_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *draw, dri2_x11_post_sub_buffer(_EGLDisplay *disp, _EGLSurface *draw, EGLint x,
EGLint x, EGLint y, EGLint width, EGLint height) EGLint y, EGLint width, EGLint height)
{ {
const EGLint rect[4] = {x, y, width, height}; const EGLint rect[4] = {x, y, width, height};
@ -1038,7 +1031,8 @@ dri2_x11_swap_interval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval)
} }
static EGLBoolean 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_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
@ -1062,14 +1056,8 @@ dri2_x11_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_
gc = xcb_generate_id(dri2_dpy->conn); gc = xcb_generate_id(dri2_dpy->conn);
xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL); xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL);
xcb_copy_area(dri2_dpy->conn, xcb_copy_area(dri2_dpy->conn, dri2_surf->drawable, target, gc, 0, 0, 0, 0,
dri2_surf->drawable, dri2_surf->base.Width, dri2_surf->base.Height);
target,
gc,
0, 0,
0, 0,
dri2_surf->base.Width,
dri2_surf->base.Height);
xcb_free_gc(dri2_dpy->conn, gc); xcb_free_gc(dri2_dpy->conn, gc);
return EGL_TRUE; return EGL_TRUE;
@ -1117,12 +1105,11 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
drawable = (xcb_drawable_t)(uintptr_t)buffer; drawable = (xcb_drawable_t)(uintptr_t)buffer;
xcb_dri2_create_drawable(dri2_dpy->conn, drawable); xcb_dri2_create_drawable(dri2_dpy->conn, drawable);
attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT; attachments[0] = XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT;
buffers_cookie = buffers_cookie = xcb_dri2_get_buffers_unchecked(dri2_dpy->conn, drawable, 1,
xcb_dri2_get_buffers_unchecked (dri2_dpy->conn, 1, attachments);
drawable, 1, 1, attachments);
geometry_cookie = xcb_get_geometry(dri2_dpy->conn, drawable); geometry_cookie = xcb_get_geometry(dri2_dpy->conn, drawable);
buffers_reply = xcb_dri2_get_buffers_reply (dri2_dpy->conn, buffers_reply =
buffers_cookie, NULL); xcb_dri2_get_buffers_reply(dri2_dpy->conn, buffers_cookie, NULL);
if (buffers_reply == NULL) if (buffers_reply == NULL)
return NULL; return NULL;
@ -1132,8 +1119,8 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
return NULL; return NULL;
} }
geometry_reply = xcb_get_geometry_reply (dri2_dpy->conn, geometry_reply =
geometry_cookie, &error); xcb_get_geometry_reply(dri2_dpy->conn, geometry_cookie, &error);
if (geometry_reply == NULL || error != NULL) { if (geometry_reply == NULL || error != NULL) {
_eglError(EGL_BAD_ALLOC, "xcb_get_geometry"); _eglError(EGL_BAD_ALLOC, "xcb_get_geometry");
free(error); free(error);
@ -1162,14 +1149,9 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
_eglInitImage(&dri2_img->base, disp); _eglInitImage(&dri2_img->base, disp);
stride = buffers[0].pitch / buffers[0].cpp; stride = buffers[0].pitch / buffers[0].cpp;
dri2_img->dri_image = dri2_img->dri_image = dri2_dpy->image->createImageFromName(
dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_render_gpu, buffers_reply->width,
buffers_reply->width, buffers_reply->height, format, buffers[0].name, stride, dri2_img);
buffers_reply->height,
format,
buffers[0].name,
stride,
dri2_img);
free(buffers_reply); free(buffers_reply);
free(geometry_reply); free(geometry_reply);
@ -1214,9 +1196,8 @@ dri2_x11_get_sync_values(_EGLDisplay *display, _EGLSurface *surface,
} }
static int static int
box_intersection_area(int16_t a_x, int16_t a_y, box_intersection_area(int16_t a_x, int16_t a_y, int16_t a_width,
int16_t a_width, int16_t a_height, int16_t a_height, int16_t b_x, int16_t b_y,
int16_t b_x, int16_t b_y,
int16_t b_width, int16_t b_height) 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);
@ -1272,13 +1253,11 @@ dri2_x11_get_msc_rate(_EGLDisplay *display, _EGLSurface *surface,
int area = 0; int area = 0;
for (unsigned c = 0; c < dri2_dpy->screen_resources.num_crtcs; c++) { for (unsigned c = 0; c < dri2_dpy->screen_resources.num_crtcs; c++) {
struct loader_crtc_info *crtc = struct loader_crtc_info *crtc = &dri2_dpy->screen_resources.crtcs[c];
&dri2_dpy->screen_resources.crtcs[c];
int c_area = box_intersection_area(reply->dst_x, reply->dst_y, int c_area = box_intersection_area(
surface->Width, surface->Height, reply->dst_x, reply->dst_y, surface->Width, surface->Height, crtc->x,
crtc->x, crtc->y, crtc->y, crtc->width, crtc->height);
crtc->width, crtc->height);
if (c_area > area) { if (c_area > area) {
*numerator = crtc->refresh_numerator; *numerator = crtc->refresh_numerator;
*denominator = crtc->refresh_denominator; *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); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
_EGLSurface *surf; _EGLSurface *surf;
surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, surf = dri2_x11_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
native_window, attrib_list); attrib_list);
if (surf != NULL) { if (surf != NULL) {
/* When we first create the DRI2 drawable, its swap interval on the /* When we first create the DRI2 drawable, its swap interval on the
* server side is 1. * server side is 1.
@ -1404,13 +1383,16 @@ static const __DRIswrastLoaderExtension swrast_loader_extension = {
.getImage = swrastGetImage, .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 static void
kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *ci) kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *ci)
{ {
struct dri2_egl_surface *dri2_surf = _draw; struct dri2_egl_surface *dri2_surf = _draw;
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);
VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&ci->bos; VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&ci->bos;
if (dri2_surf->base.Type != EGL_WINDOW_BIT) if (dri2_surf->base.Type != EGL_WINDOW_BIT)
@ -1454,8 +1436,7 @@ dri2_find_screen_for_display(const _EGLDisplay *disp, int fallback_screen)
} }
static EGLBoolean static EGLBoolean
dri2_get_xcb_connection(_EGLDisplay *disp, dri2_get_xcb_connection(_EGLDisplay *disp, struct dri2_egl_display *dri2_dpy)
struct dri2_egl_display *dri2_dpy)
{ {
xcb_screen_iterator_t s; xcb_screen_iterator_t s;
int screen; int screen;
@ -1668,8 +1649,8 @@ dri2_initialize_x11_dri3(_EGLDisplay *disp)
if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, false)) if (!dri2_x11_add_configs_for_visuals(dri2_dpy, disp, false))
goto cleanup; goto cleanup;
loader_init_screen_resources(&dri2_dpy->screen_resources, loader_init_screen_resources(&dri2_dpy->screen_resources, dri2_dpy->conn,
dri2_dpy->conn, dri2_dpy->screen); dri2_dpy->screen);
dri2_dpy->loader_dri3_ext.core = dri2_dpy->core; dri2_dpy->loader_dri3_ext.core = dri2_dpy->core;
dri2_dpy->loader_dri3_ext.image_driver = dri2_dpy->image_driver; dri2_dpy->loader_dri3_ext.image_driver = dri2_dpy->image_driver;

View file

@ -20,15 +20,15 @@
* OF THIS SOFTWARE. * OF THIS SOFTWARE.
*/ */
#include <fcntl.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <xcb/xcb.h>
#include <xcb/dri3.h> #include <xcb/dri3.h>
#include <xcb/present.h> #include <xcb/present.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h> #include <xcb/xfixes.h>
#include <xf86drm.h> #include <xf86drm.h>
@ -41,14 +41,15 @@
#include "loader_dri3_helper.h" #include "loader_dri3_helper.h"
static struct dri3_egl_surface * 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); 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 static void
egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw, egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw, int width,
int width, int height) int height)
{ {
struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw); struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw);
@ -84,7 +85,8 @@ egl_dri3_get_dri_screen(void)
if (!ctx) if (!ctx)
return NULL; return NULL;
dri2_ctx = dri2_egl_context(ctx); 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 static void
@ -164,37 +166,34 @@ dri3_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
return NULL; return NULL;
} }
if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, attrib_list,
attrib_list, false, native_surface)) false, native_surface))
goto cleanup_surf; goto cleanup_surf;
if (type == EGL_PBUFFER_BIT) { if (type == EGL_PBUFFER_BIT) {
drawable = xcb_generate_id(dri2_dpy->conn); drawable = xcb_generate_id(dri2_dpy->conn);
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, drawable,
drawable, dri2_dpy->screen->root, dri2_dpy->screen->root, dri3_surf->surf.base.Width,
dri3_surf->surf.base.Width, dri3_surf->surf.base.Height); dri3_surf->surf.base.Height);
} else { } else {
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface)); 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, dri_config =
dri3_surf->surf.base.GLColorspace); dri2_get_dri_config(dri2_conf, type, dri3_surf->surf.base.GLColorspace);
if (!dri_config) { if (!dri_config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); _eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_pixmap; goto cleanup_pixmap;
} }
if (loader_dri3_drawable_init(dri2_dpy->conn, drawable, if (loader_dri3_drawable_init(
egl_to_loader_dri3_drawable_type(type), dri2_dpy->conn, drawable, egl_to_loader_dri3_drawable_type(type),
dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_display_gpu,
dri2_dpy->dri_screen_display_gpu, dri2_dpy->multibuffers_available, true, dri_config,
dri2_dpy->multibuffers_available, &dri2_dpy->loader_dri3_ext, &egl_dri3_vtable,
true,
dri_config,
&dri2_dpy->loader_dri3_ext,
&egl_dri3_vtable,
&dri3_surf->loader_drawable)) { &dri3_surf->loader_drawable)) {
_eglError(EGL_BAD_ALLOC, "dri3_surface_create"); _eglError(EGL_BAD_ALLOC, "dri3_surface_create");
goto cleanup_pixmap; goto cleanup_pixmap;
@ -249,8 +248,8 @@ dri3_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
_EGLSurface *surf; _EGLSurface *surf;
surf = dri3_create_surface(disp, EGL_WINDOW_BIT, conf, surf = dri3_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
native_window, attrib_list); attrib_list);
if (surf != NULL) if (surf != NULL)
dri3_set_swap_interval(disp, surf, dri2_dpy->default_swap_interval); 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, dri3_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_pixmap, const EGLint *attrib_list) void *native_pixmap, const EGLint *attrib_list)
{ {
return dri3_create_surface(disp, EGL_PIXMAP_BIT, conf, return dri3_create_surface(disp, EGL_PIXMAP_BIT, conf, native_pixmap,
native_pixmap, attrib_list); attrib_list);
} }
static _EGLSurface * static _EGLSurface *
dri3_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, dri3_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list) const EGLint *attrib_list)
{ {
return dri3_create_surface(disp, EGL_PBUFFER_BIT, conf, return dri3_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list);
NULL, attrib_list);
} }
static EGLBoolean static EGLBoolean
dri3_get_sync_values(_EGLDisplay *display, _EGLSurface *surface, dri3_get_sync_values(_EGLDisplay *display, _EGLSurface *surface,
EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc)
EGLuint64KHR *sbc)
{ {
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surface); struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surface);
return loader_dri3_wait_for_msc(&dri3_surf->loader_drawable, 0, 0, 0, return loader_dri3_wait_for_msc(&dri3_surf->loader_drawable, 0, 0, 0,
(int64_t *)ust, (int64_t *)msc, (int64_t *)ust, (int64_t *)msc,
(int64_t *) sbc) ? EGL_TRUE : EGL_FALSE; (int64_t *)sbc)
? EGL_TRUE
: EGL_FALSE;
} }
static _EGLImage * static _EGLImage *
@ -298,8 +297,8 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
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_cookie = xcb_dri3_buffer_from_pixmap(dri2_dpy->conn, drawable);
bp_reply = xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn, bp_reply =
bp_cookie, NULL); xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn, bp_cookie, NULL);
if (!bp_reply) { if (!bp_reply) {
_eglError(EGL_BAD_ALLOC, "xcb_dri3_buffer_from_pixmap"); _eglError(EGL_BAD_ALLOC, "xcb_dri3_buffer_from_pixmap");
return NULL; return NULL;
@ -322,12 +321,9 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
_eglInitImage(&dri2_img->base, disp); _eglInitImage(&dri2_img->base, disp);
dri2_img->dri_image = loader_dri3_create_image(dri2_dpy->conn, dri2_img->dri_image = loader_dri3_create_image(
bp_reply, dri2_dpy->conn, bp_reply, format, dri2_dpy->dri_screen_render_gpu,
format, dri2_dpy->image, dri2_img);
dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image,
dri2_img);
free(bp_reply); free(bp_reply);
@ -349,8 +345,8 @@ dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx,
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_cookie = xcb_dri3_buffers_from_pixmap(dri2_dpy->conn, drawable);
bp_reply = xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn, bp_reply =
bp_cookie, NULL); xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn, bp_cookie, NULL);
if (!bp_reply) { if (!bp_reply) {
_eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr"); _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); _eglInitImage(&dri2_img->base, disp);
dri2_img->dri_image = loader_dri3_create_image_from_buffers(dri2_dpy->conn, dri2_img->dri_image = loader_dri3_create_image_from_buffers(
bp_reply, dri2_dpy->conn, bp_reply, format, dri2_dpy->dri_screen_render_gpu,
format, dri2_dpy->image, dri2_img);
dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image,
dri2_img);
free(bp_reply); free(bp_reply);
if (!dri2_img->dri_image) { if (!dri2_img->dri_image) {
@ -428,7 +421,8 @@ dri3_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
* http://lists.freedesktop.org/archives/mesa-dev/2013-June/040129.html * http://lists.freedesktop.org/archives/mesa-dev/2013-June/040129.html
*/ */
if (draw->type == LOADER_DRI3_DRAWABLE_WINDOW) 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 = { const __DRIimageLoaderExtension dri3_image_loader_extension = {
@ -444,9 +438,8 @@ dri3_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw,
{ {
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(draw); struct dri3_egl_surface *dri3_surf = dri3_egl_surface(draw);
return loader_dri3_swap_buffers_msc(&dri3_surf->loader_drawable, return loader_dri3_swap_buffers_msc(
0, 0, 0, 0, &dri3_surf->loader_drawable, 0, 0, 0, 0, rects, n_rects,
rects, n_rects,
draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1; draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1;
} }
@ -457,7 +450,8 @@ dri3_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
} }
static EGLBoolean 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); struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf);
xcb_pixmap_t target; xcb_pixmap_t target;
@ -480,8 +474,8 @@ dri3_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surf)
} }
static EGLBoolean static EGLBoolean
dri3_query_surface(_EGLDisplay *disp, _EGLSurface *surf, dri3_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint attribute, EGLint *value) EGLint *value)
{ {
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf); struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf);
@ -572,17 +566,14 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
if (!(extension && extension->present)) if (!(extension && extension->present))
return EGL_FALSE; return EGL_FALSE;
dri3_query_cookie = xcb_dri3_query_version(dri2_dpy->conn, dri3_query_cookie = xcb_dri3_query_version(
DRI3_SUPPORTED_MAJOR, dri2_dpy->conn, DRI3_SUPPORTED_MAJOR, DRI3_SUPPORTED_MINOR);
DRI3_SUPPORTED_MINOR);
present_query_cookie = xcb_present_query_version(dri2_dpy->conn, present_query_cookie = xcb_present_query_version(
PRESENT_SUPPORTED_MAJOR, dri2_dpy->conn, PRESENT_SUPPORTED_MAJOR, PRESENT_SUPPORTED_MINOR);
PRESENT_SUPPORTED_MINOR);
xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn, xfixes_query_cookie = xcb_xfixes_query_version(
XCB_XFIXES_MAJOR_VERSION, dri2_dpy->conn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
XCB_XFIXES_MINOR_VERSION);
dri3_query = dri3_query =
xcb_dri3_query_version_reply(dri2_dpy->conn, dri3_query_cookie, &error); 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; dri2_dpy->dri3_minor_version = dri3_query->minor_version;
free(dri3_query); free(dri3_query);
present_query = present_query = xcb_present_query_version_reply(
xcb_present_query_version_reply(dri2_dpy->conn, dri2_dpy->conn, present_query_cookie, &error);
present_query_cookie, &error);
if (present_query == NULL || error != NULL) { if (present_query == NULL || error != NULL) {
_eglLog(_EGL_WARNING, "DRI3: failed to query Present version"); _eglLog(_EGL_WARNING, "DRI3: failed to query Present version");
free(present_query); free(present_query);
@ -611,8 +601,7 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
dri2_dpy->present_minor_version = present_query->minor_version; dri2_dpy->present_minor_version = present_query->minor_version;
free(present_query); free(present_query);
xfixes_query = xfixes_query = xcb_xfixes_query_version_reply(dri2_dpy->conn,
xcb_xfixes_query_version_reply(dri2_dpy->conn,
xfixes_query_cookie, &error); xfixes_query_cookie, &error);
if (xfixes_query == NULL || error != NULL || if (xfixes_query == NULL || error != NULL ||
xfixes_query->major_version < 2) { xfixes_query->major_version < 2) {
@ -623,7 +612,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
} }
free(xfixes_query); 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) { if (dri2_dpy->fd_render_gpu < 0) {
int conn_error = xcb_connection_has_error(dri2_dpy->conn); int conn_error = xcb_connection_has_error(dri2_dpy->conn);
_eglLog(_EGL_WARNING, "DRI3: Screen seems not DRI3 capable"); _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; 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); dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu);
if (!dri2_dpy->driver_name) { 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 /* Only try to get a render device name since dri3 doesn't provide a
* mechanism for authenticating client opened device node fds. If this * mechanism for authenticating client opened device node fds. If this
* fails then don't advertise the extension. */ * 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 #endif
return EGL_TRUE; return EGL_TRUE;

View file

@ -22,8 +22,8 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include <errno.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -31,20 +31,20 @@
#include "eglconfig.h" #include "eglconfig.h"
#include "eglcontext.h" #include "eglcontext.h"
#include "eglcurrent.h"
#include "egldevice.h" #include "egldevice.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "eglcurrent.h" #include "eglimage.h"
#include "egllog.h" #include "egllog.h"
#include "eglsurface.h" #include "eglsurface.h"
#include "eglimage.h"
#include "egltypedefs.h" #include "egltypedefs.h"
#include <mapi/glapi/glapi.h>
#include "util/u_atomic.h"
#include "pipe/p_context.h" #include "pipe/p_context.h"
#include "pipe/p_defines.h" #include "pipe/p_defines.h"
#include "state_tracker/st_context.h" #include "state_tracker/st_context.h"
#include "util/u_atomic.h"
#include <mapi/glapi/glapi.h>
#include "hgl_context.h" #include "hgl_context.h"
#include "hgl_sw_winsys.h" #include "hgl_sw_winsys.h"
@ -67,7 +67,6 @@ extern "C" {
#define BGL_STENCIL 512 #define BGL_STENCIL 512
#define BGL_SHARE_CONTEXT 1024 #define BGL_SHARE_CONTEXT 1024
#ifdef DEBUG #ifdef DEBUG
#define TRACE(x...) printf("egl_haiku: " x) #define TRACE(x...) printf("egl_haiku: " x)
#define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__) #define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
@ -77,10 +76,8 @@ extern "C" {
#endif #endif
#define ERROR(x...) printf("egl_haiku: " x) #define ERROR(x...) printf("egl_haiku: " x)
_EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl) _EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl)
struct haiku_egl_display { struct haiku_egl_display {
int ref_count; int ref_count;
struct hgl_display *disp; struct hgl_display *disp;
@ -101,21 +98,23 @@ struct haiku_egl_surface {
struct pipe_fence_handle *throttle_fence; struct pipe_fence_handle *throttle_fence;
}; };
// #pragma mark EGLSurface // #pragma mark EGLSurface
// Called via eglCreateWindowSurface(), drv->CreateWindowSurface(). // Called via eglCreateWindowSurface(), drv->CreateWindowSurface().
static _EGLSurface * 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"); printf("haiku_create_window_surface\n");
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); 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)); struct haiku_egl_surface *wgl_surf =
(struct haiku_egl_surface *)calloc(1, sizeof(*wgl_surf));
if (!wgl_surf) if (!wgl_surf)
return NULL; return NULL;
if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf, attrib_list, NULL)) { if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf,
attrib_list, NULL)) {
free(wgl_surf); free(wgl_surf);
return NULL; return NULL;
} }
@ -123,7 +122,8 @@ haiku_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_wi
struct st_visual visual; struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH); hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH);
wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, native_window); wgl_surf->fb =
hgl_create_st_framebuffer(hgl_dpy->disp, &visual, native_window);
if (!wgl_surf->fb) { if (!wgl_surf->fb) {
free(wgl_surf); free(wgl_surf);
return NULL; return NULL;
@ -132,31 +132,32 @@ haiku_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_wi
return &wgl_surf->base; return &wgl_surf->base;
} }
static _EGLSurface * 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"); printf("haiku_create_pixmap_surface\n");
return NULL; return NULL;
} }
static _EGLSurface * 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"); printf("haiku_create_pbuffer_surface\n");
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp); 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)); struct haiku_egl_surface *wgl_surf =
(struct haiku_egl_surface *)calloc(1, sizeof(*wgl_surf));
if (!wgl_surf) if (!wgl_surf)
return NULL; 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); free(wgl_surf);
return NULL; return NULL;
} }
struct st_visual visual; struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH); hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH);
@ -173,7 +174,6 @@ haiku_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *
return &wgl_surf->base; return &wgl_surf->base;
} }
static EGLBoolean static EGLBoolean
haiku_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf) haiku_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
{ {
@ -225,14 +225,16 @@ haiku_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf)
struct pipe_fence_handle *new_fence = NULL; struct pipe_fence_handle *new_fence = NULL;
st_context_flush(st, ST_FLUSH_FRONT, &new_fence, NULL, NULL); st_context_flush(st, ST_FLUSH_FRONT, &new_fence, NULL, NULL);
if (hgl_surf->throttle_fence) { if (hgl_surf->throttle_fence) {
screen->fence_finish(screen, NULL, hgl_surf->throttle_fence, OS_TIMEOUT_INFINITE); screen->fence_finish(screen, NULL, hgl_surf->throttle_fence,
OS_TIMEOUT_INFINITE);
screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL); screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL);
} }
hgl_surf->throttle_fence = new_fence; hgl_surf->throttle_fence = new_fence;
// flush back buffer and swap buffers if double buffering is used // flush back buffer and swap buffers if double buffering is used
if (backBuffer != NULL) { if (backBuffer != NULL) {
screen->flush_frontbuffer(screen, st->pipe, backBuffer, 0, 0, buffer->winsysContext, NULL); screen->flush_frontbuffer(screen, st->pipe, backBuffer, 0, 0,
buffer->winsysContext, NULL);
std::swap(frontBuffer, backBuffer); std::swap(frontBuffer, backBuffer);
p_atomic_inc(&buffer->base.stamp); p_atomic_inc(&buffer->base.stamp);
} }
@ -244,7 +246,6 @@ haiku_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf)
return EGL_TRUE; return EGL_TRUE;
} }
// #pragma mark EGLDisplay // #pragma mark EGLDisplay
static EGLBoolean static EGLBoolean
@ -266,10 +267,8 @@ haiku_add_configs_for_visuals(_EGLDisplay *disp)
conf->base.LuminanceSize = 0; conf->base.LuminanceSize = 0;
conf->base.AlphaSize = 8; conf->base.AlphaSize = 8;
conf->base.ColorBufferType = EGL_RGB_BUFFER; conf->base.ColorBufferType = EGL_RGB_BUFFER;
conf->base.BufferSize = conf->base.RedSize conf->base.BufferSize = conf->base.RedSize + conf->base.GreenSize +
+ conf->base.GreenSize conf->base.BlueSize + conf->base.AlphaSize;
+ conf->base.BlueSize
+ conf->base.AlphaSize;
conf->base.ConfigCaveat = EGL_NONE; conf->base.ConfigCaveat = EGL_NONE;
conf->base.ConfigID = 1; conf->base.ConfigID = 1;
conf->base.BindToTextureRGB = EGL_FALSE; conf->base.BindToTextureRGB = EGL_FALSE;
@ -323,7 +322,8 @@ haiku_display_destroy(_EGLDisplay *disp)
return; return;
struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen; struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen;
hgl_destroy_display(hgl_dpy->disp); hgl_dpy->disp = NULL; hgl_destroy_display(hgl_dpy->disp);
hgl_dpy->disp = NULL;
screen->destroy(screen); // destroy will deallocate object screen->destroy(screen); // destroy will deallocate object
free(hgl_dpy); free(hgl_dpy);
@ -335,7 +335,8 @@ haiku_initialize_impl(_EGLDisplay *disp, void *platformDisplay)
struct haiku_egl_display *hgl_dpy; struct haiku_egl_display *hgl_dpy;
const char *err; const char *err;
hgl_dpy = (struct haiku_egl_display*)calloc(1, sizeof(struct haiku_egl_display)); hgl_dpy =
(struct haiku_egl_display *)calloc(1, sizeof(struct haiku_egl_display));
if (!hgl_dpy) if (!hgl_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize"); return _eglError(EGL_BAD_ALLOC, "eglInitialize");
@ -350,7 +351,8 @@ haiku_initialize_impl(_EGLDisplay *disp, void *platformDisplay)
if (_eglIsApiValid(EGL_OPENGL_API)) if (_eglIsApiValid(EGL_OPENGL_API))
disp->ClientAPIs |= EGL_OPENGL_BIT; disp->ClientAPIs |= EGL_OPENGL_BIT;
if (_eglIsApiValid(EGL_OPENGL_ES_API)) 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_no_config_context = EGL_TRUE;
disp->Extensions.KHR_surfaceless_context = EGL_TRUE; disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
@ -358,14 +360,14 @@ haiku_initialize_impl(_EGLDisplay *disp, void *platformDisplay)
/* Report back to EGL the bitmask of priorities supported */ /* Report back to EGL the bitmask of priorities supported */
disp->Extensions.IMG_context_priority = disp->Extensions.IMG_context_priority =
hgl_dpy->disp->fscreen->screen->get_param(hgl_dpy->disp->fscreen->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK); 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, if (hgl_dpy->disp->fscreen->screen->is_format_supported(
PIPE_FORMAT_B8G8R8A8_SRGB, hgl_dpy->disp->fscreen->screen, PIPE_FORMAT_B8G8R8A8_SRGB,
PIPE_TEXTURE_2D, 0, 0, PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_RENDER_TARGET))
PIPE_BIND_RENDER_TARGET))
disp->Extensions.KHR_gl_colorspace = EGL_TRUE; disp->Extensions.KHR_gl_colorspace = EGL_TRUE;
disp->Extensions.KHR_create_context = EGL_TRUE; disp->Extensions.KHR_create_context = EGL_TRUE;
@ -380,7 +382,6 @@ cleanup:
return _eglError(EGL_NOT_INITIALIZED, err); return _eglError(EGL_NOT_INITIALIZED, err);
} }
static EGLBoolean static EGLBoolean
haiku_initialize(_EGLDisplay *disp) haiku_initialize(_EGLDisplay *disp)
{ {
@ -413,7 +414,6 @@ haiku_initialize(_EGLDisplay *disp)
return EGL_TRUE; return EGL_TRUE;
} }
static EGLBoolean static EGLBoolean
haiku_terminate(_EGLDisplay *disp) haiku_terminate(_EGLDisplay *disp)
{ {
@ -421,7 +421,6 @@ haiku_terminate(_EGLDisplay *disp)
return EGL_TRUE; return EGL_TRUE;
} }
// #pragma mark EGLContext // #pragma mark EGLContext
static _EGLContext * static _EGLContext *
@ -435,7 +434,8 @@ haiku_create_context(_EGLDisplay *disp, _EGLConfig *conf,
struct st_visual visual; struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH); hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH);
struct haiku_egl_context* context = (struct haiku_egl_context*) calloc(1, sizeof (*context)); struct haiku_egl_context *context =
(struct haiku_egl_context *)calloc(1, sizeof(*context));
if (!context) { if (!context) {
_eglError(EGL_BAD_ALLOC, "haiku_create_context"); _eglError(EGL_BAD_ALLOC, "haiku_create_context");
return NULL; return NULL;
@ -444,7 +444,9 @@ haiku_create_context(_EGLDisplay *disp, _EGLConfig *conf,
if (!_eglInitContext(&context->base, disp, conf, share_list, attrib_list)) if (!_eglInitContext(&context->base, disp, conf, share_list, attrib_list))
goto cleanup; goto cleanup;
context->ctx = hgl_create_context(hgl_dpy->disp, &visual, share_list == NULL ? NULL : haiku_egl_context(share_list)->ctx->st); context->ctx = hgl_create_context(
hgl_dpy->disp, &visual,
share_list == NULL ? NULL : haiku_egl_context(share_list)->ctx->st);
if (context->ctx == NULL) if (context->ctx == NULL)
goto cleanup; goto cleanup;
@ -455,7 +457,6 @@ cleanup:
return NULL; return NULL;
} }
static EGLBoolean static EGLBoolean
haiku_destroy_context(_EGLDisplay *disp, _EGLContext *ctx) haiku_destroy_context(_EGLDisplay *disp, _EGLContext *ctx)
{ {
@ -468,9 +469,9 @@ haiku_destroy_context(_EGLDisplay *disp, _EGLContext* ctx)
return EGL_TRUE; return EGL_TRUE;
} }
static EGLBoolean 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();
@ -501,16 +502,17 @@ haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf, _E
hgl_rsurf == NULL ? NULL : &hgl_rsurf->fb->base); hgl_rsurf == NULL ? NULL : &hgl_rsurf->fb->base);
} }
if (old_dsurf != NULL) haiku_destroy_surface(disp, old_dsurf); if (old_dsurf != NULL)
if (old_rsurf != NULL) haiku_destroy_surface(disp, old_rsurf); haiku_destroy_surface(disp, old_dsurf);
if (old_ctx != NULL) haiku_destroy_context(disp, old_ctx); 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 = {
extern "C"
const _EGLDriver _eglDriver = {
.Initialize = haiku_initialize, .Initialize = haiku_initialize,
.Terminate = haiku_terminate, .Terminate = haiku_terminate,
.CreateContext = haiku_create_context, .CreateContext = haiku_create_context,

View file

@ -23,30 +23,30 @@
#include "state_tracker/st_context.h" #include "state_tracker/st_context.h"
#include <eglcontext.h>
#include <eglcurrent.h>
#include <egldriver.h> #include <egldriver.h>
#include <egllog.h> #include <egllog.h>
#include <eglcurrent.h>
#include <eglcontext.h>
#include <eglsurface.h> #include <eglsurface.h>
#include "egl_wgl.h" #include "egl_wgl.h"
#include <stw_device.h>
#include <stw_pixelformat.h>
#include <stw_context.h> #include <stw_context.h>
#include <stw_device.h>
#include <stw_ext_interop.h>
#include <stw_framebuffer.h> #include <stw_framebuffer.h>
#include <stw_image.h> #include <stw_image.h>
#include <stw_pixelformat.h>
#include <stw_winsys.h> #include <stw_winsys.h>
#include <stw_ext_interop.h>
#include <GL/wglext.h> #include <GL/wglext.h>
#include <pipe/p_context.h>
#include <pipe/p_screen.h> #include <pipe/p_screen.h>
#include <pipe/p_state.h> #include <pipe/p_state.h>
#include <pipe/p_context.h>
#include <mapi/glapi/glapi.h>
#include "util/u_call_once.h" #include "util/u_call_once.h"
#include <mapi/glapi/glapi.h>
#include <GL/mesa_glinterop.h> #include <GL/mesa_glinterop.h>
@ -63,7 +63,8 @@ wgl_match_config(const _EGLConfig *conf, const _EGLConfig *criteria)
} }
static struct wgl_egl_config * 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; struct wgl_egl_config *conf;
_EGLConfig base; _EGLConfig base;
@ -144,8 +145,7 @@ wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config,
else else
/* a similar config type is already added (unlikely) => discard */ /* a similar config type is already added (unlikely) => discard */
return NULL; return NULL;
} } else if (num_configs == 0) {
else if (num_configs == 0) {
conf = calloc(1, sizeof(*conf)); conf = calloc(1, sizeof(*conf));
if (conf == NULL) if (conf == NULL)
return NULL; return NULL;
@ -157,8 +157,7 @@ wgl_add_config(_EGLDisplay *disp, const struct stw_pixelformat_info *stw_config,
conf->base.ConfigID = config_id; conf->base.ConfigID = config_id;
_eglLinkConfig(&conf->base); _eglLinkConfig(&conf->base);
} } else {
else {
unreachable("duplicates should not be possible"); unreachable("duplicates should not be possible");
return NULL; return NULL;
} }
@ -178,8 +177,8 @@ wgl_add_configs(_EGLDisplay *disp)
// and there's no further filtering needed per-visual // and there's no further filtering needed per-visual
for (unsigned i = 1; stw_pixelformat_get_info(i) != NULL; i++) { 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), struct wgl_egl_config *wgl_conf = wgl_add_config(
config_count + 1, surface_type); disp, stw_pixelformat_get_info(i), config_count + 1, surface_type);
if (wgl_conf) { if (wgl_conf) {
if (wgl_conf->base.ConfigID == config_count + 1) if (wgl_conf->base.ConfigID == config_count + 1)
@ -200,14 +199,16 @@ wgl_display_destroy(_EGLDisplay *disp)
} }
static int 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 */ /* no-op */
return 0; return 0;
} }
static bool 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; struct wgl_egl_image *wgl_img = (struct wgl_egl_image *)image;
stw_translate_image(wgl_img->img, out); stw_translate_image(wgl_img->img, out);
@ -260,21 +261,21 @@ wgl_initialize_impl(_EGLDisplay *disp, HDC hdc)
if (_eglIsApiValid(EGL_OPENGL_API)) if (_eglIsApiValid(EGL_OPENGL_API))
disp->ClientAPIs |= EGL_OPENGL_BIT; disp->ClientAPIs |= EGL_OPENGL_BIT;
if (_eglIsApiValid(EGL_OPENGL_ES_API)) 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_no_config_context = EGL_TRUE;
disp->Extensions.KHR_surfaceless_context = EGL_TRUE; disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
disp->Extensions.MESA_query_driver = EGL_TRUE; disp->Extensions.MESA_query_driver = EGL_TRUE;
/* Report back to EGL the bitmask of priorities supported */ /* Report back to EGL the bitmask of priorities supported */
disp->Extensions.IMG_context_priority = disp->Extensions.IMG_context_priority = wgl_dpy->screen->get_param(
wgl_dpy->screen->get_param(wgl_dpy->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK); wgl_dpy->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK);
disp->Extensions.EXT_pixel_format_float = EGL_TRUE; disp->Extensions.EXT_pixel_format_float = EGL_TRUE;
if (wgl_dpy->screen->is_format_supported(wgl_dpy->screen, if (wgl_dpy->screen->is_format_supported(
PIPE_FORMAT_B8G8R8A8_SRGB, wgl_dpy->screen, PIPE_FORMAT_B8G8R8A8_SRGB, PIPE_TEXTURE_2D, 0, 0,
PIPE_TEXTURE_2D, 0, 0,
PIPE_BIND_RENDER_TARGET)) PIPE_BIND_RENDER_TARGET))
disp->Extensions.KHR_gl_colorspace = EGL_TRUE; disp->Extensions.KHR_gl_colorspace = EGL_TRUE;
@ -388,14 +389,13 @@ wgl_terminate(_EGLDisplay *disp)
* Called via eglCreateContext(), drv->CreateContext(). * Called via eglCreateContext(), drv->CreateContext().
*/ */
static _EGLContext * static _EGLContext *
wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf, _EGLContext *share_list,
_EGLContext *share_list, const EGLint *attrib_list) const EGLint *attrib_list)
{ {
struct wgl_egl_context *wgl_ctx; struct wgl_egl_context *wgl_ctx;
struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp); struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp);
struct wgl_egl_context *wgl_ctx_shared = wgl_egl_context(share_list); struct wgl_egl_context *wgl_ctx_shared = wgl_egl_context(share_list);
struct stw_context *shared = struct stw_context *shared = wgl_ctx_shared ? wgl_ctx_shared->ctx : NULL;
wgl_ctx_shared ? wgl_ctx_shared->ctx : NULL;
struct wgl_egl_config *wgl_config = wgl_egl_config(conf); struct wgl_egl_config *wgl_config = wgl_egl_config(conf);
const struct stw_pixelformat_info *stw_config; const struct stw_pixelformat_info *stw_config;
@ -414,10 +414,10 @@ wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf,
profile_mask = WGL_CONTEXT_ES_PROFILE_BIT_EXT; profile_mask = WGL_CONTEXT_ES_PROFILE_BIT_EXT;
break; break;
case EGL_OPENGL_API: case EGL_OPENGL_API:
if ((wgl_ctx->base.ClientMajorVersion >= 4 if ((wgl_ctx->base.ClientMajorVersion >= 4 ||
|| (wgl_ctx->base.ClientMajorVersion == 3 (wgl_ctx->base.ClientMajorVersion == 3 &&
&& wgl_ctx->base.ClientMinorVersion >= 2)) wgl_ctx->base.ClientMinorVersion >= 2)) &&
&& wgl_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR) wgl_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR)
profile_mask = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; profile_mask = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
else if (wgl_ctx->base.ClientMajorVersion == 3 && else if (wgl_ctx->base.ClientMajorVersion == 3 &&
wgl_ctx->base.ClientMinorVersion == 1) wgl_ctx->base.ClientMinorVersion == 1)
@ -443,8 +443,7 @@ wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf,
stw_config = wgl_config->stw_config[1]; stw_config = wgl_config->stw_config[1];
else else
stw_config = wgl_config->stw_config[0]; stw_config = wgl_config->stw_config[0];
} } else
else
stw_config = NULL; stw_config = NULL;
unsigned flags = 0; unsigned flags = 0;
@ -455,14 +454,10 @@ wgl_create_context(_EGLDisplay *disp, _EGLConfig *conf,
unsigned resetStrategy = WGL_NO_RESET_NOTIFICATION_ARB; unsigned resetStrategy = WGL_NO_RESET_NOTIFICATION_ARB;
if (wgl_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION) if (wgl_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION)
resetStrategy = WGL_LOSE_CONTEXT_ON_RESET_ARB; resetStrategy = WGL_LOSE_CONTEXT_ON_RESET_ARB;
wgl_ctx->ctx = stw_create_context_attribs(disp->PlatformDisplay, 0, shared, wgl_ctx->ctx = stw_create_context_attribs(
&wgl_dpy->base, disp->PlatformDisplay, 0, shared, &wgl_dpy->base,
wgl_ctx->base.ClientMajorVersion, wgl_ctx->base.ClientMajorVersion, wgl_ctx->base.ClientMinorVersion, flags,
wgl_ctx->base.ClientMinorVersion, profile_mask, stw_config, resetStrategy);
flags,
profile_mask,
stw_config,
resetStrategy);
if (!wgl_ctx->ctx) if (!wgl_ctx->ctx)
goto cleanup; goto cleanup;
@ -520,8 +515,8 @@ wgl_gl_flush()
static void (*glFlush)(void); static void (*glFlush)(void);
static util_once_flag once = UTIL_ONCE_FLAG_INIT; static util_once_flag once = UTIL_ONCE_FLAG_INIT;
util_call_once_data(&once, util_call_once_data(&once, (util_call_once_data_func)wgl_gl_flush_get,
(util_call_once_data_func)wgl_gl_flush_get, &glFlush); &glFlush);
/* if glFlush is not available things are horribly broken */ /* if glFlush is not available things are horribly broken */
if (!glFlush) { if (!glFlush) {
@ -536,8 +531,8 @@ wgl_gl_flush()
* Called via eglMakeCurrent(), drv->MakeCurrent(). * Called via eglMakeCurrent(), drv->MakeCurrent().
*/ */
static EGLBoolean static EGLBoolean
wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf,
_EGLSurface *rsurf, _EGLContext *ctx) _EGLContext *ctx)
{ {
struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp); struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp);
struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
@ -581,9 +576,9 @@ wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf,
egl_error = EGL_BAD_MATCH; egl_error = EGL_BAD_MATCH;
/* undo the previous _eglBindContext */ /* undo the previous _eglBindContext */
_eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf, &tmp_rsurf); _eglBindContext(old_ctx, old_dsurf, old_rsurf, &ctx, &tmp_dsurf,
assert(&wgl_ctx->base == ctx && &tmp_rsurf);
tmp_dsurf == dsurf && assert(&wgl_ctx->base == ctx && tmp_dsurf == dsurf &&
tmp_rsurf == rsurf); tmp_rsurf == rsurf);
_eglPutSurface(dsurf); _eglPutSurface(dsurf);
@ -616,8 +611,7 @@ wgl_make_current(_EGLDisplay *disp, _EGLSurface *dsurf,
tmp_rsurf == old_rsurf); tmp_rsurf == old_rsurf);
_eglLog(_EGL_WARNING, "wgl: failed to rebind the previous context"); _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->core->bindContext succeeded, so take a reference on the
* wgl_dpy. This prevents wgl_dpy from being reinitialized when a * wgl_dpy. This prevents wgl_dpy from being reinitialized when a
* EGLDisplay is terminated and then initialized again while a * EGLDisplay is terminated and then initialized again while a
@ -652,14 +646,17 @@ wgl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
if (!wgl_surf) if (!wgl_surf)
return NULL; 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); free(wgl_surf);
return NULL; return NULL;
} }
const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1] ? const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1]
wgl_conf->stw_config[1] : wgl_conf->stw_config[0]; ? wgl_conf->stw_config[1]
wgl_surf->fb = stw_framebuffer_create(native_window, stw_conf, STW_FRAMEBUFFER_EGL_WINDOW, &wgl_dpy->base); : 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) { if (!wgl_surf->fb) {
free(wgl_surf); free(wgl_surf);
return NULL; return NULL;
@ -682,14 +679,17 @@ wgl_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
if (!wgl_surf) if (!wgl_surf)
return NULL; 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); free(wgl_surf);
return NULL; return NULL;
} }
const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1] ? const struct stw_pixelformat_info *stw_conf = wgl_conf->stw_config[1]
wgl_conf->stw_config[1] : wgl_conf->stw_config[0]; ? wgl_conf->stw_config[1]
wgl_surf->fb = stw_pbuffer_create(stw_conf, wgl_surf->base.Width, wgl_surf->base.Height, &wgl_dpy->base); : 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) { if (!wgl_surf->fb) {
free(wgl_surf); free(wgl_surf);
return NULL; return NULL;
@ -702,8 +702,8 @@ wgl_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
} }
static EGLBoolean static EGLBoolean
wgl_query_surface(_EGLDisplay *disp, _EGLSurface *surf, wgl_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint attribute, EGLint *value) EGLint *value)
{ {
struct wgl_egl_surface *wgl_surf = wgl_egl_surface(surf); struct wgl_egl_surface *wgl_surf = wgl_egl_surface(surf);
RECT client_rect; RECT client_rect;
@ -733,7 +733,8 @@ wgl_bind_tex_image(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
if (!_eglBindTexImage(disp, surf, buffer)) if (!_eglBindTexImage(disp, surf, buffer))
return EGL_FALSE; 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; enum pipe_format format = pres->format;
switch (surf->TextureFormat) { 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()"); assert(!"Unexpected texture target in wgl_bind_tex_image()");
} }
st_context_teximage(wgl_ctx->ctx->st, GL_TEXTURE_2D, 0, format, pres, st_context_teximage(wgl_ctx->ctx->st, GL_TEXTURE_2D, 0, format, pres, false);
false);
return EGL_TRUE; 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 wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
struct pipe_fence_handle *fence = NULL; 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; return EGL_TRUE;
} }
@ -839,8 +840,7 @@ egl_error_from_stw_image_error(enum stw_image_error err)
static _EGLImage * static _EGLImage *
wgl_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx, wgl_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
EGLenum target, EGLenum target, EGLClientBuffer buffer,
EGLClientBuffer buffer,
const EGLint *attr_list) const EGLint *attr_list)
{ {
struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
@ -890,12 +890,8 @@ wgl_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
_eglInitImage(&wgl_img->base, disp); _eglInitImage(&wgl_img->base, disp);
wgl_img->img = stw_create_image_from_texture(wgl_ctx->ctx, wgl_img->img = stw_create_image_from_texture(
gl_target, wgl_ctx->ctx, gl_target, texture, depth, attrs.GLTextureLevel, &error);
texture,
depth,
attrs.GLTextureLevel,
&error);
assert(!!wgl_img->img == (error == STW_IMAGE_ERROR_SUCCESS)); assert(!!wgl_img->img == (error == STW_IMAGE_ERROR_SUCCESS));
if (!wgl_img->img) { if (!wgl_img->img) {
@ -929,7 +925,8 @@ wgl_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx,
_eglInitImage(&wgl_img->base, disp); _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)); assert(!!wgl_img->img == (error == STW_IMAGE_ERROR_SUCCESS));
if (!wgl_img->img) { if (!wgl_img->img) {
@ -973,7 +970,8 @@ wgl_destroy_image_khr(_EGLDisplay *disp, _EGLImage *img)
} }
static _EGLSync * 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(); _EGLContext *ctx = _eglGetCurrentContext();
@ -1017,7 +1015,8 @@ wgl_create_sync_khr(_EGLDisplay *disp, EGLenum type, const EGLAttrib *attrib_lis
} }
static void 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) if (InterlockedDecrement((volatile LONG *)&wgl_sync->refcount) > 0)
return; return;
@ -1039,7 +1038,8 @@ wgl_destroy_sync_khr(_EGLDisplay *disp, _EGLSync *sync)
} }
static EGLint 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(); _EGLContext *ctx = _eglGetCurrentContext();
struct wgl_egl_display *wgl_dpy = wgl_egl_display(disp); 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) { switch (sync->Type) {
case EGL_SYNC_FENCE_KHR: 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; wgl_sync->base.SyncStatus = EGL_SIGNALED_KHR;
else else
ret = EGL_TIMEOUT_EXPIRED_KHR; ret = EGL_TIMEOUT_EXPIRED_KHR;
@ -1066,7 +1067,9 @@ wgl_client_wait_sync_khr(_EGLDisplay *disp, _EGLSync *sync, EGLint flags, EGLTim
wgl_gl_flush(); 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); DWORD wait_ret = WaitForSingleObject(wgl_sync->event, wait_milliseconds);
switch (wait_ret) { switch (wait_ret) {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
@ -1159,8 +1162,8 @@ wgl_interop_export_object(_EGLDisplay *disp, _EGLContext *ctx,
} }
static int static int
wgl_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, wgl_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, unsigned count,
unsigned count, struct mesa_glinterop_export_in *objects, struct mesa_glinterop_export_in *objects,
GLsync *sync) GLsync *sync)
{ {
struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx); struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
@ -1196,4 +1199,3 @@ struct _egl_driver _eglDriver = {
.GLInteropExportObject = wgl_interop_export_object, .GLInteropExportObject = wgl_interop_export_object,
.GLInteropFlushObjects = wgl_interop_flush_objects, .GLInteropFlushObjects = wgl_interop_flush_objects,
}; };

View file

@ -23,49 +23,43 @@
#pragma once #pragma once
#include <egldriver.h>
#include <egldisplay.h>
#include <eglconfig.h> #include <eglconfig.h>
#include <egldisplay.h>
#include <egldriver.h>
#include <eglimage.h> #include <eglimage.h>
#include <eglsync.h> #include <eglsync.h>
#include <stw_pixelformat.h>
#include <windows.h> #include <windows.h>
#include <stw_pixelformat.h>
struct wgl_egl_display struct wgl_egl_display {
{
struct pipe_frontend_screen base; struct pipe_frontend_screen base;
_EGLDisplay *parent; _EGLDisplay *parent;
int ref_count; int ref_count;
struct pipe_screen *screen; struct pipe_screen *screen;
}; };
struct wgl_egl_config struct wgl_egl_config {
{
_EGLConfig base; _EGLConfig base;
const struct stw_pixelformat_info *stw_config[2]; const struct stw_pixelformat_info *stw_config[2];
}; };
struct wgl_egl_context struct wgl_egl_context {
{
_EGLContext base; _EGLContext base;
struct stw_context *ctx; struct stw_context *ctx;
}; };
struct wgl_egl_surface struct wgl_egl_surface {
{
_EGLSurface base; _EGLSurface base;
struct stw_framebuffer *fb; struct stw_framebuffer *fb;
}; };
struct wgl_egl_image struct wgl_egl_image {
{
_EGLImage base; _EGLImage base;
struct stw_image *img; struct stw_image *img;
}; };
struct wgl_egl_sync struct wgl_egl_sync {
{
_EGLSync base; _EGLSync base;
int refcount; int refcount;
struct pipe_fence_handle *fence; struct pipe_fence_handle *fence;

File diff suppressed because it is too large Load diff

View file

@ -25,14 +25,12 @@
* *
**************************************************************************/ **************************************************************************/
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "egllog.h"
#include "eglarray.h" #include "eglarray.h"
#include "egllog.h"
/** /**
* Grow the size of the array. * Grow the size of the array.
@ -49,8 +47,8 @@ _eglGrowArray(_EGLArray *array)
elems = realloc(array->Elements, new_size * sizeof(array->Elements[0])); elems = realloc(array->Elements, new_size * sizeof(array->Elements[0]));
if (!elems) { if (!elems) {
_eglLog(_EGL_DEBUG, "failed to grow %s array to %d", _eglLog(_EGL_DEBUG, "failed to grow %s array to %d", array->Name,
array->Name, new_size); new_size);
return EGL_FALSE; return EGL_FALSE;
} }
@ -60,7 +58,6 @@ _eglGrowArray(_EGLArray *array)
return EGL_TRUE; return EGL_TRUE;
} }
/** /**
* Create an array. * Create an array.
*/ */
@ -82,7 +79,6 @@ _eglCreateArray(const char *name, EGLint init_size)
return array; return array;
} }
/** /**
* Destroy an array, optionally free the data. * Destroy an array, optionally free the data.
*/ */
@ -98,7 +94,6 @@ _eglDestroyArray(_EGLArray *array, void (*free_cb)(void *))
free(array); free(array);
} }
/** /**
* Append a element to an array. * Append a element to an array.
*/ */
@ -111,7 +106,6 @@ _eglAppendArray(_EGLArray *array, void *elem)
array->Elements[array->Size++] = elem; array->Elements[array->Size++] = elem;
} }
/** /**
* Erase an element from an array. * Erase an element from an array.
*/ */
@ -127,7 +121,6 @@ _eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *))
array->Size--; array->Size--;
} }
/** /**
* Find in an array for the given element. * Find in an array for the given element.
*/ */
@ -145,7 +138,6 @@ _eglFindArray(_EGLArray *array, void *elem)
return NULL; return NULL;
} }
/** /**
* Filter an array and return the number of filtered elements. * Filter an array and return the number of filtered elements.
*/ */
@ -172,7 +164,6 @@ _eglFilterArray(_EGLArray *array, void **data, EGLint size,
return count; return count;
} }
/** /**
* Flatten an array by converting array elements into another form and store * Flatten an array by converting array elements into another form and store
* them in a buffer. * them in a buffer.
@ -195,8 +186,7 @@ _eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size,
if (count > size) if (count > size)
count = size; count = size;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
flatten(array->Elements[i], flatten(array->Elements[i], (void *)((char *)buffer + elem_size * i));
(void *) ((char *) buffer + elem_size * i));
} }
return count; return count;

View file

@ -25,20 +25,17 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLARRAY_INCLUDED #ifndef EGLARRAY_INCLUDED
#define EGLARRAY_INCLUDED #define EGLARRAY_INCLUDED
#include "egltypedefs.h" #include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef EGLBoolean (*_EGLArrayForEach)(void *elem, void *foreach_data); typedef EGLBoolean (*_EGLArrayForEach)(void *elem, void *foreach_data);
struct _egl_array { struct _egl_array {
const char *Name; const char *Name;
EGLint MaxSize; EGLint MaxSize;
@ -47,44 +44,35 @@ struct _egl_array {
EGLint Size; EGLint Size;
}; };
extern _EGLArray * extern _EGLArray *
_eglCreateArray(const char *name, EGLint init_size); _eglCreateArray(const char *name, EGLint init_size);
extern void extern void
_eglDestroyArray(_EGLArray *array, void (*free_cb)(void *)); _eglDestroyArray(_EGLArray *array, void (*free_cb)(void *));
extern void extern void
_eglAppendArray(_EGLArray *array, void *elem); _eglAppendArray(_EGLArray *array, void *elem);
extern void extern void
_eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *)); _eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *));
void * void *
_eglFindArray(_EGLArray *array, void *elem); _eglFindArray(_EGLArray *array, void *elem);
extern EGLint extern EGLint
_eglFilterArray(_EGLArray *array, void **data, EGLint size, _eglFilterArray(_EGLArray *array, void **data, EGLint size,
_EGLArrayForEach filter, void *filter_data); _EGLArrayForEach filter, void *filter_data);
EGLint EGLint
_eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size, _eglFlattenArray(_EGLArray *array, void *buffer, EGLint elem_size, EGLint size,
_EGLArrayForEach flatten); _EGLArrayForEach flatten);
static inline EGLint static inline EGLint
_eglGetArraySize(_EGLArray *array) _eglGetArraySize(_EGLArray *array)
{ {
return (array) ? array->Size : 0; return (array) ? array->Size : 0;
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -27,26 +27,21 @@
* *
**************************************************************************/ **************************************************************************/
/** /**
* EGL Configuration (pixel format) functions. * EGL Configuration (pixel format) functions.
*/ */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include "util/macros.h" #include "util/macros.h"
#include "eglconfig.h" #include "eglconfig.h"
#include "eglconfigdebug.h" #include "eglconfigdebug.h"
#include "egldisplay.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "egldisplay.h"
#include "egllog.h" #include "egllog.h"
/** /**
* Init the given _EGLconfig to default values. * Init the given _EGLconfig to default values.
* \param id the configuration's ID. * \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; conf->ComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
} }
/** /**
* Link a config to its display and return the handle of the link. * Link a config to its display and return the handle of the link.
* The handle can be passed to client directly. * The handle can be passed to client directly.
@ -98,7 +92,6 @@ _eglLinkConfig(_EGLConfig *conf)
return (EGLConfig)conf; return (EGLConfig)conf;
} }
/** /**
* Lookup a handle to find the linked config. * Lookup a handle to find the linked config.
* Return NULL if the handle has no corresponding linked config. * Return NULL if the handle has no corresponding linked config.
@ -118,7 +111,6 @@ _eglLookupConfig(EGLConfig config, _EGLDisplay *disp)
return conf; return conf;
} }
enum type { enum type {
ATTRIB_TYPE_INTEGER, ATTRIB_TYPE_INTEGER,
ATTRIB_TYPE_BOOLEAN, ATTRIB_TYPE_BOOLEAN,
@ -136,15 +128,13 @@ enum criterion {
ATTRIB_CRITERION_IGNORE ATTRIB_CRITERION_IGNORE
}; };
/* EGL spec Table 3.1 and 3.4 */ /* EGL spec Table 3.1 and 3.4 */
static const struct { static const struct {
EGLint attr; EGLint attr;
enum type type; enum type type;
enum criterion criterion; enum criterion criterion;
EGLint default_value; EGLint default_value;
} _eglValidationTable[] = } _eglValidationTable[] = {
{
/* clang-format off */ /* clang-format off */
/* core */ /* core */
{ EGL_BUFFER_SIZE, ATTRIB_TYPE_INTEGER, { EGL_BUFFER_SIZE, ATTRIB_TYPE_INTEGER,
@ -262,7 +252,6 @@ static const struct {
/* clang-format on */ /* clang-format on */
}; };
/** /**
* Return true if a config is valid. When for_matching is true, * Return true if a config is valid. When for_matching is true,
* EGL_DONT_CARE is accepted as a valid attribute value, and checks * 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: case ATTRIB_TYPE_BITMASK:
switch (attr) { switch (attr) {
case EGL_SURFACE_TYPE: case EGL_SURFACE_TYPE:
mask = EGL_PBUFFER_BIT | mask = EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT |
EGL_PIXMAP_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT |
EGL_WINDOW_BIT |
EGL_VG_COLORSPACE_LINEAR_BIT |
EGL_VG_ALPHA_FORMAT_PRE_BIT |
EGL_MULTISAMPLE_RESOLVE_BOX_BIT | EGL_MULTISAMPLE_RESOLVE_BOX_BIT |
EGL_SWAP_BEHAVIOR_PRESERVED_BIT; EGL_SWAP_BEHAVIOR_PRESERVED_BIT;
if (disp->Extensions.KHR_mutable_render_buffer) if (disp->Extensions.KHR_mutable_render_buffer)
@ -348,11 +334,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
break; break;
case EGL_RENDERABLE_TYPE: case EGL_RENDERABLE_TYPE:
case EGL_CONFORMANT: case EGL_CONFORMANT:
mask = EGL_OPENGL_ES_BIT | mask = EGL_OPENGL_ES_BIT | EGL_OPENVG_BIT | EGL_OPENGL_ES2_BIT |
EGL_OPENVG_BIT | EGL_OPENGL_ES3_BIT_KHR | EGL_OPENGL_BIT;
EGL_OPENGL_ES2_BIT |
EGL_OPENGL_ES3_BIT_KHR |
EGL_OPENGL_BIT;
break; break;
default: default:
unreachable("check _eglValidationTable[]"); unreachable("check _eglValidationTable[]");
@ -380,8 +363,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
valid = EGL_TRUE; valid = EGL_TRUE;
} }
if (!valid) { if (!valid) {
_eglLog(_EGL_DEBUG, _eglLog(_EGL_DEBUG, "attribute 0x%04x has an invalid value 0x%x", attr,
"attribute 0x%04x has an invalid value 0x%x", attr, val); val);
break; break;
} }
} }
@ -396,8 +379,8 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
case EGL_RGB_BUFFER: case EGL_RGB_BUFFER:
if (conf->LuminanceSize) if (conf->LuminanceSize)
valid = EGL_FALSE; valid = EGL_FALSE;
if (conf->RedSize + conf->GreenSize + if (conf->RedSize + conf->GreenSize + conf->BlueSize + conf->AlphaSize !=
conf->BlueSize + conf->AlphaSize != conf->BufferSize) conf->BufferSize)
valid = EGL_FALSE; valid = EGL_FALSE;
break; break;
case EGL_LUMINANCE_BUFFER: case EGL_LUMINANCE_BUFFER:
@ -428,14 +411,14 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
valid = EGL_FALSE; valid = EGL_FALSE;
} }
if (!valid) { 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 EGL_FALSE;
} }
return valid; return valid;
} }
/** /**
* Return true if a config matches the criteria. This and * Return true if a config matches the criteria. This and
* _eglParseConfigAttribList together implement the algorithm * _eglParseConfigAttribList together implement the algorithm
@ -489,7 +472,8 @@ _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria)
break; break;
#endif #endif
_eglLog(_EGL_DEBUG, _eglLog(_EGL_DEBUG,
"the value (0x%x) of attribute 0x%04x did not meet the criteria (0x%x)", "the value (0x%x) of attribute 0x%04x did not meet the "
"criteria (0x%x)",
val, attr, cmp); val, attr, cmp);
break; break;
} }
@ -552,8 +536,7 @@ _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
return EGL_FALSE; return EGL_FALSE;
/* EGL_LEVEL and EGL_MATCH_NATIVE_PIXMAP cannot be EGL_DONT_CARE */ /* EGL_LEVEL and EGL_MATCH_NATIVE_PIXMAP cannot be EGL_DONT_CARE */
if (conf->Level == EGL_DONT_CARE || if (conf->Level == EGL_DONT_CARE || conf->MatchNativePixmap == EGL_DONT_CARE)
conf->MatchNativePixmap == EGL_DONT_CARE)
return EGL_FALSE; return EGL_FALSE;
/* ignore other attributes when EGL_CONFIG_ID is given */ /* ignore other attributes when EGL_CONFIG_ID is given */
@ -563,8 +546,7 @@ _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
if (attr != EGL_CONFIG_ID) if (attr != EGL_CONFIG_ID)
_eglSetConfigKey(conf, attr, EGL_DONT_CARE); _eglSetConfigKey(conf, attr, EGL_DONT_CARE);
} }
} } else {
else {
if (!(conf->SurfaceType & EGL_WINDOW_BIT)) if (!(conf->SurfaceType & EGL_WINDOW_BIT))
conf->NativeVisualType = EGL_DONT_CARE; conf->NativeVisualType = EGL_DONT_CARE;
@ -578,7 +560,6 @@ _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
return EGL_TRUE; return EGL_TRUE;
} }
/** /**
* Decide the ordering of conf1 and conf2, under the given criteria. * Decide the ordering of conf1 and conf2, under the given criteria.
* When compare_id is true, this implements the algorithm described * 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 _EGLConfig *criteria, EGLBoolean compare_id)
{ {
const EGLint compare_attribs[] = { const EGLint compare_attribs[] = {
EGL_BUFFER_SIZE, EGL_BUFFER_SIZE, EGL_SAMPLE_BUFFERS, EGL_SAMPLES,
EGL_SAMPLE_BUFFERS, EGL_DEPTH_SIZE, EGL_STENCIL_SIZE, EGL_ALPHA_MASK_SIZE,
EGL_SAMPLES,
EGL_DEPTH_SIZE,
EGL_STENCIL_SIZE,
EGL_ALPHA_MASK_SIZE,
}; };
EGLint val1, val2; EGLint val1, val2;
EGLint i; EGLint i;
@ -638,8 +615,7 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
val1 += conf1->BlueSize; val1 += conf1->BlueSize;
val2 += conf2->BlueSize; val2 += conf2->BlueSize;
} }
} } else {
else {
if (criteria->LuminanceSize > 0) { if (criteria->LuminanceSize > 0) {
val1 += conf1->LuminanceSize; val1 += conf1->LuminanceSize;
val2 += conf2->LuminanceSize; val2 += conf2->LuminanceSize;
@ -649,8 +625,7 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
val1 += conf1->AlphaSize; val1 += conf1->AlphaSize;
val2 += conf2->AlphaSize; val2 += conf2->AlphaSize;
} }
} } else {
else {
/* assume the default criteria, which gives no specific ordering */ /* assume the default criteria, which gives no specific ordering */
val1 = val2 = 0; val1 = val2 = 0;
} }
@ -671,16 +646,14 @@ _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
return (compare_id) ? (conf1->ConfigID - conf2->ConfigID) : 0; return (compare_id) ? (conf1->ConfigID - conf2->ConfigID) : 0;
} }
static inline void
static inline _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2)
void _eglSwapConfigs(const _EGLConfig **conf1, const _EGLConfig **conf2)
{ {
const _EGLConfig *tmp = *conf1; const _EGLConfig *tmp = *conf1;
*conf1 = *conf2; *conf1 = *conf2;
*conf2 = tmp; *conf2 = tmp;
} }
/** /**
* Quick sort an array of configs. This differs from the standard * Quick sort an array of configs. This differs from the standard
* qsort() in that the compare function accepts an additional * qsort() in that the compare function accepts an additional
@ -710,8 +683,7 @@ _eglSortConfigs(const _EGLConfig **configs, EGLint count,
_eglSwapConfigs(&configs[i], &configs[j]); _eglSwapConfigs(&configs[i], &configs[j]);
i++; i++;
j--; j--;
} } else if (i == j) {
else if (i == j) {
i++; i++;
j--; j--;
break; break;
@ -723,14 +695,13 @@ _eglSortConfigs(const _EGLConfig **configs, EGLint count,
_eglSortConfigs(configs + i, count - i, compare, priv_data); _eglSortConfigs(configs + i, count - i, compare, priv_data);
} }
/** /**
* A helper function for implementing eglChooseConfig. See _eglFilterArray and * A helper function for implementing eglChooseConfig. See _eglFilterArray and
* _eglSortConfigs for the meanings of match and compare. * _eglSortConfigs for the meanings of match and compare.
*/ */
EGLBoolean EGLBoolean
_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, EGLint config_size,
EGLint config_size, EGLint *num_configs, EGLint *num_configs,
EGLBoolean (*match)(const _EGLConfig *, void *), EGLBoolean (*match)(const _EGLConfig *, void *),
EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
void *), void *),
@ -740,8 +711,7 @@ _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
EGLint i, count; EGLint i, count;
/* get the number of matched configs */ /* get the number of matched configs */
count = _eglFilterArray(array, NULL, 0, count = _eglFilterArray(array, NULL, 0, (_EGLArrayForEach)match, priv_data);
(_EGLArrayForEach) match, priv_data);
if (!count) { if (!count) {
*num_configs = count; *num_configs = count;
return EGL_TRUE; return EGL_TRUE;
@ -752,13 +722,13 @@ _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)"); return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)");
/* get the matched configs */ /* get the matched configs */
_eglFilterArray(array, (void **) configList, count, _eglFilterArray(array, (void **)configList, count, (_EGLArrayForEach)match,
(_EGLArrayForEach) match, priv_data); priv_data);
/* perform sorting of configs */ /* perform sorting of configs */
if (configs && count) { if (configs && count) {
_eglSortConfigs((const _EGLConfig **) configList, count, _eglSortConfigs((const _EGLConfig **)configList, count, compare,
compare, priv_data); priv_data);
count = MIN2(count, config_size); count = MIN2(count, config_size);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
configs[i] = _eglGetConfigHandle(configList[i]); configs[i] = _eglGetConfigHandle(configList[i]);
@ -771,23 +741,20 @@ _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
return EGL_TRUE; return EGL_TRUE;
} }
static EGLBoolean static EGLBoolean
_eglFallbackMatch(const _EGLConfig *conf, void *priv_data) _eglFallbackMatch(const _EGLConfig *conf, void *priv_data)
{ {
return _eglMatchConfig(conf, (const _EGLConfig *)priv_data); return _eglMatchConfig(conf, (const _EGLConfig *)priv_data);
} }
static EGLint static EGLint
_eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2, _eglFallbackCompare(const _EGLConfig *conf1, const _EGLConfig *conf2,
void *priv_data) void *priv_data)
{ {
return _eglCompareConfigs(conf1, conf2, return _eglCompareConfigs(conf1, conf2, (const _EGLConfig *)priv_data,
(const _EGLConfig *) priv_data, EGL_TRUE); EGL_TRUE);
} }
/** /**
* Typical fallback routine for eglChooseConfig * Typical fallback routine for eglChooseConfig
*/ */
@ -801,10 +768,9 @@ _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list,
if (!_eglParseConfigAttribList(&criteria, disp, attrib_list)) if (!_eglParseConfigAttribList(&criteria, disp, attrib_list))
return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig"); return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
result = _eglFilterConfigArray(disp->Configs, result = _eglFilterConfigArray(disp->Configs, configs, config_size,
configs, config_size, num_configs, num_configs, _eglFallbackMatch,
_eglFallbackMatch, _eglFallbackCompare, _eglFallbackCompare, (void *)&criteria);
(void *) &criteria);
if (result && (_eglGetLogLevel() == _EGL_DEBUG)) if (result && (_eglGetLogLevel() == _EGL_DEBUG))
eglPrintConfigDebug(disp, configs, *num_configs, EGL_TRUE); eglPrintConfigDebug(disp, configs, *num_configs, EGL_TRUE);
@ -812,7 +778,6 @@ _eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list,
return result; return result;
} }
/** /**
* Fallback for eglGetConfigAttrib. * Fallback for eglGetConfigAttrib.
*/ */
@ -839,7 +804,6 @@ _eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf,
return EGL_TRUE; return EGL_TRUE;
} }
static EGLBoolean static EGLBoolean
_eglFlattenConfig(void *elem, void *buffer) _eglFlattenConfig(void *elem, void *buffer)
{ {
@ -853,11 +817,12 @@ _eglFlattenConfig(void *elem, void *buffer)
* Fallback for eglGetConfigs. * Fallback for eglGetConfigs.
*/ */
EGLBoolean EGLBoolean
_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, _eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size,
EGLint config_size, EGLint *num_config) EGLint *num_config)
{ {
*num_config = _eglFlattenArray(disp->Configs, (void *) configs, *num_config =
sizeof(configs[0]), config_size, _eglFlattenConfig); _eglFlattenArray(disp->Configs, (void *)configs, sizeof(configs[0]),
config_size, _eglFlattenConfig);
if (_eglGetLogLevel() == _EGL_DEBUG) if (_eglGetLogLevel() == _EGL_DEBUG)
eglPrintConfigDebug(disp, configs, *num_config, EGL_FALSE); eglPrintConfigDebug(disp, configs, *num_config, EGL_FALSE);

View file

@ -27,25 +27,21 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLCONFIG_INCLUDED #ifndef EGLCONFIG_INCLUDED
#define EGLCONFIG_INCLUDED #define EGLCONFIG_INCLUDED
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#include "egltypedefs.h" #include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* update _eglValidationTable and _eglOffsetOfConfig before updating this /* update _eglValidationTable and _eglOffsetOfConfig before updating this
* struct */ * struct */
struct _egl_config struct _egl_config {
{
_EGLDisplay *Display; _EGLDisplay *Display;
/* core */ /* core */
@ -90,7 +86,6 @@ struct _egl_config
EGLint ComponentType; EGLint ComponentType;
}; };
/** /**
* Map an EGL attribute enum to the offset of the member in _EGLConfig. * Map an EGL attribute enum to the offset of the member in _EGLConfig.
*/ */
@ -98,7 +93,9 @@ static inline EGLint
_eglOffsetOfConfig(EGLint attr) _eglOffsetOfConfig(EGLint attr)
{ {
switch (attr) { switch (attr) {
#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb) #define ATTRIB_MAP(attr, memb) \
case attr: \
return offsetof(_EGLConfig, memb)
/* core */ /* core */
ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize); ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize); ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
@ -144,7 +141,6 @@ _eglOffsetOfConfig(EGLint attr)
} }
} }
/** /**
* Update a config for a given key. * Update a config for a given key.
* *
@ -160,7 +156,6 @@ _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
*((EGLint *)((char *)conf + offset)) = val; *((EGLint *)((char *)conf + offset)) = val;
} }
/** /**
* Return the value for a given key. * Return the value for a given key.
*/ */
@ -172,19 +167,15 @@ _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
return *((EGLint *)((char *)conf + offset)); return *((EGLint *)((char *)conf + offset));
} }
extern void extern void
_eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id); _eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
extern EGLConfig extern EGLConfig
_eglLinkConfig(_EGLConfig *conf); _eglLinkConfig(_EGLConfig *conf);
extern _EGLConfig * extern _EGLConfig *
_eglLookupConfig(EGLConfig config, _EGLDisplay *disp); _eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
/** /**
* Return the handle of a linked config. * Return the handle of a linked config.
*/ */
@ -194,45 +185,39 @@ _eglGetConfigHandle(_EGLConfig *conf)
return (EGLConfig)conf; return (EGLConfig)conf;
} }
extern EGLBoolean extern EGLBoolean
_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching); _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
extern EGLBoolean extern EGLBoolean
_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria); _eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
extern EGLBoolean extern EGLBoolean
_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp, _eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
const EGLint *attrib_list); const EGLint *attrib_list);
extern EGLint extern EGLint
_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2, _eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
const _EGLConfig *criteria, EGLBoolean compare_id); const _EGLConfig *criteria, EGLBoolean compare_id);
extern EGLBoolean extern EGLBoolean
_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, _eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, EGLint config_size,
EGLint config_size, EGLint *num_configs, EGLint *num_configs,
EGLBoolean (*match)(const _EGLConfig *, void *), EGLBoolean (*match)(const _EGLConfig *, void *),
EGLint (*compare)(const _EGLConfig *, const _EGLConfig *, EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
void *), void *),
void *filter_data); void *filter_data);
extern EGLBoolean
_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list,
EGLConfig *configs, EGLint config_size, EGLint *num_config);
extern EGLBoolean 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 extern EGLBoolean
_eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf, EGLint attribute, EGLint *value); _eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size,
EGLint *num_config);
extern EGLBoolean
_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -23,18 +23,18 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "util/macros.h"
#include "eglarray.h" #include "eglarray.h"
#include "eglconfig.h" #include "eglconfig.h"
#include "eglconfigdebug.h" #include "eglconfigdebug.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egllog.h" #include "egllog.h"
#include "egltypedefs.h" #include "egltypedefs.h"
#include "util/macros.h"
/* Max debug message length */ /* Max debug message length */
#define CONFIG_DEBUG_MSG_MAX 1000 #define CONFIG_DEBUG_MSG_MAX 1000
@ -136,10 +136,10 @@ _eglPrintConfig(_EGLConfig *const conf, const int chosenIndex)
_strnAppend(printMsg, sizeof(printMsg), _strnAppend(printMsg, sizeof(printMsg),
"0x%03x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%08x%2s ", "0x%03x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%08x%2s ",
conf->ConfigID, conf->BufferSize, conf->Level, conf->ConfigID, conf->BufferSize, conf->Level, conf->RedSize,
conf->RedSize, conf->GreenSize, conf->BlueSize, conf->AlphaSize, conf->GreenSize, conf->BlueSize, conf->AlphaSize,
conf->DepthSize, conf->StencilSize, conf->DepthSize, conf->StencilSize, conf->Samples,
conf->Samples, conf->SampleBuffers, conf->NativeVisualID, conf->SampleBuffers, conf->NativeVisualID,
vtype < 6 ? vnames[vtype] : "--"); vtype < 6 ? vnames[vtype] : "--");
bindRgb = conf->BindToTextureRGB; bindRgb = conf->BindToTextureRGB;
@ -149,20 +149,22 @@ _eglPrintConfig(_EGLConfig *const conf, const int chosenIndex)
_strnAppend(printMsg, sizeof(printMsg), _strnAppend(printMsg, sizeof(printMsg),
"%c %c %c %c %c %c %c %15s", "%c %c %c %c %c %c %c %15s",
(conf->ConfigCaveat != EGL_NONE) ? 'y' : ' ', (conf->ConfigCaveat != EGL_NONE) ? 'y' : ' ',
(bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ', (bindRgba) ? 'a'
: (bindRgb) ? 'y'
: ' ',
(renderable & EGL_OPENGL_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_BIT) ? 'y' : ' ',
(renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ',
(renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ',
(renderable & EGL_OPENGL_ES3_BIT) ? 'y' : ' ', (renderable & EGL_OPENGL_ES3_BIT) ? 'y' : ' ',
(renderable & EGL_OPENVG_BIT) ? 'y' : ' ', (renderable & EGL_OPENVG_BIT) ? 'y' : ' ', surfString);
surfString);
_eglLog(_EGL_DEBUG, printMsg); _eglLog(_EGL_DEBUG, printMsg);
} }
void eglPrintConfigDebug(const _EGLDisplay *const disp, void
const EGLConfig *const configs, eglPrintConfigDebug(const _EGLDisplay *const disp,
const EGLint numConfigs, const EGLBoolean printChosen) const EGLConfig *const configs, const EGLint numConfigs,
const EGLBoolean printChosen)
{ {
EGLint numConfigsToPrint; EGLint numConfigsToPrint;
_EGLConfig **configsToPrint; _EGLConfig **configsToPrint;

View file

@ -36,9 +36,10 @@ extern "C" {
/** /**
* Print the list of configs and the associated attributes. * Print the list of configs and the associated attributes.
*/ */
void eglPrintConfigDebug(const _EGLDisplay *const disp, void
const EGLConfig *const configs, eglPrintConfigDebug(const _EGLDisplay *const disp,
EGLint numConfigs, EGLBoolean printChosen); const EGLConfig *const configs, EGLint numConfigs,
EGLBoolean printChosen);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -27,18 +27,16 @@
* *
**************************************************************************/ **************************************************************************/
#include "eglcontext.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldisplay.h"
#include "eglcurrent.h"
#include "eglsurface.h"
#include "egllog.h"
#include "util/macros.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. * Return the API bit (one of EGL_xxx_BIT) of the context.
@ -77,7 +75,6 @@ _eglGetContextAPIBit(_EGLContext *ctx)
return bit; return bit;
} }
/** /**
* Parse the list of context attributes and return the proper error code. * Parse the list of context attributes and return the proper error code.
*/ */
@ -119,7 +116,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* generate an error." * generate an error."
*/ */
if ((api != EGL_OPENGL_ES_API && if ((api != EGL_OPENGL_ES_API &&
(!disp->Extensions.KHR_create_context || api != EGL_OPENGL_API))) { (!disp->Extensions.KHR_create_context ||
api != EGL_OPENGL_API))) {
err = EGL_BAD_ATTRIBUTE; err = EGL_BAD_ATTRIBUTE;
break; break;
} }
@ -179,8 +177,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* forward-compatible context for OpenGL versions less than 3.0 * forward-compatible context for OpenGL versions less than 3.0
* will generate an error." * will generate an error."
* *
* Note: since the forward-compatible flag can be set more than one way, * Note: since the forward-compatible flag can be set more than one
* the OpenGL version check is performed once, below. * way, the OpenGL version check is performed once, below.
*/ */
if ((val & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) && if ((val & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) &&
api != EGL_OPENGL_API) { api != EGL_OPENGL_API) {
@ -258,9 +256,9 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* "This attribute is supported only for OpenGL and OpenGL ES * "This attribute is supported only for OpenGL and OpenGL ES
* contexts." * contexts."
*/ */
if (!(disp->Extensions.KHR_create_context && api == EGL_OPENGL_API) if (!(disp->Extensions.KHR_create_context && api == EGL_OPENGL_API) &&
&& !(disp->Version >= 15 && (api == EGL_OPENGL_API || !(disp->Version >= 15 &&
api == EGL_OPENGL_ES_API))) { (api == EGL_OPENGL_API || api == EGL_OPENGL_ES_API))) {
err = EGL_BAD_ATTRIBUTE; err = EGL_BAD_ATTRIBUTE;
break; break;
} }
@ -275,8 +273,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* meaningful for OpenGL ES contexts, and specifying it for other * meaningful for OpenGL ES contexts, and specifying it for other
* types of contexts will generate an EGL_BAD_ATTRIBUTE error." * types of contexts will generate an EGL_BAD_ATTRIBUTE error."
*/ */
if (!disp->Extensions.EXT_create_context_robustness if (!disp->Extensions.EXT_create_context_robustness ||
|| api != EGL_OPENGL_ES_API) { api != EGL_OPENGL_ES_API) {
err = EGL_BAD_ATTRIBUTE; err = EGL_BAD_ATTRIBUTE;
break; break;
} }
@ -335,7 +333,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* OpenGL ES 2.0+ * OpenGL ES 2.0+
*/ */
if (((api != EGL_OPENGL_API && api != EGL_OPENGL_ES_API) || 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; err = EGL_BAD_ATTRIBUTE;
break; break;
} }
@ -437,8 +436,8 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
* Since the value is ignored, only validate the setting if the version * Since the value is ignored, only validate the setting if the version
* is >= 3.2. * is >= 3.2.
*/ */
if (ctx->ClientMajorVersion >= 4 if (ctx->ClientMajorVersion >= 4 ||
|| (ctx->ClientMajorVersion == 3 && ctx->ClientMinorVersion >= 2)) { (ctx->ClientMajorVersion == 3 && ctx->ClientMinorVersion >= 2)) {
switch (ctx->Profile) { switch (ctx->Profile) {
case EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR: case EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR:
case EGL_CONTEXT_OPENGL_COMPATIBILITY_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 * "* If an OpenGL context is requested, the requested version
* is greater than 3.2, and the value for attribute * is greater than 3.2, and the value for attribute
* EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has
* any bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR * any bits set other than
* and EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has * EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and
* more than one of these bits set; or if the implementation does * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than
* not support the requested profile, then an EGL_BAD_MATCH error * one of these bits set; or if the implementation does not support
* is generated." * the requested profile, then an EGL_BAD_MATCH error is generated."
*/ */
err = EGL_BAD_MATCH; err = EGL_BAD_MATCH;
break; break;
@ -486,14 +485,14 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
switch (ctx->ClientMajorVersion) { switch (ctx->ClientMajorVersion) {
case 1: case 1:
if (ctx->ClientMinorVersion > 5 if (ctx->ClientMinorVersion > 5 ||
|| (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0)
err = EGL_BAD_MATCH; err = EGL_BAD_MATCH;
break; break;
case 2: case 2:
if (ctx->ClientMinorVersion > 1 if (ctx->ClientMinorVersion > 1 ||
|| (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0) (ctx->Flags & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR) != 0)
err = EGL_BAD_MATCH; err = EGL_BAD_MATCH;
break; break;
@ -563,24 +562,24 @@ _eglParseContextAttribList(_EGLContext *ctx, _EGLDisplay *disp,
/* The EGL_KHR_create_context_no_error spec says: /* The EGL_KHR_create_context_no_error spec says:
* *
* "BAD_MATCH is generated if the EGL_CONTEXT_OPENGL_NO_ERROR_KHR is TRUE at * "BAD_MATCH is generated if the EGL_CONTEXT_OPENGL_NO_ERROR_KHR is TRUE
* the same time as a debug or robustness context is specified." * at the same time as a debug or robustness context is specified."
*/ */
if (ctx->NoError && (ctx->Flags & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR || if (ctx->NoError &&
(ctx->Flags & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR ||
ctx->Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) { ctx->Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) {
err = EGL_BAD_MATCH; err = EGL_BAD_MATCH;
} }
if ((ctx->Flags & ~(EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR if ((ctx->Flags & ~(EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR |
| EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR |
| EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) != 0) { EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR)) != 0) {
err = EGL_BAD_ATTRIBUTE; err = EGL_BAD_ATTRIBUTE;
} }
return err; return err;
} }
/** /**
* Initialize the given _EGLContext object to defaults and/or the values * Initialize the given _EGLContext object to defaults and/or the values
* in the attrib_list. * in the attrib_list.
@ -641,7 +640,8 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *conf,
*/ */
if (share_list && share_list->ResetNotificationStrategy != if (share_list && share_list->ResetNotificationStrategy !=
ctx->ResetNotificationStrategy) { ctx->ResetNotificationStrategy) {
return _eglError(EGL_BAD_MATCH, return _eglError(
EGL_BAD_MATCH,
"eglCreateContext() share list notification strategy mismatch"); "eglCreateContext() share list notification strategy mismatch");
} }
@ -659,7 +659,6 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *conf,
return EGL_TRUE; return EGL_TRUE;
} }
static EGLint static EGLint
_eglQueryContextRenderBuffer(_EGLContext *ctx) _eglQueryContextRenderBuffer(_EGLContext *ctx)
{ {
@ -702,7 +701,6 @@ _eglQueryContextRenderBuffer(_EGLContext *ctx)
} }
} }
EGLBoolean EGLBoolean
_eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value) _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
{ {
@ -746,7 +744,6 @@ _eglQueryContext(_EGLContext *c, EGLint attribute, EGLint *value)
return EGL_TRUE; return EGL_TRUE;
} }
/** /**
* Bind the context to the thread and return the previous context. * Bind the context to the thread and return the previous context.
* *
@ -770,7 +767,6 @@ _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t)
return oldCtx; return oldCtx;
} }
/** /**
* Return true if the given context and surfaces can be made current. * 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; disp = ctx->Resource.Display;
if (!disp->Extensions.KHR_surfaceless_context if (!disp->Extensions.KHR_surfaceless_context &&
&& (draw == NULL || read == NULL)) (draw == NULL || read == NULL))
return _eglError(EGL_BAD_MATCH, "eglMakeCurrent"); return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
/* /*
@ -830,7 +826,6 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read)
return EGL_TRUE; return EGL_TRUE;
} }
/** /**
* Bind the context to the current thread and given surfaces. Return the * Bind the context to the current thread and given surfaces. Return the
* previous bound context and surfaces. The caller should unreference the * previous bound context and surfaces. The caller should unreference the
@ -842,8 +837,8 @@ _eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read)
*/ */
EGLBoolean EGLBoolean
_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
_EGLContext **old_ctx, _EGLContext **old_ctx, _EGLSurface **old_draw,
_EGLSurface **old_draw, _EGLSurface **old_read) _EGLSurface **old_read)
{ {
_EGLThreadInfo *t = _eglGetCurrentThread(); _EGLThreadInfo *t = _eglGetCurrentThread();
_EGLContext *prev_ctx; _EGLContext *prev_ctx;
@ -872,8 +867,7 @@ _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
prev_ctx->DrawSurface = NULL; prev_ctx->DrawSurface = NULL;
prev_ctx->ReadSurface = NULL; prev_ctx->ReadSurface = NULL;
} } else {
else {
prev_draw = prev_read = NULL; prev_draw = prev_read = NULL;
} }

View file

@ -27,13 +27,11 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLCONTEXT_INCLUDED #ifndef EGLCONTEXT_INCLUDED
#define EGLCONTEXT_INCLUDED #define EGLCONTEXT_INCLUDED
#include "egltypedefs.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -42,8 +40,7 @@ extern "C" {
/** /**
* "Base" class for device driver contexts. * "Base" class for device driver contexts.
*/ */
struct _egl_context struct _egl_context {
{
/* A context is a display resource */ /* A context is a display resource */
_EGLResource Resource; _EGLResource Resource;
@ -66,25 +63,21 @@ struct _egl_context
EGLBoolean Protected; /* EGL_EXT_protected_content */ EGLBoolean Protected; /* EGL_EXT_protected_content */
}; };
extern EGLBoolean extern EGLBoolean
_eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *config,
_EGLConfig *config, _EGLContext *share_list, const EGLint *attrib_list); _EGLContext *share_list, const EGLint *attrib_list);
extern EGLBoolean extern EGLBoolean
_eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value); _eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);
extern EGLBoolean extern EGLBoolean
_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
_EGLContext **old_ctx, _EGLContext **old_ctx, _EGLSurface **old_draw,
_EGLSurface **old_draw, _EGLSurface **old_read); _EGLSurface **old_read);
extern _EGLContext * extern _EGLContext *
_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t); _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);
/** /**
* Increment reference count for the context. * Increment reference count for the context.
*/ */
@ -96,7 +89,6 @@ _eglGetContext(_EGLContext *ctx)
return ctx; return ctx;
} }
/** /**
* Decrement reference count for the context. * Decrement reference count for the context.
*/ */
@ -106,7 +98,6 @@ _eglPutContext(_EGLContext *ctx)
return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE; return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
} }
/** /**
* Link a context to its display and return the handle of the link. * Link a context to its display and return the handle of the link.
* The handle can be passed to client directly. * The handle can be passed to client directly.
@ -118,7 +109,6 @@ _eglLinkContext(_EGLContext *ctx)
return (EGLContext)ctx; return (EGLContext)ctx;
} }
/** /**
* Unlink a linked context from its display. * Unlink a linked context from its display.
* Accessing an unlinked context should generate EGL_BAD_CONTEXT error. * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
@ -129,7 +119,6 @@ _eglUnlinkContext(_EGLContext *ctx)
_eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
} }
/** /**
* Lookup a handle to find the linked context. * Lookup a handle to find the linked context.
* Return NULL if the handle has no corresponding linked context. * Return NULL if the handle has no corresponding linked context.
@ -143,7 +132,6 @@ _eglLookupContext(EGLContext context, _EGLDisplay *disp)
return ctx; return ctx;
} }
/** /**
* Return the handle of a linked context, or EGL_NO_CONTEXT. * Return the handle of a linked context, or EGL_NO_CONTEXT.
*/ */
@ -151,11 +139,9 @@ static inline EGLContext
_eglGetContextHandle(_EGLContext *ctx) _eglGetContextHandle(_EGLContext *ctx)
{ {
_EGLResource *res = (_EGLResource *)ctx; _EGLResource *res = (_EGLResource *)ctx;
return (res && _eglIsResourceLinked(res)) ? return (res && _eglIsResourceLinked(res)) ? (EGLContext)ctx : EGL_NO_CONTEXT;
(EGLContext) ctx : EGL_NO_CONTEXT;
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -25,19 +25,18 @@
* *
**************************************************************************/ **************************************************************************/
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include "c11/threads.h" #include "c11/threads.h"
#include "util/u_thread.h"
#include "util/u_string.h" #include "util/u_string.h"
#include "util/u_thread.h"
#include "egllog.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "egllog.h"
static __THREAD_INITIAL_EXEC _EGLThreadInfo _egl_TLS = { static __THREAD_INITIAL_EXEC _EGLThreadInfo _egl_TLS = {
.inited = false, .inited = false,
@ -51,7 +50,6 @@ _eglInitThreadInfo(_EGLThreadInfo *t)
t->CurrentAPI = EGL_OPENGL_ES_API; t->CurrentAPI = EGL_OPENGL_ES_API;
} }
/** /**
* Return the calling thread's thread info. * Return the calling thread's thread info.
* If the calling thread never calls this function before, or if its thread * If the calling thread never calls this function before, or if its thread
@ -69,7 +67,6 @@ _eglGetCurrentThread(void)
return current; return current;
} }
/** /**
* Destroy the calling thread's thread info. * Destroy the calling thread's thread info.
*/ */
@ -80,7 +77,6 @@ _eglDestroyCurrentThread(void)
t->inited = false; t->inited = false;
} }
/** /**
* Return the currently bound context of the current API, or NULL. * Return the currently bound context of the current API, or NULL.
*/ */
@ -91,7 +87,6 @@ _eglGetCurrentContext(void)
return t->CurrentContext; return t->CurrentContext;
} }
/** /**
* Record EGL error code and return EGL_FALSE. * Record EGL error code and return EGL_FALSE.
*/ */
@ -172,8 +167,8 @@ _eglError(EGLint errCode, const char *msg)
} }
void void
_eglDebugReport(EGLenum error, const char *funcName, _eglDebugReport(EGLenum error, const char *funcName, EGLint type,
EGLint type, const char *message, ...) const char *message, ...)
{ {
_EGLThreadInfo *thr = _eglGetCurrentThread(); _EGLThreadInfo *thr = _eglGetCurrentThread();
EGLDEBUGPROCKHR callback = NULL; EGLDEBUGPROCKHR callback = NULL;

View file

@ -25,7 +25,6 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLCURRENT_INCLUDED #ifndef EGLCURRENT_INCLUDED
#define EGLCURRENT_INCLUDED #define EGLCURRENT_INCLUDED
@ -33,24 +32,18 @@
#include "egltypedefs.h" #include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define _EGL_API_ALL_BITS \ #define _EGL_API_ALL_BITS \
(EGL_OPENGL_ES_BIT | \ (EGL_OPENGL_ES_BIT | EGL_OPENVG_BIT | EGL_OPENGL_ES2_BIT | \
EGL_OPENVG_BIT | \ EGL_OPENGL_ES3_BIT_KHR | EGL_OPENGL_BIT)
EGL_OPENGL_ES2_BIT | \
EGL_OPENGL_ES3_BIT_KHR | \
EGL_OPENGL_BIT)
/** /**
* Per-thread info * Per-thread info
*/ */
struct _egl_thread_info struct _egl_thread_info {
{
bool inited; bool inited;
EGLint LastError; EGLint LastError;
_EGLContext *CurrentContext; _EGLContext *CurrentContext;
@ -65,7 +58,6 @@ struct _egl_thread_info
EGLLabelKHR CurrentObjectLabel; EGLLabelKHR CurrentObjectLabel;
}; };
/** /**
* Return true if a client API enum is recognized. * Return true if a client API enum is recognized.
*/ */
@ -80,25 +72,21 @@ _eglIsApiValid(EGLenum api)
#endif #endif
} }
extern _EGLThreadInfo * extern _EGLThreadInfo *
_eglGetCurrentThread(void); _eglGetCurrentThread(void);
extern void extern void
_eglDestroyCurrentThread(void); _eglDestroyCurrentThread(void);
extern _EGLContext * extern _EGLContext *
_eglGetCurrentContext(void); _eglGetCurrentContext(void);
extern EGLBoolean extern EGLBoolean
_eglError(EGLint errCode, const char *msg); _eglError(EGLint errCode, const char *msg);
extern void extern void
_eglDebugReport(EGLenum error, const char *funcName, _eglDebugReport(EGLenum error, const char *funcName, EGLint type,
EGLint type, const char *message, ...); const char *message, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -25,12 +25,10 @@
* *
**************************************************************************/ **************************************************************************/
/** /**
* Internal EGL defines * Internal EGL defines
*/ */
#ifndef EGLDEFINES_INCLUDED #ifndef EGLDEFINES_INCLUDED
#define EGLDEFINES_INCLUDED #define EGLDEFINES_INCLUDED

View file

@ -33,11 +33,10 @@
#include "eglcurrent.h" #include "eglcurrent.h"
#include "egldevice.h" #include "egldevice.h"
#include "egllog.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "egllog.h"
#include "egltypedefs.h" #include "egltypedefs.h"
struct _egl_device { struct _egl_device {
_EGLDevice *Next; _EGLDevice *Next;
@ -113,8 +112,8 @@ _eglAddDRMDevice(drmDevicePtr device, _EGLDevice **out_dev)
{ {
_EGLDevice *dev; _EGLDevice *dev;
if ((device->available_nodes & (1 << DRM_NODE_PRIMARY | if ((device->available_nodes &
1 << DRM_NODE_RENDER)) == 0) (1 << DRM_NODE_PRIMARY | 1 << DRM_NODE_RENDER)) == 0)
return -1; return -1;
dev = _eglGlobal.DeviceList; dev = _eglGlobal.DeviceList;
@ -189,7 +188,8 @@ _eglAddDevice(int fd, bool software)
if (_eglAddDRMDevice(device, &dev) != 0) if (_eglAddDRMDevice(device, &dev) != 0)
drmFreeDevice(&device); drmFreeDevice(&device);
#else #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; dev = NULL;
#endif #endif
@ -215,8 +215,7 @@ _eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext)
} }
EGLBoolean EGLBoolean
_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, _eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, EGLAttrib *value)
EGLAttrib *value)
{ {
switch (attribute) { switch (attribute) {
default: default:
@ -304,8 +303,7 @@ _eglRefreshDeviceList(void)
} }
EGLBoolean EGLBoolean
_eglQueryDevicesEXT(EGLint max_devices, _eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices,
_EGLDevice **devices,
EGLint *num_devices) EGLint *num_devices)
{ {
_EGLDevice *dev, *devs, *swrast; _EGLDevice *dev, *devs, *swrast;

View file

@ -25,11 +25,9 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLDEVICE_INCLUDED #ifndef EGLDEVICE_INCLUDED
#define EGLDEVICE_INCLUDED #define EGLDEVICE_INCLUDED
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "egltypedefs.h" #include "egltypedefs.h"
@ -70,8 +68,7 @@ EGLBoolean
_eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext); _eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext);
EGLBoolean EGLBoolean
_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, _eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, EGLAttrib *value);
EGLAttrib *value);
const char * const char *
_eglQueryDeviceStringEXT(_EGLDevice *dev, EGLint name); _eglQueryDeviceStringEXT(_EGLDevice *dev, EGLint name);

View file

@ -28,8 +28,8 @@
#include "egldispatchstubs.h" #include "egldispatchstubs.h"
#include "g_egldispatchstubs.h" #include "g_egldispatchstubs.h"
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "eglcurrent.h" #include "eglcurrent.h"
@ -38,16 +38,19 @@ static const __EGLapiExports *exports;
const int __EGL_DISPATCH_FUNC_COUNT = __EGL_DISPATCH_COUNT; const int __EGL_DISPATCH_FUNC_COUNT = __EGL_DISPATCH_COUNT;
int __EGL_DISPATCH_FUNC_INDICES[__EGL_DISPATCH_COUNT + 1]; 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; const char *s = *(const char **)r;
return strcmp(l, s); 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, const char **match =
__EGL_DISPATCH_COUNT, sizeof(const char *), Compare); bsearch(name, __EGL_DISPATCH_FUNC_NAMES, __EGL_DISPATCH_COUNT,
sizeof(const char *), Compare);
if (match == NULL) if (match == NULL)
return __EGL_DISPATCH_COUNT; return __EGL_DISPATCH_COUNT;
@ -55,7 +58,8 @@ static int FindProcIndex(const char *name)
return match - __EGL_DISPATCH_FUNC_NAMES; return match - __EGL_DISPATCH_FUNC_NAMES;
} }
void __eglInitDispatchStubs(const __EGLapiExports *exportsTable) void
__eglInitDispatchStubs(const __EGLapiExports *exportsTable)
{ {
int i; int i;
exports = exportsTable; exports = exportsTable;
@ -64,25 +68,28 @@ void __eglInitDispatchStubs(const __EGLapiExports *exportsTable)
} }
} }
void __eglSetDispatchIndex(const char *name, int dispatchIndex) void
__eglSetDispatchIndex(const char *name, int dispatchIndex)
{ {
int index = FindProcIndex(name); int index = FindProcIndex(name);
__EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex; __EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex;
} }
void *__eglDispatchFindDispatchFunction(const char *name) void *
__eglDispatchFindDispatchFunction(const char *name)
{ {
int index = FindProcIndex(name); int index = FindProcIndex(name);
return (void *)__EGL_DISPATCH_FUNCS[index]; return (void *)__EGL_DISPATCH_FUNCS[index];
} }
static __eglMustCastToProperFunctionPointerType FetchVendorFunc(__EGLvendorInfo *vendor, static __eglMustCastToProperFunctionPointerType
int index, EGLint errorCode) FetchVendorFunc(__EGLvendorInfo *vendor, int index, EGLint errorCode)
{ {
__eglMustCastToProperFunctionPointerType func = NULL; __eglMustCastToProperFunctionPointerType func = NULL;
if (vendor != NULL) { if (vendor != NULL) {
func = exports->fetchDispatchEntry(vendor, __EGL_DISPATCH_FUNC_INDICES[index]); func = exports->fetchDispatchEntry(vendor,
__EGL_DISPATCH_FUNC_INDICES[index]);
} }
if (func == NULL) { if (func == NULL) {
if (errorCode != EGL_SUCCESS) { if (errorCode != EGL_SUCCESS) {
@ -106,7 +113,8 @@ static __eglMustCastToProperFunctionPointerType FetchVendorFunc(__EGLvendorInfo
return func; return func;
} }
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index) __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index)
{ {
__EGLvendorInfo *vendor; __EGLvendorInfo *vendor;
@ -118,7 +126,8 @@ __eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index)
return FetchVendorFunc(vendor, index, EGL_SUCCESS); return FetchVendorFunc(vendor, index, EGL_SUCCESS);
} }
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index) __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDisplay(EGLDisplay dpy, int index)
{ {
__EGLvendorInfo *vendor; __EGLvendorInfo *vendor;
@ -127,7 +136,8 @@ __eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay
return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY); return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY);
} }
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dev, int index) __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dev, int index)
{ {
__EGLvendorInfo *vendor; __EGLvendorInfo *vendor;
@ -135,4 +145,3 @@ __eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT
vendor = exports->getVendorFromDevice(dev); vendor = exports->getVendorFromDevice(dev);
return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT); return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT);
} }

View file

@ -36,18 +36,24 @@ extern const char * const __EGL_DISPATCH_FUNC_NAMES[];
extern int __EGL_DISPATCH_FUNC_INDICES[]; extern int __EGL_DISPATCH_FUNC_INDICES[];
extern const __eglMustCastToProperFunctionPointerType __EGL_DISPATCH_FUNCS[]; extern const __eglMustCastToProperFunctionPointerType __EGL_DISPATCH_FUNCS[];
void __eglInitDispatchStubs(const __EGLapiExports *exportsTable); void
void __eglSetDispatchIndex(const char *name, int index); __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 * Returns the dispatch function for the given name, or \c NULL if the function
* isn't supported. * isn't supported.
*/ */
void *__eglDispatchFindDispatchFunction(const char *name); void *
__eglDispatchFindDispatchFunction(const char *name);
// Helper functions used by the generated stubs. // Helper functions used by the generated stubs.
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index); __eglMustCastToProperFunctionPointerType
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dpy, int index); __eglDispatchFetchByDisplay(EGLDisplay dpy, int index);
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index); __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dpy, int index);
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index);
#endif // EGLDISPATCHSTUBS_H #endif // EGLDISPATCHSTUBS_H

View file

@ -27,7 +27,6 @@
* *
**************************************************************************/ **************************************************************************/
/** /**
* Functions related to EGLDisplay. * Functions related to EGLDisplay.
*/ */
@ -48,13 +47,13 @@
#include "eglcontext.h" #include "eglcontext.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "eglsurface.h"
#include "egldevice.h" #include "egldevice.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "eglglobals.h" #include "eglglobals.h"
#include "egllog.h"
#include "eglimage.h" #include "eglimage.h"
#include "egllog.h"
#include "eglsurface.h"
#include "eglsync.h" #include "eglsync.h"
/* Includes for _eglNativePlatformDetectNativeDisplay */ /* Includes for _eglNativePlatformDetectNativeDisplay */
@ -68,7 +67,6 @@
#include <windows.h> #include <windows.h>
#endif #endif
/** /**
* Map build-system platform names to platform types. * Map build-system platform names to platform types.
*/ */
@ -87,7 +85,6 @@ static const struct {
{_EGL_PLATFORM_WINDOWS, "windows"}, {_EGL_PLATFORM_WINDOWS, "windows"},
}; };
/** /**
* Return the native platform by parsing EGL_PLATFORM. * Return the native platform by parsing EGL_PLATFORM.
*/ */
@ -121,7 +118,6 @@ _eglGetNativePlatformFromEnv(void)
return plat; return plat;
} }
/** /**
* Try detecting native platform with the help of native display characteristics. * Try detecting native platform with the help of native display characteristics.
*/ */
@ -158,7 +154,6 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
return _EGL_INVALID_PLATFORM; return _EGL_INVALID_PLATFORM;
} }
/** /**
* Return the native platform. It is the platform of the EGL native types. * Return the native platform. It is the platform of the EGL native types.
*/ */
@ -184,7 +179,6 @@ _eglGetNativePlatform(void *nativeDisplay)
return detected_platform; return detected_platform;
} }
/** /**
* Finish display management. * Finish display management.
*/ */
@ -209,7 +203,6 @@ _eglFiniDisplay(void)
} }
} }
/* The fcntl() code in _eglGetDeviceDisplay() ensures that valid fd >= 3, /* The fcntl() code in _eglGetDeviceDisplay() ensures that valid fd >= 3,
* and invalid one is 0. * and invalid one is 0.
*/ */
@ -304,7 +297,6 @@ out:
return disp; return disp;
} }
/** /**
* Destroy the contexts and surfaces that are linked to the display. * Destroy the contexts and surfaces that are linked to the display.
*/ */
@ -357,7 +349,6 @@ _eglReleaseDisplayResources(_EGLDisplay *display)
assert(!display->ResourceLists[_EGL_RESOURCE_SYNC]); assert(!display->ResourceLists[_EGL_RESOURCE_SYNC]);
} }
/** /**
* Free all the data hanging of an _EGLDisplay object, but not * Free all the data hanging of an _EGLDisplay object, but not
* the object itself. * the object itself.
@ -373,7 +364,6 @@ _eglCleanupDisplay(_EGLDisplay *disp)
/* XXX incomplete */ /* XXX incomplete */
} }
/** /**
* Return EGL_TRUE if the given resource is valid. That is, the display does * Return EGL_TRUE if the given resource is valid. That is, the display does
* own the resource. * own the resource.
@ -399,7 +389,6 @@ _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp)
return (list != NULL); return (list != NULL);
} }
/** /**
* Initialize a display resource. The size of the subclass object is * Initialize a display resource. The size of the subclass object is
* specified. * specified.
@ -415,7 +404,6 @@ _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp)
res->RefCount = 1; res->RefCount = 1;
} }
/** /**
* Increment reference count for the resource. * Increment reference count for the resource.
*/ */
@ -426,7 +414,6 @@ _eglGetResource(_EGLResource *res)
p_atomic_inc(&res->RefCount); p_atomic_inc(&res->RefCount);
} }
/** /**
* Decrement reference count for the resource. * Decrement reference count for the resource.
*/ */
@ -437,7 +424,6 @@ _eglPutResource(_EGLResource *res)
return p_atomic_dec_zero(&res->RefCount); return p_atomic_dec_zero(&res->RefCount);
} }
/** /**
* Link a resource to its display. * Link a resource to its display.
*/ */
@ -453,7 +439,6 @@ _eglLinkResource(_EGLResource *res, _EGLResourceType type)
_eglGetResource(res); _eglGetResource(res);
} }
/** /**
* Unlink a linked resource from its display. * Unlink a linked resource from its display.
*/ */
@ -473,8 +458,7 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type)
} }
assert(prev); assert(prev);
prev->Next = res->Next; prev->Next = res->Next;
} } else {
else {
res->Display->ResourceLists[type] = res->Next; res->Display->ResourceLists[type] = res->Next;
} }
@ -488,8 +472,7 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type)
#ifdef HAVE_X11_PLATFORM #ifdef HAVE_X11_PLATFORM
_EGLDisplay * _EGLDisplay *
_eglGetX11Display(Display *native_display, _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list)
const EGLAttrib *attrib_list)
{ {
/* EGL_EXT_platform_x11 recognizes exactly one attribute, /* EGL_EXT_platform_x11 recognizes exactly one attribute,
* EGL_PLATFORM_X11_SCREEN_EXT, which is optional. * EGL_PLATFORM_X11_SCREEN_EXT, which is optional.
@ -558,8 +541,7 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
#endif /* HAVE_WAYLAND_PLATFORM */ #endif /* HAVE_WAYLAND_PLATFORM */
_EGLDisplay * _EGLDisplay *
_eglGetSurfacelessDisplay(void *native_display, _eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list)
const EGLAttrib *attrib_list)
{ {
/* This platform has no native display. */ /* This platform has no native display. */
if (native_display != NULL) { if (native_display != NULL) {
@ -579,8 +561,7 @@ _eglGetSurfacelessDisplay(void *native_display,
#ifdef HAVE_ANDROID_PLATFORM #ifdef HAVE_ANDROID_PLATFORM
_EGLDisplay * _EGLDisplay *
_eglGetAndroidDisplay(void *native_display, _eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list)
const EGLAttrib *attrib_list)
{ {
/* This platform recognizes no display attributes. */ /* This platform recognizes no display attributes. */
@ -589,14 +570,12 @@ _eglGetAndroidDisplay(void *native_display,
return NULL; return NULL;
} }
return _eglFindDisplay(_EGL_PLATFORM_ANDROID, native_display, return _eglFindDisplay(_EGL_PLATFORM_ANDROID, native_display, attrib_list);
attrib_list);
} }
#endif /* HAVE_ANDROID_PLATFORM */ #endif /* HAVE_ANDROID_PLATFORM */
_EGLDisplay * _EGLDisplay *
_eglGetDeviceDisplay(void *native_display, _eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list)
const EGLAttrib *attrib_list)
{ {
_EGLDevice *dev; _EGLDevice *dev;
_EGLDisplay *display; _EGLDisplay *display;

View file

@ -27,16 +27,15 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLDISPLAY_INCLUDED #ifndef EGLDISPLAY_INCLUDED
#define EGLDISPLAY_INCLUDED #define EGLDISPLAY_INCLUDED
#include "util/simple_mtx.h"
#include "util/rwlock.h" #include "util/rwlock.h"
#include "util/simple_mtx.h"
#include "egltypedefs.h"
#include "egldefines.h"
#include "eglarray.h" #include "eglarray.h"
#include "egldefines.h"
#include "egltypedefs.h"
#ifdef HAVE_X11_PLATFORM #ifdef HAVE_X11_PLATFORM
#include <X11/Xlib.h> #include <X11/Xlib.h>
@ -62,7 +61,6 @@ enum _egl_platform_type {
}; };
typedef enum _egl_platform_type _EGLPlatformType; typedef enum _egl_platform_type _EGLPlatformType;
enum _egl_resource_type { enum _egl_resource_type {
_EGL_RESOURCE_CONTEXT, _EGL_RESOURCE_CONTEXT,
_EGL_RESOURCE_SURFACE, _EGL_RESOURCE_SURFACE,
@ -74,12 +72,10 @@ enum _egl_resource_type {
/* this cannot and need not go into egltypedefs.h */ /* this cannot and need not go into egltypedefs.h */
typedef enum _egl_resource_type _EGLResourceType; typedef enum _egl_resource_type _EGLResourceType;
/** /**
* A resource of a display. * A resource of a display.
*/ */
struct _egl_resource struct _egl_resource {
{
/* which display the resource belongs to */ /* which display the resource belongs to */
_EGLDisplay *Display; _EGLDisplay *Display;
EGLBoolean IsLinked; EGLBoolean IsLinked;
@ -91,12 +87,10 @@ struct _egl_resource
_EGLResource *Next; _EGLResource *Next;
}; };
/** /**
* Optional EGL extensions info. * Optional EGL extensions info.
*/ */
struct _egl_extensions struct _egl_extensions {
{
/* Please keep these sorted alphabetically. */ /* Please keep these sorted alphabetically. */
EGLBoolean ANDROID_blob_cache; EGLBoolean ANDROID_blob_cache;
EGLBoolean ANDROID_framebuffer_target; EGLBoolean ANDROID_framebuffer_target;
@ -159,8 +153,7 @@ struct _egl_extensions
EGLBoolean WL_create_wayland_buffer_from_image; EGLBoolean WL_create_wayland_buffer_from_image;
}; };
struct _egl_display struct _egl_display {
{
/* used to link displays */ /* used to link displays */
_EGLDisplay *Next; _EGLDisplay *Next;
@ -230,39 +223,30 @@ struct _egl_display
EGLGetBlobFuncANDROID BlobCacheGet; EGLGetBlobFuncANDROID BlobCacheGet;
}; };
extern _EGLDisplay * extern _EGLDisplay *
_eglLockDisplay(EGLDisplay dpy); _eglLockDisplay(EGLDisplay dpy);
extern void extern void
_eglUnlockDisplay(_EGLDisplay *disp); _eglUnlockDisplay(_EGLDisplay *disp);
extern _EGLPlatformType extern _EGLPlatformType
_eglGetNativePlatform(void *nativeDisplay); _eglGetNativePlatform(void *nativeDisplay);
extern void extern void
_eglFiniDisplay(void); _eglFiniDisplay(void);
extern _EGLDisplay * extern _EGLDisplay *
_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr); _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr);
extern void extern void
_eglReleaseDisplayResources(_EGLDisplay *disp); _eglReleaseDisplayResources(_EGLDisplay *disp);
extern void extern void
_eglCleanupDisplay(_EGLDisplay *disp); _eglCleanupDisplay(_EGLDisplay *disp);
extern EGLBoolean extern EGLBoolean
_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp); _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp);
/** /**
* Return the handle of a linked display, or EGL_NO_DISPLAY. * Return the handle of a linked display, or EGL_NO_DISPLAY.
*/ */
@ -272,27 +256,21 @@ _eglGetDisplayHandle(_EGLDisplay *disp)
return (EGLDisplay)((disp) ? disp : EGL_NO_DISPLAY); return (EGLDisplay)((disp) ? disp : EGL_NO_DISPLAY);
} }
extern void extern void
_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp); _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp);
extern void extern void
_eglGetResource(_EGLResource *res); _eglGetResource(_EGLResource *res);
extern EGLBoolean extern EGLBoolean
_eglPutResource(_EGLResource *res); _eglPutResource(_EGLResource *res);
extern void extern void
_eglLinkResource(_EGLResource *res, _EGLResourceType type); _eglLinkResource(_EGLResource *res, _EGLResourceType type);
extern void extern void
_eglUnlinkResource(_EGLResource *res, _EGLResourceType type); _eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
/** /**
* Return true if the resource is linked. * Return true if the resource is linked.
*/ */
@ -323,7 +301,8 @@ _eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);
#ifdef HAVE_XCB_PLATFORM #ifdef HAVE_XCB_PLATFORM
typedef struct xcb_connection_t xcb_connection_t; typedef struct xcb_connection_t xcb_connection_t;
_EGLDisplay * _EGLDisplay *
_eglGetXcbDisplay(xcb_connection_t *native_display, const EGLAttrib *attrib_list); _eglGetXcbDisplay(xcb_connection_t *native_display,
const EGLAttrib *attrib_list);
#endif #endif
#ifdef HAVE_DRM_PLATFORM #ifdef HAVE_DRM_PLATFORM
@ -343,18 +322,15 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
#endif #endif
_EGLDisplay * _EGLDisplay *
_eglGetSurfacelessDisplay(void *native_display, _eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list);
const EGLAttrib *attrib_list);
#ifdef HAVE_ANDROID_PLATFORM #ifdef HAVE_ANDROID_PLATFORM
_EGLDisplay * _EGLDisplay *
_eglGetAndroidDisplay(void *native_display, _eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list);
const EGLAttrib *attrib_list);
#endif #endif
_EGLDisplay * _EGLDisplay *
_eglGetDeviceDisplay(void *native_display, _eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list);
const EGLAttrib *attrib_list);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -27,15 +27,12 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLDRIVER_INCLUDED #ifndef EGLDRIVER_INCLUDED
#define EGLDRIVER_INCLUDED #define EGLDRIVER_INCLUDED
#include "egltypedefs.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -49,8 +46,9 @@ extern "C" {
*/ */
#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \ #define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \
static inline struct drvtype *drvtype(const egltype *obj) \ static inline struct drvtype *drvtype(const egltype *obj) \
{ return (struct drvtype *) code; } { \
return (struct drvtype *)code; \
}
/** /**
* Define the driver typecast functions for _EGLDisplay, * Define the driver typecast functions for _EGLDisplay,
@ -80,28 +78,29 @@ typedef struct __GLsync *GLsync;
/** /**
* The API dispatcher jumps through these functions * The API dispatcher jumps through these functions
*/ */
struct _egl_driver struct _egl_driver {
{
/* driver funcs */ /* driver funcs */
EGLBoolean (*Initialize)(_EGLDisplay *disp); EGLBoolean (*Initialize)(_EGLDisplay *disp);
EGLBoolean (*Terminate)(_EGLDisplay *disp); EGLBoolean (*Terminate)(_EGLDisplay *disp);
/* context funcs */ /* context funcs */
_EGLContext *(*CreateContext)(_EGLDisplay *disp, _EGLConfig *config, _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); EGLBoolean (*DestroyContext)(_EGLDisplay *disp, _EGLContext *ctx);
/* this is the only function (other than Initialize) that may be called /* this is the only function (other than Initialize) that may be called
* with an uninitialized display * with an uninitialized display
*/ */
EGLBoolean (*MakeCurrent)(_EGLDisplay *disp, EGLBoolean (*MakeCurrent)(_EGLDisplay *disp, _EGLSurface *draw,
_EGLSurface *draw, _EGLSurface *read, _EGLSurface *read, _EGLContext *ctx);
_EGLContext *ctx);
/* surface funcs */ /* surface funcs */
_EGLSurface *(*CreateWindowSurface)(_EGLDisplay *disp, _EGLConfig *config, _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, _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, _EGLSurface *(*CreatePbufferSurface)(_EGLDisplay *disp, _EGLConfig *config,
const EGLint *attrib_list); const EGLint *attrib_list);
EGLBoolean (*DestroySurface)(_EGLDisplay *disp, _EGLSurface *surface); EGLBoolean (*DestroySurface)(_EGLDisplay *disp, _EGLSurface *surface);
@ -135,8 +134,8 @@ struct _egl_driver
_EGLSync *(*CreateSyncKHR)(_EGLDisplay *disp, EGLenum type, _EGLSync *(*CreateSyncKHR)(_EGLDisplay *disp, EGLenum type,
const EGLAttrib *attrib_list); const EGLAttrib *attrib_list);
EGLBoolean (*DestroySyncKHR)(_EGLDisplay *disp, _EGLSync *sync); EGLBoolean (*DestroySyncKHR)(_EGLDisplay *disp, _EGLSync *sync);
EGLint (*ClientWaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLint (*ClientWaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLint flags,
EGLint flags, EGLTime timeout); EGLTime timeout);
EGLint (*WaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync); EGLint (*WaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync);
/* for EGL_KHR_reusable_sync */ /* for EGL_KHR_reusable_sync */
EGLBoolean (*SignalSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLenum mode); EGLBoolean (*SignalSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLenum mode);
@ -155,21 +154,27 @@ struct _egl_driver
EGLint *stride); EGLint *stride);
/* for EGL_WL_bind_wayland_display */ /* for EGL_WL_bind_wayland_display */
EGLBoolean (*BindWaylandDisplayWL)(_EGLDisplay *disp, struct wl_display *display); EGLBoolean (*BindWaylandDisplayWL)(_EGLDisplay *disp,
EGLBoolean (*UnbindWaylandDisplayWL)(_EGLDisplay *disp, struct wl_display *display); struct wl_display *display);
EGLBoolean (*QueryWaylandBufferWL)(_EGLDisplay *displ, struct wl_resource *buffer, EGLBoolean (*UnbindWaylandDisplayWL)(_EGLDisplay *disp,
struct wl_display *display);
EGLBoolean (*QueryWaylandBufferWL)(_EGLDisplay *displ,
struct wl_resource *buffer,
EGLint attribute, EGLint *value); EGLint attribute, EGLint *value);
/* for EGL_WL_create_wayland_buffer_from_image */ /* 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 */ /* 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); const EGLint *rects, EGLint n_rects);
/* for EGL_NV_post_sub_buffer */ /* for EGL_NV_post_sub_buffer */
EGLBoolean (*PostSubBufferNV)(_EGLDisplay *disp, _EGLSurface *surface, 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 */ /* for EGL_EXT_buffer_age/EGL_KHR_partial_update */
EGLint (*QueryBufferAge)(_EGLDisplay *disp, _EGLSurface *surface); EGLint (*QueryBufferAge)(_EGLDisplay *disp, _EGLSurface *surface);
@ -201,15 +206,16 @@ struct _egl_driver
struct mesa_glinterop_export_in *in, struct mesa_glinterop_export_in *in,
struct mesa_glinterop_export_out *out); struct mesa_glinterop_export_out *out);
int (*GLInteropFlushObjects)(_EGLDisplay *disp, _EGLContext *ctx, int (*GLInteropFlushObjects)(_EGLDisplay *disp, _EGLContext *ctx,
unsigned count, struct mesa_glinterop_export_in *in, unsigned count,
struct mesa_glinterop_export_in *in,
GLsync *sync); GLsync *sync);
/* for EGL_EXT_image_dma_buf_import_modifiers */ /* for EGL_EXT_image_dma_buf_import_modifiers */
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp, EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp, EGLint max_formats,
EGLint max_formats, EGLint *formats, EGLint *formats, EGLint *num_formats);
EGLint *num_formats);
EGLBoolean (*QueryDmaBufModifiersEXT)(_EGLDisplay *disp, EGLint format, EGLBoolean (*QueryDmaBufModifiersEXT)(_EGLDisplay *disp, EGLint format,
EGLint max_modifiers, EGLuint64KHR *modifiers, EGLint max_modifiers,
EGLuint64KHR *modifiers,
EGLBoolean *external_only, EGLBoolean *external_only,
EGLint *num_modifiers); EGLint *num_modifiers);
@ -219,10 +225,8 @@ struct _egl_driver
EGLGetBlobFuncANDROID get); EGLGetBlobFuncANDROID get);
}; };
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* EGLDRIVER_INCLUDED */ #endif /* EGLDRIVER_INCLUDED */

View file

@ -27,16 +27,15 @@
* *
**************************************************************************/ **************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util/simple_mtx.h" #include "util/simple_mtx.h"
#include "eglglobals.h"
#include "egldevice.h" #include "egldevice.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "eglglobals.h"
#include "util/macros.h" #include "util/macros.h"
#include "util/os_misc.h" #include "util/os_misc.h"
@ -46,16 +45,15 @@
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
static simple_mtx_t _eglGlobalMutex = SIMPLE_MTX_INITIALIZER; static simple_mtx_t _eglGlobalMutex = SIMPLE_MTX_INITIALIZER;
struct _egl_global _eglGlobal = struct _egl_global _eglGlobal = {
{
.Mutex = &_eglGlobalMutex, .Mutex = &_eglGlobalMutex,
.DisplayList = NULL, .DisplayList = NULL,
.DeviceList = &_eglSoftwareDevice, .DeviceList = &_eglSoftwareDevice,
.NumAtExitCalls = 2, .NumAtExitCalls = 2,
.AtExitCalls = { .AtExitCalls =
{
/* default AtExitCalls, called in reverse order */ /* default AtExitCalls, called in reverse order */
_eglFiniDevice, /* always called last */ _eglFiniDevice, /* always called last */
_eglFiniDisplay, _eglFiniDisplay,
@ -108,7 +106,6 @@ struct _egl_global _eglGlobal =
.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR, .debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR,
}; };
static void static void
_eglAtExit(void) _eglAtExit(void)
{ {
@ -117,7 +114,6 @@ _eglAtExit(void)
_eglGlobal.AtExitCalls[i](); _eglGlobal.AtExitCalls[i]();
} }
void void
_eglAddAtExitCall(void (*func)(void)) _eglAddAtExitCall(void (*func)(void))
{ {

View file

@ -27,7 +27,6 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLGLOBALS_INCLUDED #ifndef EGLGLOBALS_INCLUDED
#define EGLGLOBALS_INCLUDED #define EGLGLOBALS_INCLUDED
@ -36,8 +35,7 @@
#include "egltypedefs.h" #include "egltypedefs.h"
enum enum {
{
_EGL_DEBUG_BIT_CRITICAL = 0x1, _EGL_DEBUG_BIT_CRITICAL = 0x1,
_EGL_DEBUG_BIT_ERROR = 0x2, _EGL_DEBUG_BIT_ERROR = 0x2,
_EGL_DEBUG_BIT_WARN = 0x4, _EGL_DEBUG_BIT_WARN = 0x4,
@ -47,8 +45,7 @@ enum
/** /**
* Global library data * Global library data
*/ */
struct _egl_global struct _egl_global {
{
simple_mtx_t *Mutex; simple_mtx_t *Mutex;
/* the list of all displays */ /* the list of all displays */
@ -75,14 +72,13 @@ struct _egl_global
unsigned int debugTypesEnabled; unsigned int debugTypesEnabled;
}; };
extern struct _egl_global _eglGlobal; extern struct _egl_global _eglGlobal;
extern void extern void
_eglAddAtExitCall(void (*func)(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); assert(type >= EGL_DEBUG_MSG_CRITICAL_KHR && type <= EGL_DEBUG_MSG_INFO_KHR);
return (1 << (type - EGL_DEBUG_MSG_CRITICAL_KHR)); return (1 << (type - EGL_DEBUG_MSG_CRITICAL_KHR));

View file

@ -25,8 +25,8 @@
* Kyle Brenneman <kbrenneman@nvidia.com> * Kyle Brenneman <kbrenneman@nvidia.com>
*/ */
#include <string.h>
#include <assert.h> #include <assert.h>
#include <string.h>
#include <glvnd/libeglabi.h> #include <glvnd/libeglabi.h>
@ -99,4 +99,3 @@ __egl_Main(uint32_t version, const __EGLapiExports *exports,
return EGL_TRUE; return EGL_TRUE;
} }

View file

@ -26,7 +26,6 @@
* *
**************************************************************************/ **************************************************************************/
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -214,8 +213,8 @@ _eglParseEXTImageDmaBufImportAttribs(_EGLImageAttribs *attrs, _EGLDisplay *disp,
static EGLint static EGLint
_eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs *attrs, _eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs *attrs,
_EGLDisplay *disp, _EGLDisplay *disp, EGLint attr,
EGLint attr, EGLint val) EGLint val)
{ {
if (!disp->Extensions.EXT_image_dma_buf_import_modifiers) if (!disp->Extensions.EXT_image_dma_buf_import_modifiers)
return EGL_BAD_PARAMETER; return EGL_BAD_PARAMETER;
@ -316,7 +315,8 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,
if (err == EGL_BAD_ATTRIBUTE) if (err == EGL_BAD_ATTRIBUTE)
return _eglError(err, __func__); return _eglError(err, __func__);
err = _eglParseEXTImageDmaBufImportModifiersAttribs(attrs, disp, attr, val); err =
_eglParseEXTImageDmaBufImportModifiersAttribs(attrs, disp, attr, val);
if (err == EGL_SUCCESS) if (err == EGL_SUCCESS)
continue; continue;

View file

@ -26,28 +26,24 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLIMAGE_INCLUDED #ifndef EGLIMAGE_INCLUDED
#define EGLIMAGE_INCLUDED #define EGLIMAGE_INCLUDED
#include "egltypedefs.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
struct _egl_image_attrib_int struct _egl_image_attrib_int {
{
EGLint Value; EGLint Value;
EGLBoolean IsPresent; EGLBoolean IsPresent;
}; };
#define DMA_BUF_MAX_PLANES 4 #define DMA_BUF_MAX_PLANES 4
struct _egl_image_attribs struct _egl_image_attribs {
{
/* EGL_KHR_image_base */ /* EGL_KHR_image_base */
EGLBoolean ImagePreserved; EGLBoolean ImagePreserved;
@ -85,25 +81,21 @@ struct _egl_image_attribs
/** /**
* "Base" class for device driver images. * "Base" class for device driver images.
*/ */
struct _egl_image struct _egl_image {
{
/* An image is a display resource */ /* An image is a display resource */
_EGLResource Resource; _EGLResource Resource;
}; };
EGLBoolean EGLBoolean
_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp, _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,
const EGLint *attrib_list); const EGLint *attrib_list);
static inline void static inline void
_eglInitImage(_EGLImage *img, _EGLDisplay *disp) _eglInitImage(_EGLImage *img, _EGLDisplay *disp)
{ {
_eglInitResource(&img->Resource, sizeof(*img), disp); _eglInitResource(&img->Resource, sizeof(*img), disp);
} }
/** /**
* Increment reference count for the image. * Increment reference count for the image.
*/ */
@ -115,7 +107,6 @@ _eglGetImage(_EGLImage *img)
return img; return img;
} }
/** /**
* Decrement reference count for the image. * Decrement reference count for the image.
*/ */
@ -125,7 +116,6 @@ _eglPutImage(_EGLImage *img)
return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE; return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE;
} }
/** /**
* Link an image to its display and return the handle of the link. * Link an image to its display and return the handle of the link.
* The handle can be passed to client directly. * The handle can be passed to client directly.
@ -137,7 +127,6 @@ _eglLinkImage(_EGLImage *img)
return (EGLImage)img; return (EGLImage)img;
} }
/** /**
* Unlink a linked image from its display. * Unlink a linked image from its display.
* Accessing an unlinked image should generate EGL_BAD_PARAMETER error. * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
@ -148,7 +137,6 @@ _eglUnlinkImage(_EGLImage *img)
_eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE); _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
} }
/** /**
* Lookup a handle to find the linked image. * Lookup a handle to find the linked image.
* Return NULL if the handle has no corresponding linked image. * Return NULL if the handle has no corresponding linked image.
@ -162,7 +150,6 @@ _eglLookupImage(EGLImage image, _EGLDisplay *disp)
return img; return img;
} }
/** /**
* Return the handle of a linked image, or EGL_NO_IMAGE_KHR. * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
*/ */
@ -170,11 +157,9 @@ static inline EGLImage
_eglGetImageHandle(_EGLImage *img) _eglGetImageHandle(_EGLImage *img)
{ {
_EGLResource *res = (_EGLResource *)img; _EGLResource *res = (_EGLResource *)img;
return (res && _eglIsResourceLinked(res)) ? return (res && _eglIsResourceLinked(res)) ? (EGLImage)img : EGL_NO_IMAGE_KHR;
(EGLImage) img : EGL_NO_IMAGE_KHR;
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -27,14 +27,12 @@
* *
**************************************************************************/ **************************************************************************/
/** /**
* Logging facility for debug/info messages. * Logging facility for debug/info messages.
* _EGL_FATAL messages are printed to stderr * _EGL_FATAL messages are printed to stderr
* The EGL_LOG_LEVEL var controls the output of other warning/info/debug msgs. * The EGL_LOG_LEVEL var controls the output of other warning/info/debug msgs.
*/ */
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -59,7 +57,6 @@
#define MAXSTRING 1000 #define MAXSTRING 1000
#define FALLBACK_LOG_LEVEL _EGL_WARNING #define FALLBACK_LOG_LEVEL _EGL_WARNING
static struct { static struct {
simple_mtx_t mutex; simple_mtx_t mutex;
@ -78,7 +75,6 @@ static const char *level_strings[] = {
[_EGL_DEBUG] = "debug", [_EGL_DEBUG] = "debug",
}; };
/** /**
* The default logger. It prints the message to stderr. * The default logger. It prints the message to stderr.
*/ */
@ -98,7 +94,6 @@ _eglDefaultLogger(EGLint level, const char *msg)
#endif /* HAVE_ANDROID_PLATFORM */ #endif /* HAVE_ANDROID_PLATFORM */
} }
/** /**
* Initialize the logging facility. * Initialize the logging facility.
*/ */
@ -143,7 +138,6 @@ _eglGetLogLevel(void)
return logging.level; return logging.level;
} }
/** /**
* Log a message with message logger. * Log a message with message logger.
* \param level one of _EGL_FATAL, _EGL_WARNING, _EGL_INFO, _EGL_DEBUG. * \param level one of _EGL_FATAL, _EGL_WARNING, _EGL_INFO, _EGL_DEBUG.

View file

@ -26,14 +26,11 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLLOG_INCLUDED #ifndef EGLLOG_INCLUDED
#define EGLLOG_INCLUDED #define EGLLOG_INCLUDED
#include "egltypedefs.h" #include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -43,15 +40,12 @@ extern "C" {
#define _EGL_INFO 2 /* just useful info */ #define _EGL_INFO 2 /* just useful info */
#define _EGL_DEBUG 3 /* useful info for debugging */ #define _EGL_DEBUG 3 /* useful info for debugging */
extern EGLint extern EGLint
_eglGetLogLevel(void); _eglGetLogLevel(void);
extern void extern void
_eglLog(EGLint level, const char *fmtStr, ...); _eglLog(EGLint level, const char *fmtStr, ...);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -27,23 +27,21 @@
* *
**************************************************************************/ **************************************************************************/
/** /**
* Surface-related functions. * Surface-related functions.
*/ */
#include "eglsurface.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "eglconfig.h"
#include "eglcontext.h"
#include "eglcurrent.h"
#include "egldefines.h" #include "egldefines.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egldriver.h" #include "egldriver.h"
#include "eglcontext.h"
#include "eglconfig.h"
#include "eglcurrent.h"
#include "egllog.h" #include "egllog.h"
#include "eglsurface.h"
#include "util/macros.h" #include "util/macros.h"
@ -232,8 +230,7 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
surf->PresentOpaque = val; surf->PresentOpaque = val;
break; break;
case EGL_POST_SUB_BUFFER_SUPPORTED_NV: case EGL_POST_SUB_BUFFER_SUPPORTED_NV:
if (!disp->Extensions.NV_post_sub_buffer || if (!disp->Extensions.NV_post_sub_buffer || type != EGL_WINDOW_BIT) {
type != EGL_WINDOW_BIT) {
err = EGL_BAD_ATTRIBUTE; err = EGL_BAD_ATTRIBUTE;
break; break;
} }
@ -338,9 +335,12 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
} }
if (err == EGL_SUCCESS && type == EGL_PBUFFER_BIT) { if (err == EGL_SUCCESS && type == EGL_PBUFFER_BIT) {
if ((surf->TextureTarget == EGL_NO_TEXTURE && surf->TextureFormat != EGL_NO_TEXTURE) || if ((surf->TextureTarget == EGL_NO_TEXTURE &&
(surf->TextureFormat == EGL_NO_TEXTURE && surf->TextureTarget != EGL_NO_TEXTURE)) { surf->TextureFormat != EGL_NO_TEXTURE) ||
attr = surf->TextureTarget == EGL_NO_TEXTURE ? EGL_TEXTURE_TARGET : EGL_TEXTURE_FORMAT; (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; err = EGL_BAD_MATCH;
} }
} }
@ -351,7 +351,6 @@ _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
return err; return err;
} }
/** /**
* Do error check on parameters and initialize the given _EGLSurface object. * Do error check on parameters and initialize the given _EGLSurface object.
* \return EGL_TRUE if no errors, EGL_FALSE otherwise. * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
@ -453,10 +452,9 @@ _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
return EGL_TRUE; return EGL_TRUE;
} }
EGLBoolean EGLBoolean
_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface, _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface, EGLint attribute,
EGLint attribute, EGLint *value) EGLint *value)
{ {
switch (attribute) { switch (attribute) {
case EGL_WIDTH: case EGL_WIDTH:
@ -627,19 +625,17 @@ _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface,
return EGL_TRUE; return EGL_TRUE;
} }
/** /**
* Default fallback routine - drivers might override this. * Default fallback routine - drivers might override this.
*/ */
EGLBoolean EGLBoolean
_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surface, _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surface, EGLint attribute,
EGLint attribute, EGLint value) EGLint value)
{ {
EGLint confval; EGLint confval;
EGLint err = EGL_SUCCESS; EGLint err = EGL_SUCCESS;
EGLint all_es_bits = EGL_OPENGL_ES_BIT | EGLint all_es_bits =
EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR;
EGL_OPENGL_ES3_BIT_KHR;
switch (attribute) { switch (attribute) {
case EGL_MIPMAP_LEVEL: case EGL_MIPMAP_LEVEL:
@ -755,7 +751,6 @@ _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surface,
return EGL_TRUE; return EGL_TRUE;
} }
EGLBoolean EGLBoolean
_eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surface, EGLint buffer) _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surface, EGLint buffer)
{ {
@ -797,8 +792,7 @@ _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
if (surf == EGL_NO_SURFACE) if (surf == EGL_NO_SURFACE)
return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage"); return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
if (!surf->BoundToTexture) if (!surf->BoundToTexture) {
{
/* Not an error, simply nothing to do */ /* Not an error, simply nothing to do */
return EGL_TRUE; return EGL_TRUE;
} }
@ -823,8 +817,7 @@ _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
EGLBoolean EGLBoolean
_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf) _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf)
{ {
return surf->Type == EGL_WINDOW_BIT && return surf->Type == EGL_WINDOW_BIT && surf->Config &&
surf->Config &&
(surf->Config->SurfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR); (surf->Config->SurfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR);
} }

View file

@ -27,26 +27,22 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLSURFACE_INCLUDED #ifndef EGLSURFACE_INCLUDED
#define EGLSURFACE_INCLUDED #define EGLSURFACE_INCLUDED
#include "egltypedefs.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egltypedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
struct _egl_xy struct _egl_xy {
{
EGLint x; EGLint x;
EGLint y; EGLint y;
}; };
struct _egl_hdr_metadata struct _egl_hdr_metadata {
{
struct _egl_xy display_primary_r; struct _egl_xy display_primary_r;
struct _egl_xy display_primary_g; struct _egl_xy display_primary_g;
struct _egl_xy display_primary_b; struct _egl_xy display_primary_b;
@ -60,8 +56,7 @@ struct _egl_hdr_metadata
/** /**
* "Base" class for device driver surfaces. * "Base" class for device driver surfaces.
*/ */
struct _egl_surface struct _egl_surface {
{
/* A surface is a display resource */ /* A surface is a display resource */
_EGLResource Resource; _EGLResource Resource;
@ -176,20 +171,18 @@ struct _egl_surface
void *NativeSurface; void *NativeSurface;
}; };
extern EGLBoolean extern EGLBoolean
_eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type, _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
_EGLConfig *config, const EGLint *attrib_list, _EGLConfig *config, const EGLint *attrib_list,
void *native_surface); void *native_surface);
extern EGLBoolean
_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint *value);
extern EGLBoolean extern EGLBoolean
_eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value); _eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint value);
extern EGLBoolean
_eglSurfaceAttrib(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint value);
extern EGLBoolean extern EGLBoolean
_eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
@ -197,7 +190,6 @@ _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
extern EGLBoolean extern EGLBoolean
_eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer); _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
extern EGLBoolean extern EGLBoolean
_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf); _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);
@ -215,7 +207,6 @@ _eglGetSurface(_EGLSurface *surf)
return surf; return surf;
} }
/** /**
* Decrement reference count for the surface. * Decrement reference count for the surface.
*/ */
@ -225,7 +216,6 @@ _eglPutSurface(_EGLSurface *surf)
return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE; return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
} }
/** /**
* Link a surface to its display and return the handle of the link. * Link a surface to its display and return the handle of the link.
* The handle can be passed to client directly. * The handle can be passed to client directly.
@ -237,7 +227,6 @@ _eglLinkSurface(_EGLSurface *surf)
return (EGLSurface)surf; return (EGLSurface)surf;
} }
/** /**
* Unlink a linked surface from its display. * Unlink a linked surface from its display.
* Accessing an unlinked surface should generate EGL_BAD_SURFACE error. * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
@ -248,7 +237,6 @@ _eglUnlinkSurface(_EGLSurface *surf)
_eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE); _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
} }
/** /**
* Lookup a handle to find the linked surface. * Lookup a handle to find the linked surface.
* Return NULL if the handle has no corresponding linked surface. * Return NULL if the handle has no corresponding linked surface.
@ -262,7 +250,6 @@ _eglLookupSurface(EGLSurface surface, _EGLDisplay *disp)
return surf; return surf;
} }
/** /**
* Return the handle of a linked surface, or EGL_NO_SURFACE. * Return the handle of a linked surface, or EGL_NO_SURFACE.
*/ */
@ -270,11 +257,10 @@ static inline EGLSurface
_eglGetSurfaceHandle(_EGLSurface *surf) _eglGetSurfaceHandle(_EGLSurface *surf)
{ {
_EGLResource *res = (_EGLResource *)surf; _EGLResource *res = (_EGLResource *)surf;
return (res && _eglIsResourceLinked(res)) ? return (res && _eglIsResourceLinked(res)) ? (EGLSurface)surf
(EGLSurface) surf : EGL_NO_SURFACE; : EGL_NO_SURFACE;
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -25,15 +25,13 @@
* *
**************************************************************************/ **************************************************************************/
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include "eglsync.h"
#include "eglcurrent.h" #include "eglcurrent.h"
#include "egldriver.h" #include "egldriver.h"
#include "egllog.h" #include "egllog.h"
#include "eglsync.h"
/** /**
* Parse the list of sync attributes and return the proper error code. * 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; return EGL_SUCCESS;
} }
EGLBoolean EGLBoolean
_eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, _eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type,
const EGLAttrib *attrib_list) const EGLAttrib *attrib_list)
@ -118,10 +115,9 @@ _eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type,
return EGL_TRUE; return EGL_TRUE;
} }
EGLBoolean EGLBoolean
_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, _eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, EGLint attribute,
EGLint attribute, EGLAttrib *value) EGLAttrib *value)
{ {
switch (attribute) { switch (attribute) {
case EGL_SYNC_TYPE_KHR: case EGL_SYNC_TYPE_KHR:

View file

@ -25,20 +25,16 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLSYNC_INCLUDED #ifndef EGLSYNC_INCLUDED
#define EGLSYNC_INCLUDED #define EGLSYNC_INCLUDED
#include "egltypedefs.h"
#include "egldisplay.h" #include "egldisplay.h"
#include "egltypedefs.h"
/** /**
* "Base" class for device driver syncs. * "Base" class for device driver syncs.
*/ */
struct _egl_sync struct _egl_sync {
{
/* A sync is a display resource */ /* A sync is a display resource */
_EGLResource Resource; _EGLResource Resource;
@ -49,16 +45,13 @@ struct _egl_sync
EGLint SyncFd; EGLint SyncFd;
}; };
extern EGLBoolean extern EGLBoolean
_eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type, _eglInitSync(_EGLSync *sync, _EGLDisplay *disp, EGLenum type,
const EGLAttrib *attrib_list); const EGLAttrib *attrib_list);
extern EGLBoolean extern EGLBoolean
_eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, _eglGetSyncAttrib(_EGLDisplay *disp, _EGLSync *sync, EGLint attribute,
EGLint attribute, EGLAttrib *value); EGLAttrib *value);
/** /**
* Increment reference count for the sync. * Increment reference count for the sync.
@ -71,7 +64,6 @@ _eglGetSync(_EGLSync *sync)
return sync; return sync;
} }
/** /**
* Decrement reference count for the sync. * Decrement reference count for the sync.
*/ */
@ -81,7 +73,6 @@ _eglPutSync(_EGLSync *sync)
return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE; return (sync) ? _eglPutResource(&sync->Resource) : EGL_FALSE;
} }
/** /**
* Link a sync to its display and return the handle of the link. * Link a sync to its display and return the handle of the link.
* The handle can be passed to client directly. * The handle can be passed to client directly.
@ -93,7 +84,6 @@ _eglLinkSync(_EGLSync *sync)
return (EGLSync)sync; return (EGLSync)sync;
} }
/** /**
* Unlink a linked sync from its display. * Unlink a linked sync from its display.
*/ */
@ -103,7 +93,6 @@ _eglUnlinkSync(_EGLSync *sync)
_eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC); _eglUnlinkResource(&sync->Resource, _EGL_RESOURCE_SYNC);
} }
/** /**
* Lookup a handle to find the linked sync. * Lookup a handle to find the linked sync.
* Return NULL if the handle has no corresponding linked sync. * Return NULL if the handle has no corresponding linked sync.
@ -117,7 +106,6 @@ _eglLookupSync(EGLSync handle, _EGLDisplay *disp)
return sync; return sync;
} }
/** /**
* Return the handle of a linked sync, or EGL_NO_SYNC_KHR. * Return the handle of a linked sync, or EGL_NO_SYNC_KHR.
*/ */
@ -125,9 +113,7 @@ static inline EGLSync
_eglGetSyncHandle(_EGLSync *sync) _eglGetSyncHandle(_EGLSync *sync)
{ {
_EGLResource *res = (_EGLResource *)sync; _EGLResource *res = (_EGLResource *)sync;
return (res && _eglIsResourceLinked(res)) ? return (res && _eglIsResourceLinked(res)) ? (EGLSync)sync : EGL_NO_SYNC_KHR;
(EGLSync) sync : EGL_NO_SYNC_KHR;
} }
#endif /* EGLSYNC_INCLUDED */ #endif /* EGLSYNC_INCLUDED */

View file

@ -27,14 +27,13 @@
* *
**************************************************************************/ **************************************************************************/
#ifndef EGLTYPEDEFS_INCLUDED #ifndef EGLTYPEDEFS_INCLUDED
#define EGLTYPEDEFS_INCLUDED #define EGLTYPEDEFS_INCLUDED
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <EGL/eglmesaext.h>
#include <EGL/eglext_angle.h> #include <EGL/eglext_angle.h>
#include <EGL/eglmesaext.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -70,7 +69,6 @@ typedef struct _egl_sync _EGLSync;
typedef struct _egl_thread_info _EGLThreadInfo; typedef struct _egl_thread_info _EGLThreadInfo;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -27,15 +27,15 @@
* Benjamin Franzke <benjaminfranzke@googlemail.com> * Benjamin Franzke <benjaminfranzke@googlemail.com>
*/ */
#include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stddef.h>
#include <unistd.h> #include <unistd.h>
#include <wayland-server.h>
#include "wayland-drm.h"
#include "wayland-drm-server-protocol.h" #include "wayland-drm-server-protocol.h"
#include "wayland-drm.h"
#include <wayland-server.h>
#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y))
@ -57,12 +57,10 @@ buffer_destroy(struct wl_client *client, struct wl_resource *resource)
static void static void
create_buffer(struct wl_client *client, struct wl_resource *resource, create_buffer(struct wl_client *client, struct wl_resource *resource,
uint32_t id, uint32_t name, int fd, uint32_t id, uint32_t name, int fd, int32_t width, int32_t height,
int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0,
uint32_t format, int32_t offset1, int32_t stride1, int32_t offset2,
int32_t offset0, int32_t stride0, int32_t stride2)
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 *drm = wl_resource_get_user_data(resource);
struct wl_drm_buffer *buffer; struct wl_drm_buffer *buffer;
@ -86,14 +84,12 @@ create_buffer(struct wl_client *client, struct wl_resource *resource,
drm->callbacks.reference_buffer(drm->user_data, name, fd, buffer); drm->callbacks.reference_buffer(drm->user_data, name, fd, buffer);
if (buffer->driver_buffer == NULL) { if (buffer->driver_buffer == NULL) {
wl_resource_post_error(resource, wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME,
WL_DRM_ERROR_INVALID_NAME,
"invalid name"); "invalid name");
return; return;
} }
buffer->resource = buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id);
wl_resource_create(client, &wl_buffer_interface, 1, id);
if (!buffer->resource) { if (!buffer->resource) {
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
free(buffer); free(buffer);
@ -121,23 +117,20 @@ drm_create_buffer(struct wl_client *client, struct wl_resource *resource,
case WL_DRM_FORMAT_RGB565: case WL_DRM_FORMAT_RGB565:
break; break;
default: default:
wl_resource_post_error(resource, wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT,
WL_DRM_ERROR_INVALID_FORMAT,
"invalid format"); "invalid format");
return; return;
} }
create_buffer(client, resource, id, create_buffer(client, resource, id, name, -1, width, height, format, 0,
name, -1, width, height, format, 0, stride, 0, 0, 0, 0); stride, 0, 0, 0, 0);
} }
static void static void
drm_create_planar_buffer(struct wl_client *client, drm_create_planar_buffer(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *resource, uint32_t id, uint32_t name, int32_t width,
uint32_t id, uint32_t name, int32_t height, uint32_t format, int32_t offset0,
int32_t width, int32_t height, uint32_t format, int32_t stride0, int32_t offset1, int32_t stride1,
int32_t offset0, int32_t stride0,
int32_t offset1, int32_t stride1,
int32_t offset2, int32_t stride2) int32_t offset2, int32_t stride2)
{ {
switch (format) { switch (format) {
@ -150,40 +143,36 @@ drm_create_planar_buffer(struct wl_client *client,
case WL_DRM_FORMAT_NV16: case WL_DRM_FORMAT_NV16:
break; break;
default: default:
wl_resource_post_error(resource, wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT,
WL_DRM_ERROR_INVALID_FORMAT,
"invalid format"); "invalid format");
return; return;
} }
create_buffer(client, resource, id, name, -1, width, height, format, create_buffer(client, resource, id, name, -1, width, height, format, offset0,
offset0, stride0, offset1, stride1, offset2, stride2); stride0, offset1, stride1, offset2, stride2);
} }
static void static void
drm_create_prime_buffer(struct wl_client *client, drm_create_prime_buffer(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *resource, uint32_t id, int fd, int32_t width, int32_t height,
uint32_t id, int fd, uint32_t format, int32_t offset0, int32_t stride0,
int32_t width, int32_t height, uint32_t format, int32_t offset1, int32_t stride1, int32_t offset2,
int32_t offset0, int32_t stride0, int32_t stride2)
int32_t offset1, int32_t stride1,
int32_t offset2, int32_t stride2)
{ {
create_buffer(client, resource, id, 0, fd, width, height, format, create_buffer(client, resource, id, 0, fd, width, height, format, offset0,
offset0, stride0, offset1, stride1, offset2, stride2); stride0, offset1, stride1, offset2, stride2);
close(fd); close(fd);
} }
static void static void
drm_authenticate(struct wl_client *client, drm_authenticate(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *resource, uint32_t id) 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 || if (!drm->callbacks.authenticate ||
drm->callbacks.authenticate(drm->user_data, id) < 0) drm->callbacks.authenticate(drm->user_data, id) < 0)
wl_resource_post_error(resource, wl_resource_post_error(resource, WL_DRM_ERROR_AUTHENTICATE_FAIL,
WL_DRM_ERROR_AUTHENTICATE_FAIL,
"authenticate failed"); "authenticate failed");
else else
wl_resource_post_event(resource, WL_DRM_AUTHENTICATED); wl_resource_post_event(resource, WL_DRM_AUTHENTICATED);
@ -203,8 +192,8 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct wl_resource *resource; struct wl_resource *resource;
uint32_t capabilities; uint32_t capabilities;
resource = wl_resource_create(client, &wl_drm_interface, resource =
MIN(version, 2), id); wl_resource_create(client, &wl_drm_interface, MIN(version, 2), id);
if (!resource) { if (!resource) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
@ -238,12 +227,9 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
WL_DRM_FORMAT_XBGR2101010); WL_DRM_FORMAT_XBGR2101010);
} }
wl_resource_post_event(resource, WL_DRM_FORMAT, wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_ARGB8888);
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_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_RGB565);
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_YUV410);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV411); 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_YUV420);
@ -281,8 +267,7 @@ wayland_drm_init(struct wl_display *display, char *device_name,
drm->buffer_interface.destroy = buffer_destroy; drm->buffer_interface.destroy = buffer_destroy;
drm->wl_drm_global = drm->wl_drm_global =
wl_global_create(display, &wl_drm_interface, 2, wl_global_create(display, &wl_drm_interface, 2, drm, bind_drm);
drm, bind_drm);
return drm; return drm;
} }

View file

@ -18,7 +18,6 @@ struct wayland_drm_callbacks {
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_drm {
struct wl_display *display; struct wl_display *display;
struct wl_global *wl_drm_global; struct wl_global *wl_drm_global;