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>
#ifdef HAVE_X11_PLATFORM
#include <xcb/xcb.h>
#include <X11/Xlib-xcb.h>
#include <xcb/dri2.h>
#include <xcb/randr.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
#include <X11/Xlib-xcb.h>
#include "loader_dri_helper.h"
#ifdef HAVE_DRI3
@ -82,18 +82,18 @@ struct zwp_linux_dmabuf_feedback_v1;
#include "eglconfig.h"
#include "eglcontext.h"
#include "eglcurrent.h"
#include "egldevice.h"
#include "egldisplay.h"
#include "egldriver.h"
#include "eglcurrent.h"
#include "eglimage.h"
#include "egllog.h"
#include "eglsurface.h"
#include "eglimage.h"
#include "eglsync.h"
#include "util/u_vector.h"
#include "util/u_dynarray.h"
#include "util/bitset.h"
#include "util/u_dynarray.h"
#include "util/u_vector.h"
struct wl_buffer;
@ -102,17 +102,17 @@ struct dri2_egl_display_vtbl {
int (*authenticate)(_EGLDisplay *disp, uint32_t id);
/* mandatory */
_EGLSurface* (*create_window_surface)(_EGLDisplay *disp, _EGLConfig *config,
_EGLSurface *(*create_window_surface)(_EGLDisplay *disp, _EGLConfig *config,
void *native_window,
const EGLint *attrib_list);
/* optional */
_EGLSurface* (*create_pixmap_surface)(_EGLDisplay *disp, _EGLConfig *config,
_EGLSurface *(*create_pixmap_surface)(_EGLDisplay *disp, _EGLConfig *config,
void *native_pixmap,
const EGLint *attrib_list);
/* optional */
_EGLSurface* (*create_pbuffer_surface)(_EGLDisplay *disp, _EGLConfig *config,
_EGLSurface *(*create_pbuffer_surface)(_EGLDisplay *disp, _EGLConfig *config,
const EGLint *attrib_list);
/* mandatory */
@ -123,7 +123,7 @@ struct dri2_egl_display_vtbl {
EGLint interval);
/* mandatory */
_EGLImage* (*create_image)(_EGLDisplay *disp, _EGLContext *ctx,
_EGLImage *(*create_image)(_EGLDisplay *disp, _EGLContext *ctx,
EGLenum target, EGLClientBuffer buffer,
const EGLint *attr_list);
@ -131,7 +131,8 @@ struct dri2_egl_display_vtbl {
EGLBoolean (*swap_buffers)(_EGLDisplay *disp, _EGLSurface *surf);
/* optional - falls back to .swap_buffers */
EGLBoolean (*swap_buffers_with_damage)(_EGLDisplay *disp, _EGLSurface *surface,
EGLBoolean (*swap_buffers_with_damage)(_EGLDisplay *disp,
_EGLSurface *surface,
const EGLint *rects, EGLint n_rects);
/* optional */
@ -139,9 +140,8 @@ struct dri2_egl_display_vtbl {
EGLint numRects, const EGLint *rects);
/* optional */
EGLBoolean (*post_sub_buffer)(_EGLDisplay *disp, _EGLSurface *surf,
EGLint x, EGLint y,
EGLint width, EGLint height);
EGLBoolean (*post_sub_buffer)(_EGLDisplay *disp, _EGLSurface *surf, EGLint x,
EGLint y, EGLint width, EGLint height);
/* optional */
EGLBoolean (*copy_buffers)(_EGLDisplay *disp, _EGLSurface *surf,
@ -155,7 +155,7 @@ struct dri2_egl_display_vtbl {
EGLint attribute, EGLint *value);
/* optional */
struct wl_buffer* (*create_wayland_buffer_from_image)(_EGLDisplay *disp,
struct wl_buffer *(*create_wayland_buffer_from_image)(_EGLDisplay *disp,
_EGLImage *img);
/* optional */
@ -215,8 +215,7 @@ struct dmabuf_feedback {
};
#endif
struct dri2_egl_display
{
struct dri2_egl_display {
const struct dri2_egl_display_vtbl *vtbl;
mtx_t lock;
@ -224,11 +223,11 @@ struct dri2_egl_display
int dri2_major;
int dri2_minor;
__DRIscreen *dri_screen_render_gpu;
/* dri_screen_display_gpu holds display GPU in case of prime gpu offloading else
* dri_screen_render_gpu and dri_screen_display_gpu is same.
* In case of prime gpu offloading, if display and render driver names are different
* (potentially not compatible), dri_screen_display_gpu will be NULL but fd_display_gpu
* will still hold fd for display driver.
/* dri_screen_display_gpu holds display GPU in case of prime gpu offloading
* else dri_screen_render_gpu and dri_screen_display_gpu is same. In case of
* prime gpu offloading, if display and render driver names are different
* (potentially not compatible), dri_screen_display_gpu will be NULL but
* fd_display_gpu will still hold fd for display driver.
*/
__DRIscreen *dri_screen_display_gpu;
bool own_dri_screen;
@ -319,14 +318,12 @@ struct dri2_egl_display
bool is_render_node;
};
struct dri2_egl_context
{
struct dri2_egl_context {
_EGLContext base;
__DRIcontext *dri_context;
};
struct dri2_egl_surface
{
struct dri2_egl_surface {
_EGLSurface base;
__DRIdrawable *dri_drawable;
__DRIbuffer buffers[5];
@ -418,14 +415,12 @@ struct dri2_egl_surface
char *swrast_device_buffer;
};
struct dri2_egl_config
{
struct dri2_egl_config {
_EGLConfig base;
const __DRIconfig *dri_config[2][2];
};
struct dri2_egl_image
{
struct dri2_egl_image {
_EGLImage base;
__DRIimage *dri_image;
};
@ -455,7 +450,8 @@ dri2_egl_display_lock(_EGLDisplay *disp)
}
static inline EGLBoolean
dri2_egl_error_unlock(struct dri2_egl_display *dri2_dpy, EGLint err, const char *msg)
dri2_egl_error_unlock(struct dri2_egl_display *dri2_dpy, EGLint err,
const char *msg)
{
mtx_unlock(&dri2_dpy->lock);
return _eglError(err, msg);
@ -502,13 +498,12 @@ dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data);
void
dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
const __DRIconfig *config, int *shifts,
unsigned int *sizes);
const __DRIconfig *config, int *shifts,
unsigned int *sizes);
void
dri2_get_render_type_float(const __DRIcoreExtension *core,
const __DRIconfig *config,
bool *is_float);
const __DRIconfig *config, bool *is_float);
unsigned int
dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy,
@ -547,7 +542,9 @@ dri2_initialize_x11(_EGLDisplay *disp)
return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
}
static inline void
dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) {}
dri2_teardown_x11(struct dri2_egl_display *dri2_dpy)
{
}
static inline unsigned int
dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
{
@ -567,7 +564,9 @@ dri2_initialize_drm(_EGLDisplay *disp)
return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built");
}
static inline void
dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {}
dri2_teardown_drm(struct dri2_egl_display *dri2_dpy)
{
}
#endif
#ifdef HAVE_WAYLAND_PLATFORM
@ -576,7 +575,7 @@ dri2_initialize_wayland(_EGLDisplay *disp);
void
dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy);
bool
dri2_wl_is_format_supported(void* user_data, uint32_t format);
dri2_wl_is_format_supported(void *user_data, uint32_t format);
#else
static inline EGLBoolean
dri2_initialize_wayland(_EGLDisplay *disp)
@ -584,7 +583,9 @@ dri2_initialize_wayland(_EGLDisplay *disp)
return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built");
}
static inline void
dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {}
dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy)
{
}
#endif
#ifdef HAVE_ANDROID_PLATFORM
@ -604,11 +605,14 @@ dri2_initialize_surfaceless(_EGLDisplay *disp);
EGLBoolean
dri2_initialize_device(_EGLDisplay *disp);
static inline void
dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ }
dri2_teardown_device(struct dri2_egl_display *dri2_dpy)
{ /* noop */
}
void
dri2_flush_drawable_for_swapbuffers_flags(_EGLDisplay *disp, _EGLSurface *draw,
enum __DRI2throttleReason throttle_reason);
dri2_flush_drawable_for_swapbuffers_flags(
_EGLDisplay *disp, _EGLSurface *draw,
enum __DRI2throttleReason throttle_reason);
void
dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
@ -623,17 +627,17 @@ dri2_set_WL_bind_wayland_display(_EGLDisplay *disp)
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
if (dri2_dpy->device_name && dri2_dpy->image) {
if (dri2_dpy->image->base.version >= 10 &&
dri2_dpy->image->getCapabilities != NULL) {
int capabilities;
if (dri2_dpy->image->base.version >= 10 &&
dri2_dpy->image->getCapabilities != NULL) {
int capabilities;
capabilities =
dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen_render_gpu);
disp->Extensions.WL_bind_wayland_display =
(capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
} else {
disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
}
capabilities =
dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen_render_gpu);
disp->Extensions.WL_bind_wayland_display =
(capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
} else {
disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
}
}
#endif
}
@ -650,8 +654,8 @@ dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
EGLBoolean
dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
_EGLConfig *conf, const EGLint *attrib_list,
EGLBoolean enable_out_fence, void *native_surface);
_EGLConfig *conf, const EGLint *attrib_list,
EGLBoolean enable_out_fence, void *native_surface);
void
dri2_fini_surface(_EGLSurface *surf);
@ -659,13 +663,12 @@ dri2_fini_surface(_EGLSurface *surf);
EGLBoolean
dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
const __DRIconfig *config,
struct dri2_egl_surface *dri2_surf,
void *loaderPrivate);
struct dri2_egl_surface *dri2_surf, void *loaderPrivate);
static inline uint64_t
combine_u32_into_u64(uint32_t hi, uint32_t lo)
{
return (((uint64_t) hi) << 32) | (((uint64_t) lo) & 0xffffffff);
return (((uint64_t)hi) << 32) | (((uint64_t)lo) & 0xffffffff);
}
#endif /* EGL_DRI2_INCLUDED */

View file

