diff options
68 files changed, 1582 insertions, 657 deletions
@@ -8,8 +8,8 @@ waffle_top := $(LOCAL_PATH) # waffle_major_version := 1 waffle_minor_version := 5 -waffle_patch_version := 1 -waffle_api_version := 0x0105 +waffle_patch_version := 90 +waffle_api_version := 0x0106 waffle_android_major_version := $(word 1, $(subst ., , $(PLATFORM_VERSION))) waffle_android_minor_version := $(word 2, $(subst ., , $(PLATFORM_VERSION))) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fabb54..02e995e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ # 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. -project(waffle1 C) +project(waffle1 C CXX) cmake_minimum_required(VERSION 2.8.11) @@ -128,8 +128,8 @@ if(waffle_build_examples) endif() # ------------------------------------------------------------------------------ -# Install packaging files: waffle.pc, FindWaffle.cmake, -# WaffleConfigVersion.cmake, and WaffleConfig.cmake +# Install packaging files: waffle.pc WaffleConfigVersion.cmake, and +# WaffleConfig.cmake # ------------------------------------------------------------------------------ configure_file(waffle.pc.in ${waffle_libname}.pc @ONLY) @@ -140,12 +140,6 @@ install( COMPONENT pkgconfig ) -install( - FILES cmake/Modules/FindWaffle.cmake - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/Modules" - COMPONENT cmakefind - ) - set(ConfigPackageLocation "${CMAKE_INSTALL_LIBDIR}/cmake/Waffle") include(CMakePackageConfigHelpers) write_basic_package_version_file( diff --git a/Options.cmake b/Options.cmake index c316070..4f097a0 100644 --- a/Options.cmake +++ b/Options.cmake @@ -28,6 +28,11 @@ if(waffle_on_linux) option(waffle_has_wayland "Build support for Wayland" ${wayland_default}) option(waffle_has_x11_egl "Build support for X11/EGL" ${x11_egl_default}) option(waffle_has_gbm "Build support for GBM" ${gbm_default}) + option(waffle_has_nacl "Build support for NaCl" OFF) + + # NaCl specific settings. + set(nacl_sdk_path "" CACHE STRING "Set nacl_sdk path here") + set(nacl_version "pepper_39" CACHE STRING "Set NaCl bundle here") endif() option(waffle_build_tests "Build tests" ON) diff --git a/cmake/Modules/FindWaffle.cmake b/cmake/Modules/FindWaffle.cmake deleted file mode 100644 index 4e16c4e..0000000 --- a/cmake/Modules/FindWaffle.cmake +++ /dev/null @@ -1,78 +0,0 @@ -# - Locate the Waffle library and headers. -# This module defines the following variables: -# WAFFLE_INCLUDE_DIRS Full path to directory of the main Waffle header, waffle.h. -# WAFFLE_LIBRARIES Full path to the Waffle library. -# WAFFLE_FOUND True if Waffle was found. -# WAFFLE_VERSION_STRING Waffle's version in form "Major.Minor.Patch". - -#============================================================================= -# 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. -#============================================================================= - -# See /usr/share/cmake/Modules/readme.txt for CMake official guidelines for -# FindXXX.cmake files. - -if(NOT DEFINED WAFFLE_FIND_VERSION_MAJOR) - set(WAFFLE_FIND_VERSION_MAJOR 1) -endif() - -find_path(WAFFLE_INCLUDE_DIRS - NAMES waffle.h - PATH_SUFFIXES "waffle-${WAFFLE_FIND_VERSION_MAJOR}" - ) - -find_library(WAFFLE_LIBRARIES - NAMES "waffle-${WAFFLE_FIND_VERSION_MAJOR}" -) - -if(WAFFLE_INCLUDE_DIRS AND EXISTS "${WAFFLE_INCLUDE_DIRS}/waffle_version.h") - file(STRINGS "${WAFFLE_INCLUDE_DIRS}/waffle_version.h" WAFFLE_VERSION_H) - string(REGEX REPLACE "^.*WAFFLE_MAJOR_VERSION ([0-9]+).*$" "\\1" WAFFLE_MAJOR_VERSION "${WAFFLE_VERSION_H}") - string(REGEX REPLACE "^.*WAFFLE_MINOR_VERSION ([0-9]+).*$" "\\1" WAFFLE_MINOR_VERSION "${WAFFLE_VERSION_H}") - string(REGEX REPLACE "^.*WAFFLE_PATCH_VERSION ([0-9]+).*$" "\\1" WAFFLE_PATCH_VERSION "${WAFFLE_VERSION_H}") - set(WAFFLE_VERSION_STRING "${WAFFLE_MAJOR_VERSION}.${WAFFLE_MINOR_VERSION}.${WAFFLE_PATCH_VERSION}") -endif() - -# handle the 'QUIETLY' and 'REQUIRED' arguments and -# set 'WAFFLE_FOUND' to TRUE if all listed variables are TRUE -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Waffle - REQUIRED_VARS WAFFLE_LIBRARIES WAFFLE_INCLUDE_DIRS - VERSION_VAR WAFFLE_VERSION_STRING - ) - -mark_as_advanced(WAFFLE_LIBRARIES WAFFLE_INCLUDE_DIRS) - -# Don't expose these variables. -# -# Some were set in the cache and some were not. To be safe, remove the -# variables from the cache *and* local scope. -# -unset(WAFFLE_FIND_VERSION_MAJOR CACHE) -unset(WAFFLE_VERSION_H CACHE) - -unset(WAFFLE_FIND_VERSION_MAJOR) -unset(WAFFLE_VERSION_H) diff --git a/cmake/Modules/WaffleDefineCompilerFlags.cmake b/cmake/Modules/WaffleDefineCompilerFlags.cmake index 710b7e0..7532a91 100644 --- a/cmake/Modules/WaffleDefineCompilerFlags.cmake +++ b/cmake/Modules/WaffleDefineCompilerFlags.cmake @@ -125,6 +125,10 @@ if(waffle_on_linux) add_definitions(-D_XOPEN_SOURCE=600) endif() +if(waffle_has_nacl) + add_definitions(-DWAFFLE_HAS_NACL) +endif() + if(waffle_on_windows) add_definitions(-DWAFFLE_HAS_WGL) endif() diff --git a/cmake/Modules/WaffleDefineVersion.cmake b/cmake/Modules/WaffleDefineVersion.cmake index a9f41ca..cbb3aaa 100644 --- a/cmake/Modules/WaffleDefineVersion.cmake +++ b/cmake/Modules/WaffleDefineVersion.cmake @@ -40,7 +40,7 @@ # set(waffle_major_version "1") set(waffle_minor_version "5") -set(waffle_patch_version "1") +set(waffle_patch_version "90") set(waffle_version "${waffle_major_version}.${waffle_minor_version}.${waffle_patch_version}") diff --git a/cmake/Modules/WaffleValidateOptions.cmake b/cmake/Modules/WaffleValidateOptions.cmake index ea60b0e..1275463 100644 --- a/cmake/Modules/WaffleValidateOptions.cmake +++ b/cmake/Modules/WaffleValidateOptions.cmake @@ -46,11 +46,38 @@ endif() if(waffle_on_linux) if(NOT waffle_has_glx AND NOT waffle_has_wayland AND - NOT waffle_has_x11_egl AND NOT waffle_has_gbm) + NOT waffle_has_x11_egl AND NOT waffle_has_gbm AND + NOT waffle_has_nacl) message(FATAL_ERROR "Must enable at least one of: " "waffle_has_glx, waffle_has_wayland, " - "waffle_has_x11_egl, waffle_has_gbm.") + "waffle_has_x11_egl, waffle_has_gbm, " + "waffle_has_nacl.") + endif() + if(waffle_has_nacl) + if(NOT EXISTS ${nacl_sdk_path}) + message(FATAL_ERROR "NaCl SDK path not found : ${nacl_sdk_path}") + endif() + + if(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE}) + message(FATAL_ERROR "Toolchain for Nacl not found. This must be " + "configured using CMAKE_TOOLCHAIN_FILE.") + endif() + + # Warn the user that building tests is disabled. + if(waffle_build_tests) + message(WARNING "Building the tests with the NaCl backend " + "is not supported, skipping tests.") + set(waffle_build_tests OFF) + endif() + + # When building for NaCl, disable incompatible backends. + set(waffle_has_gbm OFF) + set(waffle_has_egl OFF) + set(waffle_has_glx OFF) + set(waffle_has_x11 OFF) + set(waffle_has_x11_egl OFF) + set(waffle_has_wayland OFF) endif() if(waffle_has_gbm) if(NOT gbm_FOUND) diff --git a/cmake/toolchain-nacl-x86_32-glibc.cmake b/cmake/toolchain-nacl-x86_32-glibc.cmake new file mode 100644 index 0000000..ec5779f --- /dev/null +++ b/cmake/toolchain-nacl-x86_32-glibc.cmake @@ -0,0 +1,41 @@ +# +# NaCl toolchain file for 32bit x86 using glibc C library +# + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(CMAKE_SYSTEM_NAME "Linux") + set(nacl_host_os "linux") +else() + message(FATAL_ERROR "TODO: NaCl support on ${CMAKE_HOST_SYSTEM_NAME}") +endif() + +set(nacl_target_arch "i686") +set(nacl_ports "glibc_x86_32") +set(nacl_toolchain "${nacl_host_os}_x86_glibc") + +# setup paths for nacl +set(nacl_root ${nacl_sdk_path}/${nacl_version}) +set(nacl_toolpath ${nacl_root}/toolchain/${nacl_toolchain}/bin) + +# setup compilers from toolchain +set(CMAKE_C_COMPILER ${nacl_toolpath}/${nacl_target_arch}-nacl-gcc) +set(CMAKE_CXX_COMPILER ${nacl_toolpath}/${nacl_target_arch}-nacl-g++) + +set(CMAKE_FIND_ROOT_PATH ${nacl_root}) + +# for FIND_LIBRARY|INCLUDE use ${nacl_root} only, +# for helper programs during build time, use host +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# setup nacl includes and required libraries +set(nacl_INCLUDE_DIRS ${nacl_INCLUDE_DIRS} ${nacl_sdk_path}/${nacl_version}/include) +set(nacl_LIBS ${nacl_sdk_path}/${nacl_version}/lib/${nacl_ports}/${CMAKE_BUILD_TYPE}) +set(nacl_LDFLAGS + -L${nacl_LIBS} + -lppapi_cpp + -lppapi + -lpthread + -ldl + ) diff --git a/cmake/toolchain-nacl-x86_64-glibc.cmake b/cmake/toolchain-nacl-x86_64-glibc.cmake new file mode 100644 index 0000000..f3109ab --- /dev/null +++ b/cmake/toolchain-nacl-x86_64-glibc.cmake @@ -0,0 +1,41 @@ +# +# NaCl toolchain file for 64bit x86 using glibc C library +# + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(CMAKE_SYSTEM_NAME "Linux") + set(nacl_host_os "linux") +else() + message(FATAL_ERROR "TODO: NaCl support on ${CMAKE_HOST_SYSTEM_NAME}") +endif() + +set(nacl_target_arch "x86_64") +set(nacl_ports "glibc_x86_64") +set(nacl_toolchain "${nacl_host_os}_x86_glibc") + +# setup paths for nacl +set(nacl_root ${nacl_sdk_path}/${nacl_version}) +set(nacl_toolpath ${nacl_root}/toolchain/${nacl_toolchain}/bin) + +# setup compilers from toolchain +set(CMAKE_C_COMPILER ${nacl_toolpath}/${nacl_target_arch}-nacl-gcc) +set(CMAKE_CXX_COMPILER ${nacl_toolpath}/${nacl_target_arch}-nacl-g++) + +set(CMAKE_FIND_ROOT_PATH ${nacl_root}) + +# for FIND_LIBRARY|INCLUDE use ${nacl_root} only, +# for helper programs during build time, use host +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# setup nacl includes and required libraries +set(nacl_INCLUDE_DIRS ${nacl_INCLUDE_DIRS} ${nacl_sdk_path}/${nacl_version}/include) +set(nacl_LIBS ${nacl_sdk_path}/${nacl_version}/lib/${nacl_ports}/${CMAKE_BUILD_TYPE}) +set(nacl_LDFLAGS + -L${nacl_LIBS} + -lppapi_cpp + -lppapi + -lpthread + -ldl + ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 281ef47..fc0bda2 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,7 +11,7 @@ install( # Target: simple-x11-egl (executable) # ---------------------------------------------------------------------------- -if(waffle_on_linux) +if(waffle_on_linux AND waffle_has_x11_egl) add_executable(simple-x11-egl simple-x11-egl.c) target_link_libraries(simple-x11-egl ${waffle_libname}) endif() @@ -20,6 +20,10 @@ endif() # Target: gl_basic (executable) # ---------------------------------------------------------------------------- +if(waffle_has_nacl) + return() +endif() + add_executable(gl_basic gl_basic.c) target_link_libraries(gl_basic ${waffle_libname} ${GETOPT_LIBRARIES}) diff --git a/examples/gl_basic.c b/examples/gl_basic.c index 69418c8..77bb1dc 100644 --- a/examples/gl_basic.c +++ b/examples/gl_basic.c @@ -34,7 +34,7 @@ /// each buffer swap. #define _POSIX_C_SOURCE 199309L // glibc feature macro for nanosleep. -#define WAFFLE_API_VERSION 0x0103 +#define WAFFLE_API_VERSION 0x0106 #define WAFFLE_API_EXPERIMENTAL #include <getopt.h> @@ -530,6 +530,7 @@ main(int argc, char **argv) int32_t init_attrib_list[3]; int32_t config_attrib_list[64]; + intptr_t window_attrib_list[5]; struct waffle_display *dpy; struct waffle_config *config; @@ -628,7 +629,15 @@ main(int argc, char **argv) if (!ctx) error_waffle(); - window = waffle_window_create(config, window_width, window_height); + + i = 0; + window_attrib_list[i++] = WAFFLE_WINDOW_WIDTH; + window_attrib_list[i++] = window_width; + window_attrib_list[i++] = WAFFLE_WINDOW_HEIGHT; + window_attrib_list[i++] = window_height; + window_attrib_list[i++] = 0; + + window = waffle_window_create2(config, window_attrib_list); if (!window) error_waffle(); diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h index e04b23f..80cb793 100644 --- a/include/waffle/waffle.h +++ b/include/waffle/waffle.h @@ -36,6 +36,20 @@ extern "C" { #endif +#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301) +# define WAFFLE_DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +# define WAFFLE_DEPRECATED __declspec(deprecated) +#else +# define WAFFLE_DEPRECATED +#endif + +#if WAFFLE_API_VERSION >= 0x0106 +# define WAFFLE_DEPRECATED_1_06 WAFFLE_DEPRECATED +#else +# define WAFFLE_DEPRECATED_1_06 +#endif + struct waffle_display; struct waffle_config; struct waffle_context; @@ -104,6 +118,7 @@ enum waffle_enum { WAFFLE_PLATFORM_X11_EGL = 0x0015, WAFFLE_PLATFORM_GBM = 0x0016, WAFFLE_PLATFORM_WGL = 0x0017, + WAFFLE_PLATFORM_NACL = 0x0018, // ------------------------------------------------------------------ // For waffle_config_choose() @@ -150,6 +165,13 @@ enum waffle_enum { WAFFLE_DL_OPENGL_ES1 = 0x0302, WAFFLE_DL_OPENGL_ES2 = 0x0303, WAFFLE_DL_OPENGL_ES3 = 0x0304, + + // ------------------------------------------------------------------ + // For waffle_window + // ------------------------------------------------------------------ + + WAFFLE_WINDOW_WIDTH = 0x0310, + WAFFLE_WINDOW_HEIGHT = 0x0311, }; const char* @@ -221,6 +243,13 @@ waffle_context_get_native(struct waffle_context *self); // waffle_window // --------------------------------------------------------------------------- +#if WAFFLE_API_VERSION >= 0x0106 +struct waffle_window* +waffle_window_create2( + struct waffle_config *config, + const intptr_t attrib_list[]); +#endif + struct waffle_window* waffle_window_create( struct waffle_config *config, @@ -310,23 +339,23 @@ union waffle_native_window { // waffle_attrib_list // --------------------------------------------------------------------------- -int32_t +WAFFLE_DEPRECATED_1_06 int32_t waffle_attrib_list_length(const int32_t attrib_list[]); -bool +WAFFLE_DEPRECATED_1_06 bool waffle_attrib_list_get( const int32_t attrib_list[], int32_t key, int32_t *value); -bool +WAFFLE_DEPRECATED_1_06 bool waffle_attrib_list_get_with_default( const int32_t attrib_list[], int32_t key, int32_t *value, int32_t default_value); -bool +WAFFLE_DEPRECATED_1_06 bool waffle_attrib_list_update( int32_t *attrib_list, int32_t key, diff --git a/man/waffle_attrib_list.3.xml b/man/waffle_attrib_list.3.xml index 9b390ba..277fe26 100644 --- a/man/waffle_attrib_list.3.xml +++ b/man/waffle_attrib_list.3.xml @@ -44,19 +44,19 @@ <funcsynopsisinfo>#include <waffle.h></funcsynopsisinfo> <funcprototype> - <funcdef>bool <function>waffle_attrib_list_length</function></funcdef> + <funcdef>DEPRECATED bool <function>waffle_attrib_list_length</function></funcdef> <paramdef>const int32_t <parameter>attrib_list</parameter>[]</paramdef> </funcprototype> <funcprototype> - <funcdef>bool <function>waffle_attrib_list_get</function></funcdef> + <funcdef>DEPRECATED bool <function>waffle_attrib_list_get</function></funcdef> <paramdef>const int32_t <parameter>attrib_list</parameter>[]</paramdef> <paramdef>int32_t <parameter>key</parameter></paramdef> <paramdef>int32_t *<parameter>value</parameter></paramdef> </funcprototype> <funcprototype> - <funcdef>bool <function>waffle_attrib_list_get_with_default</function></funcdef> + <funcdef>DEPRECATED bool <function>waffle_attrib_list_get_with_default</function></funcdef> <paramdef>const int32_t <parameter>attrib_list</parameter>[]</paramdef> <paramdef>int32_t <parameter>key</parameter></paramdef> <paramdef>int32_t *<parameter>value</parameter></paramdef> @@ -64,13 +64,19 @@ </funcprototype> <funcprototype> - <funcdef>bool <function>waffle_attrib_list_update</function></funcdef> + <funcdef>DEPRECATED bool <function>waffle_attrib_list_update</function></funcdef> <paramdef>int32_t <parameter>attrib_list</parameter>[]</paramdef> <paramdef>int32_t <parameter>key</parameter></paramdef> <paramdef>int32_t *<parameter>value</parameter></paramdef> </funcprototype> </funcsynopsis> + + <refsect2> + <title>Deprecation</title> + <para>All functions above are deprecated in Waffle 1.6 and later.</para> + </refsect2> + </refsynopsisdiv> <refsect1> diff --git a/man/waffle_enum.3.xml b/man/waffle_enum.3.xml index a96bd20..4874fe7 100644 --- a/man/waffle_enum.3.xml +++ b/man/waffle_enum.3.xml @@ -101,6 +101,7 @@ enum waffle_enum { WAFFLE_PLATFORM_X11_EGL = 0x0015, WAFFLE_PLATFORM_GBM = 0x0016, WAFFLE_PLATFORM_WGL = 0x0017, + WAFFLE_PLATFORM_NACL = 0x0018, // ------------------------------------------------------------------ // For waffle_config_choose() @@ -141,6 +142,13 @@ enum waffle_enum { WAFFLE_DL_OPENGL = 0x0301, WAFFLE_DL_OPENGL_ES1 = 0x0302, WAFFLE_DL_OPENGL_ES2 = 0x0303, + + // ------------------------------------------------------------------ + // For waffle_window + // ------------------------------------------------------------------ + + WAFFLE_WINDOW_WIDTH = 0x0310, + WAFFLE_WINDOW_HEIGHT = 0x0311, }; ]]> </programlisting> diff --git a/man/waffle_init.3.xml b/man/waffle_init.3.xml index a22723d..d74601a 100644 --- a/man/waffle_init.3.xml +++ b/man/waffle_init.3.xml @@ -121,6 +121,14 @@ </listitem> </varlistentry> <varlistentry> + <term><constant>WAFFLE_PLATFORM_NACL</constant></term> + <listitem> + <para> + [Linux only, other systems not yet supported] + </para> + </listitem> + </varlistentry> + <varlistentry> <term><constant>WAFFLE_PLATFORM_WAYLAND</constant></term> <listitem> <para> diff --git a/man/waffle_window.3.xml b/man/waffle_window.3.xml index de046fa..795152a 100644 --- a/man/waffle_window.3.xml +++ b/man/waffle_window.3.xml @@ -56,6 +56,12 @@ struct waffle_window; </funcprototype> <funcprototype> + <funcdef>struct waffle_window* <function>waffle_window_create2</function></funcdef> + <paramdef>struct waffle_window *<parameter>config</parameter></paramdef> + <paramdef>const intptr_t <parameter>attrib_list</parameter>[]</paramdef> + </funcprototype> + + <funcprototype> <funcdef>bool <function>waffle_window_destroy</function></funcdef> <paramdef>struct waffle_window *<parameter>self</parameter></paramdef> </funcprototype> @@ -104,6 +110,27 @@ struct waffle_window; </varlistentry> <varlistentry> + <term><function>waffle_window_create2()</function></term> + <listitem> + <para> + Feature test macro: <code>WAFFLE_API_VERSION >= 0x0106</code>. + (See <citerefentry><refentrytitle>waffle_feature_test_macros</refentrytitle><manvolnum>7</manvolnum></citerefentry>). + </para> + <para> + Create a window with the properties specified by + <parameter>config</parameter> and + <parameter>attrib_list</parameter>. + + <parameter>attrib_list</parameter> must contain the attributes + <constant>WAFFLE_WINDOW_WIDTH</constant> and + <constant>WAFFLE_WINDOW_HEIGHT</constant>, + whose values must be positive + and no greater than <constant>INT32_MAX</constant>. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><function>waffle_window_destroy()</function></term> <listitem> <para> diff --git a/pkg/archlinux/lib32-waffle-1.3.0/PKGBUILD b/pkg/archlinux/lib32-waffle-1.3.0/PKGBUILD deleted file mode 100644 index 5e16f68..0000000 --- a/pkg/archlinux/lib32-waffle-1.3.0/PKGBUILD +++ /dev/null @@ -1,63 +0,0 @@ -# Maintainer: Chad Versace <chad.versace@linux.intel.com> - -pkgbase='waffle' -pkgname="lib32-$pkgbase" -pkgver='1.3.0' -pkgrel=1 -pkgdesc='a library for choosing window system and OpenGL API at runtime (32 bits)' -arch=('x86_64') -url='http://www.waffle-gl.org' -license=('BSD') - -depends=( - 'lib32-libgl' # for GLX - 'lib32-libegl' - 'lib32-libgbm' - 'lib32-libx11' - 'lib32-libxcb' - 'lib32-wayland' - - "$pkgbase=$pkgver" - ) -makedepends=( - 'gcc-multilib' - 'cmake' - 'xcb-proto' - ) - -source=("http://www.waffle-gl.org/files/release/$pkgbase-$pkgver/$pkgbase-$pkgver.tar.xz") -sha256sums=('340ee04172dba878249469018cd7ec9d1ecd41af26b612c741b8b52e713bca8e') - -build() { - cd "$srcdir/$pkgbase-$pkgver" - - export CC='gcc -m32' - export CXX='g++ -m32' - export PKG_CONFIG_PATH='/usr/lib32/pkgconfig' - - cmake \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_INSTALL_LIBDIR=/usr/lib32 \ - -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_has_gbm=1 \ - -Dwaffle_has_glx=1 \ - -Dwaffle_has_x11_egl=1 \ - -Dwaffle_has_wayland=1 \ - -Dwaffle_build_manpages=0 \ - -Dwaffle_build_htmldocs=0 \ - -Dwaffle_build_examples=0 - make -} - -package() { - cd "$srcdir/$pkgbase-$pkgver" - make DESTDIR="$pkgdir/" install - - rm -rf "$pkgdir/usr/include" - rm -rf "$pkgdir/usr/share" - - install -m755 -d "$pkgdir/usr/share/licenses" - ln -s $pkgbase "$pkgdir/usr/share/licenses/$pkgname" -} - -# vim:set ts=2 sw=2 et: diff --git a/pkg/archlinux/mingw-w64-waffle/PKGBUILD b/pkg/archlinux/mingw-w64-waffle/PKGBUILD deleted file mode 100644 index c563948..0000000 --- a/pkg/archlinux/mingw-w64-waffle/PKGBUILD +++ /dev/null @@ -1,86 +0,0 @@ -# Maintainer: Chad Versace <chad.versace@linux.intel.com> - -pkgname='mingw-w64-waffle' -pkgver='1.3.0' -pkgrel=1 -pkgdesc='a library for choosing window system and OpenGL API at runtime (mingw-w64)' -arch=('any') -url='http://waffle-gl.github.io' -license=('BSD') - -depends=( - 'mingw-w64-crt>=3.1.0-3' - ) -makedepends=( - 'mingw-w64-cmake' - - # For building the docs. -# XXX: Add as soon as we enable docs/manpages -# 'libxslt' -# 'docbook-xsl' - - ) - -options=('!strip' '!buildflags' 'staticlibs') -_architectures="i686-w64-mingw32 x86_64-w64-mingw32" - -if [[ ! -v _srcroot ]]; then - msg "Environment variable _srcroot is unset" - msg "Fall back to using git worktree for _srcroot ..." - _srcroot="$(git rev-parse --show-toplevel)" || exit - msg "Using _srcroot=$_srcroot" -fi - -build() { - unset LDFLAGS - cd "${_srcroot}" - msg "Building mingw-w64-waffle for cross-building" - for _arch in ${_architectures}; do - mkdir -p build-${_arch} && pushd build-${_arch} - ${_arch}-cmake .. \ - -DCMAKE_INSTALL_PREFIX=/usr/${_arch} \ - -DCMAKE_INSTALL_LIBDIR=/usr/${_arch}/lib \ - -DCMAKE_BUILD_TYPE=Release \ - \ - -Dwaffle_build_tests=0 \ - -Dwaffle_build_manpages=0 \ - -Dwaffle_build_htmldocs=0 \ - -Dwaffle_build_examples=1 - make - popd - done - - # There should be a better way to do this - msg "Building mingw-w64-waffle for native builds" - for _arch in ${_architectures}; do - mkdir -p "build-${_arch}-win" && pushd "build-${_arch}-win" - ${_arch}-cmake .. \ - -DCMAKE_INSTALL_PREFIX="" \ - -DCMAKE_INSTALL_LIBDIR="lib" \ - -DCMAKE_BUILD_TYPE=Release \ - \ - -Dwaffle_build_tests=0 \ - -Dwaffle_build_manpages=0 \ - -Dwaffle_build_htmldocs=0 \ - -Dwaffle_build_examples=1 - make - popd - done -} - -package() { - for _arch in ${_architectures}; do - cd "${_srcroot}/build-${_arch}" - make DESTDIR="${pkgdir}" install -# ${_arch}-strip --strip-unneeded "$pkgdir"/usr/${_arch}/bin/*.dll -# ${_arch}-strip -g "$pkgdir"/usr/${_arch}/lib/*.a - done - - for _arch in ${_architectures}; do - cd "${_srcroot}/build-${_arch}-win" - # Create Windows zip archives - make package - done -} - -# vim:set ts=2 sw=2 et: diff --git a/pkg/archlinux/waffle-1.3.0/PKGBUILD b/pkg/archlinux/waffle-1.3.0/PKGBUILD deleted file mode 100644 index e2fa153..0000000 --- a/pkg/archlinux/waffle-1.3.0/PKGBUILD +++ /dev/null @@ -1,55 +0,0 @@ -# Maintainer: Chad Versace <chad.versace@linux.intel.com> - -pkgname='waffle' -pkgver='1.3.0' -pkgrel=1 -pkgdesc='a library for choosing window system and OpenGL API at runtime' -arch=('i686' 'x86_64') -url='http://www.waffle-gl.org' -license=('BSD') - -depends=( - 'libgl' # for GLX - 'libegl' - 'libgbm' - 'libx11' - 'libxcb' - 'wayland' - ) -makedepends=( - 'cmake' - 'xcb-proto' - - # For building the docs. - 'libxslt' - 'docbook-xsl' - ) -source=("http://www.waffle-gl.org/files/release/$pkgname-$pkgver/$pkgname-$pkgver.tar.xz") -sha256sums=('340ee04172dba878249469018cd7ec9d1ecd41af26b612c741b8b52e713bca8e') - -build() { - cd "$srcdir/$pkgname-$pkgver" - - cmake \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_INSTALL_LIBDIR=/usr/lib \ - -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_has_gbm=1 \ - -Dwaffle_has_glx=1 \ - -Dwaffle_has_x11_egl=1 \ - -Dwaffle_has_wayland=1 \ - -Dwaffle_build_manpages=1 \ - -Dwaffle_build_htmldocs=1 \ - -Dwaffle_build_examples=0 - make -} - -package() { - cd "$srcdir/$pkgname-$pkgver" - make DESTDIR="$pkgdir/" install - install -m755 -d "$pkgdir/usr/share/licenses/$pkgname" - install -m644 "$pkgdir/usr/share/doc/waffle1/LICENSE.txt" \ - "$pkgdir/usr/share/licenses/$pkgname/LICENSE.txt" -} - -# vim:set ts=2 sw=2 et: diff --git a/pkg/archlinux/waffle-1.4.0/.gitignore b/pkg/archlinux/waffle-1.4.0/.gitignore deleted file mode 100644 index f69628a..0000000 --- a/pkg/archlinux/waffle-1.4.0/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -pkg/ -src/ -waffle/ - -*.gz -*.sig -*.xz diff --git a/pkg/archlinux/waffle-1.4.0/PKGBUILD b/pkg/archlinux/waffle-1.4.0/PKGBUILD deleted file mode 100644 index 61cd7ab..0000000 --- a/pkg/archlinux/waffle-1.4.0/PKGBUILD +++ /dev/null @@ -1,56 +0,0 @@ -# maintainer: chad versace <chad.versace@linux.intel.com> - -pkgname='waffle' -pkgver='1.4.0' -pkgrel=1 -pkgdesc='a library for choosing window system and OpenGL API at runtime' -arch=('i686' 'x86_64') -url='http://www.waffle-gl.org' -license=('BSD') - -depends=( - 'libgl' # for glx - 'libegl' - 'libgbm' - 'libx11' - 'libxcb' - 'wayland' - ) -makedepends=( - 'cmake' - 'xcb-proto' - - # for building the docs. - 'libxslt' - 'docbook-xsl' - ) -source=("http://www.waffle-gl.org/files/release/${pkgname}-${pkgver}/${pkgname}-${pkgver}.tar.xz") -sha256sums=('3238b3da5d066750084c7cdd7b3e185bd8dce3a974cb1f804ccf0a8c87600923') - -_unpackdir="${pkgname}-${pkgver}" - -build() { - cd "$srcdir/$_unpackdir" - cmake \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_INSTALL_LIBDIR=/usr/lib \ - -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_has_glx=1 \ - -Dwaffle_has_x11_egl=1 \ - -Dwaffle_has_wayland=1 \ - -Dwaffle_has_gbm=1 \ - -Dwaffle_build_manpages=1 \ - -Dwaffle_build_htmldocs=1 \ - -Dwaffle_build_examples=0 - make -} - -package() { - cd "$srcdir/${_unpackdir}" - make DESTDIR="$pkgdir/" install - install -m755 -d "$pkgdir/usr/share/licenses/$pkgname" - install -m644 "$pkgdir/usr/share/doc/waffle1/LICENSE.txt" \ - "$pkgdir/usr/share/licenses/$pkgname/LICENSE.txt" -} - -# vim:set ts=2 sw=2 et: diff --git a/pkg/archlinux/waffle-1.4.1/PKGBUILD b/pkg/archlinux/waffle-1.4.1/PKGBUILD deleted file mode 100644 index 5426e4b..0000000 --- a/pkg/archlinux/waffle-1.4.1/PKGBUILD +++ /dev/null @@ -1,51 +0,0 @@ -# Maintainer: Chad Versace <chad.versace@linux.intel.com> - -pkgname='waffle' -pkgver='1.4.1' -pkgrel=2 -pkgdesc='a library for choosing window system and OpenGL API at runtime' -arch=('i686' 'x86_64') -url='http://www.waffle-gl.org' -license=('BSD') - -depends=( - 'libgl' # for GLX - 'libegl' - 'libgbm' - 'libx11' - 'libxcb' - 'wayland' - ) -makedepends=( - 'cmake' - 'xcb-proto' - - # For building the docs. - 'libxslt' - 'docbook-xsl' - ) -source=("http://www.waffle-gl.org/files/release/$pkgname-$pkgver/$pkgname-$pkgver.tar.xz") -sha256sums=('66b3240b94abc30cd18c644ffc145024ad60e5b8a8a7d1e718c265b4c24351c9') - -build() { - cd "$srcdir/$pkgname-$pkgver" - - cmake \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_INSTALL_LIBDIR=/usr/lib \ - -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_build_manpages=1 \ - -Dwaffle_build_htmldocs=1 \ - -Dwaffle_build_examples=0 - make -} - -package() { - cd "$srcdir/$pkgname-$pkgver" - make DESTDIR="$pkgdir/" install - install -m755 -d "$pkgdir/usr/share/licenses/$pkgname" - install -m644 "$pkgdir/usr/share/doc/waffle1/LICENSE.txt" \ - "$pkgdir/usr/share/licenses/$pkgname/LICENSE.txt" -} - -# vim:set ts=2 sw=2 et: diff --git a/pkg/archlinux/waffle-git/.gitignore b/pkg/archlinux/waffle-git/.gitignore deleted file mode 100644 index 965f3ae..0000000 --- a/pkg/archlinux/waffle-git/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -src/ -pkg/ -waffle/ - -*.xz -*.sig diff --git a/pkg/archlinux/waffle-git/PKGBUILD b/pkg/archlinux/waffle-git/PKGBUILD deleted file mode 100644 index 932595c..0000000 --- a/pkg/archlinux/waffle-git/PKGBUILD +++ /dev/null @@ -1,64 +0,0 @@ -# maintainer: chad versace <chad.versace@linux.intel.com> - -pkgname='waffle-git' -pkgver=1.4.0.rc1.r3.ge7bbe42 -pkgrel=1 -pkgdesc='a library for choosing window system and OpenGL API at runtime' -arch=('i686' 'x86_64') -url='http://www.waffle-gl.org' -license=('BSD') - -provides=(waffle) -conflicts=(waffle) -depends=( - 'libgl' # for glx - 'libx11' - 'libxcb' - 'wayland' - ) -makedepends=( - 'cmake' - 'xcb-proto' - - 'libegl' - 'libgbm' - - # for building the docs. - 'libxslt' - 'docbook-xsl' - ) -source=("git://github.com/waffle-gl/waffle") -sha256sums=('SKIP') - -_unpackdir='waffle' - -pkgver() { - cd "$srcdir/$_unpackdir" - git describe --long --match 'v*' | - sed -r 's/^v//;s/([^-]*-g)/r\1/;s/-/./g;' -} - -build() { - cd "$srcdir/$_unpackdir" - cmake \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_INSTALL_LIBDIR=/usr/lib \ - -DCMAKE_BUILD_TYPE=Release \ - -Dwaffle_build_manpages=1 \ - -Dwaffle_build_htmldocs=1 \ - -Dwaffle_build_examples=0 - make -} - -package() { - optdepends=('libegl: for x11_egl, gbm or wayland support') - optdepends=('libgbm: for gbm support') - - cd "$srcdir/${_unpackdir}" - make DESTDIR="$pkgdir/" install - install -m755 -d "$pkgdir/usr/share/licenses/$pkgname" - install -m644 "$pkgdir/usr/share/doc/waffle1/LICENSE.txt" \ - "$pkgdir/usr/share/licenses/$pkgname/LICENSE.txt" -} - -# vim:set ts=2 sw=2 et: diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 9cb6cc7..22edc6e 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -2,6 +2,10 @@ # Target: wflinfo (executable) # ---------------------------------------------------------------------------- +if(waffle_has_nacl) + return() +endif() + add_executable(wflinfo wflinfo.c) target_link_libraries(wflinfo ${waffle_libname} ${GETOPT_LIBRARIES}) diff --git a/src/waffle/CMakeLists.txt b/src/waffle/CMakeLists.txt index d76e029..ac9b415 100644 --- a/src/waffle/CMakeLists.txt +++ b/src/waffle/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories( egl glx linux + nacl wayland wgl x11 @@ -25,6 +26,7 @@ include_directories( ${gl_INCLUDE_DIRS} ${GLEXT_INCLUDE_DIR} ${libudev_INCLUDE_DIRS} + ${nacl_INCLUDE_DIRS} ${wayland-client_INCLUDE_DIRS} ${wayland-egl_INCLUDE_DIRS} ${x11-xcb_INCLUDE_DIRS} @@ -57,6 +59,12 @@ if(waffle_on_linux) endif() endif() +if(waffle_has_nacl) + list(APPEND waffle_libdeps + ${nacl_LDFLAGS} + ) +endif() + set(waffle_sources api/api_priv.c api/waffle_attrib_list.c @@ -173,6 +181,19 @@ if(waffle_on_windows) ) endif() +if(waffle_has_nacl) + list(APPEND waffle_sources + nacl/nacl_config.c + nacl/nacl_context.c + nacl/nacl_display.c + nacl/nacl_platform.c + nacl/nacl_window.c + ) + list(APPEND waffle_cxx_sources + nacl/nacl_container.cpp + ) +endif() + # CMake will pass to the C compiler only C sources. CMake does not recognize the # .m extension and ignores any such files in the source lists. To coerce CMake # to pass .m files to the compiler, we must lie and claim that they are @@ -202,7 +223,7 @@ include_directories( ${XCB_INCLUDE_DIRS} ) -add_library(${waffle_libname} SHARED ${waffle_sources}) +add_library(${waffle_libname} SHARED ${waffle_sources} ${waffle_cxx_sources}) # Debian's packaging system emits warnings if wflinfo directly links to any # library that it doesn't directly use. Silence the warnings by annotating diff --git a/src/waffle/android/droid_window.c b/src/waffle/android/droid_window.c index a9e6f9b..20a566f 100644 --- a/src/waffle/android/droid_window.c +++ b/src/waffle/android/droid_window.c @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "wegl_config.h" @@ -37,14 +38,19 @@ struct wcore_window* droid_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct droid_window *self; struct wegl_config *config = wegl_config(wc_config); struct droid_display *dpy = droid_display(wc_config->display); bool ok = true; + if (wcore_attrib_list_length(attrib_list) > 0) { + wcore_error_bad_attribute(attrib_list[0]); + } + self = wcore_calloc(sizeof(*self)); if (self == NULL) return NULL; diff --git a/src/waffle/android/droid_window.h b/src/waffle/android/droid_window.h index 85064cd..b4288d0 100644 --- a/src/waffle/android/droid_window.h +++ b/src/waffle/android/droid_window.h @@ -51,8 +51,8 @@ droid_window(struct wcore_window *wc_self) struct wcore_window* droid_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height); bool droid_window_destroy(struct wcore_window *wc_self); diff --git a/src/waffle/api/waffle_attrib_list.c b/src/waffle/api/waffle_attrib_list.c index 94327bb..8ddfa9f 100644 --- a/src/waffle/api/waffle_attrib_list.c +++ b/src/waffle/api/waffle_attrib_list.c @@ -33,7 +33,7 @@ waffle_attrib_list_length(const int32_t attrib_list[]) { wcore_error_reset(); - return wcore_attrib_list_length(attrib_list); + return wcore_attrib_list32_length(attrib_list); } WAFFLE_API bool @@ -43,7 +43,7 @@ waffle_attrib_list_get( int32_t *value) { wcore_error_reset(); - return wcore_attrib_list_get(attrib_list, key, value); + return wcore_attrib_list32_get(attrib_list, key, value); } WAFFLE_API bool @@ -54,7 +54,7 @@ waffle_attrib_list_get_with_default( int32_t default_value) { wcore_error_reset(); - return wcore_attrib_list_get_with_default(attrib_list, key, value, + return wcore_attrib_list32_get_with_default(attrib_list, key, value, default_value); } @@ -65,5 +65,5 @@ waffle_attrib_list_update( int32_t value) { wcore_error_reset(); - return wcore_attrib_list_update(attrib_list, key, value); + return wcore_attrib_list32_update(attrib_list, key, value); } diff --git a/src/waffle/api/waffle_init.c b/src/waffle/api/waffle_init.c index ebc6cd5..fcf8456 100644 --- a/src/waffle/api/waffle_init.c +++ b/src/waffle/api/waffle_init.c @@ -35,6 +35,7 @@ struct wcore_platform* wayland_platform_create(void); 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); static bool waffle_init_parse_attrib_list( @@ -104,6 +105,12 @@ waffle_init_parse_attrib_list( CASE_UNDEFINED_PLATFORM(WGL) #endif +#ifdef WAFFLE_HAS_NACL + CASE_DEFINED_PLATFORM(NACL) +#else + CASE_UNDEFINED_PLATFORM(NACL) +#endif + default: wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, "WAFFLE_PLATFORM has bad value 0x%x", @@ -164,6 +171,10 @@ waffle_init_create_platform(int32_t waffle_platform) case WAFFLE_PLATFORM_WGL: return wgl_platform_create(); #endif +#ifdef WAFFLE_HAS_NACL + case WAFFLE_PLATFORM_NACL: + return nacl_platform_create(); +#endif default: assert(false); return NULL; diff --git a/src/waffle/api/waffle_window.c b/src/waffle/api/waffle_window.c index 81f95f8..9ab63ca 100644 --- a/src/waffle/api/waffle_window.c +++ b/src/waffle/api/waffle_window.c @@ -27,36 +27,96 @@ #include "api_priv.h" +#include "wcore_attrib_list.h" #include "wcore_config.h" #include "wcore_error.h" #include "wcore_platform.h" #include "wcore_window.h" WAFFLE_API struct waffle_window* -waffle_window_create( +waffle_window_create2( struct waffle_config *config, - int width, int height) + const intptr_t attrib_list[]) { - struct wcore_window *wc_self; + struct wcore_window *wc_self = NULL; struct wcore_config *wc_config = wcore_config(config); + intptr_t *attrib_list_filtered = NULL; + intptr_t width = 0, height = 0; const struct api_object *obj_list[] = { wc_config ? &wc_config->api : NULL, }; - if (!api_check_entry(obj_list, 1)) - return NULL; + if (!api_check_entry(obj_list, 1)) { + goto done; + } + + attrib_list_filtered = wcore_attrib_list_copy(attrib_list); + + if (!wcore_attrib_list_pop(attrib_list_filtered, + WAFFLE_WINDOW_WIDTH, &width)) { + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "required attribute WAFFLE_WINDOW_WIDTH is missing"); + goto done; + } + + if (!wcore_attrib_list_pop(attrib_list_filtered, + WAFFLE_WINDOW_HEIGHT, &height)) { + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "required attribute WAFFLE_WINDOW_HEIGHT is missing"); + goto done; + } + + if (width <= 0) { + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "WAFFLE_WINDOW_WIDTH is not positive"); + goto done; + } else if (width > INT32_MAX) { + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "WAFFLE_WINDOW_WIDTH is greater than INT32_MAX"); + goto done; + } + + if (height <= 0) { + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "WAFFLE_WINDOW_HEIGHT is not positive"); + goto done; + } else if (height > INT32_MAX) { + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "WAFFLE_WINDOW_HEIGHT is greater than INT32_MAX"); + goto done; + } wc_self = api_platform->vtbl->window.create(api_platform, wc_config, - width, - height); - if (!wc_self) + (int32_t) width, + (int32_t) height, + attrib_list_filtered); + +done: + free(attrib_list_filtered); + + if (!wc_self) { return NULL; + } return waffle_window(wc_self); } +WAFFLE_API struct waffle_window* +waffle_window_create( + struct waffle_config *config, + int32_t width, int32_t height) +{ + const intptr_t attrib_list[] = { + WAFFLE_WINDOW_WIDTH, width, + WAFFLE_WINDOW_HEIGHT, height, + 0, + }; + + return waffle_window_create2(config, attrib_list); +} + WAFFLE_API bool waffle_window_destroy(struct waffle_window *self) { diff --git a/src/waffle/cgl/cgl_window.h b/src/waffle/cgl/cgl_window.h index 4038e09..b565d58 100644 --- a/src/waffle/cgl/cgl_window.h +++ b/src/waffle/cgl/cgl_window.h @@ -48,8 +48,9 @@ DEFINE_CONTAINER_CAST_FUNC(cgl_window, struct wcore_window* cgl_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool cgl_window_destroy(struct wcore_window *wc_self); diff --git a/src/waffle/cgl/cgl_window.m b/src/waffle/cgl/cgl_window.m index e4711e1..5ff1ec7 100644 --- a/src/waffle/cgl/cgl_window.m +++ b/src/waffle/cgl/cgl_window.m @@ -26,6 +26,7 @@ #import <Cocoa/Cocoa.h> #import <OpenGL/OpenGL.h> +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "cgl_config.h" @@ -53,7 +54,7 @@ cgl_window_destroy(struct wcore_window *wc_self) static WaffleGLView* -cgl_window_create_gl_view(int width, int height) +cgl_window_create_gl_view(int32_t width, int32_t height) { WaffleGLView *view = [[WaffleGLView alloc] initWithFrame:NSMakeRect(0, 0, width, height)]; @@ -94,12 +95,18 @@ cgl_window_create_ns_window(NSView *view) struct wcore_window* cgl_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct cgl_window *self; bool ok = true; + if (wcore_attrib_list_length(attrib_list) > 0) { + wcore_error_bad_attribute(attrib_list[0]); + return NULL; + } + self = wcore_calloc(sizeof(*self)); if (!self) return NULL; diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c index 48d4b33..985e13a 100644 --- a/src/waffle/core/wcore_attrib_list.c +++ b/src/waffle/core/wcore_attrib_list.c @@ -28,76 +28,219 @@ #include <stdbool.h> #include <stdint.h> #include <stddef.h> +#include <string.h> -int32_t -wcore_attrib_list_length(const int32_t attrib_list[]) -{ - const int32_t *i = attrib_list; +#include "wcore_error.h" +#include "wcore_util.h" + +#define WCORE_ATTRIB_LIST_COMMON_FUNCS(T, \ + length_func, \ + get_func, \ + get_with_default_func, \ + update_func) \ + \ + size_t \ + length_func(const T attrib_list[]) \ + { \ + const T *i = attrib_list; \ + \ + if (!attrib_list) { \ + return 0; \ + } \ + \ + while (*i) { \ + i += 2; \ + } \ + \ + return (i - attrib_list) / 2; \ + } \ + \ + bool \ + get_func(const T *attrib_list, \ + T key, \ + T *value) \ + { \ + if (!attrib_list) { \ + return false; \ + } \ + \ + for (size_t i = 0; attrib_list[i] != 0; i += 2) { \ + if (attrib_list[i] == key) { \ + *value = attrib_list[i + 1]; \ + return true; \ + } \ + } \ + \ + return false; \ + } \ + \ + bool \ + get_with_default_func( \ + const T attrib_list[], \ + T key, \ + T *value, \ + T default_value) \ + { \ + if (get_func(attrib_list, key, value)) { \ + return true; \ + } else { \ + *value = default_value; \ + return false; \ + } \ + } \ + \ + bool \ + update_func(T *attrib_list, \ + T key, \ + T value) \ + { \ + T *i = attrib_list; \ + \ + if (attrib_list == NULL) { \ + return false; \ + } \ + \ + while (*i != 0 && *i != key) { \ + i += 2; \ + } \ + \ + if (*i == key) { \ + i[1] = value; \ + return true; \ + } else { \ + return false; \ + } \ + } + +WCORE_ATTRIB_LIST_COMMON_FUNCS(int32_t, + wcore_attrib_list32_length, + wcore_attrib_list32_get, + wcore_attrib_list32_get_with_default, + wcore_attrib_list32_update) - if (attrib_list == NULL) - return 0; +WCORE_ATTRIB_LIST_COMMON_FUNCS(intptr_t, + wcore_attrib_list_length, + wcore_attrib_list_get, + wcore_attrib_list_get_with_default, + wcore_attrib_list_update) - while (*i != 0) - i += 2; +/// Given length of attribute list, calculate its size in bytes. Return false +/// on arithemtic overflow. +static bool +wcore_attrib_list_get_size(size_t *size, size_t len) { + bool ok; - return (int32_t) (i - attrib_list) / 2; + ok = wcore_mul_size(size, 2, len); + ok &= wcore_iadd_size(size, 1); + ok &= wcore_imul_size(size, sizeof(intptr_t)); + + return ok; } -bool -wcore_attrib_list_get( - const int32_t *attrib_list, - int32_t key, - int32_t *value) +intptr_t* +wcore_attrib_list_from_int32(const int32_t attrib_list32[]) { - if (attrib_list == NULL) - return false; + size_t len = 0; + size_t size = 0; + intptr_t *attrib_list = NULL; - for (int i = 0; attrib_list[i] != 0; i += 2) { - if (attrib_list[i] != key) - continue; + len = wcore_attrib_list32_length(attrib_list32); - *value = attrib_list[i + 1]; - return true; + if (!wcore_attrib_list_get_size(&size, len)) { + // Arithmetic overflow occurred, therefore we can't allocate the + // memory. + wcore_error(WAFFLE_ERROR_BAD_ALLOC); + return NULL; } - return false; + attrib_list = wcore_malloc(size); + if (!attrib_list) { + return NULL; + } + + // Copy all key/value pairs. + for (size_t i = 0; i < 2 * len; ++i) { + attrib_list[i] = attrib_list32[i]; + } + + // Add terminal null. + attrib_list[2 * len] = 0; + + return attrib_list; } -bool -wcore_attrib_list_get_with_default( - const int32_t attrib_list[], - int32_t key, - int32_t *value, - int32_t default_value) +intptr_t* +wcore_attrib_list_copy(const intptr_t attrib_list[]) { - if (wcore_attrib_list_get(attrib_list, key, value)) { - return true; - } - else { - *value = default_value; - return false; + intptr_t *copy = NULL; + + if (attrib_list) { + size_t len; + size_t size = 0; + + len = wcore_attrib_list_length(attrib_list); + + if (!wcore_attrib_list_get_size(&size, len)) { + // Arithmetic overflow occurred, therefore we can't allocate the + // memory. + wcore_error(WAFFLE_ERROR_BAD_ALLOC); + return NULL; + } + + copy = wcore_malloc(size); + if (!copy) { + return NULL; + } + + memcpy(copy, attrib_list, size); + } else { + copy = wcore_malloc(sizeof(intptr_t)); + if (!copy) { + return NULL; + } + + copy[0] = 0; } + + return copy; } bool -wcore_attrib_list_update( - int32_t *attrib_list, - int32_t key, - int32_t value) +wcore_attrib_list_pop( + intptr_t attrib_list[], + intptr_t key, + intptr_t *value) { - int32_t *i = attrib_list; + // Address of key in attrib_list. + intptr_t *key_addr = NULL; - if (attrib_list == NULL) - return false; + // Address of the terminal zero in attrib_list. + intptr_t *end_addr = NULL; - while (*i != 0 && *i != key) - i += 2; + if (attrib_list == NULL) { + return false; + } - if (*i == key) { - i[1] = value; - return true; + for (intptr_t *i = attrib_list; *i != 0; i += 2) { + if (i[0] == key) { + key_addr = i; + *value = i[1]; + break; + } } - else { + + if (!key_addr) { return false; } + + end_addr = key_addr + 2; // Step to next pair. + while (*end_addr != 0) { + end_addr += 2; // Step to next pair. + } + + // Move all key/value pairs located at or above (key_addr + 2), and + // move the terminal null too. + memmove(key_addr, key_addr + 2, + sizeof(intptr_t) * (end_addr - key_addr - 1)); + return true; } diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h index 30d2096..561fb1d 100644 --- a/src/waffle/core/wcore_attrib_list.h +++ b/src/waffle/core/wcore_attrib_list.h @@ -26,26 +26,63 @@ #pragma once #include <stdbool.h> +#include <stddef.h> #include <stdint.h> +#include <stdlib.h> -int32_t -wcore_attrib_list_length(const int32_t attrib_list[]); +/// @brief Convert int32_t attribute list to an intptr_t attribute list. +intptr_t* +wcore_attrib_list_from_int32(const int32_t attrib_list[]); + +size_t +wcore_attrib_list_length(const intptr_t attrib_list[]); + +intptr_t* +wcore_attrib_list_copy(const intptr_t attrib_list[]); bool wcore_attrib_list_get( + const intptr_t *attrib_list, + intptr_t key, + intptr_t *value); + +bool +wcore_attrib_list_get_with_default( + const intptr_t attrib_list[], + intptr_t key, + intptr_t *value, + intptr_t default_value); + +bool +wcore_attrib_list_pop( + intptr_t attrib_list[], + intptr_t key, + intptr_t *value); + +bool +wcore_attrib_list_update( + intptr_t *attrib_list, + intptr_t key, + intptr_t value); + +size_t +wcore_attrib_list32_length(const int32_t attrib_list[]); + +bool +wcore_attrib_list32_get( const int32_t *attrib_list, int32_t key, int32_t *value); bool -wcore_attrib_list_get_with_default( +wcore_attrib_list32_get_with_default( const int32_t attrib_list[], int32_t key, int32_t *value, int32_t default_value); bool -wcore_attrib_list_update( +wcore_attrib_list32_update( int32_t *attrib_list, int32_t key, int32_t value); diff --git a/src/waffle/core/wcore_attrib_list_unittest.c b/src/waffle/core/wcore_attrib_list_unittest.c index 4c8e371..2eb95f2 100644 --- a/src/waffle/core/wcore_attrib_list_unittest.c +++ b/src/waffle/core/wcore_attrib_list_unittest.c @@ -33,25 +33,25 @@ #include "wcore_attrib_list.h" static void -test_wcore_attrib_list_get_null(void **state) { +test_wcore_attrib_list32_get_null(void **state) { int32_t *attrib_list = NULL; int32_t key = 0; int32_t value; - assert_false(wcore_attrib_list_get(attrib_list, key, &value)); + assert_false(wcore_attrib_list32_get(attrib_list, key, &value)); } static void -test_wcore_attrib_list_get_empty(void **state) { +test_wcore_attrib_list32_get_empty(void **state) { int32_t attrib_list[] = { 0 }; int32_t key = 0; int32_t value; - assert_false(wcore_attrib_list_get(attrib_list, key, &value)); + assert_false(wcore_attrib_list32_get(attrib_list, key, &value)); } static void -test_wcore_attrib_list_get_missing_value(void **state) { +test_wcore_attrib_list32_get_missing_value(void **state) { int32_t attrib_list[] = { 1, 11, 0, @@ -59,11 +59,11 @@ test_wcore_attrib_list_get_missing_value(void **state) { int32_t key = 2; int32_t value; - assert_false(wcore_attrib_list_get(attrib_list, key, &value)); + assert_false(wcore_attrib_list32_get(attrib_list, key, &value)); } static void -test_wcore_attrib_list_get_trailing_items(void **state) { +test_wcore_attrib_list32_get_trailing_items(void **state) { int32_t attrib_list[] = { 1, 11, 0, @@ -72,23 +72,23 @@ test_wcore_attrib_list_get_trailing_items(void **state) { int32_t key = 2; int32_t value; - assert_false(wcore_attrib_list_get(attrib_list, key, &value)); + assert_false(wcore_attrib_list32_get(attrib_list, key, &value)); } static void -test_wcore_attrib_list_get_value_not_modified_if_not_found(void **state) { +test_wcore_attrib_list32_get_value_not_modified_if_not_found(void **state) { int32_t attrib_list[] = { 1, 11, 0, }; int32_t value = 17; - assert_false(wcore_attrib_list_get(attrib_list, 2, &value)); + assert_false(wcore_attrib_list32_get(attrib_list, 2, &value)); assert_int_equal(value, 17); } static void -test_wcore_attrib_list_get_key_is_first(void **state) { +test_wcore_attrib_list32_get_key_is_first(void **state) { int32_t attrib_list[] = { 1, 11, 2, 22, @@ -98,12 +98,12 @@ test_wcore_attrib_list_get_key_is_first(void **state) { int32_t key = 1; int32_t value; - assert_true(wcore_attrib_list_get(attrib_list, key, &value)); + assert_true(wcore_attrib_list32_get(attrib_list, key, &value)); assert_int_equal(value, 11); } static void -test_wcore_attrib_list_get_key_is_last(void **state) { +test_wcore_attrib_list32_get_key_is_last(void **state) { int32_t attrib_list[] = { 1, 11, 2, 22, @@ -113,52 +113,52 @@ test_wcore_attrib_list_get_key_is_last(void **state) { int32_t key = 3; int32_t value; - assert_true(wcore_attrib_list_get(attrib_list, key, &value)); + assert_true(wcore_attrib_list32_get(attrib_list, key, &value)); assert_int_equal(value, 33); } static void -test_wcore_attrib_list_length_null(void **state) { +test_wcore_attrib_list32_length_null(void **state) { int32_t *attrib_list = NULL; - assert_int_equal(wcore_attrib_list_length(attrib_list), 0); + assert_int_equal(wcore_attrib_list32_length(attrib_list), 0); } static void -test_wcore_attrib_list_length_is_0(void **state) { +test_wcore_attrib_list32_length_is_0(void **state) { int32_t attrib_list[] = {0}; - assert_int_equal(wcore_attrib_list_length(attrib_list), 0); + assert_int_equal(wcore_attrib_list32_length(attrib_list), 0); } static void -test_wcore_attrib_list_length_is_1(void **state) { +test_wcore_attrib_list32_length_is_1(void **state) { int32_t attrib_list[] = { 1, 1, 0, }; - assert_int_equal(wcore_attrib_list_length(attrib_list), 1); + assert_int_equal(wcore_attrib_list32_length(attrib_list), 1); } static void -test_wcore_attrib_list_length_is_2(void **state) { +test_wcore_attrib_list32_length_is_2(void **state) { int32_t attrib_list[] = { 1, 1, 2, 2, 0, }; - assert_int_equal(wcore_attrib_list_length(attrib_list), 2); + assert_int_equal(wcore_attrib_list32_length(attrib_list), 2); } static void -test_wcore_attrib_list_length_is_37(void **state) { +test_wcore_attrib_list32_length_is_37(void **state) { int32_t attrib_list[75]; memset(attrib_list, 0xff, 74 * sizeof(int32_t)); attrib_list[74] = 0; - assert_int_equal(wcore_attrib_list_length(attrib_list), 37); + assert_int_equal(wcore_attrib_list32_length(attrib_list), 37); } static void -test_wcore_attrib_list_length_trailing_items(void **state) { +test_wcore_attrib_list32_length_trailing_items(void **state) { int32_t attrib_list[] = { 1, 1, 2, 2, @@ -169,23 +169,23 @@ test_wcore_attrib_list_length_trailing_items(void **state) { 0, }; - assert_int_equal(wcore_attrib_list_length(attrib_list), 3); + assert_int_equal(wcore_attrib_list32_length(attrib_list), 3); } static void -test_wcore_attrib_list_update_null(void **state) { +test_wcore_attrib_list32_update_null(void **state) { int32_t *attrib_list = NULL; - assert_false(wcore_attrib_list_update(attrib_list, 7, 7)); + assert_false(wcore_attrib_list32_update(attrib_list, 7, 7)); } static void -test_wcore_attrib_list_update_empty_list(void **state) { +test_wcore_attrib_list32_update_empty_list(void **state) { int32_t attrib_list[] = {0}; - assert_false(wcore_attrib_list_update(attrib_list, 7, 7)); + assert_false(wcore_attrib_list32_update(attrib_list, 7, 7)); } static void -test_wcore_attrib_list_update_at_0(void **state) { +test_wcore_attrib_list32_update_at_0(void **state) { int32_t v; int32_t attrib_list[] = { 10, 10, @@ -194,13 +194,13 @@ test_wcore_attrib_list_update_at_0(void **state) { 0, }; - assert_true(wcore_attrib_list_update(attrib_list, 10, 99)); - assert_true(wcore_attrib_list_get(attrib_list, 10, &v)); + assert_true(wcore_attrib_list32_update(attrib_list, 10, 99)); + assert_true(wcore_attrib_list32_get(attrib_list, 10, &v)); assert_int_equal(v, 99); } static void -test_wcore_attrib_list_update_at_1(void **state) { +test_wcore_attrib_list32_update_at_1(void **state) { int32_t v; int32_t attrib_list[] = { 10, 10, @@ -209,13 +209,13 @@ test_wcore_attrib_list_update_at_1(void **state) { 0, }; - assert_true(wcore_attrib_list_update(attrib_list, 20, 99)); - assert_true(wcore_attrib_list_get(attrib_list, 20, &v)); + assert_true(wcore_attrib_list32_update(attrib_list, 20, 99)); + assert_true(wcore_attrib_list32_get(attrib_list, 20, &v)); assert_int_equal(v, 99); } static void -test_wcore_attrib_list_update_missing_key(void **state) { +test_wcore_attrib_list32_update_missing_key(void **state) { int32_t attrib_list[] = { 10, 10, 20, 20, @@ -223,30 +223,30 @@ test_wcore_attrib_list_update_missing_key(void **state) { 0, }; - assert_false(wcore_attrib_list_update(attrib_list, 50, 99)); + assert_false(wcore_attrib_list32_update(attrib_list, 50, 99)); } int main(void) { const UnitTest tests[] = { - unit_test(test_wcore_attrib_list_get_null), - unit_test(test_wcore_attrib_list_get_empty), - unit_test(test_wcore_attrib_list_get_missing_value), - unit_test(test_wcore_attrib_list_get_trailing_items), - unit_test(test_wcore_attrib_list_get_value_not_modified_if_not_found), - unit_test(test_wcore_attrib_list_get_key_is_first), - unit_test(test_wcore_attrib_list_get_key_is_last), - unit_test(test_wcore_attrib_list_length_null), - unit_test(test_wcore_attrib_list_length_is_0), - unit_test(test_wcore_attrib_list_length_is_1), - unit_test(test_wcore_attrib_list_length_is_2), - unit_test(test_wcore_attrib_list_length_is_37), - unit_test(test_wcore_attrib_list_length_trailing_items), - unit_test(test_wcore_attrib_list_update_null), - unit_test(test_wcore_attrib_list_update_empty_list), - unit_test(test_wcore_attrib_list_update_at_0), - unit_test(test_wcore_attrib_list_update_at_1), - unit_test(test_wcore_attrib_list_update_missing_key), + unit_test(test_wcore_attrib_list32_get_null), + unit_test(test_wcore_attrib_list32_get_empty), + unit_test(test_wcore_attrib_list32_get_missing_value), + unit_test(test_wcore_attrib_list32_get_trailing_items), + unit_test(test_wcore_attrib_list32_get_value_not_modified_if_not_found), + unit_test(test_wcore_attrib_list32_get_key_is_first), + unit_test(test_wcore_attrib_list32_get_key_is_last), + unit_test(test_wcore_attrib_list32_length_null), + unit_test(test_wcore_attrib_list32_length_is_0), + unit_test(test_wcore_attrib_list32_length_is_1), + unit_test(test_wcore_attrib_list32_length_is_2), + unit_test(test_wcore_attrib_list32_length_is_37), + unit_test(test_wcore_attrib_list32_length_trailing_items), + unit_test(test_wcore_attrib_list32_update_null), + unit_test(test_wcore_attrib_list32_update_empty_list), + unit_test(test_wcore_attrib_list32_update_at_0), + unit_test(test_wcore_attrib_list32_update_at_1), + unit_test(test_wcore_attrib_list32_update_missing_key), }; return run_tests(tests); diff --git a/src/waffle/core/wcore_config_attrs.c b/src/waffle/core/wcore_config_attrs.c index dba28f7..21c62a2 100644 --- a/src/waffle/core/wcore_config_attrs.c +++ b/src/waffle/core/wcore_config_attrs.c @@ -84,7 +84,7 @@ parse_bool(const int32_t attrib_list[], { int32_t raw_value; - wcore_attrib_list_get_with_default(attrib_list, attrib_name, + wcore_attrib_list32_get_with_default(attrib_list, attrib_name, &raw_value, default_value); if (raw_value == WAFFLE_DONT_CARE) { @@ -108,7 +108,7 @@ parse_context_api(struct wcore_config_attrs *attrs, { bool found; - found = wcore_attrib_list_get(attrib_list, + found = wcore_attrib_list32_get(attrib_list, WAFFLE_CONTEXT_API, &attrs->context_api); if (!found) { wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, @@ -163,11 +163,11 @@ static bool parse_context_version(struct wcore_config_attrs *attrs, const int32_t attrib_list[]) { - wcore_attrib_list_get_with_default(attrib_list, + wcore_attrib_list32_get_with_default(attrib_list, WAFFLE_CONTEXT_MAJOR_VERSION, &attrs->context_major_version, attrs->context_major_version); - wcore_attrib_list_get_with_default(attrib_list, + wcore_attrib_list32_get_with_default(attrib_list, WAFFLE_CONTEXT_MINOR_VERSION, &attrs->context_minor_version, attrs->context_minor_version); @@ -260,7 +260,7 @@ static bool parse_context_profile(struct wcore_config_attrs *attrs, const int32_t attrib_list[]) { - wcore_attrib_list_get_with_default(attrib_list, + wcore_attrib_list32_get_with_default(attrib_list, WAFFLE_CONTEXT_PROFILE, &attrs->context_profile, attrs->context_profile); diff --git a/src/waffle/core/wcore_error.c b/src/waffle/core/wcore_error.c index fdf70f8..e755ac5 100644 --- a/src/waffle/core/wcore_error.c +++ b/src/waffle/core/wcore_error.c @@ -24,6 +24,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <errno.h> +#include <inttypes.h> #include <stdarg.h> #include <stdbool.h> #include <stdio.h> @@ -170,6 +171,13 @@ wcore_error_errno(const char *format, ...) } void +wcore_error_bad_attribute(intptr_t attr) +{ + wcore_errorf(WAFFLE_ERROR_BAD_ATTRIBUTE, + "bad attribute 0x%"PRIxPTR, attr); +} + +void _wcore_error_internal(const char *file, int line, const char *format, ...) { struct wcore_error_tinfo *t = wcore_tinfo_get()->error; diff --git a/src/waffle/core/wcore_error.h b/src/waffle/core/wcore_error.h index e2d3189..0a9767c 100644 --- a/src/waffle/core/wcore_error.h +++ b/src/waffle/core/wcore_error.h @@ -63,6 +63,10 @@ wcore_errorf(enum waffle_error error, const char *format, ...); void wcore_error_errno(const char *format, ...); +/// @brief Emit WAFFLE_ERROR_BAD_ATTRIBUTE with a default error message. +void +wcore_error_bad_attribute(intptr_t attr); + /// @brief Set error to WAFFLE_INTERNAL_ERROR with source location. #define wcore_error_internal(format, ...) \ _wcore_error_internal(__FILE__, __LINE__, format, __VA_ARGS__) diff --git a/src/waffle/core/wcore_platform.h b/src/waffle/core/wcore_platform.h index 77943e4..2f9b9f8 100644 --- a/src/waffle/core/wcore_platform.h +++ b/src/waffle/core/wcore_platform.h @@ -114,8 +114,9 @@ struct wcore_platform_vtbl { struct wcore_window* (*create)(struct wcore_platform *platform, struct wcore_config *config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool (*destroy)(struct wcore_window *window); diff --git a/src/waffle/core/wcore_util.c b/src/waffle/core/wcore_util.c index deee1bf..b7809a3 100644 --- a/src/waffle/core/wcore_util.c +++ b/src/waffle/core/wcore_util.c @@ -28,6 +28,28 @@ #include "wcore_error.h" #include "wcore_util.h" +bool +wcore_add_size(size_t *res, size_t x, size_t y) +{ + if (x > SIZE_MAX - y) { + return false; + } + + *res = x + y; + return true; +} + +bool +wcore_mul_size(size_t *res, size_t x, size_t y) +{ + if (x > SIZE_MAX / y) { + return false; + } + + *res = x * y; + return true; +} + void* wcore_malloc(size_t size) { @@ -62,6 +84,7 @@ wcore_enum_to_string(int32_t e) CASE(WAFFLE_PLATFORM_X11_EGL); CASE(WAFFLE_PLATFORM_GBM); CASE(WAFFLE_PLATFORM_WGL); + CASE(WAFFLE_PLATFORM_NACL); CASE(WAFFLE_CONTEXT_API); CASE(WAFFLE_CONTEXT_OPENGL); CASE(WAFFLE_CONTEXT_OPENGL_ES1); @@ -88,6 +111,8 @@ wcore_enum_to_string(int32_t e) CASE(WAFFLE_DL_OPENGL_ES1); CASE(WAFFLE_DL_OPENGL_ES2); CASE(WAFFLE_DL_OPENGL_ES3); + CASE(WAFFLE_WINDOW_WIDTH); + CASE(WAFFLE_WINDOW_HEIGHT); default: return NULL; diff --git a/src/waffle/core/wcore_util.h b/src/waffle/core/wcore_util.h index d2aaa27..183134f 100644 --- a/src/waffle/core/wcore_util.h +++ b/src/waffle/core/wcore_util.h @@ -26,6 +26,7 @@ #pragma once #include <stddef.h> +#include "c99_compat.h" #define container_of(ptr, type, member) ({ \ const __typeof__(((type *)0)->member ) *__mptr = (ptr); \ @@ -49,6 +50,32 @@ return 0; \ } +/// @brief Addition that detects arithmetic overflow. +/// +/// If the addition would result in overflow, then return false and do not +/// update @a res. +bool +wcore_add_size(size_t *res, size_t x, size_t y); + +/// @brief In-place variant of wcore_add_size(). +static inline bool +wcore_iadd_size(size_t *x, size_t y) { + return wcore_add_size(x, *x, y); +} + +/// @brief Multiplication that detects arithmetic overflow. +/// +/// If the multiplication would result in overflow, then return false and do +/// not update @a res. +bool +wcore_mul_size(size_t *res, size_t x, size_t y); + +/// @brief In-place variant of wcore_mul_size(). +static inline bool +wcore_imul_size(size_t *x, size_t y) { + return wcore_mul_size(x, *x, y); +} + /// @brief Wrapper around malloc() that emits error if allocation fails. void* wcore_malloc(size_t size); diff --git a/src/waffle/gbm/wgbm_window.c b/src/waffle/gbm/wgbm_window.c index edac449..9fbf1be 100644 --- a/src/waffle/gbm/wgbm_window.c +++ b/src/waffle/gbm/wgbm_window.c @@ -30,6 +30,7 @@ #include "waffle_gbm.h" +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "wegl_config.h" @@ -59,8 +60,9 @@ wgbm_window_destroy(struct wcore_window *wc_self) struct wcore_window* wgbm_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct wgbm_display *dpy = wgbm_display(wc_config->display); struct wgbm_platform *plat = wgbm_platform(wegl_platform(wc_plat)); @@ -68,6 +70,11 @@ wgbm_window_create(struct wcore_platform *wc_plat, uint32_t gbm_format; bool ok = true; + 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; diff --git a/src/waffle/gbm/wgbm_window.h b/src/waffle/gbm/wgbm_window.h index 729612b..7827823 100644 --- a/src/waffle/gbm/wgbm_window.h +++ b/src/waffle/gbm/wgbm_window.h @@ -52,8 +52,9 @@ wgbm_window(struct wcore_window *wc_self) struct wcore_window* wgbm_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool wgbm_window_destroy(struct wcore_window *wc_self); diff --git a/src/waffle/glx/glx_window.c b/src/waffle/glx/glx_window.c index 34fa784..331bb51 100644 --- a/src/waffle/glx/glx_window.c +++ b/src/waffle/glx/glx_window.c @@ -27,6 +27,7 @@ #include <string.h> #include <xcb/xcb.h> +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "glx_config.h" @@ -52,14 +53,20 @@ glx_window_destroy(struct wcore_window *wc_self) struct wcore_window* glx_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct glx_window *self; struct glx_display *dpy = glx_display(wc_config->display); struct glx_config *config = glx_config(wc_config); bool ok = true; + 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; diff --git a/src/waffle/glx/glx_window.h b/src/waffle/glx/glx_window.h index 5aed497..b4fd7f9 100644 --- a/src/waffle/glx/glx_window.h +++ b/src/waffle/glx/glx_window.h @@ -46,8 +46,9 @@ DEFINE_CONTAINER_CAST_FUNC(glx_window, struct wcore_window* glx_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool glx_window_destroy(struct wcore_window *wc_self); diff --git a/src/waffle/nacl/nacl_config.c b/src/waffle/nacl/nacl_config.c new file mode 100644 index 0000000..27a75e1 --- /dev/null +++ b/src/waffle/nacl/nacl_config.c @@ -0,0 +1,63 @@ +// Copyright 2014 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 "nacl_config.h" + +bool +nacl_config_destroy(struct wcore_config *wc_self) +{ + bool ok = true; + + if (wc_self == NULL) + return ok; + + ok &= wcore_config_teardown(wc_self); + free(nacl_config(wc_self)); + return ok; +} + +struct wcore_config* +nacl_config_choose(struct wcore_platform *wc_plat, + struct wcore_display *wc_dpy, + const struct wcore_config_attrs *attrs) +{ + struct nacl_config *self; + bool ok = true; + + self = wcore_calloc(sizeof(*self)); + if (self == NULL) + return NULL; + + ok = wcore_config_init(&self->wcore, wc_dpy, attrs); + if (!ok) + goto error; + + return &self->wcore; + +error: + nacl_config_destroy(&self->wcore); + self = NULL; + return NULL; +} diff --git a/src/waffle/nacl/nacl_config.h b/src/waffle/nacl/nacl_config.h new file mode 100644 index 0000000..3270179 --- /dev/null +++ b/src/waffle/nacl/nacl_config.h @@ -0,0 +1,49 @@ +// Copyright 2014 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. + +#pragma once + +#include "wcore_config.h" +#include "wcore_util.h" + +struct wcore_config_attrs; +struct wcore_platform; + +struct nacl_config { + struct wcore_config wcore; +}; + +DEFINE_CONTAINER_CAST_FUNC(nacl_config, + struct nacl_config, + struct wcore_config, + wcore) + +struct wcore_config* +nacl_config_choose(struct wcore_platform *wc_plat, + struct wcore_display *wc_dpy, + const struct wcore_config_attrs *attrs); + +bool +nacl_config_destroy(struct wcore_config *wc_self); diff --git a/src/waffle/nacl/nacl_container.cpp b/src/waffle/nacl/nacl_container.cpp new file mode 100644 index 0000000..3e8073c --- /dev/null +++ b/src/waffle/nacl/nacl_container.cpp @@ -0,0 +1,66 @@ +// Copyright 2014 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 "ppapi/cpp/graphics_3d.h" +#include "nacl_container.h" + +namespace waffle { + +struct nacl_container { + pp::Graphics3D ctx; +}; + +static void +nacl_container_dtor(waffle::nacl_container *nc) +{ + if (!nc) + return; + delete nc; +} + +static nacl_container* +nacl_container_ctor() +{ + nacl_container *nc = new nacl_container; + + if (!nc) + return NULL; + + return nc; +} + +}; // namespace waffle ends + +extern "C" struct nacl_container* +nacl_init() +{ + return reinterpret_cast<nacl_container*>(waffle::nacl_container_ctor()); +} + +extern "C" void +nacl_teardown(nacl_container *nc) +{ + waffle::nacl_container_dtor(reinterpret_cast<waffle::nacl_container*>(nc)); +} diff --git a/src/waffle/nacl/nacl_container.h b/src/waffle/nacl/nacl_container.h new file mode 100644 index 0000000..61d935c --- /dev/null +++ b/src/waffle/nacl/nacl_container.h @@ -0,0 +1,38 @@ +// Copyright 2014 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. + +#ifdef __cplusplus + +extern "C" { +#endif + +struct nacl_container; + +struct nacl_container *nacl_init(); +void nacl_teardown(struct nacl_container *nc); + +#ifdef __cplusplus +}; +#endif diff --git a/src/waffle/nacl/nacl_context.c b/src/waffle/nacl/nacl_context.c new file mode 100644 index 0000000..2e68a64 --- /dev/null +++ b/src/waffle/nacl/nacl_context.c @@ -0,0 +1,65 @@ +// Copyright 2014 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 "nacl_context.h" + +bool +nacl_context_destroy(struct wcore_context *wc_self) +{ + struct nacl_context *self; + bool ok = true; + + if (!wc_self) + return ok; + + self = nacl_context(wc_self); + + ok &= wcore_context_teardown(wc_self); + free(self); + return ok; +} + +struct wcore_context* +nacl_context_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx) +{ + struct nacl_context *self; + bool ok = true; + + self = wcore_calloc(sizeof(*self)); + if (self == NULL) + return NULL; + + ok = wcore_context_init(&self->wcore, wc_config); + if (!ok) + goto error; + + return &self->wcore; + +error: + nacl_context_destroy(&self->wcore); + return NULL; +} diff --git a/src/waffle/nacl/nacl_context.h b/src/waffle/nacl/nacl_context.h new file mode 100644 index 0000000..bb4481a --- /dev/null +++ b/src/waffle/nacl/nacl_context.h @@ -0,0 +1,52 @@ +// Copyright 2014 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. + +#pragma once + +#include "wcore_context.h" +#include "wcore_util.h" + +#include "nacl_display.h" +#include "nacl_platform.h" + +struct wcore_config; +struct wcore_platform; + +struct nacl_context { + struct wcore_context wcore; +}; + +DEFINE_CONTAINER_CAST_FUNC(nacl_context, + struct nacl_context, + struct wcore_context, + wcore) + +struct wcore_context* +nacl_context_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + struct wcore_context *wc_share_ctx); + +bool +nacl_context_destroy(struct wcore_context *wc_self); diff --git a/src/waffle/nacl/nacl_display.c b/src/waffle/nacl/nacl_display.c new file mode 100644 index 0000000..2d1162e --- /dev/null +++ b/src/waffle/nacl/nacl_display.c @@ -0,0 +1,70 @@ +// Copyright 2014 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 "nacl_display.h" + +bool +nacl_display_destroy(struct wcore_display *wc_self) +{ + struct nacl_display *self = nacl_display(wc_self); + bool ok = true; + + if (!self) + return ok; + + ok &= wcore_display_teardown(&self->wcore); + + free(self); + return ok; +} + +struct wcore_display* +nacl_display_connect(struct wcore_platform *wc_plat, + const char *name) +{ + struct nacl_display *self; + bool ok = true; + + self = wcore_calloc(sizeof(*self)); + if (self == NULL) + return NULL; + + ok = wcore_display_init(&self->wcore, wc_plat); + if (!ok) + goto error; + + return &self->wcore; + +error: + nacl_display_destroy(&self->wcore); + return NULL; +} + +bool +nacl_display_supports_context_api(struct wcore_display *wc_self, + int32_t context_api) +{ + return false; +} diff --git a/src/waffle/nacl/nacl_display.h b/src/waffle/nacl/nacl_display.h new file mode 100644 index 0000000..34eee21 --- /dev/null +++ b/src/waffle/nacl/nacl_display.h @@ -0,0 +1,52 @@ +// Copyright 2014 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. + +#pragma once + +#include "wcore_display.h" +#include "wcore_error.h" +#include "wcore_util.h" + +struct wcore_platform; + +struct nacl_display { + struct wcore_display wcore; +}; + +DEFINE_CONTAINER_CAST_FUNC(nacl_display, + struct nacl_display, + struct wcore_display, + wcore) + +struct wcore_display* +nacl_display_connect(struct wcore_platform *wc_plat, + const char *name); + +bool +nacl_display_destroy(struct wcore_display *wc_self); + +bool +nacl_display_supports_context_api(struct wcore_display *wc_self, + int32_t context_api); diff --git a/src/waffle/nacl/nacl_platform.c b/src/waffle/nacl/nacl_platform.c new file mode 100644 index 0000000..b4df9d9 --- /dev/null +++ b/src/waffle/nacl/nacl_platform.c @@ -0,0 +1,134 @@ +// Copyright 2014 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 <dlfcn.h> +#include <stdio.h> + +#include "nacl_platform.h" + +static const struct wcore_platform_vtbl nacl_platform_vtbl; + +static bool +nacl_platform_destroy(struct wcore_platform *wc_self) +{ + struct nacl_platform *self = nacl_platform(wc_self); + bool ok = true; + + if (!self) + return true; + + ok &= wcore_platform_teardown(wc_self); + + nacl_teardown(self->nacl); + + free(self); + return ok; +} + +static bool +nacl_platform_dl_can_open(struct wcore_platform *wc_self, + int32_t waffle_dl) +{ + return false; +} + +static void* +nacl_platform_dl_sym(struct wcore_platform *wc_self, + int32_t waffle_dl, + const char *name) +{ + return NULL; +} + +static bool +nacl_platform_make_current(struct wcore_platform *wc_self, + struct wcore_display *wc_dpy, + struct wcore_window *wc_window, + struct wcore_context *wc_ctx) +{ + return false; +} + +struct wcore_platform* +nacl_platform_create(void) +{ + struct nacl_platform *self; + bool ok = true; + + self = wcore_calloc(sizeof(*self)); + if (self == NULL) + return NULL; + + ok = wcore_platform_init(&self->wcore); + if (!ok) + goto error; + + self->nacl = nacl_init(); + if (!self->nacl) + goto error; + + self->wcore.vtbl = &nacl_platform_vtbl; + return &self->wcore; + +error: + nacl_platform_destroy(&self->wcore); + return NULL; +} + +static const struct wcore_platform_vtbl nacl_platform_vtbl = { + .destroy = nacl_platform_destroy, + + .make_current = nacl_platform_make_current, + .dl_can_open = nacl_platform_dl_can_open, + .dl_sym = nacl_platform_dl_sym, + + .display = { + .connect = nacl_display_connect, + .destroy = nacl_display_destroy, + .supports_context_api = nacl_display_supports_context_api, + .get_native = NULL, + }, + + .config = { + .choose = nacl_config_choose, + .destroy = nacl_config_destroy, + .get_native = NULL, + }, + + .context = { + .create = nacl_context_create, + .destroy = nacl_context_destroy, + .get_native = NULL, + }, + + .window = { + .create = nacl_window_create, + .destroy = nacl_window_destroy, + .show = nacl_window_show, + .swap_buffers = nacl_window_swap_buffers, + .resize = nacl_window_resize, + .get_native = NULL, + }, +}; diff --git a/src/waffle/nacl/nacl_platform.h b/src/waffle/nacl/nacl_platform.h new file mode 100644 index 0000000..ba58de5 --- /dev/null +++ b/src/waffle/nacl/nacl_platform.h @@ -0,0 +1,49 @@ +// Copyright 2014 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. + +#pragma once + +#include "wcore_platform.h" +#include "wcore_error.h" +#include "wcore_util.h" + +#include "nacl_config.h" +#include "nacl_container.h" +#include "nacl_context.h" +#include "nacl_display.h" +#include "nacl_window.h" + +struct nacl_platform { + struct wcore_platform wcore; + struct nacl_container *nacl; +}; + +DEFINE_CONTAINER_CAST_FUNC(nacl_platform, + struct nacl_platform, + struct wcore_platform, + wcore) + +struct wcore_platform* +nacl_platform_create(void); diff --git a/src/waffle/nacl/nacl_window.c b/src/waffle/nacl/nacl_window.c new file mode 100644 index 0000000..c5ba4e0 --- /dev/null +++ b/src/waffle/nacl/nacl_window.c @@ -0,0 +1,90 @@ +// Copyright 2014 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 "wcore_error.h" +#include "nacl_config.h" +#include "nacl_display.h" +#include "nacl_window.h" +#include "nacl_platform.h" + +bool +nacl_window_destroy(struct wcore_window *wc_self) +{ + struct nacl_window *self = nacl_window(wc_self); + bool ok = true; + + if (!wc_self) + return ok; + + ok &= wcore_window_teardown(wc_self); + free(self); + return ok; +} + +struct wcore_window* +nacl_window_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + int width, + int height) +{ + struct nacl_window *self; + bool ok = true; + + self = wcore_calloc(sizeof(*self)); + if (self == NULL) + return NULL; + + ok = wcore_window_init(&self->wcore, wc_config); + if (!ok) + goto error; + + if (!ok) + goto error; + + return &self->wcore; + +error: + nacl_window_destroy(&self->wcore); + return NULL; +} + +bool +nacl_window_show(struct wcore_window *wc_self) +{ + return true; +} + +bool +nacl_window_resize(struct wcore_window *wc_self, + int32_t width, int32_t height) +{ + return false; +} + +bool +nacl_window_swap_buffers(struct wcore_window *wc_self) +{ + return false; +} diff --git a/src/waffle/nacl/nacl_window.h b/src/waffle/nacl/nacl_window.h new file mode 100644 index 0000000..5f0906d --- /dev/null +++ b/src/waffle/nacl/nacl_window.h @@ -0,0 +1,59 @@ +// Copyright 2014 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. + +#pragma once + +#include "wcore_window.h" +#include "wcore_util.h" +#include "nacl_platform.h" + +struct wcore_platform; + +struct nacl_window { + struct wcore_window wcore; +}; + +DEFINE_CONTAINER_CAST_FUNC(nacl_window, + struct nacl_window, + struct wcore_window, + wcore) +struct wcore_window* +nacl_window_create(struct wcore_platform *wc_plat, + struct wcore_config *wc_config, + int width, + int height); + +bool +nacl_window_destroy(struct wcore_window *wc_self); + +bool +nacl_window_show(struct wcore_window *wc_self); + +bool +nacl_window_resize(struct wcore_window *wc_self, + int32_t width, int32_t height); + +bool +nacl_window_swap_buffers(struct wcore_window *wc_self); diff --git a/src/waffle/waffle.def.in b/src/waffle/waffle.def.in index db8464f..ca3078a 100644 --- a/src/waffle/waffle.def.in +++ b/src/waffle/waffle.def.in @@ -20,6 +20,7 @@ EXPORTS waffle_context_destroy waffle_context_get_native waffle_window_create + waffle_window_create2 waffle_window_destroy waffle_window_show waffle_window_swap_buffers diff --git a/src/waffle/wayland/wayland_window.c b/src/waffle/wayland/wayland_window.c index f32e995..4ac9c16 100644 --- a/src/waffle/wayland/wayland_window.c +++ b/src/waffle/wayland/wayland_window.c @@ -33,6 +33,7 @@ #include "waffle_wayland.h" +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "wegl_config.h" @@ -96,13 +97,19 @@ static const struct wl_shell_surface_listener shell_surface_listener = { struct wcore_window* wayland_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct wayland_window *self; struct wayland_display *dpy = wayland_display(wc_config->display); bool ok = true; + 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; diff --git a/src/waffle/wayland/wayland_window.h b/src/waffle/wayland/wayland_window.h index 933e751..11e6791 100644 --- a/src/waffle/wayland/wayland_window.h +++ b/src/waffle/wayland/wayland_window.h @@ -59,8 +59,9 @@ wayland_window(struct wcore_window *wc_self) struct wcore_window* wayland_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool wayland_window_destroy(struct wcore_window *wc_self); diff --git a/src/waffle/wgl/wgl_window.c b/src/waffle/wgl/wgl_window.c index 7c3932f..99dd194 100644 --- a/src/waffle/wgl/wgl_window.c +++ b/src/waffle/wgl/wgl_window.c @@ -25,6 +25,7 @@ #include <windows.h> +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "wgl_config.h" @@ -68,14 +69,20 @@ wgl_window_priv_destroy(struct wcore_window *wc_self) struct wcore_window* wgl_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct wgl_config *config = wgl_config(wc_config); bool ok; assert(config->window); + if (wcore_attrib_list_length(attrib_list) > 0) { + wcore_error_bad_attribute(attrib_list[0]); + return NULL; + } + // Currently we do not allow multiple windows per config. // Neither piglit nor the waffle examples do that yet, so just // return NULL in case that ever changes. @@ -95,8 +102,8 @@ wgl_window_create(struct wcore_platform *wc_plat, struct wcore_window* wgl_window_priv_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height) { struct wgl_platform *plat = wgl_platform(wc_plat); struct wgl_window *self; diff --git a/src/waffle/wgl/wgl_window.h b/src/waffle/wgl/wgl_window.h index a60205d..9b11509 100644 --- a/src/waffle/wgl/wgl_window.h +++ b/src/waffle/wgl/wgl_window.h @@ -48,8 +48,8 @@ wgl_window(struct wcore_window *wcore) struct wcore_window* wgl_window_priv_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height); bool wgl_window_priv_destroy(struct wcore_window *wc_self); @@ -57,8 +57,9 @@ wgl_window_priv_destroy(struct wcore_window *wc_self); struct wcore_window* wgl_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool wgl_window_destroy(struct wcore_window *wc_self); diff --git a/src/waffle/x11/x11_window.c b/src/waffle/x11/x11_window.c index b2e3631..308d4ce 100644 --- a/src/waffle/x11/x11_window.c +++ b/src/waffle/x11/x11_window.c @@ -70,8 +70,8 @@ bool x11_window_init(struct x11_window *self, struct x11_display *dpy, xcb_visualid_t visual_id, - int width, - int height) + int32_t width, + int32_t height) { xcb_colormap_t colormap = 0; xcb_window_t window = 0; diff --git a/src/waffle/x11/x11_window.h b/src/waffle/x11/x11_window.h index 812b146..262b156 100644 --- a/src/waffle/x11/x11_window.h +++ b/src/waffle/x11/x11_window.h @@ -40,8 +40,8 @@ bool x11_window_init(struct x11_window *self, struct x11_display *dpy, xcb_visualid_t visual_id, - int width, - int height); + int32_t width, + int32_t height); bool x11_window_teardown(struct x11_window *self); diff --git a/src/waffle/xegl/xegl_window.c b/src/waffle/xegl/xegl_window.c index ce638b4..ab66314 100644 --- a/src/waffle/xegl/xegl_window.c +++ b/src/waffle/xegl/xegl_window.c @@ -28,6 +28,7 @@ #include <xcb/xcb.h> +#include "wcore_attrib_list.h" #include "wcore_error.h" #include "wegl_config.h" @@ -55,8 +56,9 @@ xegl_window_destroy(struct wcore_window *wc_self) struct wcore_window* xegl_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height) + int32_t width, + int32_t height, + const intptr_t attrib_list[]) { struct xegl_window *self; struct xegl_display *dpy = xegl_display(wc_config->display); @@ -65,6 +67,11 @@ xegl_window_create(struct wcore_platform *wc_plat, xcb_visualid_t visual; bool ok = true; + 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; diff --git a/src/waffle/xegl/xegl_window.h b/src/waffle/xegl/xegl_window.h index 1f963ba..e59c02f 100644 --- a/src/waffle/xegl/xegl_window.h +++ b/src/waffle/xegl/xegl_window.h @@ -56,8 +56,9 @@ xegl_window(struct wcore_window *wc_self) struct wcore_window* xegl_window_create(struct wcore_platform *wc_plat, struct wcore_config *wc_config, - int width, - int height); + int32_t width, + int32_t height, + const intptr_t attrib_list[]); bool xegl_window_destroy(struct wcore_window *wc_self); diff --git a/tests/functional/gl_basic_test.c b/tests/functional/gl_basic_test.c index 0e932e3..19b0dac 100644 --- a/tests/functional/gl_basic_test.c +++ b/tests/functional/gl_basic_test.c @@ -216,6 +216,12 @@ gl_basic_draw__(struct gl_basic_draw_args__ args) struct waffle_window *window = NULL; struct waffle_context *ctx = NULL; + const intptr_t window_attrib_list[] = { + WAFFLE_WINDOW_WIDTH, WINDOW_WIDTH, + WAFFLE_WINDOW_HEIGHT, WINDOW_HEIGHT, + 0, + }; + libgl = libgl_from_context_api(waffle_context_api); i = 0; @@ -271,8 +277,7 @@ gl_basic_draw__(struct gl_basic_draw_args__ args) } } - ASSERT_TRUE(window = waffle_window_create(config, - WINDOW_WIDTH, WINDOW_HEIGHT)); + ASSERT_TRUE(window = waffle_window_create2(config, window_attrib_list)); ASSERT_TRUE(waffle_window_show(window)); ctx = waffle_context_create(config, NULL); |