Commit 9730478f authored by Chad Versace's avatar Chad Versace

xegl: Add xegl platform

Define the following types:
    struct xegl_config
    struct xegl_context
    struct xegl_display
    struct xegl_platform
    struct xegl_window

Implement the following functions, which includes all entries in the
native dispatch table:
    xegl_config_choose
    xegl_config_destroy
    xegl_context_create
    xegl_context_destroy
    xegl_display_connect
    xegl_display_disconnect
    xegl_dlsym_gl
    xegl_get_proc_address
    xegl_make_current
    xegl_platform_create
    xegl_platform_destroy
    xegl_window_create
    xegl_window_destroy
    xegl_window_swap_buffers
Signed-off-by: default avatarChad Versace <chad.versace@linux.intel.com>
parent 5e56c701
......@@ -20,6 +20,18 @@ if(waffle_has_x11)
)
endif(waffle_has_x11)
if(waffle_has_x11_egl)
list(APPEND waffle_sources
x11_egl/xegl_config.c
x11_egl/xegl_context.c
x11_egl/xegl_display.c
x11_egl/xegl_gl_misc.c
x11_egl/xegl_platform.c
x11_egl/xegl_priv_egl.c
x11_egl/xegl_window.c
)
endif(waffle_has_x11_egl)
add_library(waffle SHARED ${waffle_sources})
if(waffle_has_egl)
......
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_config.h"
#include <stdlib.h>
#include <string.h>
#include <waffle/native.h>
#include <waffle/waffle_enum.h>
#include <waffle/core/wcore_error.h>
#include "xegl_priv_egl.h"
#include "xegl_priv_types.h"
union native_config*
xegl_config_choose(
union native_display *dpy,
const int32_t attrib_list[])
{
union native_platform *platform = dpy->xegl->platform;
bool ok = true;
union native_config *self;
NATIVE_ALLOC(self, xegl);
if (!self) {
wcore_error(WAFFLE_OUT_OF_MEMORY);
return NULL;
}
self->xegl->display = dpy;
ok &= egl_get_render_buffer_attrib(attrib_list,
&self->xegl->egl_render_buffer);
if (!ok) goto error;
self->xegl->egl_config = egl_choose_config(dpy->xegl->egl_display,
attrib_list,
platform->xegl->gl_api);
if (!self->xegl->egl_config) goto error;
ok &= eglGetConfigAttrib(dpy->xegl->egl_display,
self->xegl->egl_config,
EGL_NATIVE_VISUAL_ID,
(EGLint*) &self->xegl->xcb_visual_id);
if (!ok) {
egl_get_error("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID)");
goto error;
}
return self;
error:
free(self);
return NULL;
}
bool
xegl_config_destroy(union native_config *self)
{
free(self);
return true;
}
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
#include <stdint.h>
union native_config;
union native_display;
union native_config*
xegl_config_choose(
union native_display *dpy,
const int32_t attrib_list[]);
bool
xegl_config_destroy(union native_config *self);
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_context.h"
#include <stdlib.h>
#include <waffle/native.h>
#include <waffle/core/wcore_error.h>
#include "xegl_priv_egl.h"
#include "xegl_priv_types.h"
union native_context*
xegl_context_create(
union native_config *config,
union native_context *share_ctx)
{
union native_display *dpy = config->xegl->display;
union native_platform *platform = dpy->xegl->platform;
union native_context *self;
NATIVE_ALLOC(self, xegl);
if (!self) {
wcore_error(WAFFLE_OUT_OF_MEMORY);
return NULL;
}
self->xegl->display = config->xegl->display;
self->xegl->egl_context = egl_create_context(
dpy->xegl->egl_display,
config->xegl->egl_config,
share_ctx
? share_ctx->xegl->egl_context
: NULL,
platform->xegl->gl_api);
if (!self->xegl->egl_context) {
free(self);
return NULL;
}
return self;
}
bool
xegl_context_destroy(union native_context *self)
{
if (!self)
return true;
bool ok = true;
union native_display *dpy = self->xegl->display;
if (self->xegl->egl_context)
ok &= egl_destroy_context(dpy->xegl->egl_display,
self->xegl->egl_context);
free(self);
return ok;
}
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
union native_context;
union native_config;
union native_context*
xegl_context_create(
union native_config *config,
union native_context *share_ctx);
bool
xegl_context_destroy(union native_context *self);
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_display.h"
#include <stdlib.h>
#include <xcb/xcb.h>
#include <X11/Xlib-xcb.h>
#include <waffle/native.h>
#include <waffle/core/wcore_error.h>
#include <waffle/x11/x11.h>
#include "xegl_priv_egl.h"
#include "xegl_priv_types.h"
union native_display*
xegl_display_connect(
union native_platform *platform,
const char *name)
{
bool ok = true;
union native_display *self;
NATIVE_ALLOC(self, xegl);
if (!self) {
wcore_error(WAFFLE_OUT_OF_MEMORY);
return NULL;
}
self->xegl->platform = platform;
ok &= x11_display_connect(name, &self->xegl->xlib_display, &self->xegl->xcb_connection);
if (!ok)
goto error;
self->xegl->egl_display = xegl_egl_initialize(self->xegl->xlib_display);
if (!self->xegl->egl_display)
goto error;
return self;
error:
WCORE_ERROR_DISABLED({
xegl_display_disconnect(self);
});
return NULL;
}
bool
xegl_display_disconnect(union native_display *self)
{
bool ok = true;
if (!self)
return true;
if (self->xegl->egl_display)
ok &= egl_terminate(self->xegl->egl_display);
if (self->xegl->xlib_display)
ok &= x11_display_disconnect(self->xegl->xlib_display);
free(self);
return ok;
}
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
union native_display;
union native_platform;
union native_display*
xegl_display_connect(
union native_platform *platform,
const char *name);
bool
xegl_display_disconnect(union native_display *self);
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_gl_misc.h"
#include <dlfcn.h>
#include <waffle/native.h>
#include "xegl_priv_egl.h"
#include "xegl_priv_types.h"
bool
xegl_make_current(
union native_window *window,
union native_context *ctx)
{
union native_display *dpy = window->xegl->display;
bool ok = egl_make_current(dpy->xegl->egl_display,
window->xegl->egl_surface,
ctx->xegl->egl_context);
return ok;
}
void*
xegl_get_proc_address(
union native_platform *native,
const char *name)
{
return eglGetProcAddress(name);
}
void*
xegl_dlsym_gl(
union native_platform *native,
const char *name)
{
return dlsym(native->xegl->libgl, name);
}
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
union native_platform;
union native_display;
union native_window;
union native_context;
bool
xegl_make_current(
union native_window *window,
union native_context *ctx);
void*
xegl_get_proc_address(
union native_platform *native,
const char *name);
void*
xegl_dlsym_gl(
union native_platform *native,
const char *name);
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_platform.h"
#include <dlfcn.h>
#include <stdlib.h>
#include <waffle/native.h>
#include <waffle/waffle_enum.h>
#include <waffle/core/wcore_error.h>
#include "xegl_config.h"
#include "xegl_context.h"
#include "xegl_display.h"
#include "xegl_gl_misc.h"
#include "xegl_priv_egl.h"
#include "xegl_priv_types.h"
#include "xegl_window.h"
static const struct native_dispatch xegl_dispatch = {
.display_connect = xegl_display_connect,
.display_disconnect = xegl_display_disconnect,
.config_choose = xegl_config_choose,
.config_destroy = xegl_config_destroy,
.context_create = xegl_context_create,
.context_destroy = xegl_context_destroy,
.window_create = xegl_window_create,
.window_destroy = xegl_window_destroy,
.window_swap_buffers = xegl_window_swap_buffers,
.make_current = xegl_make_current,
.get_proc_address = xegl_get_proc_address,
.dlsym_gl = xegl_dlsym_gl,
};
union native_platform*
xegl_platform_create(
int gl_api,
const struct native_dispatch **dispatch)
{
bool ok = true;
union native_platform *self;
NATIVE_ALLOC(self, xegl);
if (!self) {
wcore_error(WAFFLE_OUT_OF_MEMORY);
return NULL;
}
self->xegl->gl_api = gl_api;
switch (gl_api) {
case WAFFLE_GL: self->xegl->libgl_name = "libGL.so"; break;
case WAFFLE_GLES1: self->xegl->libgl_name = "libGLESv1_CM.so"; break;
case WAFFLE_GLES2: self->xegl->libgl_name = "libGLESv2.so"; break;
default:
wcore_error_internal("gl_api has bad value 0x%x", gl_api);
goto error;
}
ok &= egl_bind_api(gl_api);
if (!ok)
goto error;
self->xegl->libgl = dlopen(self->xegl->libgl_name, RTLD_LAZY);
if (!self->xegl->libgl) {
wcore_errorf(WAFFLE_UNKNOWN_ERROR,
"dlopen(\"%s\") failed", self->xegl->libgl_name);
goto error;
}
*dispatch = &xegl_dispatch;
return self;
error:
WCORE_ERROR_DISABLED({
xegl_platform_destroy(self);
});
return NULL;
}
bool
xegl_platform_destroy(union native_platform *self)
{
int error = 0;
if (!self)
return true;
if (self->xegl->libgl) {
error |= dlclose(self->xegl->libgl);
if (error) {
wcore_errorf(WAFFLE_UNKNOWN_ERROR, "dlclose() failed on \"%s\"",
self->xegl->libgl_name);
}
}
free(self);
return !error;
}
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
struct native_dispatch;
union native_platform;
union native_platform*
xegl_platform_create(
int gl_api,
const struct native_dispatch **dispatch);
bool
xegl_platform_destroy(union native_platform *self);
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_priv_egl.h"
#include <waffle/egl/egl_native_template.c>
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#define NATIVE_EGL(basename) xegl_egl_##basename
#include <waffle/egl/egl.h>
\ No newline at end of file
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <EGL/egl.h>
#include <X11/Xlib.h>
#include <xcb/xcb.h>
union native_display;
union native_platform;
struct xegl_platform {
/// @brief One of WAFFLE_{GL,GLES1,GLES2}.
int gl_api;
/// @brief The GL library obtained with dlopen().
void *libgl;
/// @brief For example, "libGLESv2.so".
const char *libgl_name;
};
struct xegl_display {
union native_platform *platform;
Display *xlib_display;
xcb_connection_t *xcb_connection;
EGLDisplay egl_display;
};
struct xegl_config {
union native_display *display;
EGLConfig egl_config;
xcb_visualid_t xcb_visual_id;
/// The value of @c EGL_RENDER_BUFFER that will be set in the attrib_list
/// of eglCreateWindowSurface().
EGLint egl_render_buffer;
};
struct xegl_context {
union native_display *display;
EGLContext egl_context;
};
struct xegl_window {
union native_display *display;
xcb_window_t xcb_window;
EGLSurface egl_surface;
};
// Copyright 2012 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "xegl_window.h"
#include <stdlib.h>
#include <string.h>
#include <waffle/native.h>
#include <waffle/core/wcore_error.h>
#include <waffle/x11/x11.h>
#include "xegl_priv_egl.h"
#include "xegl_priv_types.h"
union native_window*
xegl_window_create(
union native_config *config,
int width,
int height)
{
union native_display *display = config->xegl->display;
union native_window *self;
NATIVE_ALLOC(self, xegl);
if (!self) {
wcore_error(WAFFLE_OUT_OF_MEMORY);
return NULL;
}
self->xegl->display = display;
self->xegl->xcb_window = x11_window_create(
display->xegl->xcb_connection,
config->xegl->xcb_visual_id,
width,
height);
if (!self->xegl->xcb_window)
goto error;
self->xegl->egl_surface = xegl_egl_create_window_surface(
display->xegl->egl_display,
config->xegl->egl_config,
self->xegl->xcb_window,
config->xegl->egl_render_buffer);
if (!self->xegl->egl_surface)
goto error;
return self;
error:
WCORE_ERROR_DISABLED({
xegl_window_destroy(self);
});
return NULL;
}
bool
xegl_window_destroy(union native_window *self)
{
if (!self)
return true;
bool ok = true;
union native_display *dpy = self->xegl->display;
if (self->xegl->egl_surface)
ok &= egl_destroy_surface(dpy->xegl->egl_display,
self->xegl->egl_surface);
if (self->xegl->xcb_window)