@ -27,32 +27,32 @@
* DEALINGS IN THE SOFTWARE.
*/
#include <cutils/properties.h>
#include <errno.h>
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <xf86drm.h>
#include <stdbool.h>
#include <stdio.h>
#include <xf86drm.h>
#include <cutils/properties.h>
#include <drm-uapi/drm_fourcc.h>
#include <sync/sync.h>
#include <sys/types.h>
#include <drm-uapi/drm_fourcc.h>
#include "util/compiler.h"
#include "util/os_file.h"
#include "util/libsync.h"
#include "util/os_file.h"
#include "loader.h"
#include "egl_dri2.h"
#include "loader.h"
#include "platform_android.h"
#ifdef HAVE_DRM_GRALLOC
#include <gralloc_drm_handle.h>
#include "gralloc_drm.h"
#include <gralloc_drm_handle.h>
#endif /* HAVE_DRM_GRALLOC */
#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
#define ALIGN(val, align) (((val) + (align)-1) & ~((align)-1))
enum chroma_order {
YCbCr,
@ -61,7 +61,7 @@ enum chroma_order {
struct droid_yuv_format {
/* Lookup keys */
int native; /* HAL_PIXEL_FORMAT_ */
int native; /* HAL_PIXEL_FORMAT_ */
enum chroma_order chroma_order; /* chroma order is {Cb, Cr} or {Cr, Cb} */
int chroma_step; /* Distance in bytes between subsequent chroma pixels. */
@ -73,17 +73,17 @@ struct droid_yuv_format {
* on native format and information contained in android_ycbcr struct. */
static const struct droid_yuv_format droid_yuv_formats[] = {
/* Native format, YCrCb, Chroma step, DRI image FourCC */
{ HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12 },
{ HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420 },
{ HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420 },
{ HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420 },
{HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12},
{HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420},
{HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420},
{HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420},
/* HACK: See droid_create_image_from_prime_fds() and
* https://issuetracker.google.com/32077885. */
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12 },
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420 },
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420 },
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV },
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888 },
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12},
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420},
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420},
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV},
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888},
};
static int
@ -121,7 +121,8 @@ get_format_bpp(int native)
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
/*
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack.
* TODO: Remove this once https://issuetracker.google.com/32077885 is fixed.
* TODO: Remove this once https://issuetracker.google.com/32077885 is
* fixed.
*/
case HAL_PIXEL_FORMAT_RGBX_8888:
case HAL_PIXEL_FORMAT_BGRA_8888:
@ -140,20 +141,28 @@ get_format_bpp(int native)
}
/* createImageFromFds requires fourcc format */
static int get_fourcc(int native)
static int
get_fourcc(int native)
{
switch (native) {
case HAL_PIXEL_FORMAT_RGB_565: return DRM_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_BGRA_8888: return DRM_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_RGBA_8888: return DRM_FORMAT_ABGR8888;
case HAL_PIXEL_FORMAT_RGB_565:
return DRM_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_BGRA_8888:
return DRM_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_RGBA_8888:
return DRM_FORMAT_ABGR8888;
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
/*
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack.
* TODO: Remove this once https://issuetracker.google.com/32077885 is fixed.
* TODO: Remove this once https://issuetracker.google.com/32077885 is
* fixed.
*/
case HAL_PIXEL_FORMAT_RGBX_8888: return DRM_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_RGBA_FP16: return DRM_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102: return DRM_FORMAT_ABGR2101010;
case HAL_PIXEL_FORMAT_RGBX_8888:
return DRM_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_RGBA_FP16:
return DRM_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102:
return DRM_FORMAT_ABGR2101010;
default:
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", native);
}
@ -210,8 +219,8 @@ get_yuv_buffer_info(struct dri2_egl_display *dri2_dpy,
}
memset(&ycbcr, 0, sizeof(ycbcr));
ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle,
0, 0, 0, 0, 0, &ycbcr);
ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, 0, 0, 0,
0, 0, &ycbcr);
if (ret) {
/* HACK: See native_window_buffer_get_buffer_info() and
* https://issuetracker.google.com/32077885.*/
@ -229,8 +238,11 @@ get_yuv_buffer_info(struct dri2_egl_display *dri2_dpy,
* values of subsequent pixels, assumed to be the same for Cb and Cr. */
drm_fourcc = get_fourcc_yuv(buf->format, chroma_order, ycbcr.chroma_step);
if (drm_fourcc == -1) {
_eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = %d",
buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb", ycbcr.chroma_step);
_eglLog(_EGL_WARNING,
"unsupported YUV format, native = %x, chroma_order = %s, "
"chroma_step = %d",
buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb",
ycbcr.chroma_step);
return -EINVAL;
}
@ -239,7 +251,7 @@ get_yuv_buffer_info(struct dri2_egl_display *dri2_dpy,
.height = buf->height,
.drm_fourcc = drm_fourcc,
.num_planes = ycbcr.chroma_step == 2 ? 2 : 3,
.fds = { -1, -1, -1, -1 },
.fds = {-1, -1, -1, -1},
.modifier = DRM_FORMAT_MOD_INVALID,
.yuv_color_space = EGL_ITU_REC601_EXT,
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
@ -337,10 +349,10 @@ native_window_buffer_get_buffer_info(struct dri2_egl_display *dri2_dpy,
.height = buf->height,
.drm_fourcc = drm_fourcc,
.num_planes = num_planes,
.fds = { fds[0], -1, -1, -1 },
.fds = {fds[0], -1, -1, -1},
.modifier = DRM_FORMAT_MOD_INVALID,
.offsets = { 0, 0, 0, 0 },
.pitches = { pitch, 0, 0, 0 },
.offsets = {0, 0, 0, 0},
.pitches = {pitch, 0, 0, 0},
.yuv_color_space = EGL_ITU_REC601_EXT,
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
.horizontal_siting = EGL_YUV_CHROMA_SITING_0_EXT,
@ -355,13 +367,14 @@ native_window_buffer_get_buffer_info(struct dri2_egl_display *dri2_dpy,
* offsets and strides. If we have this, we can skip straight to
* createImageFromDmaBufs2() and avoid all the guessing and recalculations.
* This also gives us the modifier and plane offsets/strides for multiplanar
* compressed buffers (eg Intel CCS buffers) in order to make that work in Android.
* compressed buffers (eg Intel CCS buffers) in order to make that work in
* Android.
*/
static const char cros_gralloc_module_name[] = "CrOS Gralloc";
#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4
#define CROS_GRALLOC_DRM_GET_USAGE 5
#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4
#define CROS_GRALLOC_DRM_GET_USAGE 5
#define CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT 0x1
struct cros_gralloc0_buffer_info {
@ -383,14 +396,14 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy,
if (strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) == 0 &&
dri2_dpy->gralloc->perform &&
dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
CROS_GRALLOC_DRM_GET_BUFFER_INFO,
buf->handle, &info) == 0) {
CROS_GRALLOC_DRM_GET_BUFFER_INFO, buf->handle,
&info) == 0) {
*out_buf_info = (struct buffer_info){
.width = buf->width,
.height = buf->height,
.drm_fourcc = info.drm_fourcc,
.num_planes = info.num_fds,
.fds = { -1, -1, -1, -1 },
.fds = {-1, -1, -1, -1},
.modifier = info.modifier,
.yuv_color_space = EGL_ITU_REC601_EXT,
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
@ -411,8 +424,7 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy,
static __DRIimage *
droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy,
struct buffer_info *buf_info,
void *priv)
struct buffer_info *buf_info, void *priv)
{
unsigned error;
@ -423,8 +435,7 @@ droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy,
buf_info->drm_fourcc, buf_info->modifier, buf_info->fds,
buf_info->num_planes, buf_info->pitches, buf_info->offsets,
buf_info->yuv_color_space, buf_info->sample_range,
buf_info->horizontal_siting, buf_info->vertical_siting, &error,
priv);
buf_info->horizontal_siting, buf_info->vertical_siting, &error, priv);
}
return dri2_dpy->image->createImageFromDmaBufs(
@ -536,7 +547,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
}
static EGLBoolean
droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
droid_window_enqueue_buffer(_EGLDisplay *disp,
struct dri2_egl_surface *dri2_surf)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
@ -597,8 +609,10 @@ droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode)
_eglLog(_EGL_DEBUG, "%s: mode=%d", __func__, mode);
if (ANativeWindow_setSharedBufferMode(window, mode)) {
_eglLog(_EGL_WARNING, "failed ANativeWindow_setSharedBufferMode"
"(window=%p, mode=%d)", window, mode);
_eglLog(_EGL_WARNING,
"failed ANativeWindow_setSharedBufferMode"
"(window=%p, mode=%d)",
window, mode);
return false;
}
@ -616,7 +630,8 @@ droid_set_shared_buffer_mode(_EGLDisplay *disp, _EGLSurface *surf, bool mode)
return true;
#else
_eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__, __LINE__);
_eglLog(_EGL_FATAL, "%s:%d: internal error: unreachable", __FILE__,
__LINE__);
return false;
#endif
}
@ -639,8 +654,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
dri2_surf->in_fence_fd = -1;
if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
true, native_window))
if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, true,
native_window))
goto cleanup_surface;
if (type == EGL_WINDOW_BIT) {
@ -667,8 +682,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
/* Required buffer caching slots. */
buffer_count = min_undequeued_buffers + 2;
dri2_surf->color_buffers = calloc(buffer_count,
sizeof(*dri2_surf->color_buffers));
dri2_surf->color_buffers =
calloc(buffer_count, sizeof(*dri2_surf->color_buffers));
if (!dri2_surf->color_buffers) {
_eglError(EGL_BAD_ALLOC, "droid_create_surface");
goto cleanup_surface;
@ -676,8 +691,8 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
dri2_surf->color_buffers_count = buffer_count;
if (format != dri2_conf->base.NativeVisualID) {
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x",
format, dri2_conf->base.NativeVisualID);
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", format,
dri2_conf->base.NativeVisualID);
}
ANativeWindow_query(window, ANATIVEWINDOW_QUERY_DEFAULT_WIDTH,
@ -699,10 +714,10 @@ droid_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
}
}
config = dri2_get_dri_config(dri2_conf, type,
dri2_surf->base.GLColorspace);
config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
_eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surface;
}
@ -728,16 +743,15 @@ static _EGLSurface *
droid_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_window, const EGLint *attrib_list)
{
return droid_create_surface(disp, EGL_WINDOW_BIT, conf,
native_window, attrib_list);
return droid_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
attrib_list);
}
static _EGLSurface *
droid_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list)
{
return droid_create_surface(disp, EGL_PBUFFER_BIT, conf,
NULL, attrib_list);
return droid_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list);
}
static EGLBoolean
@ -756,13 +770,15 @@ droid_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
}
if (dri2_surf->dri_image_back) {
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__);
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__,
__LINE__);
dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
dri2_surf->dri_image_back = NULL;
}
if (dri2_surf->dri_image_front) {
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__);
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__,
__LINE__);
dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
dri2_surf->dri_image_front = NULL;
}
@ -832,15 +848,13 @@ get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
* and mesa doesn't have the implementation of this case.
* Add warning message, but not treat it as error.
*/
_eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface");
_eglLog(
_EGL_DEBUG,
"DRI driver requested unsupported front buffer for window surface");
} else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
dri2_surf->dri_image_front =
dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu,
dri2_surf->base.Width,
dri2_surf->base.Height,
format,
0,
NULL);
dri2_surf->dri_image_front = dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Height, format, 0, NULL);
if (!dri2_surf->dri_image_front) {
_eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
return -1;
@ -874,20 +888,24 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
} else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
/* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically,
* the spec states that they have a back buffer but no front buffer, in
* contrast to pixmaps, which have a front buffer but no back buffer.
/* The EGL 1.5 spec states that pbuffers are single-buffered.
* Specifically, the spec states that they have a back buffer but no front
* buffer, in contrast to pixmaps, which have a front buffer but no back
* buffer.
*
* Single-buffered surfaces with no front buffer confuse Mesa; so we deviate
* from the spec, following the precedent of Mesa's EGL X11 platform. The
* X11 platform correctly assigns pbuffers to single-buffered configs, but
* assigns the pbuffer a front buffer instead of a back buffer.
* Single-buffered surfaces with no front buffer confuse Mesa; so we
* deviate from the spec, following the precedent of Mesa's EGL X11
* platform. The X11 platform correctly assigns pbuffers to
* single-buffered configs, but assigns the pbuffer a front buffer instead
* of a back buffer.
*
* Pbuffers in the X11 platform mostly work today, so let's just copy its
* behavior instead of trying to fix (and hence potentially breaking) the
* world.
*/
_eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for pbuffer surface");
_eglLog(
_EGL_DEBUG,
"DRI driver requested unsupported back buffer for pbuffer surface");
}
return 0;
@ -899,12 +917,9 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
* return error when the allocation for supported buffer failed.
*/
static int
droid_image_get_buffers(__DRIdrawable *driDrawable,
unsigned int format,
uint32_t *stamp,
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *images)
droid_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
uint32_t *stamp, void *loaderPrivate,
uint32_t buffer_mask, struct __DRIimageList *images)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
@ -979,8 +994,7 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
* for which there is no pending change to the EGL_RENDER_BUFFER
* attribute, eglSwapBuffers has no effect.
*/
if (has_mutable_rb &&
draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER &&
if (has_mutable_rb && draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER &&
draw->ActiveRenderBuffer == EGL_SINGLE_BUFFER) {
_eglLog(_EGL_DEBUG, "%s: remain in shared buffer mode", __func__);
return EGL_TRUE;
@ -997,7 +1011,8 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
if (dri2_surf->back)
dri2_surf->back->age = 1;
dri2_flush_drawable_for_swapbuffers_flags(disp, draw, __DRI2_NOTHROTTLE_SWAPBUFFER);
dri2_flush_drawable_for_swapbuffers_flags(disp, draw,
__DRI2_NOTHROTTLE_SWAPBUFFER);
/* dri2_surf->buffer can be null even when no error has occurred. For
* example, if the user has called no GL rendering commands since the
@ -1013,9 +1028,9 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
/* Update the shared buffer mode */
if (has_mutable_rb &&
draw->ActiveRenderBuffer != draw->RequestedRenderBuffer) {
bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER);
_eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d",
__func__, mode);
bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER);
_eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", __func__,
mode);
if (!droid_set_shared_buffer_mode(disp, draw, mode))
return EGL_FALSE;
@ -1026,20 +1041,28 @@ droid_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
}
#ifdef HAVE_DRM_GRALLOC
static int get_format(int format)
static int
get_format(int format)
{
switch (format) {
case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FORMAT_ABGR8888;
case HAL_PIXEL_FORMAT_BGRA_8888:
return __DRI_IMAGE_FORMAT_ARGB8888;
case HAL_PIXEL_FORMAT_RGB_565:
return __DRI_IMAGE_FORMAT_RGB565;
case HAL_PIXEL_FORMAT_RGBA_8888:
return __DRI_IMAGE_FORMAT_ABGR8888;
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
/*
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack.
* TODO: Revert this once https://issuetracker.google.com/32077885 is fixed.
* TODO: Revert this once https://issuetracker.google.com/32077885 is
* fixed.
*/
case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_RGBA_FP16: return __DRI_IMAGE_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102: return __DRI_IMAGE_FORMAT_ABGR2101010;
case HAL_PIXEL_FORMAT_RGBX_8888:
return __DRI_IMAGE_FORMAT_XBGR8888;
case HAL_PIXEL_FORMAT_RGBA_FP16:
return __DRI_IMAGE_FORMAT_ABGR16161616F;
case HAL_PIXEL_FORMAT_RGBA_1010102:
return __DRI_IMAGE_FORMAT_ABGR2101010;
default:
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
}
@ -1047,8 +1070,7 @@ static int get_format(int format)
}
static __DRIimage *
droid_create_image_from_name(_EGLDisplay *disp,
struct ANativeWindowBuffer *buf,
droid_create_image_from_name(_EGLDisplay *disp, struct ANativeWindowBuffer *buf,
void *priv)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
@ -1063,48 +1085,42 @@ droid_create_image_from_name(_EGLDisplay *disp,
format = get_format(buf->format);
if (format == -1)
return NULL;
return NULL;
return
dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu,
buf->width,
buf->height,
format,
name,
buf->stride,
priv);
return dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu,
buf->width, buf->height, format,
name, buf->stride, priv);
}
#endif /* HAVE_DRM_GRALLOC */
static EGLBoolean
droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf,
EGLint attribute, EGLint *value)
droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint *value)
{
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
switch (attribute) {
case EGL_WIDTH:
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
ANativeWindow_query(dri2_surf->window,
ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, value);
return EGL_TRUE;
}
break;
case EGL_HEIGHT:
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
ANativeWindow_query(dri2_surf->window,
ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, value);
return EGL_TRUE;
}
break;
default:
break;
case EGL_WIDTH:
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
ANativeWindow_query(dri2_surf->window,
ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, value);
return EGL_TRUE;
}
break;
case EGL_HEIGHT:
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
ANativeWindow_query(dri2_surf->window,
ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, value);
return EGL_TRUE;
}
break;
default:
break;
}
return _eglQuerySurface(disp, surf, attribute, value);
}
static _EGLImage *
dri2_create_image_android_native_buffer(_EGLDisplay *disp,
_EGLContext *ctx,
dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
struct ANativeWindowBuffer *buf)
{
if (ctx != NULL) {
@ -1113,7 +1129,8 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp,
* * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not
* EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated.
*/
_eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for "
_eglError(EGL_BAD_CONTEXT,
"eglCreateEGLImageKHR: for "
"EGL_NATIVE_BUFFER_ANDROID, the context must be "
"EGL_NO_CONTEXT");
return NULL;
@ -1149,15 +1166,15 @@ droid_create_image_khr(_EGLDisplay *disp, _EGLContext *ctx, EGLenum target,
{
switch (target) {
case EGL_NATIVE_BUFFER_ANDROID:
return dri2_create_image_android_native_buffer(disp, ctx,
(struct ANativeWindowBuffer *) buffer);
return dri2_create_image_android_native_buffer(
disp, ctx, (struct ANativeWindowBuffer *)buffer);
default:
return dri2_create_image_khr(disp, ctx, target, buffer, attr_list);
}
}
static void
droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
droid_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
}
@ -1195,8 +1212,8 @@ droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
case __DRI_BUFFER_ACCUM:
case __DRI_BUFFER_DEPTH_STENCIL:
case __DRI_BUFFER_HIZ:
local = dri2_egl_surface_alloc_local_buffer(dri2_surf,
attachments[i], attachments[i + 1]);
local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
attachments[i + 1]);
if (local) {
*buf = *local;
@ -1218,17 +1235,17 @@ droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
}
static __DRIbuffer *
droid_get_buffers_with_format(__DRIdrawable * driDrawable,
int *width, int *height,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
droid_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
int *height, unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
if (update_buffers(dri2_surf) < 0)
return NULL;
*out_count = droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
*out_count =
droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
if (width)
*width = dri2_surf->base.Width;
@ -1257,7 +1274,7 @@ droid_destroy_loader_image_state(void *loaderPrivate)
#if ANDROID_API_LEVEL >= 26
if (loaderPrivate) {
AHardwareBuffer_release(
ANativeWindowBuffer_getHardwareBuffer(loaderPrivate));
ANativeWindowBuffer_getHardwareBuffer(loaderPrivate));
}
#endif
}
@ -1271,16 +1288,16 @@ droid_add_configs_for_visuals(_EGLDisplay *disp)
int rgba_shifts[4];
unsigned int rgba_sizes[4];
} visuals[] = {
{ HAL_PIXEL_FORMAT_RGBA_8888, { 0, 8, 16, 24 }, { 8, 8, 8, 8 } },
{ HAL_PIXEL_FORMAT_RGBX_8888, { 0, 8, 16, -1 }, { 8, 8, 8, 0 } },
{ HAL_PIXEL_FORMAT_RGB_565, { 11, 5, 0, -1 }, { 5, 6, 5, 0 } },
{HAL_PIXEL_FORMAT_RGBA_8888, {0, 8, 16, 24}, {8, 8, 8, 8}},
{HAL_PIXEL_FORMAT_RGBX_8888, {0, 8, 16, -1}, {8, 8, 8, 0}},
{HAL_PIXEL_FORMAT_RGB_565, {11, 5, 0, -1}, {5, 6, 5, 0}},
/* This must be after HAL_PIXEL_FORMAT_RGBA_8888, we only keep BGRA
* visual if it turns out RGBA visual is not available.
*/
{ HAL_PIXEL_FORMAT_BGRA_8888, { 16, 8, 0, 24 }, { 8, 8, 8, 8 } },
{HAL_PIXEL_FORMAT_BGRA_8888, {16, 8, 0, 24}, {8, 8, 8, 8}},
};
unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
unsigned int format_count[ARRAY_SIZE(visuals)] = {0};
int config_count = 0;
/* The nesting of loops is significant here. Also significant is the order
@ -1312,17 +1329,20 @@ droid_add_configs_for_visuals(_EGLDisplay *disp)
const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
const EGLint config_attrs[] = {
EGL_NATIVE_VISUAL_ID, visuals[i].format,
EGL_NATIVE_VISUAL_TYPE, visuals[i].format,
EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE,
EGL_RECORDABLE_ANDROID, EGL_TRUE,
EGL_NONE,
EGL_NATIVE_VISUAL_ID,
visuals[i].format,
EGL_NATIVE_VISUAL_TYPE,
visuals[i].format,
EGL_FRAMEBUFFER_TARGET_ANDROID,
EGL_TRUE,
EGL_RECORDABLE_ANDROID,
EGL_TRUE,
EGL_NONE,
};
struct dri2_egl_config *dri2_conf =
dri2_add_config(disp, dri2_dpy->driver_configs[j],
config_count + 1, surface_type, config_attrs,
visuals[i].rgba_shifts, visuals[i].rgba_sizes);
struct dri2_egl_config *dri2_conf = dri2_add_config(
disp, dri2_dpy->driver_configs[j], config_count + 1, surface_type,
config_attrs, visuals[i].rgba_shifts, visuals[i].rgba_sizes);
if (dri2_conf) {
if (dri2_conf->base.ConfigID == config_count + 1)
config_count++;
@ -1359,13 +1379,13 @@ static const struct dri2_egl_display_vtbl droid_display_vtbl = {
#ifdef HAVE_DRM_GRALLOC
static const __DRIdri2LoaderExtension droid_dri2_loader_extension = {
.base = { __DRI_DRI2_LOADER, 5 },
.base = {__DRI_DRI2_LOADER, 5},
.getBuffers = NULL,
.flushFrontBuffer = droid_flush_front_buffer,
.getBuffersWithFormat = droid_get_buffers_with_format,
.getCapability = droid_get_capability,
.destroyLoaderImageState = droid_destroy_loader_image_state,
.getBuffers = NULL,
.flushFrontBuffer = droid_flush_front_buffer,
.getBuffersWithFormat = droid_get_buffers_with_format,
.getCapability = droid_get_capability,
.destroyLoaderImageState = droid_destroy_loader_image_state,
};
static const __DRIextension *droid_dri2_loader_extensions[] = {
@ -1380,13 +1400,13 @@ static const __DRIextension *droid_dri2_loader_extensions[] = {
#endif /* HAVE_DRM_GRALLOC */
static const __DRIimageLoaderExtension droid_image_loader_extension = {
.base = { __DRI_IMAGE_LOADER, 4 },
.base = {__DRI_IMAGE_LOADER, 4},
.getBuffers = droid_image_get_buffers,
.flushFrontBuffer = droid_flush_front_buffer,
.getCapability = droid_get_capability,
.flushSwapBuffers = NULL,
.destroyLoaderImageState = droid_destroy_loader_image_state,
.getBuffers = droid_image_get_buffers,
.flushFrontBuffer = droid_flush_front_buffer,
.getCapability = droid_get_capability,
.flushSwapBuffers = NULL,
.destroyLoaderImageState = droid_destroy_loader_image_state,
};
static void
@ -1451,9 +1471,10 @@ droid_display_shared_buffer(__DRIdrawable *driDrawable, int fence_fd,
handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
}
static const __DRImutableRenderBufferLoaderExtension droid_mutable_render_buffer_extension = {
.base = { __DRI_MUTABLE_RENDER_BUFFER_LOADER, 1 },
.displaySharedBuffer = droid_display_shared_buffer,
static const __DRImutableRenderBufferLoaderExtension
droid_mutable_render_buffer_extension = {
.base = {__DRI_MUTABLE_RENDER_BUFFER_LOADER, 1},
.displaySharedBuffer = droid_display_shared_buffer,
};
static const __DRIextension *droid_image_loader_extensions[] = {
@ -1540,10 +1561,10 @@ droid_filter_device(_EGLDisplay *disp, int fd, const char *vendor)
static EGLBoolean
droid_probe_device(_EGLDisplay *disp, bool swrast)
{
/* Check that the device is supported, by attempting to:
* - load the dri module
* - and, create a screen
*/
/* Check that the device is supported, by attempting to:
* - load the dri module
* - and, create a screen
*/
if (!droid_load_driver(disp, swrast))
return EGL_FALSE;
@ -1567,8 +1588,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
if (dri2_dpy->gralloc->perform)
err = dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
GRALLOC_MODULE_PERFORM_GET_DRM_FD,
&fd);
GRALLOC_MODULE_PERFORM_GET_DRM_FD, &fd);
if (err || fd < 0) {
_eglLog(_EGL_WARNING, "fail to get drm fd");
return EGL_FALSE;
@ -1589,7 +1609,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
{
#define MAX_DRM_DEVICES 64
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
drmDevicePtr device, devices[MAX_DRM_DEVICES] = {NULL};
int num_devices;
char *vendor_name = NULL;
@ -1616,8 +1636,8 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
dri2_dpy->fd_render_gpu = loader_open_device(device->nodes[node_type]);
if (dri2_dpy->fd_render_gpu < 0) {
_eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s",
__func__, device->nodes[node_type]);
_eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", __func__,
device->nodes[node_type]);
continue;
}
@ -1652,7 +1672,7 @@ droid_open_device(_EGLDisplay *disp, bool swrast)
if (dri2_dpy->fd_render_gpu < 0) {
_eglLog(_EGL_WARNING, "Failed to open %s DRM device",
vendor_name ? "desired": "any");
vendor_name ? "desired" : "any");
return EGL_FALSE;
}
@ -1684,7 +1704,7 @@ dri2_initialize_android(_EGLDisplay *disp)
goto cleanup;
}
disp->DriverData = (void *) dri2_dpy;
disp->DriverData = (void *)dri2_dpy;
device_opened = droid_open_device(disp, disp->Options.ForceSoftware);
if (!device_opened) {
@ -1768,9 +1788,9 @@ dri2_initialize_android(_EGLDisplay *disp)
if (!strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) &&
dri2_dpy->gralloc->perform &&
dri2_dpy->gralloc->perform(
dri2_dpy->gralloc, CROS_GRALLOC_DRM_GET_USAGE,
CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT,
&front_rendering_usage) == 0) {
dri2_dpy->gralloc, CROS_GRALLOC_DRM_GET_USAGE,
CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT,
&front_rendering_usage) == 0) {
dri2_dpy->front_rendering_usage = front_rendering_usage;
disp->Extensions.KHR_mutable_render_buffer = EGL_TRUE;
}

View file

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

View file

@ -25,13 +25,13 @@
#include "platform_android.h"
#include <system/window.h>
#include <aidl/android/hardware/graphics/common/ChromaSiting.h>
#include <aidl/android/hardware/graphics/common/Dataspace.h>
#include <aidl/android/hardware/graphics/common/ExtendableType.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponent.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <gralloctypes/Gralloc4.h>
#include <system/window.h>
using aidl::android::hardware::graphics::common::ChromaSiting;
using aidl::android::hardware::graphics::common::Dataspace;
@ -39,26 +39,26 @@ using aidl::android::hardware::graphics::common::ExtendableType;
using aidl::android::hardware::graphics::common::PlaneLayout;
using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
using android::hardware::hidl_handle;
using android::hardware::hidl_vec;
using android::hardware::graphics::common::V1_2::BufferUsage;
using android::hardware::graphics::mapper::V4_0::Error;
using android::hardware::graphics::mapper::V4_0::IMapper;
using android::hardware::hidl_handle;
using android::hardware::hidl_vec;
using MetadataType =
android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;
Error
GetMetadata(android::sp<IMapper> mapper, const native_handle_t *buffer,
MetadataType type, hidl_vec<uint8_t>* metadata)
MetadataType type, hidl_vec<uint8_t> *metadata)
{
Error error = Error::NONE;
auto native_handle = const_cast<native_handle_t*>(buffer);
auto native_handle = const_cast<native_handle_t *>(buffer);
auto ret = mapper->get(native_handle, type,
[&](const auto& get_error, const auto& get_metadata) {
error = get_error;
*metadata = get_metadata;
[&](const auto &get_error, const auto &get_metadata) {
error = get_error;
*metadata = get_metadata;
});
if (!ret.isOk())
@ -67,21 +67,22 @@ GetMetadata(android::sp<IMapper> mapper, const native_handle_t *buffer,
return error;
}
std::optional<std::vector<PlaneLayout>> GetPlaneLayouts(
android::sp<IMapper> mapper, const native_handle_t *buffer)
std::optional<std::vector<PlaneLayout>>
GetPlaneLayouts(android::sp<IMapper> mapper, const native_handle_t *buffer)
{
hidl_vec<uint8_t> encoded_layouts;
Error error = GetMetadata(mapper, buffer,
android::gralloc4::MetadataType_PlaneLayouts,
&encoded_layouts);
Error error =
GetMetadata(mapper, buffer, android::gralloc4::MetadataType_PlaneLayouts,
&encoded_layouts);
if (error != Error::NONE)
return std::nullopt;
std::vector<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)
return std::nullopt;
@ -89,8 +90,7 @@ std::optional<std::vector<PlaneLayout>> GetPlaneLayouts(
return plane_layouts;
}
extern "C"
{
extern "C" {
int
mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
@ -108,20 +108,26 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
buf_info.height = buf->height;
hidl_vec<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)
return -EINVAL;
auto status = android::gralloc4::decodePixelFormatFourCC(encoded_format, &buf_info.drm_fourcc);
auto status = android::gralloc4::decodePixelFormatFourCC(
encoded_format, &buf_info.drm_fourcc);
if (status != android::OK)
return -EINVAL;
hidl_vec<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)
return -EINVAL;
status = android::gralloc4::decodePixelFormatModifier(encoded_modifier, &buf_info.modifier);
status = android::gralloc4::decodePixelFormatModifier(encoded_modifier,
&buf_info.modifier);
if (status != android::OK)
return -EINVAL;
@ -130,79 +136,89 @@ mapper_metadata_get_buffer_info(struct ANativeWindowBuffer *buf,
if (!layouts_opt)
return -EINVAL;
std::vector<PlaneLayout>& layouts = *layouts_opt;
std::vector<PlaneLayout> &layouts = *layouts_opt;
buf_info.num_planes = layouts.size();
bool per_plane_unique_fd = buf->handle->numFds == buf_info.num_planes;
for (uint32_t i = 0; i < layouts.size(); i++) {
buf_info.fds[i] = per_plane_unique_fd ? buf->handle->data[i] : buf->handle->data[0];
buf_info.fds[i] =
per_plane_unique_fd ? buf->handle->data[i] : buf->handle->data[0];
buf_info.pitches[i] = layouts[i].strideInBytes;
buf_info.offsets[i] = layouts[i].offsetInBytes;
}
/* optional attributes */
hidl_vec<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) {
ExtendableType chroma_siting_ext;
status = android::gralloc4::decodeChromaSiting(encoded_chroma_siting, &chroma_siting_ext);
status = android::gralloc4::decodeChromaSiting(encoded_chroma_siting,
&chroma_siting_ext);
if (status != android::OK)
return -EINVAL;
ChromaSiting chroma_siting = android::gralloc4::getStandardChromaSitingValue(chroma_siting_ext);
ChromaSiting chroma_siting =
android::gralloc4::getStandardChromaSitingValue(chroma_siting_ext);
switch (chroma_siting) {
case ChromaSiting::SITED_INTERSTITIAL:
buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0_5;
buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5;
break;
case ChromaSiting::COSITED_HORIZONTAL:
buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0;
buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5;
break;
default:
break;
case ChromaSiting::SITED_INTERSTITIAL:
buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0_5;
buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5;
break;
case ChromaSiting::COSITED_HORIZONTAL:
buf_info.horizontal_siting = __DRI_YUV_CHROMA_SITING_0;
buf_info.vertical_siting = __DRI_YUV_CHROMA_SITING_0_5;
break;
default:
break;
}
}
hidl_vec<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) {
Dataspace dataspace;
status = android::gralloc4::decodeDataspace(encoded_dataspace, &dataspace);
status =
android::gralloc4::decodeDataspace(encoded_dataspace, &dataspace);
if (status != android::OK)
return -EINVAL;
Dataspace standard = (Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK);
Dataspace standard =
(Dataspace)((int)dataspace & (uint32_t)Dataspace::STANDARD_MASK);
switch (standard) {
case Dataspace::STANDARD_BT709:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC709;
break;
case Dataspace::STANDARD_BT601_625:
case Dataspace::STANDARD_BT601_625_UNADJUSTED:
case Dataspace::STANDARD_BT601_525:
case Dataspace::STANDARD_BT601_525_UNADJUSTED:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC601;
break;
case Dataspace::STANDARD_BT2020:
case Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC2020;
break;
default:
break;
case Dataspace::STANDARD_BT709:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC709;
break;
case Dataspace::STANDARD_BT601_625:
case Dataspace::STANDARD_BT601_625_UNADJUSTED:
case Dataspace::STANDARD_BT601_525:
case Dataspace::STANDARD_BT601_525_UNADJUSTED:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC601;
break;
case Dataspace::STANDARD_BT2020:
case Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE:
buf_info.yuv_color_space = __DRI_YUV_COLOR_SPACE_ITU_REC2020;
break;
default:
break;
}
Dataspace range = (Dataspace)((int)dataspace & (uint32_t)Dataspace::RANGE_MASK);
Dataspace range =
(Dataspace)((int)dataspace & (uint32_t)Dataspace::RANGE_MASK);
switch (range) {
case Dataspace::RANGE_FULL:
buf_info.sample_range = __DRI_YUV_FULL_RANGE;
break;
case Dataspace::RANGE_LIMITED:
buf_info.sample_range = __DRI_YUV_NARROW_RANGE;
break;
default:
break;
case Dataspace::RANGE_FULL:
buf_info.sample_range = __DRI_YUV_FULL_RANGE;
break;
case Dataspace::RANGE_LIMITED:
buf_info.sample_range = __DRI_YUV_NARROW_RANGE;
break;
default:
break;
}
}

View file

@ -30,31 +30,27 @@
#include <xf86drm.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.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 "egl_dri2.h"
#include "kopper_interface.h"
#include "loader.h"
static __DRIimage*
static __DRIimage *
device_alloc_image(struct dri2_egl_display *dri2_dpy,
struct dri2_egl_surface *dri2_surf)
{
return dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu,
dri2_surf->base.Width,
dri2_surf->base.Height,
dri2_surf->visual,
0,
NULL);
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Height, dri2_surf->visual, 0, NULL);
}
static void
@ -73,12 +69,9 @@ device_free_images(struct dri2_egl_surface *dri2_surf)
}
static int
device_image_get_buffers(__DRIdrawable *driDrawable,
unsigned int format,
uint32_t *stamp,
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *buffers)
device_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
uint32_t *stamp, void *loaderPrivate,
uint32_t buffer_mask, struct __DRIimageList *buffers)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct dri2_egl_display *dri2_dpy =
@ -105,8 +98,7 @@ device_image_get_buffers(__DRIdrawable *driDrawable,
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
if (!dri2_surf->front)
dri2_surf->front =
device_alloc_image(dri2_dpy, dri2_surf);
dri2_surf->front = device_alloc_image(dri2_dpy, dri2_surf);
buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
buffers->front = dri2_surf->front;
@ -138,11 +130,11 @@ dri2_device_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
false, NULL))
goto cleanup_surface;
config = dri2_get_dri_config(dri2_conf, type,
dri2_surf->base.GLColorspace);
config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
_eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surface;
}
@ -155,9 +147,9 @@ dri2_device_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
return &dri2_surf->base;
cleanup_surface:
free(dri2_surf);
return NULL;
cleanup_surface:
free(dri2_surf);
return NULL;
}
static EGLBoolean
@ -207,16 +199,16 @@ device_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
}
static const __DRIimageLoaderExtension image_loader_extension = {
.base = { __DRI_IMAGE_LOADER, 2 },
.getBuffers = device_image_get_buffers,
.base = {__DRI_IMAGE_LOADER, 2},
.getBuffers = device_image_get_buffers,
.flushFrontBuffer = device_flush_front_buffer,
.getCapability = device_get_capability,
.getCapability = device_get_capability,
};
static const __DRIkopperLoaderExtension kopper_loader_extension = {
.base = { __DRI_KOPPER_LOADER, 1 },
.base = {__DRI_KOPPER_LOADER, 1},
.SetSurfaceCreateInfo = NULL,
.SetSurfaceCreateInfo = NULL,
};
static const __DRIextension *image_loader_extensions[] = {
@ -253,24 +245,24 @@ device_get_fd(_EGLDisplay *disp, _EGLDevice *dev)
if (dev != _eglAddDevice(fd, false))
return -1;
/* kms_swrast only work with primary node. It used to work with render node in
* the past because some downstream kernel carry a patch to enable dumb bo
* ioctl on render nodes.
/* kms_swrast only work with primary node. It used to work with render
* node in the past because some downstream kernel carry a patch to enable
* dumb bo ioctl on render nodes.
*/
char *node = kms_swrast ? drmGetPrimaryDeviceNameFromFd(fd) :
drmGetRenderDeviceNameFromFd(fd);
char *node = kms_swrast ? drmGetPrimaryDeviceNameFromFd(fd)
: drmGetRenderDeviceNameFromFd(fd);
/* Don't close the internal fd, get render node one based on it. */
fd = loader_open_device(node);
free(node);
return fd;
}
const char *node = _eglQueryDeviceStringEXT(dev, kms_swrast ?
EGL_DRM_DEVICE_FILE_EXT :
EGL_DRM_RENDER_NODE_FILE_EXT);
const char *node = _eglQueryDeviceStringEXT(
dev, kms_swrast ? EGL_DRM_DEVICE_FILE_EXT : EGL_DRM_RENDER_NODE_FILE_EXT);
return loader_open_device(node);
#else
_eglLog(_EGL_FATAL, "Driver bug: Built without libdrm, yet using a HW device");
_eglLog(_EGL_FATAL,
"Driver bug: Built without libdrm, yet using a HW device");
return -1;
#endif
}
@ -279,7 +271,8 @@ static bool
device_probe_device(_EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
bool request_software = debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false);
bool request_software =
debug_get_bool_option("LIBGL_ALWAYS_SOFTWARE", false);
if (request_software)
_eglLog(_EGL_WARNING, "Not allowed to force software rendering when "
@ -320,7 +313,6 @@ err_name:
close(dri2_dpy->fd_render_gpu);
dri2_dpy->fd_render_gpu = dri2_dpy->fd_display_gpu = -1;
return false;
}
static bool
@ -350,7 +342,7 @@ dri2_initialize_device(_EGLDisplay *disp)
{
_EGLDevice *dev;
struct dri2_egl_display *dri2_dpy;
const char* err;
const char *err;
dri2_dpy = calloc(1, sizeof *dri2_dpy);
if (!dri2_dpy)
@ -362,7 +354,7 @@ dri2_initialize_device(_EGLDisplay *disp)
dri2_dpy->fd_render_gpu = -1;
dri2_dpy->fd_display_gpu = -1;
disp->Device = dev;
disp->DriverData = (void *) dri2_dpy;
disp->DriverData = (void *)dri2_dpy;
err = "DRI2: failed to load driver";
if (_eglDeviceSupports(dev, _EGL_DEVICE_DRM)) {
if (!device_probe_device(disp))
@ -371,7 +363,8 @@ dri2_initialize_device(_EGLDisplay *disp)
if (!device_probe_device_sw(disp))
goto cleanup;
} else {
_eglLog(_EGL_FATAL, "Driver bug: exposed device is neither DRM nor SOFTWARE one");
_eglLog(_EGL_FATAL,
"Driver bug: exposed device is neither DRM nor SOFTWARE one");
return EGL_FALSE;
}
@ -387,7 +380,8 @@ dri2_initialize_device(_EGLDisplay *disp)
dri2_setup_screen(disp);
#ifdef HAVE_WAYLAND_PLATFORM
dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
dri2_dpy->device_name =
loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
#endif
dri2_set_WL_bind_wayland_display(disp);

View file

@ -25,16 +25,16 @@
* 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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <xf86drm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "util/os_file.h"
@ -72,8 +72,8 @@ release_buffer(struct gbm_surface *_surf, struct gbm_bo *bo)
for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
if (dri2_surf->color_buffers[i].bo == bo) {
dri2_surf->color_buffers[i].locked = false;
break;
dri2_surf->color_buffers[i].locked = false;
break;
}
}
}
@ -86,7 +86,7 @@ has_free_buffers(struct gbm_surface *_surf)
for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)
if (!dri2_surf->color_buffers[i].locked)
return 1;
return 1;
return 0;
}
@ -162,7 +162,8 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
dri2_surf->base.GLColorspace);
if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
_eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surf;
}
@ -173,7 +174,7 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
surf = gbm_dri_surface(surface);
dri2_surf->gbm_surf = surf;
dri2_surf->base.Width = surf->base.v0.width;
dri2_surf->base.Width = surf->base.v0.width;
dri2_surf->base.Height = surf->base.v0.height;
surf->dri_private = dri2_surf;
@ -182,7 +183,7 @@ dri2_drm_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
return &dri2_surf->base;
cleanup_surf:
cleanup_surf:
free(dri2_surf);
return NULL;
@ -212,7 +213,7 @@ dri2_drm_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
if (dri2_surf->color_buffers[i].bo)
gbm_bo_destroy(dri2_surf->color_buffers[i].bo);
gbm_bo_destroy(dri2_surf->color_buffers[i].bo);
}
dri2_egl_surface_free_local_buffers(dri2_surf);
@ -233,11 +234,11 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
if (dri2_surf->back == NULL) {
for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
if (!dri2_surf->color_buffers[i].locked &&
dri2_surf->color_buffers[i].age >= age) {
dri2_surf->back = &dri2_surf->color_buffers[i];
age = dri2_surf->color_buffers[i].age;
}
if (!dri2_surf->color_buffers[i].locked &&
dri2_surf->color_buffers[i].age >= age) {
dri2_surf->back = &dri2_surf->color_buffers[i];
age = dri2_surf->color_buffers[i].age;
}
}
}
@ -245,23 +246,17 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
return -1;
if (dri2_surf->back->bo == NULL) {
if (surf->base.v0.modifiers)
dri2_surf->back->bo = gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base,
surf->base.v0.width,
surf->base.v0.height,
surf->base.v0.format,
surf->base.v0.modifiers,
surf->base.v0.count);
dri2_surf->back->bo = gbm_bo_create_with_modifiers(
&dri2_dpy->gbm_dri->base, surf->base.v0.width, surf->base.v0.height,
surf->base.v0.format, surf->base.v0.modifiers, surf->base.v0.count);
else {
unsigned flags = surf->base.v0.flags;
if (dri2_surf->base.ProtectedContent)
flags |= GBM_BO_USE_PROTECTED;
dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base,
surf->base.v0.width,
surf->base.v0.height,
surf->base.v0.format,
flags);
dri2_surf->back->bo =
gbm_bo_create(&dri2_dpy->gbm_dri->base, surf->base.v0.width,
surf->base.v0.height, surf->base.v0.format, flags);
}
}
if (dri2_surf->back->bo == NULL)
return -1;
@ -282,11 +277,9 @@ get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
}
if (dri2_surf->current->bo == NULL)
dri2_surf->current->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base,
surf->base.v0.width,
surf->base.v0.height,
surf->base.v0.format,
surf->base.v0.flags);
dri2_surf->current->bo = gbm_bo_create(
&dri2_dpy->gbm_dri->base, surf->base.v0.width, surf->base.v0.height,
surf->base.v0.format, surf->base.v0.flags);
if (dri2_surf->current->bo == NULL)
return -1;
@ -314,10 +307,9 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
}
static __DRIbuffer *
dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,
int *width, int *height,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
int *height, unsigned int *attachments,
int count, int *out_count, void *loaderPrivate)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
int i, j;
@ -330,22 +322,22 @@ dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,
switch (attachments[i]) {
case __DRI_BUFFER_BACK_LEFT:
if (get_back_bo(dri2_surf) < 0) {
_eglError(EGL_BAD_ALLOC, "failed to allocate color buffer");
return NULL;
}
if (get_back_bo(dri2_surf) < 0) {
_eglError(EGL_BAD_ALLOC, "failed to allocate color buffer");
return NULL;
}
back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]);
break;
break;
default:
local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
attachments[i + 1]);
if (!local) {
_eglError(EGL_BAD_ALLOC, "failed to allocate local buffer");
return NULL;
}
dri2_surf->buffers[j] = *local;
break;
if (!local) {
_eglError(EGL_BAD_ALLOC, "failed to allocate local buffer");
return NULL;
}
dri2_surf->buffers[j] = *local;
break;
}
}
@ -360,10 +352,9 @@ dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,
}
static __DRIbuffer *
dri2_drm_get_buffers(__DRIdrawable * driDrawable,
int *width, int *height,
unsigned int *attachments, int count,
int *out_count, void *loaderPrivate)
dri2_drm_get_buffers(__DRIdrawable *driDrawable, int *width, int *height,
unsigned int *attachments, int count, int *out_count,
void *loaderPrivate)
{
unsigned int *attachments_with_format;
__DRIbuffer *buffer;
@ -376,15 +367,13 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable,
}
for (int i = 0; i < count; ++i) {
attachments_with_format[2*i] = attachments[i];
attachments_with_format[2*i + 1] = format;
attachments_with_format[2 * i] = attachments[i];
attachments_with_format[2 * i + 1] = format;
}
buffer =
dri2_drm_get_buffers_with_format(driDrawable,
width, height,
attachments_with_format, count,
out_count, loaderPrivate);
buffer = dri2_drm_get_buffers_with_format(driDrawable, width, height,
attachments_with_format, count,
out_count, loaderPrivate);
free(attachments_with_format);
@ -392,12 +381,9 @@ dri2_drm_get_buffers(__DRIdrawable * driDrawable,
}
static int
dri2_drm_image_get_buffers(__DRIdrawable *driDrawable,
unsigned int format,
uint32_t *stamp,
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *buffers)
dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
uint32_t *stamp, void *loaderPrivate,
uint32_t buffer_mask, struct __DRIimageList *buffers)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct gbm_dri_bo *bo;
@ -413,10 +399,10 @@ dri2_drm_image_get_buffers(__DRIdrawable *driDrawable,
}
static void
dri2_drm_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
dri2_drm_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
(void) driDrawable;
(void) loaderPrivate;
(void)driDrawable;
(void)loaderPrivate;
}
static EGLBoolean
@ -466,10 +452,11 @@ dri2_drm_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surface)
static _EGLImage *
dri2_drm_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
EGLClientBuffer buffer, const EGLint *attr_list)
EGLClientBuffer buffer,
const EGLint *attr_list)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *) buffer);
struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *)buffer);
struct dri2_egl_image *dri2_img;
dri2_img = malloc(sizeof *dri2_img);
@ -511,15 +498,8 @@ dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id)
}
static void
swrast_put_image2(__DRIdrawable *driDrawable,
int op,
int x,
int y,
int width,
int height,
int stride,
char *data,
void *loaderPrivate)
swrast_put_image2(__DRIdrawable *driDrawable, int op, int x, int y, int width,
int height, int stride, char *data, void *loaderPrivate)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
int internal_stride;
@ -528,8 +508,7 @@ swrast_put_image2(__DRIdrawable *driDrawable,
int x_bytes, width_bytes;
char *src, *dst;
if (op != __DRI_SWRAST_IMAGE_OP_DRAW &&
op != __DRI_SWRAST_IMAGE_OP_SWAP)
if (op != __DRI_SWRAST_IMAGE_OP_DRAW && op != __DRI_SWRAST_IMAGE_OP_SWAP)
return;
if (get_swrast_front_bo(dri2_surf) < 0)
@ -562,13 +541,8 @@ swrast_put_image2(__DRIdrawable *driDrawable,
}
static void
swrast_get_image(__DRIdrawable *driDrawable,
int x,
int y,
int width,
int height,
char *data,
void *loaderPrivate)
swrast_get_image(__DRIdrawable *driDrawable, int x, int y, int width,
int height, char *data, void *loaderPrivate)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
int internal_stride, stride;
@ -643,12 +617,14 @@ drm_add_configs_for_visuals(_EGLDisplay *disp)
continue;
const EGLint attr_list[] = {
EGL_NATIVE_VISUAL_ID, visuals[j].gbm_format,
EGL_NATIVE_VISUAL_ID,
visuals[j].gbm_format,
EGL_NONE,
};
dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
config_count + 1, EGL_WINDOW_BIT, attr_list, NULL, NULL);
dri2_conf =
dri2_add_config(disp, dri2_dpy->driver_configs[i], config_count + 1,
EGL_WINDOW_BIT, attr_list, NULL, NULL);
if (dri2_conf) {
if (dri2_conf->base.ConfigID == config_count + 1)
config_count++;
@ -693,7 +669,7 @@ dri2_initialize_drm(_EGLDisplay *disp)
dri2_dpy->fd_render_gpu = -1;
dri2_dpy->fd_display_gpu = -1;
disp->DriverData = (void *) dri2_dpy;
disp->DriverData = (void *)dri2_dpy;
gbm = disp->PlatformDisplay;
if (gbm == NULL) {
@ -731,7 +707,8 @@ dri2_initialize_drm(_EGLDisplay *disp)
disp->Device = dev;
dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->driver_name);
dri2_dpy->is_render_node = drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER;
dri2_dpy->is_render_node =
drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER;
/* render nodes cannot use Gem names, and thus do not support
* the __DRI_DRI2_LOADER extension */
@ -761,7 +738,8 @@ dri2_initialize_drm(_EGLDisplay *disp)
dri2_dpy->gbm_dri->get_buffers = dri2_drm_get_buffers;
dri2_dpy->gbm_dri->flush_front_buffer = dri2_drm_flush_front_buffer;
dri2_dpy->gbm_dri->get_buffers_with_format = dri2_drm_get_buffers_with_format;
dri2_dpy->gbm_dri->get_buffers_with_format =
dri2_drm_get_buffers_with_format;
dri2_dpy->gbm_dri->image_get_buffers = dri2_drm_image_get_buffers;
dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2;
dri2_dpy->gbm_dri->swrast_get_image = swrast_get_image;
@ -787,7 +765,8 @@ dri2_initialize_drm(_EGLDisplay *disp)
disp->Extensions.EXT_buffer_age = EGL_TRUE;
#ifdef HAVE_WAYLAND_PLATFORM
dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
dri2_dpy->device_name =
loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
#endif
dri2_set_WL_bind_wayland_display(disp);

View file

@ -23,31 +23,27 @@
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xf86drm.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <xf86drm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "egl_dri2.h"
#include "loader.h"
#include "kopper_interface.h"
#include "loader.h"
static __DRIimage*
static __DRIimage *
surfaceless_alloc_image(struct dri2_egl_display *dri2_dpy,
struct dri2_egl_surface *dri2_surf)
struct dri2_egl_surface *dri2_surf)
{
return dri2_dpy->image->createImage(
dri2_dpy->dri_screen_render_gpu,
dri2_surf->base.Width,
dri2_surf->base.Height,
dri2_surf->visual,
0,
NULL);
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
dri2_surf->base.Height, dri2_surf->visual, 0, NULL);
}
static void
@ -66,12 +62,10 @@ surfaceless_free_images(struct dri2_egl_surface *dri2_surf)
}
static int
surfaceless_image_get_buffers(__DRIdrawable *driDrawable,
unsigned int format,
uint32_t *stamp,
void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *buffers)
surfaceless_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
uint32_t *stamp, void *loaderPrivate,
uint32_t buffer_mask,
struct __DRIimageList *buffers)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
struct dri2_egl_display *dri2_dpy =
@ -98,8 +92,7 @@ surfaceless_image_get_buffers(__DRIdrawable *driDrawable,
if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
if (!dri2_surf->front)
dri2_surf->front =
surfaceless_alloc_image(dri2_dpy, dri2_surf);
dri2_surf->front = surfaceless_alloc_image(dri2_dpy, dri2_surf);
buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
buffers->front = dri2_surf->front;
@ -131,11 +124,11 @@ dri2_surfaceless_create_surface(_EGLDisplay *disp, EGLint type,
false, NULL))
goto cleanup_surface;
config = dri2_get_dri_config(dri2_conf, type,
dri2_surf->base.GLColorspace);
config = dri2_get_dri_config(dri2_conf, type, dri2_surf->base.GLColorspace);
if (!config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
_eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_surface;
}
@ -148,9 +141,9 @@ dri2_surfaceless_create_surface(_EGLDisplay *disp, EGLint type,
return &dri2_surf->base;
cleanup_surface:
free(dri2_surf);
return NULL;
cleanup_surface:
free(dri2_surf);
return NULL;
}
static EGLBoolean
@ -173,7 +166,7 @@ dri2_surfaceless_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list)
{
return dri2_surfaceless_create_surface(disp, EGL_PBUFFER_BIT, conf,
attrib_list);
attrib_list);
}
static const struct dri2_egl_display_vtbl dri2_surfaceless_display_vtbl = {
@ -201,34 +194,28 @@ surfaceless_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
}
static const __DRIkopperLoaderExtension kopper_loader_extension = {
.base = { __DRI_KOPPER_LOADER, 1 },
.base = {__DRI_KOPPER_LOADER, 1},
.SetSurfaceCreateInfo = NULL,
.SetSurfaceCreateInfo = NULL,
};
static const __DRIimageLoaderExtension image_loader_extension = {
.base = { __DRI_IMAGE_LOADER, 2 },
.getBuffers = surfaceless_image_get_buffers,
.base = {__DRI_IMAGE_LOADER, 2},
.getBuffers = surfaceless_image_get_buffers,
.flushFrontBuffer = surfaceless_flush_front_buffer,
.getCapability = surfaceless_get_capability,
.getCapability = surfaceless_get_capability,
};
static const __DRIextension *image_loader_extensions[] = {
&image_loader_extension.base,
&image_lookup_extension.base,
&use_invalidate.base,
&background_callable_extension.base,
&kopper_loader_extension.base,
NULL,
&image_loader_extension.base, &image_lookup_extension.base,
&use_invalidate.base, &background_callable_extension.base,
&kopper_loader_extension.base, NULL,
};
static const __DRIextension *swrast_loader_extensions[] = {
&swrast_pbuffer_loader_extension.base,
&image_loader_extension.base,
&image_lookup_extension.base,
&use_invalidate.base,
&kopper_loader_extension.base,
NULL,
&swrast_pbuffer_loader_extension.base, &image_loader_extension.base,
&image_lookup_extension.base, &use_invalidate.base,
&kopper_loader_extension.base, NULL,
};
static bool
@ -237,7 +224,7 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
#define MAX_DRM_DEVICES 64
const unsigned node_type = swrast ? DRM_NODE_PRIMARY : DRM_NODE_RENDER;
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
drmDevicePtr device, devices[MAX_DRM_DEVICES] = {NULL};
int i, num_devices;
num_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
@ -268,9 +255,8 @@ surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
* are unavailable since 6c5ab, and kms_swrast is more
* feature complete than swrast.
*/
if (driver_name &&
(strcmp(driver_name, "vgem") == 0 ||
strcmp(driver_name, "virtio_gpu") == 0))
if (driver_name && (strcmp(driver_name, "vgem") == 0 ||
strcmp(driver_name, "virtio_gpu") == 0))
dri2_dpy->driver_name = strdup("kms_swrast");
free(driver_name);
} else {
@ -326,7 +312,7 @@ EGLBoolean
dri2_initialize_surfaceless(_EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy;
const char* err;
const char *err;
bool driver_loaded = false;
dri2_dpy = calloc(1, sizeof *dri2_dpy);
@ -335,7 +321,7 @@ dri2_initialize_surfaceless(_EGLDisplay *disp)
dri2_dpy->fd_render_gpu = -1;
dri2_dpy->fd_display_gpu = -1;
disp->DriverData = (void *) dri2_dpy;
disp->DriverData = (void *)dri2_dpy;
/* When ForceSoftware is false, we try the HW driver. When ForceSoftware
* is true, we try kms_swrast and swrast in order.
@ -365,7 +351,8 @@ dri2_initialize_surfaceless(_EGLDisplay *disp)
dri2_setup_screen(disp);
#ifdef HAVE_WAYLAND_PLATFORM
dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
dri2_dpy->device_name =
loader_get_device_name_for_fd(dri2_dpy->fd_render_gpu);
#endif
dri2_set_WL_bind_wayland_display(disp);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -20,15 +20,15 @@
* OF THIS SOFTWARE.
*/
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <xcb/xcb.h>
#include <xcb/dri3.h>
#include <xcb/present.h>
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
#include <xf86drm.h>
@ -41,14 +41,15 @@
#include "loader_dri3_helper.h"
static struct dri3_egl_surface *
loader_drawable_to_egl_surface(struct loader_dri3_drawable *draw) {
loader_drawable_to_egl_surface(struct loader_dri3_drawable *draw)
{
size_t offset = offsetof(struct dri3_egl_surface, loader_drawable);
return (struct dri3_egl_surface *)(((void*) draw) - offset);
return (struct dri3_egl_surface *)(((void *)draw) - offset);
}
static void
egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw,
int width, int height)
egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw, int width,
int height)
{
struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw);
@ -84,7 +85,8 @@ egl_dri3_get_dri_screen(void)
if (!ctx)
return NULL;
dri2_ctx = dri2_egl_context(ctx);
return dri2_egl_display(dri2_ctx->base.Resource.Display)->dri_screen_render_gpu;
return dri2_egl_display(dri2_ctx->base.Resource.Display)
->dri_screen_render_gpu;
}
static void
@ -114,7 +116,7 @@ dri3_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
loader_dri3_drawable_fini(&dri3_surf->loader_drawable);
if (surf->Type == EGL_PBUFFER_BIT)
xcb_free_pixmap (dri2_dpy->conn, drawable);
xcb_free_pixmap(dri2_dpy->conn, drawable);
dri2_fini_surface(surf);
free(surf);
@ -164,38 +166,35 @@ dri3_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
return NULL;
}
if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf,
attrib_list, false, native_surface))
if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, attrib_list,
false, native_surface))
goto cleanup_surf;
if (type == EGL_PBUFFER_BIT) {
drawable = xcb_generate_id(dri2_dpy->conn);
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize,
drawable, dri2_dpy->screen->root,
dri3_surf->surf.base.Width, dri3_surf->surf.base.Height);
xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, drawable,
dri2_dpy->screen->root, dri3_surf->surf.base.Width,
dri3_surf->surf.base.Height);
} else {
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface));
drawable = (uintptr_t) native_surface;
drawable = (uintptr_t)native_surface;
}
dri_config = dri2_get_dri_config(dri2_conf, type,
dri3_surf->surf.base.GLColorspace);
dri_config =
dri2_get_dri_config(dri2_conf, type, dri3_surf->surf.base.GLColorspace);
if (!dri_config) {
_eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
_eglError(EGL_BAD_MATCH,
"Unsupported surfacetype/colorspace configuration");
goto cleanup_pixmap;
}
if (loader_dri3_drawable_init(dri2_dpy->conn, drawable,
egl_to_loader_dri3_drawable_type(type),
dri2_dpy->dri_screen_render_gpu,
dri2_dpy->dri_screen_display_gpu,
dri2_dpy->multibuffers_available,
true,
dri_config,
&dri2_dpy->loader_dri3_ext,
&egl_dri3_vtable,
&dri3_surf->loader_drawable)) {
if (loader_dri3_drawable_init(
dri2_dpy->conn, drawable, egl_to_loader_dri3_drawable_type(type),
dri2_dpy->dri_screen_render_gpu, dri2_dpy->dri_screen_display_gpu,
dri2_dpy->multibuffers_available, true, dri_config,
&dri2_dpy->loader_dri3_ext, &egl_dri3_vtable,
&dri3_surf->loader_drawable)) {
_eglError(EGL_BAD_ALLOC, "dri3_surface_create");
goto cleanup_pixmap;
}
@ -211,10 +210,10 @@ dri3_create_surface(_EGLDisplay *disp, EGLint type, _EGLConfig *conf,
return &dri3_surf->surf.base;
cleanup_pixmap:
cleanup_pixmap:
if (type == EGL_PBUFFER_BIT)
xcb_free_pixmap(dri2_dpy->conn, drawable);
cleanup_surf:
cleanup_surf:
free(dri3_surf);
return NULL;
@ -249,8 +248,8 @@ dri3_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
_EGLSurface *surf;
surf = dri3_create_surface(disp, EGL_WINDOW_BIT, conf,
native_window, attrib_list);
surf = dri3_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
attrib_list);
if (surf != NULL)
dri3_set_swap_interval(disp, surf, dri2_dpy->default_swap_interval);
@ -261,28 +260,28 @@ static _EGLSurface *
dri3_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_pixmap, const EGLint *attrib_list)
{
return dri3_create_surface(disp, EGL_PIXMAP_BIT, conf,
native_pixmap, attrib_list);
return dri3_create_surface(disp, EGL_PIXMAP_BIT, conf, native_pixmap,
attrib_list);
}
static _EGLSurface *
dri3_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list)
{
return dri3_create_surface(disp, EGL_PBUFFER_BIT, conf,
NULL, attrib_list);
return dri3_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list);
}
static EGLBoolean
dri3_get_sync_values(_EGLDisplay *display, _EGLSurface *surface,
EGLuint64KHR *ust, EGLuint64KHR *msc,
EGLuint64KHR *sbc)
EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc)
{
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surface);
return loader_dri3_wait_for_msc(&dri3_surf->loader_drawable, 0, 0, 0,
(int64_t *) ust, (int64_t *) msc,
(int64_t *) sbc) ? EGL_TRUE : EGL_FALSE;
(int64_t *)ust, (int64_t *)msc,
(int64_t *)sbc)
? EGL_TRUE
: EGL_FALSE;
}
static _EGLImage *
@ -293,13 +292,13 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
struct dri2_egl_image *dri2_img;
xcb_drawable_t drawable;
xcb_dri3_buffer_from_pixmap_cookie_t bp_cookie;
xcb_dri3_buffer_from_pixmap_reply_t *bp_reply;
xcb_dri3_buffer_from_pixmap_reply_t *bp_reply;
unsigned int format;
drawable = (xcb_drawable_t) (uintptr_t) buffer;
drawable = (xcb_drawable_t)(uintptr_t)buffer;
bp_cookie = xcb_dri3_buffer_from_pixmap(dri2_dpy->conn, drawable);
bp_reply = xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn,
bp_cookie, NULL);
bp_reply =
xcb_dri3_buffer_from_pixmap_reply(dri2_dpy->conn, bp_cookie, NULL);
if (!bp_reply) {
_eglError(EGL_BAD_ALLOC, "xcb_dri3_buffer_from_pixmap");
return NULL;
@ -322,12 +321,9 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
_eglInitImage(&dri2_img->base, disp);
dri2_img->dri_image = loader_dri3_create_image(dri2_dpy->conn,
bp_reply,
format,
dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image,
dri2_img);
dri2_img->dri_image = loader_dri3_create_image(
dri2_dpy->conn, bp_reply, format, dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image, dri2_img);
free(bp_reply);
@ -343,14 +339,14 @@ dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx,
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_image *dri2_img;
xcb_dri3_buffers_from_pixmap_cookie_t bp_cookie;
xcb_dri3_buffers_from_pixmap_reply_t *bp_reply;
xcb_dri3_buffers_from_pixmap_reply_t *bp_reply;
xcb_drawable_t drawable;
unsigned int format;
drawable = (xcb_drawable_t) (uintptr_t) buffer;
drawable = (xcb_drawable_t)(uintptr_t)buffer;
bp_cookie = xcb_dri3_buffers_from_pixmap(dri2_dpy->conn, drawable);
bp_reply = xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn,
bp_cookie, NULL);
bp_reply =
xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn, bp_cookie, NULL);
if (!bp_reply) {
_eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr");
@ -374,12 +370,9 @@ dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx,
_eglInitImage(&dri2_img->base, disp);
dri2_img->dri_image = loader_dri3_create_image_from_buffers(dri2_dpy->conn,
bp_reply,
format,
dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image,
dri2_img);
dri2_img->dri_image = loader_dri3_create_image_from_buffers(
dri2_dpy->conn, bp_reply, format, dri2_dpy->dri_screen_render_gpu,
dri2_dpy->image, dri2_img);
free(bp_reply);
if (!dri2_img->dri_image) {
@ -421,21 +414,22 @@ static void
dri3_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
struct loader_dri3_drawable *draw = loaderPrivate;
(void) driDrawable;
(void)driDrawable;
/* There does not seem to be any kind of consensus on whether we should
* support front-buffer rendering or not:
* http://lists.freedesktop.org/archives/mesa-dev/2013-June/040129.html
*/
if (draw->type == LOADER_DRI3_DRAWABLE_WINDOW)
_eglLog(_EGL_WARNING, "FIXME: egl/x11 doesn't support front buffer rendering.");
_eglLog(_EGL_WARNING,
"FIXME: egl/x11 doesn't support front buffer rendering.");
}
const __DRIimageLoaderExtension dri3_image_loader_extension = {
.base = { __DRI_IMAGE_LOADER, 1 },
.base = {__DRI_IMAGE_LOADER, 1},
.getBuffers = loader_dri3_get_buffers,
.flushFrontBuffer = dri3_flush_front_buffer,
.getBuffers = loader_dri3_get_buffers,
.flushFrontBuffer = dri3_flush_front_buffer,
};
static EGLBoolean
@ -444,10 +438,9 @@ dri3_swap_buffers_with_damage(_EGLDisplay *disp, _EGLSurface *draw,
{
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(draw);
return loader_dri3_swap_buffers_msc(&dri3_surf->loader_drawable,
0, 0, 0, 0,
rects, n_rects,
draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1;
return loader_dri3_swap_buffers_msc(
&dri3_surf->loader_drawable, 0, 0, 0, 0, rects, n_rects,
draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1;
}
static EGLBoolean
@ -457,13 +450,14 @@ dri3_swap_buffers(_EGLDisplay *disp, _EGLSurface *draw)
}
static EGLBoolean
dri3_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf, void *native_pixmap_target)
dri3_copy_buffers(_EGLDisplay *disp, _EGLSurface *surf,
void *native_pixmap_target)
{
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf);
xcb_pixmap_t target;
STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_pixmap_target));
target = (uintptr_t) native_pixmap_target;
target = (uintptr_t)native_pixmap_target;
loader_dri3_copy_drawable(&dri3_surf->loader_drawable, target,
dri3_surf->loader_drawable.drawable);
@ -480,8 +474,8 @@ dri3_query_buffer_age(_EGLDisplay *disp, _EGLSurface *surf)
}
static EGLBoolean
dri3_query_surface(_EGLDisplay *disp, _EGLSurface *surf,
EGLint attribute, EGLint *value)
dri3_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
EGLint *value)
{
struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf);
@ -533,15 +527,15 @@ struct dri2_egl_display_vtbl dri3_x11_display_vtbl = {
};
/* Only request versions of these protocols which we actually support. */
#define DRI3_SUPPORTED_MAJOR 1
#define DRI3_SUPPORTED_MAJOR 1
#define PRESENT_SUPPORTED_MAJOR 1
#ifdef HAVE_DRI3_MODIFIERS
#define DRI3_SUPPORTED_MINOR 2
#define DRI3_SUPPORTED_MINOR 2
#define PRESENT_SUPPORTED_MINOR 2
#else
#define PRESENT_SUPPORTED_MINOR 0
#define DRI3_SUPPORTED_MINOR 0
#define DRI3_SUPPORTED_MINOR 0
#endif
EGLBoolean
@ -556,9 +550,9 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
xcb_generic_error_t *error;
const xcb_query_extension_reply_t *extension;
xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_dri3_id);
xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_present_id);
xcb_prefetch_extension_data (dri2_dpy->conn, &xcb_xfixes_id);
xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_dri3_id);
xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_present_id);
xcb_prefetch_extension_data(dri2_dpy->conn, &xcb_xfixes_id);
extension = xcb_get_extension_data(dri2_dpy->conn, &xcb_dri3_id);
if (!(extension && extension->present))
@ -572,17 +566,14 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
if (!(extension && extension->present))
return EGL_FALSE;
dri3_query_cookie = xcb_dri3_query_version(dri2_dpy->conn,
DRI3_SUPPORTED_MAJOR,
DRI3_SUPPORTED_MINOR);
dri3_query_cookie = xcb_dri3_query_version(
dri2_dpy->conn, DRI3_SUPPORTED_MAJOR, DRI3_SUPPORTED_MINOR);
present_query_cookie = xcb_present_query_version(dri2_dpy->conn,
PRESENT_SUPPORTED_MAJOR,
PRESENT_SUPPORTED_MINOR);
present_query_cookie = xcb_present_query_version(
dri2_dpy->conn, PRESENT_SUPPORTED_MAJOR, PRESENT_SUPPORTED_MINOR);
xfixes_query_cookie = xcb_xfixes_query_version(dri2_dpy->conn,
XCB_XFIXES_MAJOR_VERSION,
XCB_XFIXES_MINOR_VERSION);
xfixes_query_cookie = xcb_xfixes_query_version(
dri2_dpy->conn, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
dri3_query =
xcb_dri3_query_version_reply(dri2_dpy->conn, dri3_query_cookie, &error);
@ -597,9 +588,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
dri2_dpy->dri3_minor_version = dri3_query->minor_version;
free(dri3_query);
present_query =
xcb_present_query_version_reply(dri2_dpy->conn,
present_query_cookie, &error);
present_query = xcb_present_query_version_reply(
dri2_dpy->conn, present_query_cookie, &error);
if (present_query == NULL || error != NULL) {
_eglLog(_EGL_WARNING, "DRI3: failed to query Present version");
free(present_query);
@ -611,9 +601,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
dri2_dpy->present_minor_version = present_query->minor_version;
free(present_query);
xfixes_query =
xcb_xfixes_query_version_reply(dri2_dpy->conn,
xfixes_query_cookie, &error);
xfixes_query = xcb_xfixes_query_version_reply(dri2_dpy->conn,
xfixes_query_cookie, &error);
if (xfixes_query == NULL || error != NULL ||
xfixes_query->major_version < 2) {
_eglLog(_EGL_WARNING, "DRI3: failed to query xfixes version");
@ -623,7 +612,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
}
free(xfixes_query);
dri2_dpy->fd_render_gpu = loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0);
dri2_dpy->fd_render_gpu =
loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0);
if (dri2_dpy->fd_render_gpu < 0) {
int conn_error = xcb_connection_has_error(dri2_dpy->conn);
_eglLog(_EGL_WARNING, "DRI3: Screen seems not DRI3 capable");
@ -634,7 +624,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
return EGL_FALSE;
}
loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu, &dri2_dpy->fd_display_gpu);
loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu,
&dri2_dpy->fd_display_gpu);
dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd_render_gpu);
if (!dri2_dpy->driver_name) {
@ -647,7 +638,8 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
/* Only try to get a render device name since dri3 doesn't provide a
* mechanism for authenticating client opened device node fds. If this
* fails then don't advertise the extension. */
dri2_dpy->device_name = drmGetRenderDeviceNameFromFd(dri2_dpy->fd_render_gpu);
dri2_dpy->device_name =
drmGetRenderDeviceNameFromFd(dri2_dpy->fd_render_gpu);
#endif
return EGL_TRUE;

View file

@ -22,8 +22,8 @@
* DEALINGS IN THE SOFTWARE.
*/
#include <errno.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
@ -31,20 +31,20 @@
#include "eglconfig.h"
#include "eglcontext.h"
#include "eglcurrent.h"
#include "egldevice.h"
#include "egldisplay.h"
#include "egldriver.h"
#include "eglcurrent.h"
#include "eglimage.h"
#include "egllog.h"
#include "eglsurface.h"
#include "eglimage.h"
#include "egltypedefs.h"
#include <mapi/glapi/glapi.h>
#include "util/u_atomic.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "state_tracker/st_context.h"
#include "util/u_atomic.h"
#include <mapi/glapi/glapi.h>
#include "hgl_context.h"
#include "hgl_sw_winsys.h"
@ -53,261 +53,260 @@ extern "C" {
#include "target-helpers/inline_sw_helper.h"
}
#define BGL_RGB 0
#define BGL_INDEX 1
#define BGL_SINGLE 0
#define BGL_DOUBLE 2
#define BGL_DIRECT 0
#define BGL_INDIRECT 4
#define BGL_ACCUM 8
#define BGL_ALPHA 16
#define BGL_DEPTH 32
#define BGL_OVERLAY 64
#define BGL_UNDERLAY 128
#define BGL_STENCIL 512
#define BGL_SHARE_CONTEXT 1024
#define BGL_RGB 0
#define BGL_INDEX 1
#define BGL_SINGLE 0
#define BGL_DOUBLE 2
#define BGL_DIRECT 0
#define BGL_INDIRECT 4
#define BGL_ACCUM 8
#define BGL_ALPHA 16
#define BGL_DEPTH 32
#define BGL_OVERLAY 64
#define BGL_UNDERLAY 128
#define BGL_STENCIL 512
#define BGL_SHARE_CONTEXT 1024
#ifdef DEBUG
# define TRACE(x...) printf("egl_haiku: " x)
# define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
#define TRACE(x...) printf("egl_haiku: " x)
#define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
#else
# define TRACE(x...)
# define CALLED()
#define TRACE(x...)
#define CALLED()
#endif
#define ERROR(x...) printf("egl_haiku: " x)
_EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl)
struct haiku_egl_display {
int ref_count;
struct hgl_display *disp;
int ref_count;
struct hgl_display *disp;
};
struct haiku_egl_config {
_EGLConfig base;
_EGLConfig base;
};
struct haiku_egl_context {
_EGLContext base;
struct hgl_context *ctx;
_EGLContext base;
struct hgl_context *ctx;
};
struct haiku_egl_surface {
_EGLSurface base;
struct hgl_buffer *fb;
struct pipe_fence_handle *throttle_fence;
_EGLSurface base;
struct hgl_buffer *fb;
struct pipe_fence_handle *throttle_fence;
};
// #pragma mark EGLSurface
// Called via eglCreateWindowSurface(), drv->CreateWindowSurface().
static _EGLSurface *
haiku_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_window, const EGLint *attrib_list)
haiku_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_window, const EGLint *attrib_list)
{
printf("haiku_create_window_surface\n");
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
printf("haiku_create_window_surface\n");
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct haiku_egl_surface *wgl_surf = (struct haiku_egl_surface*)calloc(1, sizeof(*wgl_surf));
if (!wgl_surf)
return NULL;
struct haiku_egl_surface *wgl_surf =
(struct haiku_egl_surface *)calloc(1, sizeof(*wgl_surf));
if (!wgl_surf)
return NULL;
if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf, attrib_list, NULL)) {
free(wgl_surf);
return NULL;
}
if (!_eglInitSurface(&wgl_surf->base, disp, EGL_WINDOW_BIT, conf,
attrib_list, NULL)) {
free(wgl_surf);
return NULL;
}
struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE|BGL_DEPTH);
struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH);
wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, native_window);
if (!wgl_surf->fb) {
free(wgl_surf);
return NULL;
}
wgl_surf->fb =
hgl_create_st_framebuffer(hgl_dpy->disp, &visual, native_window);
if (!wgl_surf->fb) {
free(wgl_surf);
return NULL;
}
return &wgl_surf->base;
return &wgl_surf->base;
}
static _EGLSurface *
haiku_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf, void *native_pixmap, const EGLint *attrib_list)
haiku_create_pixmap_surface(_EGLDisplay *disp, _EGLConfig *conf,
void *native_pixmap, const EGLint *attrib_list)
{
printf("haiku_create_pixmap_surface\n");
return NULL;
printf("haiku_create_pixmap_surface\n");
return NULL;
}
static _EGLSurface *
haiku_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf, const EGLint *attrib_list)
haiku_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
const EGLint *attrib_list)
{
printf("haiku_create_pbuffer_surface\n");
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
printf("haiku_create_pbuffer_surface\n");
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct haiku_egl_surface *wgl_surf = (struct haiku_egl_surface*)calloc(1, sizeof(*wgl_surf));
if (!wgl_surf)
return NULL;
struct haiku_egl_surface *wgl_surf =
(struct haiku_egl_surface *)calloc(1, sizeof(*wgl_surf));
if (!wgl_surf)
return NULL;
if (!_eglInitSurface(&wgl_surf->base, disp, EGL_PBUFFER_BIT, conf, attrib_list, NULL)) {
free(wgl_surf);
return NULL;
}
if (!_eglInitSurface(&wgl_surf->base, disp, EGL_PBUFFER_BIT, conf,
attrib_list, NULL)) {
free(wgl_surf);
return NULL;
}
struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH);
struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE|BGL_DEPTH);
wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, NULL);
if (!wgl_surf->fb) {
free(wgl_surf);
return NULL;
}
wgl_surf->fb = hgl_create_st_framebuffer(hgl_dpy->disp, &visual, NULL);
if (!wgl_surf->fb) {
free(wgl_surf);
return NULL;
}
wgl_surf->fb->newWidth = wgl_surf->base.Width;
wgl_surf->fb->newHeight = wgl_surf->base.Height;
p_atomic_inc(&wgl_surf->fb->base.stamp);
wgl_surf->fb->newWidth = wgl_surf->base.Width;
wgl_surf->fb->newHeight = wgl_surf->base.Height;
p_atomic_inc(&wgl_surf->fb->base.stamp);
return &wgl_surf->base;
return &wgl_surf->base;
}
static EGLBoolean
haiku_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
{
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
if (_eglPutSurface(surf)) {
struct haiku_egl_surface *hgl_surf = haiku_egl_surface(surf);
struct pipe_screen* screen = hgl_dpy->disp->fscreen->screen;
screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL);
hgl_destroy_st_framebuffer(hgl_surf->fb);
free(surf);
}
return EGL_TRUE;
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
if (_eglPutSurface(surf)) {
struct haiku_egl_surface *hgl_surf = haiku_egl_surface(surf);
struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen;
screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL);
hgl_destroy_st_framebuffer(hgl_surf->fb);
free(surf);
}
return EGL_TRUE;
}
static void
update_size(struct hgl_buffer *buffer)
{
uint32_t newWidth, newHeight;
((BitmapHook*)buffer->winsysContext)->GetSize(newWidth, newHeight);
if (buffer->newWidth != newWidth || buffer->newHeight != newHeight) {
buffer->newWidth = newWidth;
buffer->newHeight = newHeight;
p_atomic_inc(&buffer->base.stamp);
}
uint32_t newWidth, newHeight;
((BitmapHook *)buffer->winsysContext)->GetSize(newWidth, newHeight);
if (buffer->newWidth != newWidth || buffer->newHeight != newHeight) {
buffer->newWidth = newWidth;
buffer->newHeight = newHeight;
p_atomic_inc(&buffer->base.stamp);
}
}
static EGLBoolean
haiku_swap_buffers(_EGLDisplay *disp, _EGLSurface *surf)
{
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct haiku_egl_surface* hgl_surf = haiku_egl_surface(surf);
struct haiku_egl_context* hgl_ctx = haiku_egl_context(surf->CurrentContext);
if (hgl_ctx == NULL)
return EGL_FALSE;
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct haiku_egl_surface *hgl_surf = haiku_egl_surface(surf);
struct haiku_egl_context *hgl_ctx = haiku_egl_context(surf->CurrentContext);
if (hgl_ctx == NULL)
return EGL_FALSE;
struct st_context *st = hgl_ctx->ctx->st;
struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen;
struct st_context *st = hgl_ctx->ctx->st;
struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen;
struct hgl_buffer* buffer = hgl_surf->fb;
auto &frontBuffer = buffer->textures[ST_ATTACHMENT_FRONT_LEFT];
auto &backBuffer = buffer->textures[ST_ATTACHMENT_BACK_LEFT];
struct hgl_buffer *buffer = hgl_surf->fb;
auto &frontBuffer = buffer->textures[ST_ATTACHMENT_FRONT_LEFT];
auto &backBuffer = buffer->textures[ST_ATTACHMENT_BACK_LEFT];
// Inform ST of a flush if double buffering is used
if (backBuffer != NULL)
st->pipe->flush_resource(st->pipe, backBuffer);
// Inform ST of a flush if double buffering is used
if (backBuffer != NULL)
st->pipe->flush_resource(st->pipe, backBuffer);
_mesa_glthread_finish(st->ctx);
_mesa_glthread_finish(st->ctx);
struct pipe_fence_handle *new_fence = NULL;
st_context_flush(st, ST_FLUSH_FRONT, &new_fence, NULL, NULL);
if (hgl_surf->throttle_fence) {
screen->fence_finish(screen, NULL, hgl_surf->throttle_fence, OS_TIMEOUT_INFINITE);
screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL);
}
hgl_surf->throttle_fence = new_fence;
struct pipe_fence_handle *new_fence = NULL;
st_context_flush(st, ST_FLUSH_FRONT, &new_fence, NULL, NULL);
if (hgl_surf->throttle_fence) {
screen->fence_finish(screen, NULL, hgl_surf->throttle_fence,
OS_TIMEOUT_INFINITE);
screen->fence_reference(screen, &hgl_surf->throttle_fence, NULL);
}
hgl_surf->throttle_fence = new_fence;
// flush back buffer and swap buffers if double buffering is used
if (backBuffer != NULL) {
screen->flush_frontbuffer(screen, st->pipe, backBuffer, 0, 0, buffer->winsysContext, NULL);
std::swap(frontBuffer, backBuffer);
p_atomic_inc(&buffer->base.stamp);
}
// flush back buffer and swap buffers if double buffering is used
if (backBuffer != NULL) {
screen->flush_frontbuffer(screen, st->pipe, backBuffer, 0, 0,
buffer->winsysContext, NULL);
std::swap(frontBuffer, backBuffer);
p_atomic_inc(&buffer->base.stamp);
}
// XXX: right front / back if BGL_STEREO?
// XXX: right front / back if BGL_STEREO?
update_size(buffer);
update_size(buffer);
return EGL_TRUE;
return EGL_TRUE;
}
// #pragma mark EGLDisplay
static EGLBoolean
haiku_add_configs_for_visuals(_EGLDisplay *disp)
{
CALLED();
CALLED();
struct haiku_egl_config* conf;
conf = (struct haiku_egl_config*) calloc(1, sizeof (*conf));
if (!conf)
return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals");
struct haiku_egl_config *conf;
conf = (struct haiku_egl_config *)calloc(1, sizeof(*conf));
if (!conf)
return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals");
_eglInitConfig(&conf->base, disp, 1);
TRACE("Config inited\n");
_eglInitConfig(&conf->base, disp, 1);
TRACE("Config inited\n");
conf->base.RedSize = 8;
conf->base.BlueSize = 8;
conf->base.GreenSize = 8;
conf->base.LuminanceSize = 0;
conf->base.AlphaSize = 8;
conf->base.ColorBufferType = EGL_RGB_BUFFER;
conf->base.BufferSize = conf->base.RedSize
+ conf->base.GreenSize
+ conf->base.BlueSize
+ conf->base.AlphaSize;
conf->base.ConfigCaveat = EGL_NONE;
conf->base.ConfigID = 1;
conf->base.BindToTextureRGB = EGL_FALSE;
conf->base.BindToTextureRGBA = EGL_FALSE;
conf->base.StencilSize = 0;
conf->base.TransparentType = EGL_NONE;
conf->base.NativeRenderable = EGL_TRUE; // Let's say yes
conf->base.NativeVisualID = 0; // No visual
conf->base.NativeVisualType = EGL_NONE; // No visual
conf->base.RenderableType = 0x8;
conf->base.SampleBuffers = 0; // TODO: How to get the right value ?
conf->base.Samples = conf->base.SampleBuffers == 0 ? 0 : 0;
conf->base.DepthSize = 24; // TODO: How to get the right value ?
conf->base.Level = 0;
conf->base.MaxPbufferWidth = _EGL_MAX_PBUFFER_WIDTH;
conf->base.MaxPbufferHeight = _EGL_MAX_PBUFFER_HEIGHT;
conf->base.MaxPbufferPixels = 0; // TODO: How to get the right value ?
conf->base.SurfaceType = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT;
conf->base.RedSize = 8;
conf->base.BlueSize = 8;
conf->base.GreenSize = 8;
conf->base.LuminanceSize = 0;
conf->base.AlphaSize = 8;
conf->base.ColorBufferType = EGL_RGB_BUFFER;
conf->base.BufferSize = conf->base.RedSize + conf->base.GreenSize +
conf->base.BlueSize + conf->base.AlphaSize;
conf->base.ConfigCaveat = EGL_NONE;
conf->base.ConfigID = 1;
conf->base.BindToTextureRGB = EGL_FALSE;
conf->base.BindToTextureRGBA = EGL_FALSE;
conf->base.StencilSize = 0;
conf->base.TransparentType = EGL_NONE;
conf->base.NativeRenderable = EGL_TRUE; // Let's say yes
conf->base.NativeVisualID = 0; // No visual
conf->base.NativeVisualType = EGL_NONE; // No visual
conf->base.RenderableType = 0x8;
conf->base.SampleBuffers = 0; // TODO: How to get the right value ?
conf->base.Samples = conf->base.SampleBuffers == 0 ? 0 : 0;
conf->base.DepthSize = 24; // TODO: How to get the right value ?
conf->base.Level = 0;
conf->base.MaxPbufferWidth = _EGL_MAX_PBUFFER_WIDTH;
conf->base.MaxPbufferHeight = _EGL_MAX_PBUFFER_HEIGHT;
conf->base.MaxPbufferPixels = 0; // TODO: How to get the right value ?
conf->base.SurfaceType = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT;
TRACE("Config configuated\n");
if (!_eglValidateConfig(&conf->base, EGL_FALSE)) {
_eglLog(_EGL_DEBUG, "Haiku: failed to validate config");
goto cleanup;
}
TRACE("Validated config\n");
TRACE("Config configuated\n");
if (!_eglValidateConfig(&conf->base, EGL_FALSE)) {
_eglLog(_EGL_DEBUG, "Haiku: failed to validate config");
goto cleanup;
}
TRACE("Validated config\n");
_eglLinkConfig(&conf->base);
if (!_eglGetArraySize(disp->Configs)) {
_eglLog(_EGL_WARNING, "Haiku: failed to create any config");
goto cleanup;
}
TRACE("Config successful\n");
_eglLinkConfig(&conf->base);
if (!_eglGetArraySize(disp->Configs)) {
_eglLog(_EGL_WARNING, "Haiku: failed to create any config");
goto cleanup;
}
TRACE("Config successful\n");
return EGL_TRUE;
return EGL_TRUE;
cleanup:
free(conf);
return EGL_FALSE;
free(conf);
return EGL_FALSE;
}
static void
@ -316,209 +315,212 @@ haiku_display_destroy(_EGLDisplay *disp)
if (!disp)
return;
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
assert(hgl_dpy->ref_count > 0);
if (!p_atomic_dec_zero(&hgl_dpy->ref_count))
return;
struct pipe_screen* screen = hgl_dpy->disp->fscreen->screen;
hgl_destroy_display(hgl_dpy->disp); hgl_dpy->disp = NULL;
screen->destroy(screen); // destroy will deallocate object
struct pipe_screen *screen = hgl_dpy->disp->fscreen->screen;
hgl_destroy_display(hgl_dpy->disp);
hgl_dpy->disp = NULL;
screen->destroy(screen); // destroy will deallocate object
free(hgl_dpy);
free(hgl_dpy);
}
static EGLBoolean
haiku_initialize_impl(_EGLDisplay *disp, void *platformDisplay)
{
struct haiku_egl_display *hgl_dpy;
const char* err;
struct haiku_egl_display *hgl_dpy;
const char *err;
hgl_dpy = (struct haiku_egl_display*)calloc(1, sizeof(struct haiku_egl_display));
if (!hgl_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
hgl_dpy =
(struct haiku_egl_display *)calloc(1, sizeof(struct haiku_egl_display));
if (!hgl_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
hgl_dpy->ref_count = 1;
disp->DriverData = (void *)hgl_dpy;
hgl_dpy->ref_count = 1;
disp->DriverData = (void *)hgl_dpy;
struct sw_winsys* winsys = hgl_create_sw_winsys();
struct pipe_screen* screen = sw_screen_create(winsys);
hgl_dpy->disp = hgl_create_display(screen);
struct sw_winsys *winsys = hgl_create_sw_winsys();
struct pipe_screen *screen = sw_screen_create(winsys);
hgl_dpy->disp = hgl_create_display(screen);
disp->ClientAPIs = 0;
if (_eglIsApiValid(EGL_OPENGL_API))
disp->ClientAPIs |= EGL_OPENGL_BIT;
if (_eglIsApiValid(EGL_OPENGL_ES_API))
disp->ClientAPIs |= EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR;
disp->ClientAPIs = 0;
if (_eglIsApiValid(EGL_OPENGL_API))
disp->ClientAPIs |= EGL_OPENGL_BIT;
if (_eglIsApiValid(EGL_OPENGL_ES_API))
disp->ClientAPIs |=
EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT | EGL_OPENGL_ES3_BIT_KHR;
disp->Extensions.KHR_no_config_context = EGL_TRUE;
disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
disp->Extensions.MESA_query_driver = EGL_TRUE;
disp->Extensions.KHR_no_config_context = EGL_TRUE;
disp->Extensions.KHR_surfaceless_context = EGL_TRUE;
disp->Extensions.MESA_query_driver = EGL_TRUE;
/* Report back to EGL the bitmask of priorities supported */
disp->Extensions.IMG_context_priority =
hgl_dpy->disp->fscreen->screen->get_param(hgl_dpy->disp->fscreen->screen, PIPE_CAP_CONTEXT_PRIORITY_MASK);
/* Report back to EGL the bitmask of priorities supported */
disp->Extensions.IMG_context_priority =
hgl_dpy->disp->fscreen->screen->get_param(hgl_dpy->disp->fscreen->screen,
PIPE_CAP_CONTEXT_PRIORITY_MASK);
disp->Extensions.EXT_pixel_format_float = EGL_TRUE;
disp->Extensions.EXT_pixel_format_float = EGL_TRUE;
if (hgl_dpy->disp->fscreen->screen->is_format_supported(hgl_dpy->disp->fscreen->screen,
PIPE_FORMAT_B8G8R8A8_SRGB,
PIPE_TEXTURE_2D, 0, 0,
PIPE_BIND_RENDER_TARGET))
disp->Extensions.KHR_gl_colorspace = EGL_TRUE;
if (hgl_dpy->disp->fscreen->screen->is_format_supported(
hgl_dpy->disp->fscreen->screen, PIPE_FORMAT_B8G8R8A8_SRGB,
PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_RENDER_TARGET))
disp->Extensions.KHR_gl_colorspace = EGL_TRUE;
disp->Extensions.KHR_create_context = EGL_TRUE;
disp->Extensions.KHR_reusable_sync = EGL_TRUE;
disp->Extensions.KHR_create_context = EGL_TRUE;
disp->Extensions.KHR_reusable_sync = EGL_TRUE;
haiku_add_configs_for_visuals(disp);
haiku_add_configs_for_visuals(disp);
return EGL_TRUE;
return EGL_TRUE;
cleanup:
haiku_display_destroy(disp);
return _eglError(EGL_NOT_INITIALIZED, err);
haiku_display_destroy(disp);
return _eglError(EGL_NOT_INITIALIZED, err);
}
static EGLBoolean
haiku_initialize(_EGLDisplay *disp)
{
EGLBoolean ret = EGL_FALSE;
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
EGLBoolean ret = EGL_FALSE;
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
if (hgl_dpy) {
hgl_dpy->ref_count++;
return EGL_TRUE;
}
if (hgl_dpy) {
hgl_dpy->ref_count++;
return EGL_TRUE;
}
switch (disp->Platform) {
case _EGL_PLATFORM_SURFACELESS:
case _EGL_PLATFORM_HAIKU:
ret = haiku_initialize_impl(disp, NULL);
break;
case _EGL_PLATFORM_DEVICE:
ret = haiku_initialize_impl(disp, disp->PlatformDisplay);
break;
default:
unreachable("Callers ensure we cannot get here.");
return EGL_FALSE;
}
switch (disp->Platform) {
case _EGL_PLATFORM_SURFACELESS:
case _EGL_PLATFORM_HAIKU:
ret = haiku_initialize_impl(disp, NULL);
break;
case _EGL_PLATFORM_DEVICE:
ret = haiku_initialize_impl(disp, disp->PlatformDisplay);
break;
default:
unreachable("Callers ensure we cannot get here.");
return EGL_FALSE;
}
if (!ret)
return EGL_FALSE;
if (!ret)
return EGL_FALSE;
hgl_dpy = haiku_egl_display(disp);
hgl_dpy = haiku_egl_display(disp);
return EGL_TRUE;
return EGL_TRUE;
}
static EGLBoolean
haiku_terminate(_EGLDisplay *disp)
{
haiku_display_destroy(disp);
return EGL_TRUE;
haiku_display_destroy(disp);
return EGL_TRUE;
}
// #pragma mark EGLContext
static _EGLContext*
static _EGLContext *
haiku_create_context(_EGLDisplay *disp, _EGLConfig *conf,
_EGLContext *share_list, const EGLint *attrib_list)
_EGLContext *share_list, const EGLint *attrib_list)
{
CALLED();
CALLED();
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct haiku_egl_display *hgl_dpy = haiku_egl_display(disp);
struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE|BGL_DEPTH);
struct st_visual visual;
hgl_get_st_visual(&visual, BGL_DOUBLE | BGL_DEPTH);
struct haiku_egl_context* context = (struct haiku_egl_context*) calloc(1, sizeof (*context));
if (!context) {
_eglError(EGL_BAD_ALLOC, "haiku_create_context");
return NULL;
}
struct haiku_egl_context *context =
(struct haiku_egl_context *)calloc(1, sizeof(*context));
if (!context) {
_eglError(EGL_BAD_ALLOC, "haiku_create_context");
return NULL;
}
if (!_eglInitContext(&context->base, disp, conf, share_list, attrib_list))
goto cleanup;
if (!_eglInitContext(&context->base, disp, conf, share_list, attrib_list))
goto cleanup;
context->ctx = hgl_create_context(hgl_dpy->disp, &visual, share_list == NULL ? NULL : haiku_egl_context(share_list)->ctx->st);
if (context->ctx == NULL)
goto cleanup;
context->ctx = hgl_create_context(
hgl_dpy->disp, &visual,
share_list == NULL ? NULL : haiku_egl_context(share_list)->ctx->st);
if (context->ctx == NULL)
goto cleanup;
return &context->base;
return &context->base;
cleanup:
free(context);
return NULL;
free(context);
return NULL;
}
static EGLBoolean
haiku_destroy_context(_EGLDisplay *disp, _EGLContext* ctx)
haiku_destroy_context(_EGLDisplay *disp, _EGLContext *ctx)
{
if (_eglPutContext(ctx)) {
struct haiku_egl_context* hgl_ctx = haiku_egl_context(ctx);
hgl_destroy_context(hgl_ctx->ctx);
free(ctx);
ctx = NULL;
}
return EGL_TRUE;
if (_eglPutContext(ctx)) {
struct haiku_egl_context *hgl_ctx = haiku_egl_context(ctx);
hgl_destroy_context(hgl_ctx->ctx);
free(ctx);
ctx = NULL;
}
return EGL_TRUE;
}
static EGLBoolean
haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf, _EGLContext *ctx)
haiku_make_current(_EGLDisplay *disp, _EGLSurface *dsurf, _EGLSurface *rsurf,
_EGLContext *ctx)
{
CALLED();
CALLED();
struct haiku_egl_context* hgl_ctx = haiku_egl_context(ctx);
struct haiku_egl_surface* hgl_dsurf = haiku_egl_surface(dsurf);
struct haiku_egl_surface* hgl_rsurf = haiku_egl_surface(rsurf);
_EGLContext *old_ctx;
_EGLSurface *old_dsurf, *old_rsurf;
struct haiku_egl_context *hgl_ctx = haiku_egl_context(ctx);
struct haiku_egl_surface *hgl_dsurf = haiku_egl_surface(dsurf);
struct haiku_egl_surface *hgl_rsurf = haiku_egl_surface(rsurf);
_EGLContext *old_ctx;
_EGLSurface *old_dsurf, *old_rsurf;
if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
return EGL_FALSE;
if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
return EGL_FALSE;
if (old_ctx == ctx && old_dsurf == dsurf && old_rsurf == rsurf) {
_eglPutSurface(old_dsurf);
_eglPutSurface(old_rsurf);
_eglPutContext(old_ctx);
return EGL_TRUE;
}
if (old_ctx == ctx && old_dsurf == dsurf && old_rsurf == rsurf) {
_eglPutSurface(old_dsurf);
_eglPutSurface(old_rsurf);
_eglPutContext(old_ctx);
return EGL_TRUE;
}
if (ctx == NULL) {
st_api_make_current(NULL, NULL, NULL);
} else {
if (dsurf != NULL && dsurf != old_dsurf)
update_size(hgl_dsurf->fb);
if (ctx == NULL) {
st_api_make_current(NULL, NULL, NULL);
} else {
if (dsurf != NULL && dsurf != old_dsurf)
update_size(hgl_dsurf->fb);
st_api_make_current(hgl_ctx->ctx->st,
hgl_dsurf == NULL ? NULL : &hgl_dsurf->fb->base,
hgl_rsurf == NULL ? NULL : &hgl_rsurf->fb->base);
}
st_api_make_current(hgl_ctx->ctx->st,
hgl_dsurf == NULL ? NULL : &hgl_dsurf->fb->base,
hgl_rsurf == NULL ? NULL : &hgl_rsurf->fb->base);
}
if (old_dsurf != NULL) haiku_destroy_surface(disp, old_dsurf);
if (old_rsurf != NULL) haiku_destroy_surface(disp, old_rsurf);
if (old_ctx != NULL) haiku_destroy_context(disp, old_ctx);
if (old_dsurf != NULL)
haiku_destroy_surface(disp, old_dsurf);
if (old_rsurf != NULL)
haiku_destroy_surface(disp, old_rsurf);
if (old_ctx != NULL)
haiku_destroy_context(disp, old_ctx);
return EGL_TRUE;
return EGL_TRUE;
}
extern "C"
const _EGLDriver _eglDriver = {
.Initialize = haiku_initialize,
.Terminate = haiku_terminate,
.CreateContext = haiku_create_context,
.DestroyContext = haiku_destroy_context,
.MakeCurrent = haiku_make_current,
.CreateWindowSurface = haiku_create_window_surface,
.CreatePixmapSurface = haiku_create_pixmap_surface,
.CreatePbufferSurface = haiku_create_pbuffer_surface,
.DestroySurface = haiku_destroy_surface,
.SwapBuffers = haiku_swap_buffers,
extern "C" const _EGLDriver _eglDriver = {
.Initialize = haiku_initialize,
.Terminate = haiku_terminate,
.CreateContext = haiku_create_context,
.DestroyContext = haiku_destroy_context,
.MakeCurrent = haiku_make_current,
.CreateWindowSurface = haiku_create_window_surface,
.CreatePixmapSurface = haiku_create_pixmap_surface,
.CreatePbufferSurface = haiku_create_pbuffer_surface,
.DestroySurface = haiku_destroy_surface,
.SwapBuffers = haiku_swap_buffers,
};

View file

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

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

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

View file

@ -27,25 +27,21 @@
*
**************************************************************************/
#ifndef EGLCONFIG_INCLUDED
#define EGLCONFIG_INCLUDED
#include <assert.h>
#include <stddef.h>
#include "egltypedefs.h"
#ifdef __cplusplus
extern "C" {
#endif
/* update _eglValidationTable and _eglOffsetOfConfig before updating this
* struct */
struct _egl_config
{
struct _egl_config {
_EGLDisplay *Display;
/* core */
@ -90,7 +86,6 @@ struct _egl_config
EGLint ComponentType;
};
/**
* Map an EGL attribute enum to the offset of the member in _EGLConfig.
*/
@ -98,53 +93,54 @@ static inline EGLint
_eglOffsetOfConfig(EGLint attr)
{
switch (attr) {
#define ATTRIB_MAP(attr, memb) case attr: return offsetof(_EGLConfig, memb)
/* core */
ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize);
ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize);
ATTRIB_MAP(EGL_RED_SIZE, RedSize);
ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize);
ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize);
ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat);
ATTRIB_MAP(EGL_CONFIG_ID, ConfigID);
ATTRIB_MAP(EGL_LEVEL, Level);
ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight);
ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels);
ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth);
ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable);
ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID);
ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType);
ATTRIB_MAP(EGL_SAMPLES, Samples);
ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers);
ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType);
ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType);
ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue);
ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue);
ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue);
ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB);
ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA);
ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval);
ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval);
ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize);
ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize);
ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType);
ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType);
ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap);
ATTRIB_MAP(EGL_CONFORMANT, Conformant);
/* extensions */
ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK);
ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
ATTRIB_MAP(EGL_RECORDABLE_ANDROID, RecordableAndroid);
ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT, ComponentType);
#define ATTRIB_MAP(attr, memb) \
case attr: \
return offsetof(_EGLConfig, memb)
/* core */
ATTRIB_MAP(EGL_BUFFER_SIZE, BufferSize);
ATTRIB_MAP(EGL_ALPHA_SIZE, AlphaSize);
ATTRIB_MAP(EGL_BLUE_SIZE, BlueSize);
ATTRIB_MAP(EGL_GREEN_SIZE, GreenSize);
ATTRIB_MAP(EGL_RED_SIZE, RedSize);
ATTRIB_MAP(EGL_DEPTH_SIZE, DepthSize);
ATTRIB_MAP(EGL_STENCIL_SIZE, StencilSize);
ATTRIB_MAP(EGL_CONFIG_CAVEAT, ConfigCaveat);
ATTRIB_MAP(EGL_CONFIG_ID, ConfigID);
ATTRIB_MAP(EGL_LEVEL, Level);
ATTRIB_MAP(EGL_MAX_PBUFFER_HEIGHT, MaxPbufferHeight);
ATTRIB_MAP(EGL_MAX_PBUFFER_PIXELS, MaxPbufferPixels);
ATTRIB_MAP(EGL_MAX_PBUFFER_WIDTH, MaxPbufferWidth);
ATTRIB_MAP(EGL_NATIVE_RENDERABLE, NativeRenderable);
ATTRIB_MAP(EGL_NATIVE_VISUAL_ID, NativeVisualID);
ATTRIB_MAP(EGL_NATIVE_VISUAL_TYPE, NativeVisualType);
ATTRIB_MAP(EGL_SAMPLES, Samples);
ATTRIB_MAP(EGL_SAMPLE_BUFFERS, SampleBuffers);
ATTRIB_MAP(EGL_SURFACE_TYPE, SurfaceType);
ATTRIB_MAP(EGL_TRANSPARENT_TYPE, TransparentType);
ATTRIB_MAP(EGL_TRANSPARENT_BLUE_VALUE, TransparentBlueValue);
ATTRIB_MAP(EGL_TRANSPARENT_GREEN_VALUE, TransparentGreenValue);
ATTRIB_MAP(EGL_TRANSPARENT_RED_VALUE, TransparentRedValue);
ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGB, BindToTextureRGB);
ATTRIB_MAP(EGL_BIND_TO_TEXTURE_RGBA, BindToTextureRGBA);
ATTRIB_MAP(EGL_MIN_SWAP_INTERVAL, MinSwapInterval);
ATTRIB_MAP(EGL_MAX_SWAP_INTERVAL, MaxSwapInterval);
ATTRIB_MAP(EGL_LUMINANCE_SIZE, LuminanceSize);
ATTRIB_MAP(EGL_ALPHA_MASK_SIZE, AlphaMaskSize);
ATTRIB_MAP(EGL_COLOR_BUFFER_TYPE, ColorBufferType);
ATTRIB_MAP(EGL_RENDERABLE_TYPE, RenderableType);
ATTRIB_MAP(EGL_MATCH_NATIVE_PIXMAP, MatchNativePixmap);
ATTRIB_MAP(EGL_CONFORMANT, Conformant);
/* extensions */
ATTRIB_MAP(EGL_Y_INVERTED_NOK, YInvertedNOK);
ATTRIB_MAP(EGL_FRAMEBUFFER_TARGET_ANDROID, FramebufferTargetAndroid);
ATTRIB_MAP(EGL_RECORDABLE_ANDROID, RecordableAndroid);
ATTRIB_MAP(EGL_COLOR_COMPONENT_TYPE_EXT, ComponentType);
#undef ATTRIB_MAP
default:
return -1;
}
}
/**
* Update a config for a given key.
*
@ -157,10 +153,9 @@ _eglSetConfigKey(_EGLConfig *conf, EGLint key, EGLint val)
{
EGLint offset = _eglOffsetOfConfig(key);
assert(offset >= 0);
*((EGLint *) ((char *) conf + offset)) = val;
*((EGLint *)((char *)conf + offset)) = val;
}
/**
* Return the value for a given key.
*/
@ -169,70 +164,60 @@ _eglGetConfigKey(const _EGLConfig *conf, EGLint key)
{
EGLint offset = _eglOffsetOfConfig(key);
assert(offset >= 0);
return *((EGLint *) ((char *) conf + offset));
return *((EGLint *)((char *)conf + offset));
}
extern void
_eglInitConfig(_EGLConfig *config, _EGLDisplay *disp, EGLint id);
extern EGLConfig
_eglLinkConfig(_EGLConfig *conf);
extern _EGLConfig *
_eglLookupConfig(EGLConfig config, _EGLDisplay *disp);
/**
* Return the handle of a linked config.
*/
static inline EGLConfig
_eglGetConfigHandle(_EGLConfig *conf)
{
return (EGLConfig) conf;
return (EGLConfig)conf;
}
extern EGLBoolean
_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
extern EGLBoolean
_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
extern EGLBoolean
_eglParseConfigAttribList(_EGLConfig *conf, _EGLDisplay *disp,
const EGLint *attrib_list);
extern EGLint
_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
const _EGLConfig *criteria, EGLBoolean compare_id);
extern EGLBoolean
_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs,
EGLint config_size, EGLint *num_configs,
_eglFilterConfigArray(_EGLArray *array, EGLConfig *configs, EGLint config_size,
EGLint *num_configs,
EGLBoolean (*match)(const _EGLConfig *, void *),
EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
void *),
void *filter_data);
extern EGLBoolean
_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list,
EGLConfig *configs, EGLint config_size, EGLint *num_config);
extern EGLBoolean
_eglChooseConfig(_EGLDisplay *disp, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
_eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf,
EGLint attribute, EGLint *value);
extern EGLBoolean
_eglGetConfigAttrib(const _EGLDisplay *disp, const _EGLConfig *conf, EGLint attribute, EGLint *value);
extern EGLBoolean
_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size, EGLint *num_config);
_eglGetConfigs(_EGLDisplay *disp, EGLConfig *configs, EGLint config_size,
EGLint *num_config);
#ifdef __cplusplus
}

