Commit cdd808d3 authored by chadversary's avatar chadversary

surfaceless_egl: Implement new platform (v2)

Now waffle_init() supports WAFFLE_PLATFORM_SURFACELESS_EGL.

v2:
  - Add new enum to wcore_enum_to_string(). [per emil]

Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Haixia Shi <hshi@chromium.org>
Reviewed-by: Emil Velikov's avatarEmil Velikov <emil.l.velikov@gmail.com>
parent 7318f22c
......@@ -119,6 +119,7 @@ enum waffle_enum {
WAFFLE_PLATFORM_GBM = 0x0016,
WAFFLE_PLATFORM_WGL = 0x0017,
WAFFLE_PLATFORM_NACL = 0x0018,
WAFFLE_PLATFORM_SURFACELESS_EGL = 0x0019,
// ------------------------------------------------------------------
// For waffle_config_choose()
......
......@@ -129,6 +129,15 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>WAFFLE_PLATFORM_SURFACELESS_EGL</constant></term>
<listitem>
<para>
[Linux] Use EGL's "surfaceless" platform,
<ulink url="https://www.khronos.org/registry/egl/extensions/MESA/EGL_MESA_platform_surfaceless.txt">EGL_MESA_platform_surfaceless</ulink>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>WAFFLE_PLATFORM_WAYLAND</constant></term>
<listitem>
......
......@@ -16,6 +16,7 @@ include_directories(
glx
linux
nacl
surfaceless_egl
wayland
wgl
x11
......@@ -127,6 +128,14 @@ if(waffle_on_linux)
)
endif()
if(waffle_has_surfaceless_egl)
list(APPEND waffle_sources
surfaceless_egl/sl_display.c
surfaceless_egl/sl_platform.c
surfaceless_egl/sl_window.c
)
endif()
if(waffle_has_wayland)
list(APPEND waffle_sources
wayland/wayland_display.c
......
......@@ -36,6 +36,7 @@ struct wcore_platform* xegl_platform_create(void);
struct wcore_platform* wgbm_platform_create(void);
struct wcore_platform* wgl_platform_create(void);
struct wcore_platform* nacl_platform_create(void);
struct wcore_platform* sl_platform_create(void);
static bool
waffle_init_parse_attrib_list(
......@@ -111,6 +112,12 @@ waffle_init_parse_attrib_list(
CASE_UNDEFINED_PLATFORM(NACL)
#endif
#ifdef WAFFLE_HAS_SURFACELESS_EGL
CASE_DEFINED_PLATFORM(SURFACELESS_EGL)
#else
CASE_UNDEFINED_PLATFORM(SURFACELESS_EGL)
#endif
default:
wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE,
"WAFFLE_PLATFORM has bad value 0x%x",
......@@ -184,6 +191,11 @@ waffle_init_create_platform(int32_t waffle_platform)
case WAFFLE_PLATFORM_NACL:
wc_platform = nacl_platform_create();
break;
#endif
#ifdef WAFFLE_HAS_SURFACELESS_EGL
case WAFFLE_PLATFORM_SURFACELESS_EGL:
wc_platform = sl_platform_create();
break;
#endif
default:
assert(false);
......
......@@ -103,6 +103,7 @@ wcore_enum_to_string(int32_t e)
CASE(WAFFLE_PLATFORM_GBM);
CASE(WAFFLE_PLATFORM_WGL);
CASE(WAFFLE_PLATFORM_NACL);
CASE(WAFFLE_PLATFORM_SURFACELESS_EGL);
CASE(WAFFLE_CONTEXT_API);
CASE(WAFFLE_CONTEXT_OPENGL);
CASE(WAFFLE_CONTEXT_OPENGL_ES1);
......
......@@ -54,6 +54,9 @@ setup_env(const struct wegl_platform *self)
case EGL_PLATFORM_X11_KHR:
setenv("EGL_PLATFORM", "x11", true);
break;
case EGL_PLATFORM_SURFACELESS_MESA:
setenv("EGL_PLATFORM", "surfaceless", true);
break;
default:
assert(!"bad egl_platform enum");
break;
......@@ -207,6 +210,9 @@ wegl_platform_can_use_eglGetPlatformDisplay(const struct wegl_platform *plat)
case EGL_PLATFORM_X11_KHR:
ext = "EGL_KHR_platform_x11";
break;
case EGL_PLATFORM_SURFACELESS_MESA:
ext = "EGL_MESA_platform_surfaceless";
break;
default:
assert(!"bad egl_platform enum");
return false;
......@@ -236,6 +242,9 @@ wegl_platform_can_use_eglGetPlatformDisplayEXT(const struct wegl_platform *plat)
case EGL_PLATFORM_X11_KHR:
ext = "EGL_EXT_platform_x11";
break;
case EGL_PLATFORM_SURFACELESS_MESA:
ext = "EGL_MESA_platform_surfaceless";
break;
default:
assert(!"bad egl_platform enum");
return false;
......
// Copyright 2016 Google
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "wcore_error.h"
#include "sl_display.h"
#include "sl_platform.h"
bool
sl_display_destroy(struct wcore_display *wc_self)
{
struct sl_display *self = sl_display(wegl_display(wc_self));
bool ok = true;
if (!self)
return ok;
ok &= wegl_display_teardown(&self->wegl);
free(self);
return ok;
}
struct wcore_display*
sl_display_connect(struct wcore_platform *wc_plat, const char *name)
{
struct sl_display *self;
bool ok = true;
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
if (name != NULL) {
wcore_errorf(WAFFLE_ERROR_BAD_PARAMETER,
"parameter 'name' is not NULL");
goto fail;
}
ok = wegl_display_init(&self->wegl, wc_plat, NULL);
if (!ok)
goto fail;
return &self->wegl.wcore;
fail:
sl_display_destroy(&self->wegl.wcore);
return NULL;
}
// Copyright 2016 Google
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdbool.h>
#include "wegl_display.h"
struct sl_display {
struct wegl_display wegl;
};
DEFINE_CONTAINER_CAST_FUNC(sl_display,
struct sl_display,
struct wegl_display,
wegl)
struct wcore_display*
sl_display_connect(struct wcore_platform *wc_plat, const char *name);
bool
sl_display_destroy(struct wcore_display *wc_self);
// Copyright 2012 Intel Corporation
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <dlfcn.h>
#include "wcore_error.h"
#include "linux_platform.h"
#include "wegl_config.h"
#include "wegl_context.h"
#include "wegl_platform.h"
#include "wegl_util.h"
#include "sl_display.h"
#include "sl_platform.h"
#include "sl_window.h"
static const struct wcore_platform_vtbl sl_platform_vtbl;
static bool
sl_platform_destroy(struct wcore_platform *wc_self)
{
struct sl_platform *self = sl_platform(wegl_platform(wc_self));
bool ok = true;
if (!self)
return true;
if (self->linux)
ok &= linux_platform_destroy(self->linux);
ok &= wegl_platform_teardown(&self->wegl);
free(self);
return ok;
}
struct wcore_platform*
sl_platform_create(void)
{
bool ok = true;
struct sl_platform *self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
ok = wegl_platform_init(&self->wegl, EGL_PLATFORM_SURFACELESS_MESA);
if (!ok)
goto fail;
self->wegl.egl_surface_type_mask = EGL_PBUFFER_BIT;
self->linux = linux_platform_create();
if (!self->linux)
goto fail;
self->wegl.wcore.vtbl = &sl_platform_vtbl;
return &self->wegl.wcore;
fail:
sl_platform_destroy(&self->wegl.wcore);
return NULL;
}
static bool
sl_dl_can_open(struct wcore_platform *wc_self, int32_t waffle_dl)
{
struct sl_platform *self = sl_platform(wegl_platform(wc_self));
return linux_platform_dl_can_open(self->linux, waffle_dl);
}
static void*
sl_dl_sym(struct wcore_platform *wc_self,
int32_t waffle_dl, const char *name)
{
struct sl_platform *self = sl_platform(wegl_platform(wc_self));
return linux_platform_dl_sym(self->linux, waffle_dl, name);
}
// [chadv] I regret the design of the get_native interface, and wish to
// deprecate and replace it with the interface that Ian Romanick orignally
// recommended: waffle_display_get_egl_display(),
// waffle_display_get_gbm_device(), waffle_display_get_xlib_display(), etc. As
// a first step towards that goal, I choose to not support the interface on new
// platforms.
static const struct wcore_platform_vtbl sl_platform_vtbl = {
.destroy = sl_platform_destroy,
.make_current = wegl_make_current,
.get_proc_address = wegl_get_proc_address,
.dl_can_open = sl_dl_can_open,
.dl_sym = sl_dl_sym,
.display = {
.connect = sl_display_connect,
.destroy = sl_display_destroy,
.supports_context_api = wegl_display_supports_context_api,
.get_native = NULL, // unsupported by platform
},
.config = {
.choose = wegl_config_choose,
.destroy = wegl_config_destroy,
.get_native = NULL, // unsupported by platform
},
.context = {
.create = wegl_context_create,
.destroy = wegl_context_destroy,
.get_native = NULL, // unsupported by platform
},
.window = {
.create = sl_window_create,
.destroy = sl_window_destroy,
.show = sl_window_show,
.swap_buffers = wegl_surface_swap_buffers,
.get_native = NULL, // unsupported by platform
},
};
// Copyright 2016 Google
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdbool.h>
#include <stdlib.h>
#include <gbm.h>
#undef linux
#include "wegl_platform.h"
#include "wcore_util.h"
struct linux_platform;
struct sl_platform {
struct wegl_platform wegl;
struct linux_platform *linux;
};
DEFINE_CONTAINER_CAST_FUNC(sl_platform,
struct sl_platform,
struct wegl_platform,
wegl)
struct wcore_platform *sl_platform_create(void);
// Copyright 2016 Google
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <string.h>
#include "wcore_attrib_list.h"
#include "wcore_error.h"
#include "wegl_config.h"
#include "sl_display.h"
#include "sl_platform.h"
#include "sl_window.h"
bool
sl_window_destroy(struct wcore_window *wc_self)
{
struct sl_window *self = sl_window(wegl_surface(wc_self));
bool ok = true;
if (!self)
return true;
ok &= wegl_surface_teardown(&self->wegl);
free(self);
return ok;
}
struct wcore_window*
sl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
int32_t width,
int32_t height,
const intptr_t attrib_list[])
{
struct sl_window *self;
bool ok = true;
if (width == -1 && height == -1) {
wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
"fullscreen window not supported");
return NULL;
}
if (wcore_attrib_list_length(attrib_list) > 0) {
wcore_error_bad_attribute(attrib_list[0]);
return NULL;
}
self = wcore_calloc(sizeof(*self));
if (self == NULL)
return NULL;
ok = wegl_pbuffer_init(&self->wegl, wc_config, width, height);
if (!ok)
goto error;
return &self->wegl.wcore;
error:
sl_window_destroy(&self->wegl.wcore);
return NULL;
}
bool
sl_window_show(struct wcore_window *wc_self)
{
return true;
}
// Copyright 2016 Google
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <stdbool.h>
#include "wegl_surface.h"
struct wcore_platform;
struct sl_window {
struct wegl_surface wegl;
};
DEFINE_CONTAINER_CAST_FUNC(sl_window,
struct sl_window,
struct wegl_surface,
wegl)
struct wcore_window*
sl_window_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
int32_t width,
int32_t height,
const intptr_t attrib_list[]);
bool
sl_window_destroy(struct wcore_window *wc_self);
bool
sl_window_show(struct wcore_window *wc_self);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment