summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Versace <chad.versace@linux.intel.com>2012-04-11 07:44:16 -0700
committerChad Versace <chad.versace@linux.intel.com>2012-04-11 18:04:33 -0700
commit27830f751e12b8b34221387db6bc935b12a9ba4b (patch)
tree9b60ca5fcab3774cb856304067a7648ab16f0019
parent6341289b4934e5d9ead9eba8aaa7af9f62fe1d1f (diff)
wayland: Add wayland module
Implement functions for wayland_platform: wayland_platform_create wayland_platform_destroy Implement all functions in native dispatch table: wayland_display_connect wayland_display_disconnect wayland_config_choose wayland_config_destroy wayland_context_create wayland_context_destroy wayland_window_create wayland_window_destroy wayland_make_current wayland_get_proc_address wayland_dlsym_gl Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
-rw-r--r--src/waffle/CMakeLists.txt12
-rw-r--r--src/waffle/wayland/wayland_config.c66
-rw-r--r--src/waffle/wayland/wayland_config.h30
-rw-r--r--src/waffle/wayland/wayland_context.c71
-rw-r--r--src/waffle/wayland/wayland_context.h28
-rw-r--r--src/waffle/wayland/wayland_display.c99
-rw-r--r--src/waffle/wayland/wayland_display.h28
-rw-r--r--src/waffle/wayland/wayland_gl_misc.c49
-rw-r--r--src/waffle/wayland/wayland_gl_misc.h38
-rw-r--r--src/waffle/wayland/wayland_platform.c116
-rw-r--r--src/waffle/wayland/wayland_platform.h28
-rw-r--r--src/waffle/wayland/wayland_priv_egl.c16
-rw-r--r--src/waffle/wayland/wayland_priv_egl.h22
-rw-r--r--src/waffle/wayland/wayland_priv_types.h68
-rw-r--r--src/waffle/wayland/wayland_window.c128
-rw-r--r--src/waffle/wayland/wayland_window.h33
16 files changed, 832 insertions, 0 deletions
diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt
index da4938b..ed82321 100644
--- a/src/waffle/CMakeLists.txt
+++ b/src/waffle/CMakeLists.txt
@@ -35,6 +35,18 @@ if(waffle_has_glx)
)
endif(waffle_has_glx)
+if(waffle_has_wayland)
+ list(APPEND waffle_sources
+ wayland/wayland_config.c
+ wayland/wayland_context.c
+ wayland/wayland_display.c
+ wayland/wayland_gl_misc.c
+ wayland/wayland_platform.c
+ wayland/wayland_priv_egl.c
+ wayland/wayland_window.c
+ )
+endif(waffle_has_wayland)
+
if(waffle_has_x11)
list(APPEND waffle_sources
x11/x11.c
diff --git a/src/waffle/wayland/wayland_config.c b/src/waffle/wayland/wayland_config.c
new file mode 100644
index 0000000..1fd7fb6
--- /dev/null
+++ b/src/waffle/wayland/wayland_config.c
@@ -0,0 +1,66 @@
+// 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 "wayland_config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <waffle/native.h>
+#include <waffle/waffle_enum.h>
+#include <waffle/core/wcore_error.h>
+
+#include "wayland_priv_egl.h"
+#include "wayland_priv_types.h"
+
+union native_config*
+wayland_config_choose(
+ union native_display *dpy,
+ const struct wcore_config_attrs *attrs)
+{
+ union native_platform *platform = dpy->wl->platform;
+ bool ok = true;
+
+ union native_config *self;
+ NATIVE_ALLOC(self, wl);
+ if (!self) {
+ wcore_error(WAFFLE_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ self->wl->display = dpy;
+
+ ok &= egl_get_render_buffer_attrib(attrs, &self->wl->egl_render_buffer);
+ if (!ok)
+ goto error;
+
+ self->wl->egl_config = egl_choose_config(dpy->wl->egl_display,
+ attrs,
+ platform->wl->gl_api);
+ if (!self->wl->egl_config)
+ goto error;
+
+ return self;
+
+error:
+ free(self);
+ return NULL;
+}
+
+bool
+wayland_config_destroy(union native_config *self)
+{
+ free(self);
+ return true;
+}
diff --git a/src/waffle/wayland/wayland_config.h b/src/waffle/wayland/wayland_config.h
new file mode 100644
index 0000000..74ac9dd
--- /dev/null
+++ b/src/waffle/wayland/wayland_config.h
@@ -0,0 +1,30 @@
+// 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>
+
+struct wcore_config_attrs;
+union native_config;
+union native_display;
+
+union native_config*
+wayland_config_choose(
+ union native_display *dpy,
+ const struct wcore_config_attrs *attrs);
+
+bool
+wayland_config_destroy(union native_config *self); \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_context.c b/src/waffle/wayland/wayland_context.c
new file mode 100644
index 0000000..fe4a9a7
--- /dev/null
+++ b/src/waffle/wayland/wayland_context.c
@@ -0,0 +1,71 @@
+// 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 "wayland_context.h"
+
+#include <stdlib.h>
+
+#include <waffle/native.h>
+#include <waffle/core/wcore_error.h>
+
+#include "wayland_priv_egl.h"
+#include "wayland_priv_types.h"
+
+union native_context*
+wayland_context_create(
+ union native_config *config,
+ union native_context *share_ctx)
+{
+ union native_display *dpy = config->wl->display;
+ union native_platform *platform = dpy->wl->platform;
+
+ union native_context *self;
+ NATIVE_ALLOC(self, wl);
+ if (!self) {
+ wcore_error(WAFFLE_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ self->wl->display = config->wl->display;
+ self->wl->egl_context = egl_create_context(
+ dpy->wl->egl_display,
+ config->wl->egl_config,
+ share_ctx
+ ? share_ctx->wl->egl_context
+ : NULL,
+ platform->wl->gl_api);
+
+ if (!self->wl->egl_context) {
+ free(self);
+ return NULL;
+ }
+
+ return self;
+}
+
+bool
+wayland_context_destroy(union native_context *self)
+{
+ if (!self)
+ return true;
+
+ bool ok = true;
+ union native_display *dpy = self->wl->display;
+
+ if (self->wl->egl_context)
+ ok &= egl_destroy_context(dpy->wl->egl_display,
+ self->wl->egl_context);
+ free(self);
+ return ok;
+}
diff --git a/src/waffle/wayland/wayland_context.h b/src/waffle/wayland/wayland_context.h
new file mode 100644
index 0000000..a33eb53
--- /dev/null
+++ b/src/waffle/wayland/wayland_context.h
@@ -0,0 +1,28 @@
+// 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*
+wayland_context_create(
+ union native_config *config,
+ union native_context *share_ctx);
+
+bool
+wayland_context_destroy(union native_context *self); \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_display.c b/src/waffle/wayland/wayland_display.c
new file mode 100644
index 0000000..3372ca0
--- /dev/null
+++ b/src/waffle/wayland/wayland_display.c
@@ -0,0 +1,99 @@
+// 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 "wayland_display.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <waffle/native.h>
+#include <waffle/core/wcore_error.h>
+
+#include "wayland_priv_egl.h"
+#include "wayland_priv_types.h"
+
+static void
+wayland_display_listener(
+ struct wl_display *display,
+ uint32_t id,
+ const char *interface,
+ uint32_t version,
+ void *data)
+{
+ union native_display *self = data;
+
+ if (!strncmp(interface, "wl_compositor", 14)) {
+ self->wl->wl_compositor = wl_display_bind(display, id,
+ &wl_compositor_interface);
+ }
+ else if (!strncmp(interface, "wl_shell", 9)) {
+ self->wl->wl_shell = wl_display_bind(display, id,
+ &wl_shell_interface);
+ }
+}
+
+union native_display*
+wayland_display_connect(
+ union native_platform *platform,
+ const char *name)
+{
+ union native_display *self;
+ NATIVE_ALLOC(self, wl);
+ if (!self) {
+ wcore_error(WAFFLE_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ self->wl->platform = platform;
+
+ self->wl->wl_display = wl_display_connect(name);
+ if (!self->wl->wl_display) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wl_display_connect failed");
+ goto error;
+ }
+
+ wl_display_add_global_listener(self->wl->wl_display,
+ wayland_display_listener,
+ self);
+
+ self->wl->egl_display = wayland_egl_initialize(self->wl->wl_display);
+ if (!self->wl->egl_display)
+ goto error;
+
+ return self;
+
+error:
+ WCORE_ERROR_DISABLED({
+ wayland_display_disconnect(self);
+ });
+ return NULL;
+}
+
+bool
+wayland_display_disconnect(union native_display *self)
+{
+ bool ok = true;
+
+ if (!self)
+ return true;
+
+ if (self->wl->egl_display)
+ ok &= egl_terminate(self->wl->egl_display);
+
+ if (self->wl->wl_display)
+ wl_display_disconnect(self->wl->wl_display);
+
+ free(self);
+ return ok;
+}
diff --git a/src/waffle/wayland/wayland_display.h b/src/waffle/wayland/wayland_display.h
new file mode 100644
index 0000000..0ef772e
--- /dev/null
+++ b/src/waffle/wayland/wayland_display.h
@@ -0,0 +1,28 @@
+// 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*
+wayland_display_connect(
+ union native_platform *platform,
+ const char *name);
+
+bool
+wayland_display_disconnect(union native_display *self); \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_gl_misc.c b/src/waffle/wayland/wayland_gl_misc.c
new file mode 100644
index 0000000..fc8e558
--- /dev/null
+++ b/src/waffle/wayland/wayland_gl_misc.c
@@ -0,0 +1,49 @@
+// 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 "wayland_gl_misc.h"
+
+#include <dlfcn.h>
+
+#include <waffle/native.h>
+
+#include "wayland_priv_egl.h"
+#include "wayland_priv_types.h"
+
+bool
+wayland_make_current(
+ union native_display *dpy,
+ union native_window *window,
+ union native_context *ctx)
+{
+ return egl_make_current(dpy->wl->egl_display,
+ window ? window->wl->egl_surface : 0,
+ ctx ? ctx->wl->egl_context : 0);
+}
+
+void*
+wayland_get_proc_address(
+ union native_platform *native,
+ const char *name)
+{
+ return eglGetProcAddress(name);
+}
+
+void*
+wayland_dlsym_gl(
+ union native_platform *native,
+ const char *name)
+{
+ return dlsym(native->wl->libgl, name);
+} \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_gl_misc.h b/src/waffle/wayland/wayland_gl_misc.h
new file mode 100644
index 0000000..b329f9c
--- /dev/null
+++ b/src/waffle/wayland/wayland_gl_misc.h
@@ -0,0 +1,38 @@
+// 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
+wayland_make_current(
+ union native_display *dpy,
+ union native_window *window,
+ union native_context *ctx);
+
+void*
+wayland_get_proc_address(
+ union native_platform *native,
+ const char *name);
+
+void*
+wayland_dlsym_gl(
+ union native_platform *native,
+ const char *name); \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_platform.c b/src/waffle/wayland/wayland_platform.c
new file mode 100644
index 0000000..133c848
--- /dev/null
+++ b/src/waffle/wayland/wayland_platform.c
@@ -0,0 +1,116 @@
+// 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 "wayland_platform.h"
+
+#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
+
+#include <dlfcn.h>
+#include <stdlib.h>
+
+#include <waffle/native.h>
+#include <waffle/waffle_enum.h>
+#include <waffle/core/wcore_error.h>
+
+#include "wayland_config.h"
+#include "wayland_context.h"
+#include "wayland_display.h"
+#include "wayland_gl_misc.h"
+#include "wayland_priv_egl.h"
+#include "wayland_priv_types.h"
+#include "wayland_window.h"
+
+static const struct native_dispatch wayland_dispatch = {
+ .display_connect = wayland_display_connect,
+ .display_disconnect = wayland_display_disconnect,
+ .config_choose = wayland_config_choose,
+ .config_destroy = wayland_config_destroy,
+ .context_create = wayland_context_create,
+ .context_destroy = wayland_context_destroy,
+ .window_create = wayland_window_create,
+ .window_destroy = wayland_window_destroy,
+ .window_swap_buffers = wayland_window_swap_buffers,
+ .make_current = wayland_make_current,
+ .get_proc_address = wayland_get_proc_address,
+ .dlsym_gl = wayland_dlsym_gl,
+};
+
+union native_platform*
+wayland_platform_create(
+ int gl_api,
+ const struct native_dispatch **dispatch)
+{
+ bool ok = true;
+
+ union native_platform *self;
+ NATIVE_ALLOC(self, wl);
+ if (!self) {
+ wcore_error(WAFFLE_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ self->wl->gl_api = gl_api;
+
+ switch (gl_api) {
+ case WAFFLE_OPENGL: self->wl->libgl_name = "libGL.so"; break;
+ case WAFFLE_OPENGL_ES1: self->wl->libgl_name = "libGLESv1_CM.so"; break;
+ case WAFFLE_OPENGL_ES2: self->wl->libgl_name = "libGLESv2.so"; break;
+ default:
+ wcore_error_internal("gl_api has bad value 0x%x", gl_api);
+ goto error;
+ }
+
+ setenv("EGL_PLATFORM", "wayland", true);
+ ok &= egl_bind_api(gl_api);
+ if (!ok)
+ goto error;
+
+ self->wl->libgl = dlopen(self->wl->libgl_name, RTLD_LAZY);
+ if (!self->wl->libgl) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR,
+ "dlopen(\"%s\") failed", self->wl->libgl_name);
+ goto error;
+ }
+
+ *dispatch = &wayland_dispatch;
+ return self;
+
+error:
+ WCORE_ERROR_DISABLED({
+ wayland_platform_destroy(self);
+ });
+ return NULL;
+}
+
+bool
+wayland_platform_destroy(union native_platform *self)
+{
+ int error = 0;
+
+ if (!self)
+ return true;
+
+ unsetenv("EGL_PLATFORM");
+
+ if (self->wl->libgl) {
+ error |= dlclose(self->wl->libgl);
+ if (error) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR, "dlclose() failed on \"%s\"",
+ self->wl->libgl_name);
+ }
+ }
+
+ free(self);
+ return !error;
+}
diff --git a/src/waffle/wayland/wayland_platform.h b/src/waffle/wayland/wayland_platform.h
new file mode 100644
index 0000000..a5d0f84
--- /dev/null
+++ b/src/waffle/wayland/wayland_platform.h
@@ -0,0 +1,28 @@
+// 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*
+wayland_platform_create(
+ int gl_api,
+ const struct native_dispatch **dispatch);
+
+bool
+wayland_platform_destroy(union native_platform *self); \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_priv_egl.c b/src/waffle/wayland/wayland_priv_egl.c
new file mode 100644
index 0000000..2772532
--- /dev/null
+++ b/src/waffle/wayland/wayland_priv_egl.c
@@ -0,0 +1,16 @@
+// 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 "wayland_priv_egl.h"
+#include <waffle/egl/egl_native_template.c> \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_priv_egl.h b/src/waffle/wayland/wayland_priv_egl.h
new file mode 100644
index 0000000..1e5df88
--- /dev/null
+++ b/src/waffle/wayland/wayland_priv_egl.h
@@ -0,0 +1,22 @@
+// 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
+
+// WL_EGL_PLATFORM configures Mesa's <EGL/egl.h> to define native types (such
+// as EGLNativeDisplay) as Wayland types rather than Xlib types.
+#define WL_EGL_PLATFORM 1
+
+#define NATIVE_EGL(basename) wayland_egl_##basename
+#include <waffle/egl/egl.h>
diff --git a/src/waffle/wayland/wayland_priv_types.h b/src/waffle/wayland/wayland_priv_types.h
new file mode 100644
index 0000000..90eae6b
--- /dev/null
+++ b/src/waffle/wayland/wayland_priv_types.h
@@ -0,0 +1,68 @@
+// 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
+
+// WL_EGL_PLATFORM configures Mesa's <EGL/egl.h> to define native types (such
+// as EGLNativeDisplay) as Wayland types rather than Xlib types.
+#define WL_EGL_PLATFORM 1
+
+#include <wayland-client.h>
+#include <wayland-egl.h>
+
+#include <EGL/egl.h>
+
+union native_display;
+union native_platform;
+
+struct wayland_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 wayland_display {
+ union native_platform *platform;
+ struct wl_display *wl_display;
+ struct wl_compositor *wl_compositor;
+ struct wl_shell *wl_shell;
+ EGLDisplay egl_display;
+};
+
+struct wayland_config {
+ union native_display *display;
+ EGLConfig egl_config;
+
+ /// The value of @c EGL_RENDER_BUFFER that will be set in the attrib_list
+ /// of eglCreateWindowSurface().
+ EGLint egl_render_buffer;
+};
+
+struct wayland_context {
+ union native_display *display;
+ EGLContext egl_context;
+};
+
+struct wayland_window {
+ union native_display *display;
+ struct wl_surface *wl_surface;
+ struct wl_shell_surface *wl_shell_surface;
+ struct wl_egl_window *wl_window;
+ EGLSurface egl_surface;
+};
diff --git a/src/waffle/wayland/wayland_window.c b/src/waffle/wayland/wayland_window.c
new file mode 100644
index 0000000..ccf5bff
--- /dev/null
+++ b/src/waffle/wayland/wayland_window.c
@@ -0,0 +1,128 @@
+// 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 "wayland_window.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <waffle/native.h>
+#include <waffle/core/wcore_error.h>
+#include <waffle/x11/x11.h>
+
+#include "wayland_priv_egl.h"
+#include "wayland_priv_types.h"
+
+union native_window*
+wayland_window_create(
+ union native_config *config,
+ int width,
+ int height)
+{
+ union native_display *display = config->wl->display;
+
+ union native_window *self;
+ NATIVE_ALLOC(self, wl);
+ if (!self) {
+ wcore_error(WAFFLE_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ self->wl->display = display;
+
+ if (!display->wl->wl_compositor) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wayland compositor not found");
+ goto error;
+ }
+ if (!display->wl->wl_shell) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wayland shell not found");
+ goto error;
+ }
+
+ self->wl->wl_surface = wl_compositor_create_surface(display->wl->wl_compositor);
+ if (!self->wl->wl_surface) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR,
+ "wl_compositor_create_surface failed");
+ goto error;
+ }
+
+ self->wl->wl_shell_surface = wl_shell_get_shell_surface(
+ display->wl->wl_shell,
+ self->wl->wl_surface);
+ if (!self->wl->wl_shell_surface) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR,
+ "wl_shell_get_shell_surface failed");
+ goto error;
+ }
+
+ self->wl->wl_window = wl_egl_window_create(self->wl->wl_surface,
+ width,
+ height);
+ if (!self->wl->wl_window) {
+ wcore_errorf(WAFFLE_UNKNOWN_ERROR, "wl_egl_window_create failed");
+ goto error;
+ }
+
+ self->wl->egl_surface = wayland_egl_create_window_surface(
+ display->wl->egl_display,
+ config->wl->egl_config,
+ self->wl->wl_window,
+ config->wl->egl_render_buffer);
+ if (!self->wl->egl_surface)
+ goto error;
+
+
+ wl_shell_surface_set_toplevel(self->wl->wl_shell_surface);
+
+ return self;
+
+error:
+ WCORE_ERROR_DISABLED({
+ wayland_window_destroy(self);
+ });
+ return NULL;
+}
+
+bool
+wayland_window_destroy(union native_window *self)
+{
+ if (!self)
+ return true;
+
+ bool ok = true;
+ union native_display *dpy = self->wl->display;
+
+ if (self->wl->egl_surface)
+ ok &= egl_destroy_surface(dpy->wl->egl_display,
+ self->wl->egl_surface);
+
+ if (self->wl->wl_window)
+ wl_egl_window_destroy(self->wl->wl_window);
+ if (self->wl->wl_shell_surface)
+ wl_shell_surface_destroy(self->wl->wl_shell_surface);
+ if (self->wl->wl_surface)
+ wl_surface_destroy(self->wl->wl_surface);
+
+ free(self);
+ return ok;
+}
+
+
+bool
+wayland_window_swap_buffers(union native_window *self)
+{
+ union native_display *dpy = self->wl->display;
+ return egl_swap_buffers(dpy->wl->egl_display,
+ self->wl->egl_surface);
+} \ No newline at end of file
diff --git a/src/waffle/wayland/wayland_window.h b/src/waffle/wayland/wayland_window.h
new file mode 100644
index 0000000..81b0642
--- /dev/null
+++ b/src/waffle/wayland/wayland_window.h
@@ -0,0 +1,33 @@
+// 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_config;
+union native_display;
+union native_window;
+
+union native_window*
+wayland_window_create(
+ union native_config *config,
+ int width,
+ int height);
+
+bool
+wayland_window_destroy(union native_window *self);
+
+bool
+wayland_window_swap_buffers(union native_window *self); \ No newline at end of file