View file

@ -23,18 +23,18 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "util/macros.h"
#include "eglarray.h"
#include "eglconfig.h"
#include "eglconfigdebug.h"
#include "egldisplay.h"
#include "egllog.h"
#include "egltypedefs.h"
#include "util/macros.h"
/* Max debug message length */
#define CONFIG_DEBUG_MSG_MAX 1000
@ -43,7 +43,7 @@
* These are X visual types, so if you're running eglinfo under
* something not X, they probably don't make sense.
*/
static const char *const vnames[] = { "SG", "GS", "SC", "PC", "TC", "DC" };
static const char *const vnames[] = {"SG", "GS", "SC", "PC", "TC", "DC"};
static void
_printHeaderFormat(void)
@ -99,7 +99,7 @@ _strnAppend(char *const buf, const int bufSize, const char *fmt, ...)
assert(maxAllowed >= 0);
va_start(args, fmt);
(void) vsnprintf(&buf[bufLen], maxAllowed, fmt, args);
(void)vsnprintf(&buf[bufLen], maxAllowed, fmt, args);
va_end(args);
}
@ -136,10 +136,10 @@ _eglPrintConfig(_EGLConfig *const conf, const int chosenIndex)
_strnAppend(printMsg, sizeof(printMsg),
"0x%03x %2d %2d %2d %2d %2d %2d %2d %2d %2d%2d 0x%08x%2s ",
conf->ConfigID, conf->BufferSize, conf->Level,
conf->RedSize, conf->GreenSize, conf->BlueSize, conf->AlphaSize,
conf->DepthSize, conf->StencilSize,
conf->Samples, conf->SampleBuffers, conf->NativeVisualID,
conf->ConfigID, conf->BufferSize, conf->Level, conf->RedSize,
conf->GreenSize, conf->BlueSize, conf->AlphaSize,
conf->DepthSize, conf->StencilSize, conf->Samples,
conf->SampleBuffers, conf->NativeVisualID,
vtype < 6 ? vnames[vtype] : "--");
bindRgb = conf->BindToTextureRGB;
@ -149,20 +149,22 @@ _eglPrintConfig(_EGLConfig *const conf, const int chosenIndex)
_strnAppend(printMsg, sizeof(printMsg),
"%c %c %c %c %c %c %c %15s",
(conf->ConfigCaveat != EGL_NONE) ? 'y' : ' ',
(bindRgba) ? 'a' : (bindRgb) ? 'y' : ' ',
(bindRgba) ? 'a'
: (bindRgb) ? 'y'
: ' ',
(renderable & EGL_OPENGL_BIT) ? 'y' : ' ',
(renderable & EGL_OPENGL_ES_BIT) ? 'y' : ' ',
(renderable & EGL_OPENGL_ES2_BIT) ? 'y' : ' ',
(renderable & EGL_OPENGL_ES3_BIT) ? 'y' : ' ',
(renderable & EGL_OPENVG_BIT) ? 'y' : ' ',
surfString);
(renderable & EGL_OPENVG_BIT) ? 'y' : ' ', surfString);
_eglLog(_EGL_DEBUG, printMsg);
}
void eglPrintConfigDebug(const _EGLDisplay *const disp,
const EGLConfig *const configs,
const EGLint numConfigs, const EGLBoolean printChosen)
void
eglPrintConfigDebug(const _EGLDisplay *const disp,
const EGLConfig *const configs, const EGLint numConfigs,
const EGLBoolean printChosen)
{
EGLint numConfigsToPrint;
_EGLConfig **configsToPrint;
@ -178,11 +180,11 @@ void eglPrintConfigDebug(const _EGLDisplay *const disp,
* configs are printed, and the "chosen" configs are marked.
*/
if (printChosen) {
configsToPrint = (_EGLConfig **) disp->Configs->Elements;
configsToPrint = (_EGLConfig **)disp->Configs->Elements;
numConfigsToPrint = disp->Configs->Size;
chosenConfigs = (_EGLConfig **) configs;
chosenConfigs = (_EGLConfig **)configs;
} else {
configsToPrint = (_EGLConfig **) configs;
configsToPrint = (_EGLConfig **)configs;
numConfigsToPrint = numConfigs;
chosenConfigs = NULL;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,12 +25,10 @@
*
**************************************************************************/
/**
* Internal EGL defines
*/
#ifndef EGLDEFINES_INCLUDED
#define EGLDEFINES_INCLUDED
@ -43,7 +41,7 @@ extern "C" {
/* Hardcoded, conservative default for EGL_LARGEST_PBUFFER,
* this is used to implement EGL_LARGEST_PBUFFER.
*/
#define _EGL_MAX_PBUFFER_WIDTH 4096
#define _EGL_MAX_PBUFFER_WIDTH 4096
#define _EGL_MAX_PBUFFER_HEIGHT 4096
#define _EGL_VENDOR_STRING "Mesa Project"

View file

@ -33,11 +33,10 @@
#include "eglcurrent.h"
#include "egldevice.h"
#include "egllog.h"
#include "eglglobals.h"
#include "egllog.h"
#include "egltypedefs.h"
struct _egl_device {
_EGLDevice *Next;
@ -89,7 +88,7 @@ _eglCheckDeviceHandle(EGLDeviceEXT device)
simple_mtx_lock(_eglGlobal.Mutex);
cur = _eglGlobal.DeviceList;
while (cur) {
if (cur == (_EGLDevice *) device)
if (cur == (_EGLDevice *)device)
break;
cur = cur->Next;
}
@ -113,8 +112,8 @@ _eglAddDRMDevice(drmDevicePtr device, _EGLDevice **out_dev)
{
_EGLDevice *dev;
if ((device->available_nodes & (1 << DRM_NODE_PRIMARY |
1 << DRM_NODE_RENDER)) == 0)
if ((device->available_nodes &
(1 << DRM_NODE_PRIMARY | 1 << DRM_NODE_RENDER)) == 0)
return -1;
dev = _eglGlobal.DeviceList;
@ -189,7 +188,8 @@ _eglAddDevice(int fd, bool software)
if (_eglAddDRMDevice(device, &dev) != 0)
drmFreeDevice(&device);
#else
_eglLog(_EGL_FATAL, "Driver bug: Built without libdrm, yet looking for HW device");
_eglLog(_EGL_FATAL,
"Driver bug: Built without libdrm, yet looking for HW device");
dev = NULL;
#endif
@ -215,8 +215,7 @@ _eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext)
}
EGLBoolean
_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute,
EGLAttrib *value)
_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, EGLAttrib *value)
{
switch (attribute) {
default:
@ -304,8 +303,7 @@ _eglRefreshDeviceList(void)
}
EGLBoolean
_eglQueryDevicesEXT(EGLint max_devices,
_EGLDevice **devices,
_eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices,
EGLint *num_devices)
{
_EGLDevice *dev, *devs, *swrast;

View file

@ -25,11 +25,9 @@
*
**************************************************************************/
#ifndef EGLDEVICE_INCLUDED
#define EGLDEVICE_INCLUDED
#include <stdbool.h>
#include <stddef.h>
#include "egltypedefs.h"
@ -49,7 +47,7 @@ _eglCheckDeviceHandle(EGLDeviceEXT device);
static inline _EGLDevice *
_eglLookupDevice(EGLDeviceEXT device)
{
_EGLDevice *dev = (_EGLDevice *) device;
_EGLDevice *dev = (_EGLDevice *)device;
if (!_eglCheckDeviceHandle(device))
dev = NULL;
return dev;
@ -70,8 +68,7 @@ EGLBoolean
_eglDeviceSupports(_EGLDevice *dev, _EGLDeviceExtension ext);
EGLBoolean
_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute,
EGLAttrib *value);
_eglQueryDeviceAttribEXT(_EGLDevice *dev, EGLint attribute, EGLAttrib *value);
const char *
_eglQueryDeviceStringEXT(_EGLDevice *dev, EGLint name);

View file

@ -28,8 +28,8 @@
#include "egldispatchstubs.h"
#include "g_egldispatchstubs.h"
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include "eglcurrent.h"
@ -38,101 +38,110 @@ static const __EGLapiExports *exports;
const int __EGL_DISPATCH_FUNC_COUNT = __EGL_DISPATCH_COUNT;
int __EGL_DISPATCH_FUNC_INDICES[__EGL_DISPATCH_COUNT + 1];
static int Compare(const void *l, const void *r)
static int
Compare(const void *l, const void *r)
{
const char *s = *(const char **)r;
return strcmp(l, s);
const char *s = *(const char **)r;
return strcmp(l, s);
}
static int FindProcIndex(const char *name)
static int
FindProcIndex(const char *name)
{
const char **match = bsearch(name, __EGL_DISPATCH_FUNC_NAMES,
__EGL_DISPATCH_COUNT, sizeof(const char *), Compare);
const char **match =
bsearch(name, __EGL_DISPATCH_FUNC_NAMES, __EGL_DISPATCH_COUNT,
sizeof(const char *), Compare);
if (match == NULL)
return __EGL_DISPATCH_COUNT;
if (match == NULL)
return __EGL_DISPATCH_COUNT;
return match - __EGL_DISPATCH_FUNC_NAMES;
return match - __EGL_DISPATCH_FUNC_NAMES;
}
void __eglInitDispatchStubs(const __EGLapiExports *exportsTable)
void
__eglInitDispatchStubs(const __EGLapiExports *exportsTable)
{
int i;
exports = exportsTable;
for (i=0; i<__EGL_DISPATCH_FUNC_COUNT; i++) {
__EGL_DISPATCH_FUNC_INDICES[i] = -1;
}
int i;
exports = exportsTable;
for (i = 0; i < __EGL_DISPATCH_FUNC_COUNT; i++) {
__EGL_DISPATCH_FUNC_INDICES[i] = -1;
}
}
void __eglSetDispatchIndex(const char *name, int dispatchIndex)
void
__eglSetDispatchIndex(const char *name, int dispatchIndex)
{
int index = FindProcIndex(name);
__EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex;
int index = FindProcIndex(name);
__EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex;
}
void *__eglDispatchFindDispatchFunction(const char *name)
void *
__eglDispatchFindDispatchFunction(const char *name)
{
int index = FindProcIndex(name);
return (void *) __EGL_DISPATCH_FUNCS[index];
int index = FindProcIndex(name);
return (void *)__EGL_DISPATCH_FUNCS[index];
}
static __eglMustCastToProperFunctionPointerType FetchVendorFunc(__EGLvendorInfo *vendor,
int index, EGLint errorCode)
static __eglMustCastToProperFunctionPointerType
FetchVendorFunc(__EGLvendorInfo *vendor, int index, EGLint errorCode)
{
__eglMustCastToProperFunctionPointerType func = NULL;
__eglMustCastToProperFunctionPointerType func = NULL;
if (vendor != NULL) {
func = exports->fetchDispatchEntry(vendor, __EGL_DISPATCH_FUNC_INDICES[index]);
}
if (func == NULL) {
if (errorCode != EGL_SUCCESS) {
// Since we have no vendor, the follow-up eglGetError() call will
// end up using the GLVND error code. Set it here.
if (vendor == NULL) {
exports->setEGLError(errorCode);
}
_eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]);
}
return NULL;
}
if (vendor != NULL) {
func = exports->fetchDispatchEntry(vendor,
__EGL_DISPATCH_FUNC_INDICES[index]);
}
if (func == NULL) {
if (errorCode != EGL_SUCCESS) {
// Since we have no vendor, the follow-up eglGetError() call will
// end up using the GLVND error code. Set it here.
if (vendor == NULL) {
exports->setEGLError(errorCode);
}
_eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]);
}
return NULL;
}
if (!exports->setLastVendor(vendor)) {
// Don't bother trying to set an error code in libglvnd. If
// setLastVendor failed, then setEGLError would also fail.
_eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]);
return NULL;
}
if (!exports->setLastVendor(vendor)) {
// Don't bother trying to set an error code in libglvnd. If
// setLastVendor failed, then setEGLError would also fail.
_eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]);
return NULL;
}
return func;
return func;
}
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index)
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index)
{
__EGLvendorInfo *vendor;
__EGLvendorInfo *vendor;
// Note: This is only used for the eglWait* functions. For those, if
// there's no current context, then they're supposed to do nothing but
// return success.
exports->threadInit();
vendor = exports->getCurrentVendor();
return FetchVendorFunc(vendor, index, EGL_SUCCESS);
// Note: This is only used for the eglWait* functions. For those, if
// there's no current context, then they're supposed to do nothing but
// return success.
exports->threadInit();
vendor = exports->getCurrentVendor();
return FetchVendorFunc(vendor, index, EGL_SUCCESS);
}
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index)
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDisplay(EGLDisplay dpy, int index)
{
__EGLvendorInfo *vendor;
__EGLvendorInfo *vendor;
exports->threadInit();
vendor = exports->getVendorFromDisplay(dpy);
return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY);
exports->threadInit();
vendor = exports->getVendorFromDisplay(dpy);
return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY);
}
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dev, int index)
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dev, int index)
{
__EGLvendorInfo *vendor;
__EGLvendorInfo *vendor;
exports->threadInit();
vendor = exports->getVendorFromDevice(dev);
return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT);
exports->threadInit();
vendor = exports->getVendorFromDevice(dev);
return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT);
}

View file

@ -32,22 +32,28 @@
// These variables are all generated along with the dispatch stubs.
extern const int __EGL_DISPATCH_FUNC_COUNT;
extern const char * const __EGL_DISPATCH_FUNC_NAMES[];
extern const char *const __EGL_DISPATCH_FUNC_NAMES[];
extern int __EGL_DISPATCH_FUNC_INDICES[];
extern const __eglMustCastToProperFunctionPointerType __EGL_DISPATCH_FUNCS[];
void __eglInitDispatchStubs(const __EGLapiExports *exportsTable);
void __eglSetDispatchIndex(const char *name, int index);
void
__eglInitDispatchStubs(const __EGLapiExports *exportsTable);
void
__eglSetDispatchIndex(const char *name, int index);
/**
* Returns the dispatch function for the given name, or \c NULL if the function
* isn't supported.
*/
void *__eglDispatchFindDispatchFunction(const char *name);
void *
__eglDispatchFindDispatchFunction(const char *name);
// Helper functions used by the generated stubs.
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index);
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dpy, int index);
__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index);
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDisplay(EGLDisplay dpy, int index);
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dpy, int index);
__eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index);
#endif // EGLDISPATCHSTUBS_H

View file

@ -27,7 +27,6 @@
*
**************************************************************************/
/**
* Functions related to EGLDisplay.
*/
@ -48,13 +47,13 @@
#include "eglcontext.h"
#include "eglcurrent.h"
#include "eglsurface.h"
#include "egldevice.h"
#include "egldisplay.h"
#include "egldriver.h"
#include "eglglobals.h"
#include "egllog.h"
#include "eglimage.h"
#include "egllog.h"
#include "eglsurface.h"
#include "eglsync.h"
/* Includes for _eglNativePlatformDetectNativeDisplay */
@ -68,7 +67,6 @@
#include <windows.h>
#endif
/**
* Map build-system platform names to platform types.
*/
@ -76,18 +74,17 @@ static const struct {
_EGLPlatformType platform;
const char *name;
} egl_platforms[] = {
{ _EGL_PLATFORM_X11, "x11" },
{ _EGL_PLATFORM_XCB, "xcb" },
{ _EGL_PLATFORM_WAYLAND, "wayland" },
{ _EGL_PLATFORM_DRM, "drm" },
{ _EGL_PLATFORM_ANDROID, "android" },
{ _EGL_PLATFORM_HAIKU, "haiku" },
{ _EGL_PLATFORM_SURFACELESS, "surfaceless" },
{ _EGL_PLATFORM_DEVICE, "device" },
{ _EGL_PLATFORM_WINDOWS, "windows" },
{_EGL_PLATFORM_X11, "x11"},
{_EGL_PLATFORM_XCB, "xcb"},
{_EGL_PLATFORM_WAYLAND, "wayland"},
{_EGL_PLATFORM_DRM, "drm"},
{_EGL_PLATFORM_ANDROID, "android"},
{_EGL_PLATFORM_HAIKU, "haiku"},
{_EGL_PLATFORM_SURFACELESS, "surfaceless"},
{_EGL_PLATFORM_DEVICE, "device"},
{_EGL_PLATFORM_WINDOWS, "windows"},
};
/**
* Return the native platform by parsing EGL_PLATFORM.
*/
@ -121,7 +118,6 @@ _eglGetNativePlatformFromEnv(void)
return plat;
}
/**
* Try detecting native platform with the help of native display characteristics.
*/
@ -138,7 +134,7 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
if (_eglPointerIsDereferenceable(nativeDisplay)) {
void *first_pointer = *(void **) nativeDisplay;
void *first_pointer = *(void **)nativeDisplay;
#ifdef HAVE_WAYLAND_PLATFORM
/* wl_display is a wl_proxy, which is a wl_object.
@ -158,7 +154,6 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
return _EGL_INVALID_PLATFORM;
}
/**
* Return the native platform. It is the platform of the EGL native types.
*/
@ -184,7 +179,6 @@ _eglGetNativePlatform(void *nativeDisplay)
return detected_platform;
}
/**
* Finish display management.
*/
@ -209,7 +203,6 @@ _eglFiniDisplay(void)
}
}
/* The fcntl() code in _eglGetDeviceDisplay() ensures that valid fd >= 3,
* and invalid one is 0.
*/
@ -304,7 +297,6 @@ out:
return disp;
}
/**
* Destroy the contexts and surfaces that are linked to the display.
*/
@ -318,7 +310,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display)
list = display->ResourceLists[_EGL_RESOURCE_CONTEXT];
while (list) {
_EGLContext *ctx = (_EGLContext *) list;
_EGLContext *ctx = (_EGLContext *)list;
list = list->Next;
_eglUnlinkContext(ctx);
@ -328,7 +320,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display)
list = display->ResourceLists[_EGL_RESOURCE_SURFACE];
while (list) {
_EGLSurface *surf = (_EGLSurface *) list;
_EGLSurface *surf = (_EGLSurface *)list;
list = list->Next;
_eglUnlinkSurface(surf);
@ -338,7 +330,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display)
list = display->ResourceLists[_EGL_RESOURCE_IMAGE];
while (list) {
_EGLImage *image = (_EGLImage *) list;
_EGLImage *image = (_EGLImage *)list;
list = list->Next;
_eglUnlinkImage(image);
@ -348,7 +340,7 @@ _eglReleaseDisplayResources(_EGLDisplay *display)
list = display->ResourceLists[_EGL_RESOURCE_SYNC];
while (list) {
_EGLSync *sync = (_EGLSync *) list;
_EGLSync *sync = (_EGLSync *)list;
list = list->Next;
_eglUnlinkSync(sync);
@ -357,7 +349,6 @@ _eglReleaseDisplayResources(_EGLDisplay *display)
assert(!display->ResourceLists[_EGL_RESOURCE_SYNC]);
}
/**
* Free all the data hanging of an _EGLDisplay object, but not
* the object itself.
@ -373,7 +364,6 @@ _eglCleanupDisplay(_EGLDisplay *disp)
/* XXX incomplete */
}
/**
* Return EGL_TRUE if the given resource is valid. That is, the display does
* own the resource.
@ -382,14 +372,14 @@ EGLBoolean
_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp)
{
_EGLResource *list = disp->ResourceLists[type];
simple_mtx_assert_locked(&disp->Mutex);
if (!res)
return EGL_FALSE;
while (list) {
if (res == (void *) list) {
if (res == (void *)list) {
assert(list->Display == disp);
break;
}
@ -399,7 +389,6 @@ _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp)
return (list != NULL);
}
/**
* Initialize a display resource. The size of the subclass object is
* specified.
@ -415,7 +404,6 @@ _eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp)
res->RefCount = 1;
}
/**
* Increment reference count for the resource.
*/
@ -426,7 +414,6 @@ _eglGetResource(_EGLResource *res)
p_atomic_inc(&res->RefCount);
}
/**
* Decrement reference count for the resource.
*/
@ -437,7 +424,6 @@ _eglPutResource(_EGLResource *res)
return p_atomic_dec_zero(&res->RefCount);
}
/**
* Link a resource to its display.
*/
@ -453,7 +439,6 @@ _eglLinkResource(_EGLResource *res, _EGLResourceType type)
_eglGetResource(res);
}
/**
* Unlink a linked resource from its display.
*/
@ -473,8 +458,7 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type)
}
assert(prev);
prev->Next = res->Next;
}
else {
} else {
res->Display->ResourceLists[type] = res->Next;
}
@ -487,9 +471,8 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type)
}
#ifdef HAVE_X11_PLATFORM
_EGLDisplay*
_eglGetX11Display(Display *native_display,
const EGLAttrib *attrib_list)
_EGLDisplay *
_eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list)
{
/* EGL_EXT_platform_x11 recognizes exactly one attribute,
* EGL_PLATFORM_X11_SCREEN_EXT, which is optional.
@ -507,7 +490,7 @@ _eglGetX11Display(Display *native_display,
#endif /* HAVE_X11_PLATFORM */
#ifdef HAVE_XCB_PLATFORM
_EGLDisplay*
_EGLDisplay *
_eglGetXcbDisplay(xcb_connection_t *native_display,
const EGLAttrib *attrib_list)
{
@ -528,7 +511,7 @@ _eglGetXcbDisplay(xcb_connection_t *native_display,
#endif /* HAVE_XCB_PLATFORM */
#ifdef HAVE_DRM_PLATFORM
_EGLDisplay*
_EGLDisplay *
_eglGetGbmDisplay(struct gbm_device *native_display,
const EGLAttrib *attrib_list)
{
@ -543,7 +526,7 @@ _eglGetGbmDisplay(struct gbm_device *native_display,
#endif /* HAVE_DRM_PLATFORM */
#ifdef HAVE_WAYLAND_PLATFORM
_EGLDisplay*
_EGLDisplay *
_eglGetWaylandDisplay(struct wl_display *native_display,
const EGLAttrib *attrib_list)
{
@ -557,9 +540,8 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
}
#endif /* HAVE_WAYLAND_PLATFORM */
_EGLDisplay*
_eglGetSurfacelessDisplay(void *native_display,
const EGLAttrib *attrib_list)
_EGLDisplay *
_eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list)
{
/* This platform has no native display. */
if (native_display != NULL) {
@ -578,9 +560,8 @@ _eglGetSurfacelessDisplay(void *native_display,
}
#ifdef HAVE_ANDROID_PLATFORM
_EGLDisplay*
_eglGetAndroidDisplay(void *native_display,
const EGLAttrib *attrib_list)
_EGLDisplay *
_eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list)
{
/* This platform recognizes no display attributes. */
@ -589,14 +570,12 @@ _eglGetAndroidDisplay(void *native_display,
return NULL;
}
return _eglFindDisplay(_EGL_PLATFORM_ANDROID, native_display,
attrib_list);
return _eglFindDisplay(_EGL_PLATFORM_ANDROID, native_display, attrib_list);
}
#endif /* HAVE_ANDROID_PLATFORM */
_EGLDisplay*
_eglGetDeviceDisplay(void *native_display,
const EGLAttrib *attrib_list)
_EGLDisplay *
_eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list)
{
_EGLDevice *dev;
_EGLDisplay *display;
@ -623,7 +602,7 @@ _eglGetDeviceDisplay(void *native_display,
return NULL;
}
fd = (int) value;
fd = (int)value;
}
}

View file

@ -27,16 +27,15 @@
*
**************************************************************************/
#ifndef EGLDISPLAY_INCLUDED
#define EGLDISPLAY_INCLUDED
#include "util/simple_mtx.h"
#include "util/rwlock.h"
#include "util/simple_mtx.h"
#include "egltypedefs.h"
#include "egldefines.h"
#include "eglarray.h"
#include "egldefines.h"
#include "egltypedefs.h"
#ifdef HAVE_X11_PLATFORM
#include <X11/Xlib.h>
@ -62,7 +61,6 @@ enum _egl_platform_type {
};
typedef enum _egl_platform_type _EGLPlatformType;
enum _egl_resource_type {
_EGL_RESOURCE_CONTEXT,
_EGL_RESOURCE_SURFACE,
@ -74,12 +72,10 @@ enum _egl_resource_type {
/* this cannot and need not go into egltypedefs.h */
typedef enum _egl_resource_type _EGLResourceType;
/**
* A resource of a display.
*/
struct _egl_resource
{
struct _egl_resource {
/* which display the resource belongs to */
_EGLDisplay *Display;
EGLBoolean IsLinked;
@ -91,12 +87,10 @@ struct _egl_resource
_EGLResource *Next;
};
/**
* Optional EGL extensions info.
*/
struct _egl_extensions
{
struct _egl_extensions {
/* Please keep these sorted alphabetically. */
EGLBoolean ANDROID_blob_cache;
EGLBoolean ANDROID_framebuffer_target;
@ -120,9 +114,9 @@ struct _egl_extensions
EGLBoolean EXT_swap_buffers_with_damage;
unsigned int IMG_context_priority;
#define __EGL_CONTEXT_PRIORITY_LOW_BIT 0
#define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1
#define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2
#define __EGL_CONTEXT_PRIORITY_LOW_BIT 0
#define __EGL_CONTEXT_PRIORITY_MEDIUM_BIT 1
#define __EGL_CONTEXT_PRIORITY_HIGH_BIT 2
EGLBoolean KHR_cl_event2;
EGLBoolean KHR_config_attribs;
@ -159,8 +153,7 @@ struct _egl_extensions
EGLBoolean WL_create_wayland_buffer_from_image;
};
struct _egl_display
{
struct _egl_display {
/* used to link displays */
_EGLDisplay *Next;
@ -195,9 +188,9 @@ struct _egl_display
_EGLPlatformType Platform; /**< The type of the platform display */
void *PlatformDisplay; /**< A pointer to the platform display */
_EGLDevice *Device; /**< Device backing the display */
const _EGLDriver *Driver; /**< Matched driver of the display */
EGLBoolean Initialized; /**< True if the display is initialized */
_EGLDevice *Device; /**< Device backing the display */
const _EGLDriver *Driver; /**< Matched driver of the display */
EGLBoolean Initialized; /**< True if the display is initialized */
/* options that affect how the driver initializes the display */
struct {
@ -230,69 +223,54 @@ struct _egl_display
EGLGetBlobFuncANDROID BlobCacheGet;
};
extern _EGLDisplay *
_eglLockDisplay(EGLDisplay dpy);
extern void
_eglUnlockDisplay(_EGLDisplay *disp);
extern _EGLPlatformType
_eglGetNativePlatform(void *nativeDisplay);
extern void
_eglFiniDisplay(void);
extern _EGLDisplay *
_eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, const EGLAttrib *attr);
extern void
_eglReleaseDisplayResources(_EGLDisplay *disp);
extern void
_eglCleanupDisplay(_EGLDisplay *disp);
extern EGLBoolean
_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *disp);
/**
* Return the handle of a linked display, or EGL_NO_DISPLAY.
*/
static inline EGLDisplay
_eglGetDisplayHandle(_EGLDisplay *disp)
{
return (EGLDisplay) ((disp) ? disp : EGL_NO_DISPLAY);
return (EGLDisplay)((disp) ? disp : EGL_NO_DISPLAY);
}
extern void
_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *disp);
extern void
_eglGetResource(_EGLResource *res);
extern EGLBoolean
_eglPutResource(_EGLResource *res);
extern void
_eglLinkResource(_EGLResource *res, _EGLResourceType type);
extern void
_eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
/**
* Return true if the resource is linked.
*/
@ -316,20 +294,21 @@ _eglNumAttribs(const EGLAttrib *attribs)
}
#ifdef HAVE_X11_PLATFORM
_EGLDisplay*
_EGLDisplay *
_eglGetX11Display(Display *native_display, const EGLAttrib *attrib_list);
#endif
#ifdef HAVE_XCB_PLATFORM
typedef struct xcb_connection_t xcb_connection_t;
_EGLDisplay*
_eglGetXcbDisplay(xcb_connection_t *native_display, const EGLAttrib *attrib_list);
_EGLDisplay *
_eglGetXcbDisplay(xcb_connection_t *native_display,
const EGLAttrib *attrib_list);
#endif
#ifdef HAVE_DRM_PLATFORM
struct gbm_device;
_EGLDisplay*
_EGLDisplay *
_eglGetGbmDisplay(struct gbm_device *native_display,
const EGLAttrib *attrib_list);
#endif
@ -337,24 +316,21 @@ _eglGetGbmDisplay(struct gbm_device *native_display,
#ifdef HAVE_WAYLAND_PLATFORM
struct wl_display;
_EGLDisplay*
_EGLDisplay *
_eglGetWaylandDisplay(struct wl_display *native_display,
const EGLAttrib *attrib_list);
#endif
_EGLDisplay*
_eglGetSurfacelessDisplay(void *native_display,
const EGLAttrib *attrib_list);
_EGLDisplay *
_eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list);
#ifdef HAVE_ANDROID_PLATFORM
_EGLDisplay*
_eglGetAndroidDisplay(void *native_display,
const EGLAttrib *attrib_list);
_EGLDisplay *
_eglGetAndroidDisplay(void *native_display, const EGLAttrib *attrib_list);
#endif
_EGLDisplay*
_eglGetDeviceDisplay(void *native_display,
const EGLAttrib *attrib_list);
_EGLDisplay *
_eglGetDeviceDisplay(void *native_display, const EGLAttrib *attrib_list);
#ifdef __cplusplus
}

View file

@ -27,15 +27,12 @@
*
**************************************************************************/
#ifndef EGLDRIVER_INCLUDED
#define EGLDRIVER_INCLUDED
#include "egltypedefs.h"
#include <stdbool.h>
#include <stddef.h>
#include "egltypedefs.h"
#ifdef __cplusplus
extern "C" {
@ -47,10 +44,11 @@ extern "C" {
* Note that this macro defines a function and should not be ended with a
* semicolon when used.
*/
#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \
static inline struct drvtype *drvtype(const egltype *obj) \
{ return (struct drvtype *) code; }
#define _EGL_DRIVER_TYPECAST(drvtype, egltype, code) \
static inline struct drvtype *drvtype(const egltype *obj) \
{ \
return (struct drvtype *)code; \
}
/**
* Define the driver typecast functions for _EGLDisplay,
@ -59,12 +57,12 @@ extern "C" {
* Note that this macro defines several functions and should not be ended with
* a semicolon when used.
*/
#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \
/* note that this is not a direct cast */ \
_EGL_DRIVER_TYPECAST(drvname ## _display, _EGLDisplay, obj->DriverData) \
_EGL_DRIVER_TYPECAST(drvname ## _context, _EGLContext, obj) \
_EGL_DRIVER_TYPECAST(drvname ## _surface, _EGLSurface, obj) \
_EGL_DRIVER_TYPECAST(drvname ## _config, _EGLConfig, obj)
#define _EGL_DRIVER_STANDARD_TYPECASTS(drvname) \
/* note that this is not a direct cast */ \
_EGL_DRIVER_TYPECAST(drvname##_display, _EGLDisplay, obj->DriverData) \
_EGL_DRIVER_TYPECAST(drvname##_context, _EGLContext, obj) \
_EGL_DRIVER_TYPECAST(drvname##_surface, _EGLSurface, obj) \
_EGL_DRIVER_TYPECAST(drvname##_config, _EGLConfig, obj)
/**
* A generic function ptr type
@ -80,28 +78,29 @@ typedef struct __GLsync *GLsync;
/**
* The API dispatcher jumps through these functions
*/
struct _egl_driver
{
struct _egl_driver {
/* driver funcs */
EGLBoolean (*Initialize)(_EGLDisplay *disp);
EGLBoolean (*Terminate)(_EGLDisplay *disp);
/* context funcs */
_EGLContext *(*CreateContext)(_EGLDisplay *disp, _EGLConfig *config,
_EGLContext *share_list, const EGLint *attrib_list);
_EGLContext *share_list,
const EGLint *attrib_list);
EGLBoolean (*DestroyContext)(_EGLDisplay *disp, _EGLContext *ctx);
/* this is the only function (other than Initialize) that may be called
* with an uninitialized display
*/
EGLBoolean (*MakeCurrent)(_EGLDisplay *disp,
_EGLSurface *draw, _EGLSurface *read,
_EGLContext *ctx);
EGLBoolean (*MakeCurrent)(_EGLDisplay *disp, _EGLSurface *draw,
_EGLSurface *read, _EGLContext *ctx);
/* surface funcs */
_EGLSurface *(*CreateWindowSurface)(_EGLDisplay *disp, _EGLConfig *config,
void *native_window, const EGLint *attrib_list);
void *native_window,
const EGLint *attrib_list);
_EGLSurface *(*CreatePixmapSurface)(_EGLDisplay *disp, _EGLConfig *config,
void *native_pixmap, const EGLint *attrib_list);
void *native_pixmap,
const EGLint *attrib_list);
_EGLSurface *(*CreatePbufferSurface)(_EGLDisplay *disp, _EGLConfig *config,
const EGLint *attrib_list);
EGLBoolean (*DestroySurface)(_EGLDisplay *disp, _EGLSurface *surface);
@ -135,8 +134,8 @@ struct _egl_driver
_EGLSync *(*CreateSyncKHR)(_EGLDisplay *disp, EGLenum type,
const EGLAttrib *attrib_list);
EGLBoolean (*DestroySyncKHR)(_EGLDisplay *disp, _EGLSync *sync);
EGLint (*ClientWaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync,
EGLint flags, EGLTime timeout);
EGLint (*ClientWaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLint flags,
EGLTime timeout);
EGLint (*WaitSyncKHR)(_EGLDisplay *disp, _EGLSync *sync);
/* for EGL_KHR_reusable_sync */
EGLBoolean (*SignalSyncKHR)(_EGLDisplay *disp, _EGLSync *sync, EGLenum mode);
@ -155,21 +154,27 @@ struct _egl_driver
EGLint *stride);
/* for EGL_WL_bind_wayland_display */
EGLBoolean (*BindWaylandDisplayWL)(_EGLDisplay *disp, struct wl_display *display);
EGLBoolean (*UnbindWaylandDisplayWL)(_EGLDisplay *disp, struct wl_display *display);
EGLBoolean (*QueryWaylandBufferWL)(_EGLDisplay *displ, struct wl_resource *buffer,
EGLBoolean (*BindWaylandDisplayWL)(_EGLDisplay *disp,
struct wl_display *display);
EGLBoolean (*UnbindWaylandDisplayWL)(_EGLDisplay *disp,
struct wl_display *display);
EGLBoolean (*QueryWaylandBufferWL)(_EGLDisplay *displ,
struct wl_resource *buffer,
EGLint attribute, EGLint *value);
/* for EGL_WL_create_wayland_buffer_from_image */
struct wl_buffer *(*CreateWaylandBufferFromImageWL)(_EGLDisplay *disp, _EGLImage *img);
struct wl_buffer *(*CreateWaylandBufferFromImageWL)(_EGLDisplay *disp,
_EGLImage *img);
/* for EGL_EXT_swap_buffers_with_damage */
EGLBoolean (*SwapBuffersWithDamageEXT)(_EGLDisplay *disp, _EGLSurface *surface,
EGLBoolean (*SwapBuffersWithDamageEXT)(_EGLDisplay *disp,
_EGLSurface *surface,
const EGLint *rects, EGLint n_rects);
/* for EGL_NV_post_sub_buffer */
EGLBoolean (*PostSubBufferNV)(_EGLDisplay *disp, _EGLSurface *surface,
EGLint x, EGLint y, EGLint width, EGLint height);
EGLint x, EGLint y, EGLint width,
EGLint height);
/* for EGL_EXT_buffer_age/EGL_KHR_partial_update */
EGLint (*QueryBufferAge)(_EGLDisplay *disp, _EGLSurface *surface);
@ -201,15 +206,16 @@ struct _egl_driver
struct mesa_glinterop_export_in *in,
struct mesa_glinterop_export_out *out);
int (*GLInteropFlushObjects)(_EGLDisplay *disp, _EGLContext *ctx,
unsigned count, struct mesa_glinterop_export_in *in,
unsigned count,
struct mesa_glinterop_export_in *in,
GLsync *sync);
/* for EGL_EXT_image_dma_buf_import_modifiers */
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp, EGLint max_formats,
EGLint *formats, EGLint *num_formats);
EGLBoolean (*QueryDmaBufModifiersEXT)(_EGLDisplay *disp, EGLint format,
EGLint max_modifiers, EGLuint64KHR *modifiers,
EGLint max_modifiers,
EGLuint64KHR *modifiers,
EGLBoolean *external_only,
EGLint *num_modifiers);
@ -219,10 +225,8 @@ struct _egl_driver
EGLGetBlobFuncANDROID get);
};
#ifdef __cplusplus
}
#endif
#endif /* EGLDRIVER_INCLUDED */

View file

@ -27,16 +27,15 @@
*
**************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util/simple_mtx.h"
#include "eglglobals.h"
#include "egldevice.h"
#include "egldisplay.h"
#include "eglglobals.h"
#include "util/macros.h"
#include "util/os_misc.h"
@ -46,69 +45,67 @@
#include <sys/mman.h>
#endif
static simple_mtx_t _eglGlobalMutex = SIMPLE_MTX_INITIALIZER;
struct _egl_global _eglGlobal =
{
struct _egl_global _eglGlobal = {
.Mutex = &_eglGlobalMutex,
.DisplayList = NULL,
.DeviceList = &_eglSoftwareDevice,
.NumAtExitCalls = 2,
.AtExitCalls = {
/* default AtExitCalls, called in reverse order */
_eglFiniDevice, /* always called last */
_eglFiniDisplay,
},
.AtExitCalls =
{
/* default AtExitCalls, called in reverse order */
_eglFiniDevice, /* always called last */
_eglFiniDisplay,
},
#if USE_LIBGLVND
.ClientOnlyExtensionString =
#else
.ClientExtensionString =
#endif
"EGL_EXT_client_extensions"
"EGL_EXT_client_extensions"
#if !DETECT_OS_WINDOWS
" EGL_EXT_device_base"
" EGL_EXT_device_enumeration"
" EGL_EXT_device_query"
" EGL_EXT_device_base"
" EGL_EXT_device_enumeration"
" EGL_EXT_device_query"
#endif
" EGL_EXT_platform_base"
" EGL_KHR_client_get_all_proc_addresses"
" EGL_KHR_debug"
" EGL_EXT_platform_base"
" EGL_KHR_client_get_all_proc_addresses"
" EGL_KHR_debug"
#if USE_LIBGLVND
,
.PlatformExtensionString =
#else
" "
" "
#endif
#if !DETECT_OS_WINDOWS
"EGL_EXT_platform_device"
"EGL_EXT_platform_device"
#endif
#ifdef HAVE_WAYLAND_PLATFORM
" EGL_EXT_platform_wayland"
" EGL_KHR_platform_wayland"
" EGL_EXT_platform_wayland"
" EGL_KHR_platform_wayland"
#endif
#ifdef HAVE_X11_PLATFORM
" EGL_EXT_platform_x11"
" EGL_KHR_platform_x11"
" EGL_EXT_platform_x11"
" EGL_KHR_platform_x11"
#endif
#ifdef HAVE_XCB_PLATFORM
" EGL_EXT_platform_xcb"
" EGL_EXT_platform_xcb"
#endif
#ifdef HAVE_DRM_PLATFORM
" EGL_MESA_platform_gbm"
" EGL_KHR_platform_gbm"
" EGL_MESA_platform_gbm"
" EGL_KHR_platform_gbm"
#endif
" EGL_MESA_platform_surfaceless"
"",
" EGL_MESA_platform_surfaceless"
"",
.debugCallback = NULL,
.debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR,
};
static void
_eglAtExit(void)
{
@ -117,7 +114,6 @@ _eglAtExit(void)
_eglGlobal.AtExitCalls[i]();
}
void
_eglAddAtExitCall(void (*func)(void))
{
@ -141,7 +137,7 @@ _eglAddAtExitCall(void (*func)(void))
EGLBoolean
_eglPointerIsDereferenceable(void *p)
{
uintptr_t addr = (uintptr_t) p;
uintptr_t addr = (uintptr_t)p;
uint64_t page_size = 0;
os_get_page_size(&page_size);
#ifdef HAVE_MINCORE
@ -156,7 +152,7 @@ _eglPointerIsDereferenceable(void *p)
/* mincore expects &valid to be unsigned char* on Linux but char* on BSD:
* we cast pointers to void, to fix type mismatch warnings in all systems
*/
if (mincore((void *) addr, page_size, (void*)&valid) < 0) {
if (mincore((void *)addr, page_size, (void *)&valid) < 0) {
return EGL_FALSE;
}

View file

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

View file

@ -25,8 +25,8 @@
* Kyle Brenneman <kbrenneman@nvidia.com>
*/
#include <string.h>
#include <assert.h>
#include <string.h>
#include <glvnd/libeglabi.h>
@ -36,7 +36,7 @@
static const __EGLapiExports *__eglGLVNDApiExports = NULL;
static const char * EGLAPIENTRY
static const char *EGLAPIENTRY
__eglGLVNDQueryString(EGLDisplay dpy, EGLenum name)
{
// For client extensions, return the list of non-platform extensions. The
@ -59,12 +59,12 @@ __eglGLVNDGetVendorString(int name)
static EGLDisplay
__eglGLVNDGetPlatformDisplay(EGLenum platform, void *native_display,
const EGLAttrib *attrib_list)
const EGLAttrib *attrib_list)
{
if (platform == EGL_NONE) {
assert(native_display == (void *) EGL_DEFAULT_DISPLAY);
assert(native_display == (void *)EGL_DEFAULT_DISPLAY);
assert(attrib_list == NULL);
return eglGetDisplay((EGLNativeDisplayType) native_display);
return eglGetDisplay((EGLNativeDisplayType)native_display);
} else {
return eglGetPlatformDisplay(platform, native_display, attrib_list);
}
@ -74,14 +74,14 @@ static void *
__eglGLVNDGetProcAddress(const char *procName)
{
if (strcmp(procName, "eglQueryString") == 0)
return (void *) __eglGLVNDQueryString;
return (void *)__eglGLVNDQueryString;
return (void *) eglGetProcAddress(procName);
return (void *)eglGetProcAddress(procName);
}
PUBLIC EGLAPI EGLBoolean
__egl_Main(uint32_t version, const __EGLapiExports *exports,
__EGLvendorInfo *vendor, __EGLapiImports *imports)
__EGLvendorInfo *vendor, __EGLapiImports *imports)
{
if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
EGL_VENDOR_ABI_MAJOR_VERSION)
@ -99,4 +99,3 @@ __egl_Main(uint32_t version, const __EGLapiExports *exports,
return EGL_TRUE;
}

View file

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

View file

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

View file

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

View file

@ -26,32 +26,26 @@
*
**************************************************************************/
#ifndef EGLLOG_INCLUDED
#define EGLLOG_INCLUDED
#include "egltypedefs.h"
#ifdef __cplusplus
extern "C" {
#endif
#define _EGL_FATAL 0 /* unrecoverable error */
#define _EGL_WARNING 1 /* recoverable error/problem */
#define _EGL_INFO 2 /* just useful info */
#define _EGL_DEBUG 3 /* useful info for debugging */
#define _EGL_FATAL 0 /* unrecoverable error */
#define _EGL_WARNING 1 /* recoverable error/problem */
#define _EGL_INFO 2 /* just useful info */
#define _EGL_DEBUG 3 /* useful info for debugging */
extern EGLint
_eglGetLogLevel(void);
extern void
_eglLog(EGLint level, const char *fmtStr, ...);
#ifdef __cplusplus
}
#endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -27,238 +27,224 @@
* Benjamin Franzke <benjaminfranzke@googlemail.com>
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <unistd.h>
#include <wayland-server.h>
#include "wayland-drm.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))
static void
destroy_buffer(struct wl_resource *resource)
{
struct wl_drm_buffer *buffer = wl_resource_get_user_data(resource);
struct wl_drm *drm = buffer->drm;
struct wl_drm_buffer *buffer = wl_resource_get_user_data(resource);
struct wl_drm *drm = buffer->drm;
drm->callbacks.release_buffer(drm->user_data, buffer);
free(buffer);
drm->callbacks.release_buffer(drm->user_data, buffer);
free(buffer);
}
static void
buffer_destroy(struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy(resource);
wl_resource_destroy(resource);
}
static void
create_buffer(struct wl_client *client, struct wl_resource *resource,
uint32_t id, uint32_t name, int fd,
int32_t width, int32_t height,
uint32_t format,
int32_t offset0, int32_t stride0,
int32_t offset1, int32_t stride1,
int32_t offset2, int32_t stride2)
uint32_t id, uint32_t name, int fd, int32_t width, int32_t height,
uint32_t format, int32_t offset0, int32_t stride0,
int32_t offset1, int32_t stride1, int32_t offset2,
int32_t stride2)
{
struct wl_drm *drm = wl_resource_get_user_data(resource);
struct wl_drm_buffer *buffer;
struct wl_drm *drm = wl_resource_get_user_data(resource);
struct wl_drm_buffer *buffer;
buffer = calloc(1, sizeof *buffer);
if (buffer == NULL) {
wl_resource_post_no_memory(resource);
return;
}
buffer = calloc(1, sizeof *buffer);
if (buffer == NULL) {
wl_resource_post_no_memory(resource);
return;
}
buffer->drm = drm;
buffer->width = width;
buffer->height = height;
buffer->format = format;
buffer->offset[0] = offset0;
buffer->stride[0] = stride0;
buffer->offset[1] = offset1;
buffer->stride[1] = stride1;
buffer->offset[2] = offset2;
buffer->stride[2] = stride2;
buffer->drm = drm;
buffer->width = width;
buffer->height = height;
buffer->format = format;
buffer->offset[0] = offset0;
buffer->stride[0] = stride0;
buffer->offset[1] = offset1;
buffer->stride[1] = stride1;
buffer->offset[2] = offset2;
buffer->stride[2] = stride2;
drm->callbacks.reference_buffer(drm->user_data, name, fd, buffer);
if (buffer->driver_buffer == NULL) {
wl_resource_post_error(resource,
WL_DRM_ERROR_INVALID_NAME,
"invalid name");
return;
}
drm->callbacks.reference_buffer(drm->user_data, name, fd, buffer);
if (buffer->driver_buffer == NULL) {
wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME,
"invalid name");
return;
}
buffer->resource =
wl_resource_create(client, &wl_buffer_interface, 1, id);
if (!buffer->resource) {
wl_resource_post_no_memory(resource);
free(buffer);
return;
}
buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id);
if (!buffer->resource) {
wl_resource_post_no_memory(resource);
free(buffer);
return;
}
wl_resource_set_implementation(buffer->resource,
(void (**)(void)) &drm->buffer_interface,
buffer, destroy_buffer);
wl_resource_set_implementation(buffer->resource,
(void (**)(void)) & drm->buffer_interface,
buffer, destroy_buffer);
}
static void
drm_create_buffer(struct wl_client *client, struct wl_resource *resource,
uint32_t id, uint32_t name, int32_t width, int32_t height,
uint32_t stride, uint32_t format)
uint32_t id, uint32_t name, int32_t width, int32_t height,
uint32_t stride, uint32_t format)
{
switch (format) {
case WL_DRM_FORMAT_ABGR2101010:
case WL_DRM_FORMAT_XBGR2101010:
case WL_DRM_FORMAT_ARGB2101010:
case WL_DRM_FORMAT_XRGB2101010:
case WL_DRM_FORMAT_ARGB8888:
case WL_DRM_FORMAT_XRGB8888:
case WL_DRM_FORMAT_YUYV:
case WL_DRM_FORMAT_RGB565:
break;
default:
wl_resource_post_error(resource,
WL_DRM_ERROR_INVALID_FORMAT,
"invalid format");
return;
}
switch (format) {
case WL_DRM_FORMAT_ABGR2101010:
case WL_DRM_FORMAT_XBGR2101010:
case WL_DRM_FORMAT_ARGB2101010:
case WL_DRM_FORMAT_XRGB2101010:
case WL_DRM_FORMAT_ARGB8888:
case WL_DRM_FORMAT_XRGB8888:
case WL_DRM_FORMAT_YUYV:
case WL_DRM_FORMAT_RGB565:
break;
default:
wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT,
"invalid format");
return;
}
create_buffer(client, resource, id,
name, -1, width, height, format, 0, stride, 0, 0, 0, 0);
create_buffer(client, resource, id, name, -1, width, height, format, 0,
stride, 0, 0, 0, 0);
}
static void
drm_create_planar_buffer(struct wl_client *client,
struct wl_resource *resource,
uint32_t id, uint32_t name,
int32_t width, int32_t height, uint32_t format,
int32_t offset0, int32_t stride0,
int32_t offset1, int32_t stride1,
drm_create_planar_buffer(struct wl_client *client, struct wl_resource *resource,
uint32_t id, uint32_t name, int32_t width,
int32_t height, uint32_t format, int32_t offset0,
int32_t stride0, int32_t offset1, int32_t stride1,
int32_t offset2, int32_t stride2)
{
switch (format) {
case WL_DRM_FORMAT_YUV410:
case WL_DRM_FORMAT_YUV411:
case WL_DRM_FORMAT_YUV420:
case WL_DRM_FORMAT_YUV422:
case WL_DRM_FORMAT_YUV444:
case WL_DRM_FORMAT_NV12:
case WL_DRM_FORMAT_NV16:
break;
default:
wl_resource_post_error(resource,
WL_DRM_ERROR_INVALID_FORMAT,
"invalid format");
return;
}
switch (format) {
case WL_DRM_FORMAT_YUV410:
case WL_DRM_FORMAT_YUV411:
case WL_DRM_FORMAT_YUV420:
case WL_DRM_FORMAT_YUV422:
case WL_DRM_FORMAT_YUV444:
case WL_DRM_FORMAT_NV12:
case WL_DRM_FORMAT_NV16:
break;
default:
wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT,
"invalid format");
return;
}
create_buffer(client, resource, id, name, -1, width, height, format,
offset0, stride0, offset1, stride1, offset2, stride2);
create_buffer(client, resource, id, name, -1, width, height, format, offset0,
stride0, offset1, stride1, offset2, stride2);
}
static void
drm_create_prime_buffer(struct wl_client *client,
struct wl_resource *resource,
uint32_t id, int fd,
int32_t width, int32_t height, uint32_t format,
int32_t offset0, int32_t stride0,
int32_t offset1, int32_t stride1,
int32_t offset2, int32_t stride2)
drm_create_prime_buffer(struct wl_client *client, struct wl_resource *resource,
uint32_t id, int fd, int32_t width, int32_t height,
uint32_t format, int32_t offset0, int32_t stride0,
int32_t offset1, int32_t stride1, int32_t offset2,
int32_t stride2)
{
create_buffer(client, resource, id, 0, fd, width, height, format,
offset0, stride0, offset1, stride1, offset2, stride2);
close(fd);
create_buffer(client, resource, id, 0, fd, width, height, format, offset0,
stride0, offset1, stride1, offset2, stride2);
close(fd);
}
static void
drm_authenticate(struct wl_client *client,
struct wl_resource *resource, uint32_t id)
drm_authenticate(struct wl_client *client, struct wl_resource *resource,
uint32_t id)
{
struct wl_drm *drm = wl_resource_get_user_data(resource);
struct wl_drm *drm = wl_resource_get_user_data(resource);
if (!drm->callbacks.authenticate ||
drm->callbacks.authenticate(drm->user_data, id) < 0)
wl_resource_post_error(resource,
WL_DRM_ERROR_AUTHENTICATE_FAIL,
"authenticate failed");
else
wl_resource_post_event(resource, WL_DRM_AUTHENTICATED);
if (!drm->callbacks.authenticate ||
drm->callbacks.authenticate(drm->user_data, id) < 0)
wl_resource_post_error(resource, WL_DRM_ERROR_AUTHENTICATE_FAIL,
"authenticate failed");
else
wl_resource_post_event(resource, WL_DRM_AUTHENTICATED);
}
static const struct wl_drm_interface drm_interface = {
drm_authenticate,
drm_create_buffer,
drm_create_planar_buffer,
drm_create_prime_buffer,
drm_authenticate,
drm_create_buffer,
drm_create_planar_buffer,
drm_create_prime_buffer,
};
static void
bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
struct wl_drm *drm = data;
struct wl_resource *resource;
uint32_t capabilities;
struct wl_drm *drm = data;
struct wl_resource *resource;
uint32_t capabilities;
resource = wl_resource_create(client, &wl_drm_interface,
MIN(version, 2), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
resource =
wl_resource_create(client, &wl_drm_interface, MIN(version, 2), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &drm_interface, data, NULL);
wl_resource_set_implementation(resource, &drm_interface, data, NULL);
wl_resource_post_event(resource, WL_DRM_DEVICE, drm->device_name);
wl_resource_post_event(resource, WL_DRM_DEVICE, drm->device_name);
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_ARGB2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_ARGB2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_ARGB2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_ARGB2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_XRGB2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_XRGB2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_XRGB2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_XRGB2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_ABGR2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_ABGR2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_ABGR2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_ABGR2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_XBGR2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_XBGR2101010);
}
if (drm->callbacks.is_format_supported(drm->user_data,
WL_DRM_FORMAT_XBGR2101010)) {
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_XBGR2101010);
}
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_ARGB8888);
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_XRGB8888);
wl_resource_post_event(resource, WL_DRM_FORMAT,
WL_DRM_FORMAT_RGB565);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV410);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV411);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV420);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV422);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV444);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV16);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUYV);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_ARGB8888);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_XRGB8888);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_RGB565);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV410);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV411);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV420);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV422);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV444);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV16);
wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUYV);
capabilities = 0;
if (drm->flags & WAYLAND_DRM_PRIME)
capabilities |= WL_DRM_CAPABILITY_PRIME;
capabilities = 0;
if (drm->flags & WAYLAND_DRM_PRIME)
capabilities |= WL_DRM_CAPABILITY_PRIME;
if (version >= 2)
wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities);
if (version >= 2)
wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities);
}
struct wl_drm *
@ -266,33 +252,32 @@ wayland_drm_init(struct wl_display *display, char *device_name,
const struct wayland_drm_callbacks *callbacks, void *user_data,
uint32_t flags)
{
struct wl_drm *drm;
struct wl_drm *drm;
drm = malloc(sizeof *drm);
if (!drm)
return NULL;
drm = malloc(sizeof *drm);
if (!drm)
return NULL;
drm->display = display;
drm->device_name = strdup(device_name);
drm->callbacks = *callbacks;
drm->user_data = user_data;
drm->flags = flags;
drm->display = display;
drm->device_name = strdup(device_name);
drm->callbacks = *callbacks;
drm->user_data = user_data;
drm->flags = flags;
drm->buffer_interface.destroy = buffer_destroy;
drm->buffer_interface.destroy = buffer_destroy;
drm->wl_drm_global =
wl_global_create(display, &wl_drm_interface, 2,
drm, bind_drm);
drm->wl_drm_global =
wl_global_create(display, &wl_drm_interface, 2, drm, bind_drm);
return drm;
return drm;
}
void
wayland_drm_uninit(struct wl_drm *drm)
{
free(drm->device_name);
free(drm->device_name);
wl_global_destroy(drm->wl_drm_global);
wl_global_destroy(drm->wl_drm_global);
free(drm);
free(drm);
}

View file

@ -8,39 +8,38 @@ struct wl_resource;
struct wl_drm_buffer;
struct wayland_drm_callbacks {
int (*authenticate)(void *user_data, uint32_t id);
int (*authenticate)(void *user_data, uint32_t id);
void (*reference_buffer)(void *user_data, uint32_t name, int fd,
struct wl_drm_buffer *buffer);
void (*reference_buffer)(void *user_data, uint32_t name, int fd,
struct wl_drm_buffer *buffer);
void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
bool (*is_format_supported)(void *user_data, uint32_t format);
bool (*is_format_supported)(void *user_data, uint32_t format);
};
struct wl_drm {
struct wl_display *display;
struct wl_global *wl_drm_global;
struct wl_display *display;
struct wl_global *wl_drm_global;
void *user_data;
char *device_name;
uint32_t flags;
void *user_data;
char *device_name;
uint32_t flags;
struct wayland_drm_callbacks callbacks;
struct wayland_drm_callbacks callbacks;
struct wl_buffer_interface buffer_interface;
struct wl_buffer_interface buffer_interface;
};
struct wl_drm_buffer {
struct wl_resource *resource;
struct wl_drm *drm;
int32_t width, height;
uint32_t format;
const void *driver_format;
int32_t offset[3];
int32_t stride[3];
void *driver_buffer;
struct wl_resource *resource;
struct wl_drm *drm;
int32_t width, height;
uint32_t format;
const void *driver_format;
int32_t offset[3];
int32_t stride[3];
void *driver_buffer;
};
enum { WAYLAND_DRM_PRIME = 0x01 };
@ -48,19 +47,19 @@ enum { WAYLAND_DRM_PRIME = 0x01 };
static inline struct wl_drm_buffer *
wayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource)
{
if (resource == NULL)
return NULL;
if (resource == NULL)
return NULL;
if (wl_resource_instance_of(resource, &wl_buffer_interface,
&drm->buffer_interface))
return wl_resource_get_user_data(resource);
else
return NULL;
if (wl_resource_instance_of(resource, &wl_buffer_interface,
&drm->buffer_interface))
return wl_resource_get_user_data(resource);
else
return NULL;
}
struct wl_drm *
wayland_drm_init(struct wl_display *display, char *device_name,
const struct wayland_drm_callbacks *callbacks, void *user_data,
const struct wayland_drm_callbacks *callbacks, void *user_data,
uint32_t flags);
void