From 551458bb15f9d0628254642f1847a6a684bc50d4 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 2 Sep 2013 17:38:12 -0400 Subject: [PATCH 01/34] Initial commit of BlackBerry implementation. It compiles, but doesn't have required functions implemented. --- freeglut/freeglut/AUTHORS | 3 + freeglut/freeglut/CMakeLists.txt | 15 +- freeglut/freeglut/README.blackberry | 21 ++ freeglut/freeglut/blackberry.toolchain.cmake | 196 ++++++++++++++++++ .../src/blackberry/fg_internal_blackberry.h | 120 +++++++++++ .../src/blackberry/fg_main_blackberry.h | 37 ++++ freeglut/freeglut/src/fg_internal.h | 8 +- 7 files changed, 397 insertions(+), 3 deletions(-) create mode 100644 freeglut/freeglut/README.blackberry create mode 100644 freeglut/freeglut/blackberry.toolchain.cmake create mode 100644 freeglut/freeglut/src/blackberry/fg_internal_blackberry.h create mode 100644 freeglut/freeglut/src/blackberry/fg_main_blackberry.h diff --git a/freeglut/freeglut/AUTHORS b/freeglut/freeglut/AUTHORS index 617af75..972e662 100644 --- a/freeglut/freeglut/AUTHORS +++ b/freeglut/freeglut/AUTHORS @@ -32,6 +32,9 @@ John Tsiombikas Sylvain Beucler support for Android, X11/EGL, OpenGL(ES) 2.x, misc fixes +Vincent Simonetti + support for BlackBerry + Diederick C. Niehorster Chris Marshall Clive McCarthy diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index a3a4fd6..2bc9b2b 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -137,6 +137,11 @@ ELSEIF(ANDROID) src/android/fg_structure_android.c src/android/fg_window_android.c ) +ELSEIF(BLACKBERRY) + LIST(APPEND FREEGLUT_SRCS + src/blackberry/fg_internal_blackberry.h + src/blackberry/fg_main_blackberry.h + ) ELSE() LIST(APPEND FREEGLUT_SRCS src/x11/fg_cursor_x11.c @@ -219,14 +224,14 @@ ENDIF() IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") - IF(!ANDROID) + IF(NOT(ANDROID OR BLACKBERRY)) # not setting -ansi as EGL/KHR headers doesn't support it SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi") ENDIF() ENDIF(CMAKE_COMPILER_IS_GNUCC) INCLUDE(CheckIncludeFiles) -IF(UNIX AND NOT ANDROID) +IF(UNIX AND NOT(ANDROID OR BLACKBERRY)) FIND_PACKAGE(X11 REQUIRED) LIST(APPEND LIBS ${X11_LIBRARIES}) IF(X11_Xrandr_FOUND) @@ -251,6 +256,8 @@ IF(ANDROID) # -landroid for ANativeWindow # -llog for native Android logging LIST(APPEND LIBS android log) +ELSEIF(BLACKBERRY) + LIST(APPEND LIBS bps slog2) ENDIF() INCLUDE(CheckFunctionExists) @@ -464,12 +471,16 @@ IF(WIN32) ELSEIF(FREEGLUT_GLES2) IF(ANDROID) SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm") + ELSEIF(BLACKBERRY) + SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lGLESv2 -lEGL -lm") ELSE() SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lEGL -lm") ENDIF() ELSEIF(FREEGLUT_GLES1) IF(ANDROID) SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv1_CM -lEGL -lm") + ELSEIF(BLACKBERRY) + SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lGLESv1_CM -lEGL -lm") ELSE() SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv1_CM -lEGL -lm") ENDIF() diff --git a/freeglut/freeglut/README.blackberry b/freeglut/freeglut/README.blackberry new file mode 100644 index 0000000..6eac203 --- /dev/null +++ b/freeglut/freeglut/README.blackberry @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------ +# BlackBerry CMake toolchain file, for use with the BlackBerry 10 NDK +# Requires cmake 2.6.3 or newer (2.8.3 or newer is recommended). +# +# Usage Linux: +# $ source /absolute/path/to/the/bbndk/bbndk-env.sh +# $ mkdir build +# $ cd build +# $ cmake .. -DCMAKE_TOOLCHAIN_FILE="../blackberry.toolchain.cmake" -DBLACKBERRY_ARCHITECTURE=arm -DFREEGLUT_GLES2=ON -DFREEGLUT_BUILD_DEMOS=NO -DCMAKE_VERBOSE_MAKEFILE=TRUE -G "Eclipse CDT4 - Unix Makefiles" +# $ make -j8 +# +# Usage Mac: +# Same as the steps on Linux +# +# Usage Windows: +# > /absolute/path/to/the/bbndk/bbndk-env.bat +# > mkdir build +# > cd build +# > cmake .. -DCMAKE_TOOLCHAIN_FILE="../blackberry.toolchain.cmake" -DBLACKBERRY_ARCHITECTURE=arm -DFREEGLUT_GLES2=ON -DFREEGLUT_BUILD_DEMOS=NO -DCMAKE_VERBOSE_MAKEFILE=TRUE -G "Eclipse CDT4 - Unix Makefiles" +# > make -j8 +# \ No newline at end of file diff --git a/freeglut/freeglut/blackberry.toolchain.cmake b/freeglut/freeglut/blackberry.toolchain.cmake new file mode 100644 index 0000000..4c9d264 --- /dev/null +++ b/freeglut/freeglut/blackberry.toolchain.cmake @@ -0,0 +1,196 @@ +# ------------------------------------------------------------------------------ +# BlackBerry CMake toolchain file, for use with the BlackBerry 10 NDK +# Requires cmake 2.6.3 or newer (2.8.3 or newer is recommended). +# +# Usage Linux: +# $ source /absolute/path/to/the/bbndk/bbndk-env.sh +# $ mkdir build +# $ cd build +# $ cmake .. -DCMAKE_TOOLCHAIN_FILE="../blackberry.toolchain.cmake" -DBLACKBERRY_ARCHITECTURE=arm -DFREEGLUT_GLES2=ON -DFREEGLUT_BUILD_DEMOS=NO -DCMAKE_VERBOSE_MAKEFILE=TRUE -G "Eclipse CDT4 - Unix Makefiles" +# $ make -j8 +# +# Usage Mac: +# Same as the steps on Linux +# +# Usage Windows: +# > /absolute/path/to/the/bbndk/bbndk-env.bat +# > mkdir build +# > cd build +# > cmake .. -DCMAKE_TOOLCHAIN_FILE="../blackberry.toolchain.cmake" -DBLACKBERRY_ARCHITECTURE=arm -DFREEGLUT_GLES2=ON -DFREEGLUT_BUILD_DEMOS=NO -DCMAKE_VERBOSE_MAKEFILE=TRUE -G "Eclipse CDT4 - Unix Makefiles" +# > make -j8 +# + +cmake_minimum_required( VERSION 2.6.3 ) + +if( DEFINED CMAKE_CROSSCOMPILING ) + # Subsequent toolchain loading is not really needed + return() +endif() + +set( BLACKBERRY_TOOLCHAIN_ROOT "$ENV{QNX_HOST}" ) +set( BLACKBERRY_TARGET_ROOT "$ENV{QNX_TARGET}" ) +set( CMAKE_SYSTEM_NAME Linux ) +set( CMAKE_SYSTEM_VERSION 1 ) + +# STL version: by default gnustl_static will be used +set( BLACKBERRY_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static") +mark_as_advanced( BLACKBERRY_USE_STLPORT ) + +# Detect host platform +set( TOOL_OS_SUFFIX "" ) +if( CMAKE_HOST_APPLE ) + set( BLACKBERRY_NDK_HOST_SYSTEM_NAME "darwin-x86" ) +elseif( CMAKE_HOST_WIN32 ) + set( BLACKBERRY_NDK_HOST_SYSTEM_NAME "windows" ) + set( TOOL_OS_SUFFIX ".exe" ) +elseif( CMAKE_HOST_UNIX ) + set(BLACKBERRY_NDK_HOST_SYSTEM_NAME "linux-x86" ) +else() + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) +endif() + +# Specify the cross compiler +set( CMAKE_C_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) +set( CMAKE_CXX_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) +set( CMAKE_ASM_COMPILER "$ENV{QNX_HOST}/usr/bin/qcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" ) +if( CMAKE_VERSION VERSION_LESS 2.8.5 ) + set( CMAKE_ASM_COMPILER_ARG1 "-c" ) +endif() + +# There may be a way to make cmake reduce these TODO +if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" ) + set( NEUTRINO_ARCH "v7" ) +else() + set( NEUTRINO_ARCH "" ) +endif() +set( CMAKE_STRIP "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) +set( CMAKE_AR "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) +set( CMAKE_LINKER "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) +set( CMAKE_NM "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) +set( CMAKE_OBJCOPY "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) +set( CMAKE_OBJDUMP "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}${NEUTRINO_ARCH}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) +set( CMAKE_RANLIB "$ENV{QNX_HOST}/usr/bin/nto${BLACKBERRY_ARCHITECTURE}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) + +# Installer +#if( APPLE ) +# find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) +# if( NOT CMAKE_INSTALL_NAME_TOOL ) +# message( FATAL_ERROR "Could not find install_name_tool, please check your #installation." ) +# endif() +# mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) +# endif() + +# Setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) +set( CMAKE_INSTALL_PREFIX "${BLACKBERRY_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) +else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) +endif() + +# Includes +list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" ) + +# Flags and preprocessor definitions +if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" ) + set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntoarmv7le -D__QNX__" ) + set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntoarmv7le -Y_gpp -D__QNX__" ) +else() + set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntox86 -D__QNX__" ) + set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntox86 -Y_gpp -D__QNX__" ) +endif() +set( BLACKBERRY 1 ) + +# NDK flags +set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${BLACKBERRY_CC_FLAGS}" ) +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" ) + +# Release and Debug flags +if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" ) + set( CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3" ) + set( CMAKE_C_FLAGS_RELEASE "-mthumb -O3" ) + set( CMAKE_CXX_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) + set( CMAKE_C_FLAGS_DEBUG "-marm -Os -finline-limit=64" ) +else() + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i486" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i486" ) +endif() + +# Cache flags +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) +set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags" ) +set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" ) +set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" ) +set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" ) +set( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" ) +set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" ) +SET( CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" CACHE STRING "linker flags") +SET( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" CACHE STRING "linker flags") +set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-lstdc++ -lm -lEGL -lGLESv2 -lbps -lscreen" CACHE STRING "linker flags" ) + +# Finish flags +set( BLACKBERRY_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" CACHE INTERNAL "Extra BlackBerry compiler flags") +set( BLACKBERRY_LINKER_FLAGS "${BLACKBERRY_LINKER_FLAGS}" CACHE INTERNAL "Extra BlackBerry linker flags") +set( CMAKE_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) +set( CMAKE_C_FLAGS "${BLACKBERRY_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) + +# Global flags for cmake client scripts to change behavior +set( BLACKBERRY True ) +# Find the Target environment +set( CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}" "${BLACKBERRY_TARGET_ROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) +# Search for libraries and includes in the ndk toolchain +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) + +# Macro to find packages on the host OS +macro( find_host_package ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_package( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + +# Macro to find programs on the host OS +macro( find_host_program ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) + if( CMAKE_HOST_WIN32 ) + SET( WIN32 1 ) + SET( UNIX ) + elseif( CMAKE_HOST_APPLE ) + SET( APPLE 1 ) + SET( UNIX ) + endif() + find_program( ${ARGN} ) + SET( WIN32 ) + SET( APPLE ) + SET( UNIX 1 ) + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) +endmacro() + +# We are doing cross compiling, reset the OS information of the Building system +UNSET( APPLE ) +UNSET( WIN32 ) +UNSET( UNIX ) diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h new file mode 100644 index 0000000..0223144 --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -0,0 +1,120 @@ +/* + * fg_internal_blackberry.h + * + * The freeglut library private include file. + * + * Copyright (C) 2012 Sylvain Beucler + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef FREEGLUT_INTERNAL_BLACKBERRY_H +#define FREEGLUT_INTERNAL_BLACKBERRY_H + +//Minor modified version of fg_internal_android.h + +/* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */ +/* BlackBerry OpenGL ES is accessed through EGL */ +#include "egl/fg_internal_egl.h" + +/* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */ +/* The structure used by display initialization in freeglut_init.c */ +typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay; +struct tagSFG_PlatformDisplay +{ + struct tagSFG_PlatformDisplayEGL egl; + EGLNativeWindowType single_native_window; +}; + +typedef struct tagSFG_PlatformContext SFG_PlatformContext; +/* SFG_PlatformContext is used for SFG_Window.Window */ +struct tagSFG_PlatformContext +{ + struct tagSFG_PlatformContextEGL egl; +}; + + +/** + * Virtual PAD (spots on touchscreen that simulate keys) + */ +struct vpad_state { + bool on; + bool left; + bool right; + bool up; + bool down; +}; +struct touchscreen { + struct vpad_state vpad; + bool in_mmotion; +}; + + +/* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */ +/* + * Initial defines from "js.h" starting around line 33 with the existing "freeglut_joystick.c" + * interspersed + */ + + /* + * We'll put these values in and that should + * allow the code to at least compile when there is + * no support. The JS open routine should error out + * and shut off all the code downstream anyway and if + * the application doesn't use a joystick we'll be fine. + */ + + struct JS_DATA_TYPE + { + int buttons; + int x; + int y; + }; + +# define JS_RETURN (sizeof(struct JS_DATA_TYPE)) + +/* XXX It might be better to poll the operating system for the numbers of buttons and + * XXX axes and then dynamically allocate the arrays. + */ +# define _JS_MAX_AXES 16 +typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick; +struct tagSFG_PlatformJoystick +{ + struct JS_DATA_TYPE js; + + char fname [ 128 ]; + int fd; +}; + +/* Window's state description. This structure should be kept portable. */ +typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState; +struct tagSFG_PlatformWindowState +{ + char unused; +}; + +/* Menu font and color definitions */ +#define FREEGLUT_MENU_FONT NULL + +#define FREEGLUT_MENU_PEN_FORE_COLORS {0.0f, 0.0f, 0.0f, 1.0f} +#define FREEGLUT_MENU_PEN_BACK_COLORS {0.70f, 0.70f, 0.70f, 1.0f} +#define FREEGLUT_MENU_PEN_HFORE_COLORS {0.0f, 0.0f, 0.0f, 1.0f} +#define FREEGLUT_MENU_PEN_HBACK_COLORS {1.0f, 1.0f, 1.0f, 1.0f} + +#endif /* FREEGLUT_INTERNAL_BLACKBERRY_H */ diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h new file mode 100644 index 0000000..8febf36 --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h @@ -0,0 +1,37 @@ +/* + * fg_main_blackberry.h + * + * The BlackBerry-specific windows message processing methods. + * + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __FG_MAIN_BLACKBERRY_H__ +#define __FG_MAIN_BLACKBERRY_H__ + +#include +#include "fg_internal.h" + +/*extern void fgPlatformProcessSingleEvent(void); +extern unsigned long fgPlatformSystemTime(void); +extern void fgPlatformSleepForEvents(long msec); +extern void fgPlatformMainLoopPreliminaryWork(void);*/ + +#endif diff --git a/freeglut/freeglut/src/fg_internal.h b/freeglut/freeglut/src/fg_internal.h index 645c82f..4792ad8 100644 --- a/freeglut/freeglut/src/fg_internal.h +++ b/freeglut/freeglut/src/fg_internal.h @@ -45,6 +45,9 @@ #elif defined (__ANDROID__) # define TARGET_HOST_ANDROID 1 +#elif defined (__QNX__) +# define TARGET_HOST_BLACKBERRY 1 + #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun) # define TARGET_HOST_POSIX_X11 1 @@ -184,6 +187,9 @@ #if TARGET_HOST_ANDROID #include "android/fg_internal_android.h" #endif +#if TARGET_HOST_BLACKBERRY +#include "blackberry/fg_internal_blackberry.h" +#endif /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */ @@ -372,7 +378,7 @@ struct tagSFG_Context int DoubleBuffered; /* Treat the window as double-buffered */ - /* When drawing geometry to vertex attribute buffers, user specifies + /* When drawing geometry to vertex attribute buffers, user specifies * the attribute indices for vertices, normals and/or texture coords * to freeglut. Those are stored here */ From e865fdfe5417076775a2ca647cb8944f65f18e3a Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 2 Sep 2013 19:17:44 -0400 Subject: [PATCH 02/34] Android and BlackBerry have a fair amount of overlap, for now. --- freeglut/freeglut/CMakeLists.txt | 46 +++++---- .../src/blackberry/fg_state_blackberry.c | 99 +++++++++++++++++++ 2 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 freeglut/freeglut/src/blackberry/fg_state_blackberry.c diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 2bc9b2b..a8cb8b3 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -118,30 +118,39 @@ IF(WIN32) ) ENDIF() -ELSEIF(ANDROID) +ELSEIF(ANDROID OR BLACKBERRY) LIST(APPEND FREEGLUT_SRCS - src/android/native_app_glue/android_native_app_glue.c - src/android/native_app_glue/android_native_app_glue.h - src/android/fg_internal_android.h src/android/fg_cursor_android.c src/android/fg_ext_android.c src/android/fg_gamemode_android.c src/android/fg_init_android.c src/android/fg_input_devices_android.c src/android/fg_joystick_android.c - src/android/fg_main_android.c - src/android/fg_main_android.h - src/android/fg_runtime_android.c src/android/fg_spaceball_android.c - src/android/fg_state_android.c src/android/fg_structure_android.c - src/android/fg_window_android.c - ) -ELSEIF(BLACKBERRY) - LIST(APPEND FREEGLUT_SRCS - src/blackberry/fg_internal_blackberry.h - src/blackberry/fg_main_blackberry.h ) + IF(ANDROID) + LIST(APPEND FREEGLUT_SRCS + src/android/native_app_glue/android_native_app_glue.c + src/android/native_app_glue/android_native_app_glue.h + src/android/fg_internal_android.h + src/android/fg_main_android.c + src/android/fg_main_android.h + src/android/fg_runtime_android.c + src/android/fg_state_android.c + src/android/fg_window_android.c + ) + ELSE() + LIST(APPEND FREEGLUT_SRCS + # TODO: Anything similar to Android's app_glue? + src/blackberry/fg_internal_blackberry.h + # TODO: src/blackberry/fg_main_blackberry.c + src/blackberry/fg_main_blackberry.h + # TODO: Anything similar to fg_spaceball_android.c needed? + src/blackberry/fg_state_blackberry.c + # TODO: src/blackberry/fg_window_blackberry.c + ) + ENDIF() ELSE() LIST(APPEND FREEGLUT_SRCS src/x11/fg_cursor_x11.c @@ -257,7 +266,10 @@ IF(ANDROID) # -llog for native Android logging LIST(APPEND LIBS android log) ELSEIF(BLACKBERRY) - LIST(APPEND LIBS bps slog2) + # -lbps for event loop + # -lslog2 for logging + # -screen for native screen + LIST(APPEND LIBS bps slog2 screen) ENDIF() INCLUDE(CheckFunctionExists) @@ -472,7 +484,7 @@ ELSEIF(FREEGLUT_GLES2) IF(ANDROID) SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm") ELSEIF(BLACKBERRY) - SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lGLESv2 -lEGL -lm") + SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lEGL -lm") ELSE() SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lEGL -lm") ENDIF() @@ -480,7 +492,7 @@ ELSEIF(FREEGLUT_GLES1) IF(ANDROID) SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv1_CM -lEGL -lm") ELSEIF(BLACKBERRY) - SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lGLESv1_CM -lEGL -lm") + SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv1_CM -lEGL -lm") ELSE() SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv1_CM -lEGL -lm") ENDIF() diff --git a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c new file mode 100644 index 0000000..600a826 --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c @@ -0,0 +1,99 @@ +/* + * fg_state_blackberry.c + * + * BlackBerry-specific freeglut state query methods. + * + * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved. + * Written by John F. Fay, + * Copyright (C) 2012 Sylvain Beucler + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include "fg_internal.h" +#include "egl/fg_state_egl.h" + +//From fg_state_android.c +int fgPlatformGlutDeviceGet ( GLenum eWhat ) +{ + switch( eWhat ) + { + case GLUT_HAS_KEYBOARD: + /* BlackBerry has a keyboard, though it may be virtual. */ + return 1; + + case GLUT_HAS_MOUSE: + /* BlackBerry has a touchscreen; until we get proper touchscreen + support, consider it as a mouse. */ + return 1 ; + + case GLUT_NUM_MOUSE_BUTTONS: + /* BlackBerry has a touchscreen; until we get proper touchscreen + support, consider it as a 1-button mouse. */ + return 1; + + default: + fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat ); + break; + } + + /* And now -- the failure. */ + return -1; +} + +int fgPlatformGlutGet ( GLenum eWhat ) +{ + switch (eWhat) { + /* One full-screen window only */ + case GLUT_WINDOW_X: + case GLUT_WINDOW_Y: + case GLUT_WINDOW_BORDER_WIDTH: + case GLUT_WINDOW_HEADER_HEIGHT: + return 0; + + case GLUT_WINDOW_WIDTH: + case GLUT_WINDOW_HEIGHT: + { + if ( fgStructure.CurrentWindow == NULL ) + return 0; + int size[2]; + if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_SIZE, size) != 0 ) + return 0; + switch ( eWhat ) + { + case GLUT_WINDOW_WIDTH: + return size[0]; + case GLUT_WINDOW_HEIGHT: + return size[1]; + } + } + + case GLUT_WINDOW_COLORMAP_SIZE: + /* 0 for RGBA/non-indexed mode */ + /* Under BlackBerry and GLES more generally, no indexed-mode */ + return 0; + + default: + return fghPlatformGlutGetEGL(eWhat); + } + return -1; +} From c89d3ed7811d5b5320d8fb28701b993eff08892e Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 3 Sep 2013 00:27:13 -0400 Subject: [PATCH 03/34] Implemented fg_window_blackberry.c to initialize and cleanup windows Implemented a BlackBerry specific fg_init so that bps can be started and stopped. --- freeglut/freeglut/CMakeLists.txt | 5 +- .../src/blackberry/fg_init_blackberry.c | 60 +++++ .../src/blackberry/fg_internal_blackberry.h | 2 + .../src/blackberry/fg_state_blackberry.c | 2 +- .../src/blackberry/fg_window_blackberry.c | 212 ++++++++++++++++++ 5 files changed, 278 insertions(+), 3 deletions(-) create mode 100644 freeglut/freeglut/src/blackberry/fg_init_blackberry.c create mode 100644 freeglut/freeglut/src/blackberry/fg_window_blackberry.c diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index a8cb8b3..4baf592 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -123,7 +123,6 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/fg_cursor_android.c src/android/fg_ext_android.c src/android/fg_gamemode_android.c - src/android/fg_init_android.c src/android/fg_input_devices_android.c src/android/fg_joystick_android.c src/android/fg_spaceball_android.c @@ -133,6 +132,7 @@ ELSEIF(ANDROID OR BLACKBERRY) LIST(APPEND FREEGLUT_SRCS src/android/native_app_glue/android_native_app_glue.c src/android/native_app_glue/android_native_app_glue.h + src/android/fg_init_android.c src/android/fg_internal_android.h src/android/fg_main_android.c src/android/fg_main_android.h @@ -143,12 +143,13 @@ ELSEIF(ANDROID OR BLACKBERRY) ELSE() LIST(APPEND FREEGLUT_SRCS # TODO: Anything similar to Android's app_glue? + src/blackberry/fg_init_blackberry.c src/blackberry/fg_internal_blackberry.h # TODO: src/blackberry/fg_main_blackberry.c src/blackberry/fg_main_blackberry.h # TODO: Anything similar to fg_spaceball_android.c needed? src/blackberry/fg_state_blackberry.c - # TODO: src/blackberry/fg_window_blackberry.c + src/blackberry/fg_window_blackberry.c ) ENDIF() ELSE() diff --git a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c new file mode 100644 index 0000000..4dee11d --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c @@ -0,0 +1,60 @@ +/* + * fg_init_blackberry.c + * + * Various freeglut initialization functions. + * + * Copyright (C) 2012 Sylvain Beucler + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "fg_internal.h" +#include "fg_init.h" +#include "egl/fg_init_egl.h" +#include + +void fgPlatformInitialize() +{ + bps_initialize(); + + fghPlatformInitializeEGL(); + + /* Get start time */ + fgState.Time = fgSystemTime(); + + fgState.Initialised = GL_TRUE; +} + +void fgPlatformCloseDisplay() +{ + fghPlatformCloseDisplayEGL(); + + bps_shutdown(); +} + +/** + * Close joystick and serial input devices + */ +void fgPlatformDeinitialiseInputDevices ( void ) +{ + fghCloseInputDevices (); + fgState.JoysticksInitialised = GL_FALSE; + fgState.InputDevsInitialised = GL_FALSE; +} diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 0223144..40e9fda 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -32,6 +32,7 @@ /* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */ /* BlackBerry OpenGL ES is accessed through EGL */ #include "egl/fg_internal_egl.h" +#include /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */ /* The structure used by display initialization in freeglut_init.c */ @@ -47,6 +48,7 @@ typedef struct tagSFG_PlatformContext SFG_PlatformContext; struct tagSFG_PlatformContext { struct tagSFG_PlatformContextEGL egl; + screen_context_t screenContext; }; diff --git a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c index 600a826..a6955e2 100644 --- a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c @@ -76,7 +76,7 @@ int fgPlatformGlutGet ( GLenum eWhat ) if ( fgStructure.CurrentWindow == NULL ) return 0; int size[2]; - if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_SIZE, size) != 0 ) + if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0 ) return 0; switch ( eWhat ) { diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c new file mode 100644 index 0000000..1f13b55 --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -0,0 +1,212 @@ +/* + * fg_window_blackberry.c + * + * Window management methods for BlackBerry + * + * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. + * Written by Pawel W. Olszta, + * Copied for Platform code by Evan Felix + * Copyright (C) 2012 Sylvain Beucler + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#define FREEGLUT_BUILDING_LIB +#include +#include "fg_internal.h" +#include "egl/fg_window_egl.h" +#include +#include + +/* + * Opens a window. Requires a SFG_Window object created and attached + * to the freeglut structure. OpenGL context is created here. + */ +void fgPlatformOpenWindow( SFG_Window* window, const char* title, + GLboolean positionUse, int x, int y, + GLboolean sizeUse, int w, int h, + GLboolean gameMode, GLboolean isSubWindow ) +{ + /* TODO: only one full-screen window possible? */ + if (fgDisplay.pDisplay.single_native_window != NULL) { + fgWarning("You can't have more than one window on BlackBerry"); + return; + } + + /* Create window */ + if (screen_create_context(&window->Window.pContext.screenContext, 0)) { + fgError("Could not create screen context"); + return; + } + screen_window_t sWindow; + if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) { + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not create window"); + return; + } + fgDisplay.pDisplay.single_native_window = sWindow; + + /* Set window properties */ + int screenFormat = SCREEN_FORMAT_RGBA8888; +#ifdef __X86__ + int screenUsage = SCREEN_USAGE_OPENGL_ES2; +#else + int screenUsage = SCREEN_USAGE_DISPLAY | SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display +#endif + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not set window format"); + return; + } + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not set window usage"); + return; + } + + /* Could set size based on what is specified for window. Work on another time + int size[2]; + size[0] = w; + size[1] = h; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not set window buffer size"); + return; + }*/ + + /* Create window buffers */ + if (screen_create_window_buffers(sWindow, 2)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not create window buffers"); + return; + } + + /* Request window events */ + screen_request_events(window->Window.pContext.screenContext); + + /* Save window */ + window->Window.Handle = fgDisplay.pDisplay.single_native_window; + window->State.WorkMask |= GLUT_INIT_WORK; + + /* Create context */ + fghChooseConfig(&window->Window.pContext.egl.Config); + window->Window.Context = fghCreateNewContextEGL(window); + + /* Create EGL window */ + fghPlatformOpenWindowEGL(window); + + window->State.Visible = GL_TRUE; +} + +/* + * Request a window resize + */ +void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height ) +{ + fprintf(stderr, "fgPlatformReshapeWindow: STUB\n"); +} + +/* + * Closes a window, destroying the frame and OpenGL context + */ +void fgPlatformCloseWindow( SFG_Window* window ) +{ + fghPlatformCloseWindowEGL(window); + + screen_stop_events(window->Window.pContext.screenContext); + + screen_destroy_window((screen_window_t)window->Window.Handle); + + screen_destroy_context(window->Window.pContext.screenContext); +} + +/* + * This function makes the specified window visible + */ +void fgPlatformShowWindow( void ) +{ + fprintf(stderr, "fgPlatformShowWindow: STUB\n"); +} + +/* + * This function hides the specified window + */ +void fgPlatformHideWindow( SFG_Window *window ) +{ + fprintf(stderr, "fgPlatformHideWindow: STUB\n"); +} + +/* + * Iconify the specified window (top-level windows only) + */ +void fgPlatformIconifyWindow( SFG_Window *window ) +{ + fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n"); +} + +/* + * Set the current window's title + */ +void fgPlatformGlutSetWindowTitle( const char* title ) +{ + fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n"); +} + +/* + * Set the current window's iconified title + */ +void fgPlatformGlutSetIconTitle( const char* title ) +{ + fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");} + +/* + * Change the specified window's position + */ +void fgPlatformPositionWindow( SFG_Window *window, int x, int y ) +{ + fprintf(stderr, "fgPlatformPositionWindow: STUB\n"); +} + +/* + * Lowers the specified window (by Z order change) + */ +void fgPlatformPushWindow( SFG_Window *window ) +{ + fprintf(stderr, "fgPlatformPushWindow: STUB\n"); +} + +/* + * Raises the specified window (by Z order change) + */ +void fgPlatformPopWindow( SFG_Window *window ) +{ + fprintf(stderr, "fgPlatformPopWindow: STUB\n"); +} + +/* + * Toggle the window's full screen state. + */ +void fgPlatformFullScreenToggle( SFG_Window *win ) +{ + fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n"); +} From d0da7b524c8f5044adf6ab3e68918e1fe3fde292 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 3 Sep 2013 01:26:02 -0400 Subject: [PATCH 04/34] Final commit before implementing main loop. All other code is implemented to the same level as Android. --- freeglut/freeglut/CMakeLists.txt | 4 +- .../src/blackberry/fg_main_blackberry.c | 518 ++++++++++++++++++ .../src/blackberry/fg_main_blackberry.h | 6 +- 3 files changed, 522 insertions(+), 6 deletions(-) create mode 100644 freeglut/freeglut/src/blackberry/fg_main_blackberry.c diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 4baf592..428b6da 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -142,12 +142,10 @@ ELSEIF(ANDROID OR BLACKBERRY) ) ELSE() LIST(APPEND FREEGLUT_SRCS - # TODO: Anything similar to Android's app_glue? src/blackberry/fg_init_blackberry.c src/blackberry/fg_internal_blackberry.h - # TODO: src/blackberry/fg_main_blackberry.c + src/blackberry/fg_main_blackberry.c src/blackberry/fg_main_blackberry.h - # TODO: Anything similar to fg_spaceball_android.c needed? src/blackberry/fg_state_blackberry.c src/blackberry/fg_window_blackberry.c ) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c new file mode 100644 index 0000000..c61cddb --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -0,0 +1,518 @@ +/* + * fg_main_blackberry.c + * + * The BlackBerry-specific windows message processing methods. + * + * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. + * Written by Pawel W. Olszta, + * Copied for Platform code by Evan Felix + * Copyright (C) 2012 Sylvain Beucler + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "fg_internal.h" +#include "egl/fg_window_egl.h" + +#include +#define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__)) +#define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__)) +#include + +extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify); +extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify); +extern void fgPlatformFullScreenToggle( SFG_Window *win ); +extern void fgPlatformPositionWindow( SFG_Window *window, int x, int y ); +extern void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height ); +extern void fgPlatformPushWindow( SFG_Window *window ); +extern void fgPlatformPopWindow( SFG_Window *window ); +extern void fgPlatformHideWindow( SFG_Window *window ); +extern void fgPlatformIconifyWindow( SFG_Window *window ); +extern void fgPlatformShowWindow( SFG_Window *window ); + +static struct touchscreen touchscreen; +static unsigned char key_a2fg[256]; + +/** + * Initialize BlackBerry keycode to GLUT keycode mapping + */ +static void key_init() { + memset(key_a2fg, 0, sizeof(key_a2fg)); + + //XXX Any others? + + key_a2fg[KEYCODE_F1] = GLUT_KEY_F1; + key_a2fg[KEYCODE_F2] = GLUT_KEY_F2; + key_a2fg[KEYCODE_F3] = GLUT_KEY_F3; + key_a2fg[KEYCODE_F4] = GLUT_KEY_F4; + key_a2fg[KEYCODE_F5] = GLUT_KEY_F5; + key_a2fg[KEYCODE_F6] = GLUT_KEY_F6; + key_a2fg[KEYCODE_F7] = GLUT_KEY_F7; + key_a2fg[KEYCODE_F8] = GLUT_KEY_F8; + key_a2fg[KEYCODE_F9] = GLUT_KEY_F9; + key_a2fg[KEYCODE_F10] = GLUT_KEY_F10; + key_a2fg[KEYCODE_F11] = GLUT_KEY_F11; + key_a2fg[KEYCODE_F12] = GLUT_KEY_F12; + + key_a2fg[KEYCODE_PG_UP] = GLUT_KEY_PAGE_UP; + key_a2fg[KEYCODE_PG_DOWN] = GLUT_KEY_PAGE_DOWN; + key_a2fg[KEYCODE_HOME] = GLUT_KEY_HOME; + key_a2fg[KEYCODE_END] = GLUT_KEY_END; + key_a2fg[KEYCODE_INSERT] = GLUT_KEY_INSERT; + + key_a2fg[KEYCODE_UP] = GLUT_KEY_UP; + key_a2fg[KEYCODE_DOWN] = GLUT_KEY_DOWN; + key_a2fg[KEYCODE_LEFT] = GLUT_KEY_LEFT; + key_a2fg[KEYCODE_RIGHT] = GLUT_KEY_RIGHT; + + key_a2fg[KEYCODE_LEFT_ALT] = GLUT_KEY_ALT_L; + key_a2fg[KEYCODE_RIGHT_ALT] = GLUT_KEY_ALT_R; + key_a2fg[KEYCODE_LEFT_SHIFT] = GLUT_KEY_SHIFT_L; + key_a2fg[KEYCODE_RIGHT_SHIFT] = GLUT_KEY_SHIFT_R; + key_a2fg[KEYCODE_LEFT_CTRL] = GLUT_KEY_CTRL_L; + key_a2fg[KEYCODE_RIGHT_CTRL] = GLUT_KEY_CTRL_R; +} + +//XXX +/* * + * Convert an Android key event to ASCII. + * / +static unsigned char key_ascii(struct android_app* app, AInputEvent* event) { + int32_t code = AKeyEvent_getKeyCode(event); + + /* Handle a few special cases: * / + switch (code) { + case AKEYCODE_DEL: + return 8; + case AKEYCODE_FORWARD_DEL: + return 127; + case AKEYCODE_ESCAPE: + return 27; + } + + /* Get usable JNI context * / + JNIEnv* env = app->activity->env; + JavaVM* vm = app->activity->vm; + (*vm)->AttachCurrentThread(vm, &env, NULL); + + jclass KeyEventClass = (*env)->FindClass(env, "android/view/KeyEvent"); + jmethodID KeyEventConstructor = (*env)->GetMethodID(env, KeyEventClass, "", "(II)V"); + jobject keyEvent = (*env)->NewObject(env, KeyEventClass, KeyEventConstructor, + AKeyEvent_getAction(event), AKeyEvent_getKeyCode(event)); + jmethodID KeyEvent_getUnicodeChar = (*env)->GetMethodID(env, KeyEventClass, "getUnicodeChar", "(I)I"); + int ascii = (*env)->CallIntMethod(env, keyEvent, KeyEvent_getUnicodeChar, AKeyEvent_getMetaState(event)); + + /* LOGI("getUnicodeChar(%d) = %d ('%c')", AKeyEvent_getKeyCode(event), ascii, ascii); * / + (*vm)->DetachCurrentThread(vm); + + return ascii; +} +*/ + +uint64_t fgPlatformSystemTime ( void ) +{ + struct timeval now; + gettimeofday( &now, NULL ); + return now.tv_usec / 1000 + now.tv_sec * 1000; +} + +/* + * Does the magic required to relinquish the CPU until something interesting + * happens. + */ +void fgPlatformSleepForEvents( long msec ) +{ + //TODO +} + +/* * + * Process the next input event. + * / +int32_t handle_input(struct android_app* app, AInputEvent* event) { + SFG_Window* window = fgWindowByHandle(app->window); + if (window == NULL) + return EVENT_NOT_HANDLED; + + /* FIXME: in Android, when a key is repeated, down + and up events happen most often at the exact same time. This + makes it impossible to animate based on key press time. * / + /* e.g. down/up/wait/down/up rather than down/wait/down/wait/up * / + /* This looks like a bug in the Android virtual keyboard system :/ + Real buttons such as the Back button appear to work correctly + (series of down events with proper getRepeatCount value). * / + + if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { + /* LOGI("action: %d", AKeyEvent_getAction(event)); */ + /* LOGI("keycode: %d", code); * / + int32_t code = AKeyEvent_getKeyCode(event); + + if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN) { + int32_t keypress = 0; + unsigned char ascii = 0; + if ((keypress = key_a2fg[code]) && FETCH_WCB(*window, Special)) { + INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); + return EVENT_HANDLED; + } else if ((ascii = key_ascii(app, event)) && FETCH_WCB(*window, Keyboard)) { + INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); + return EVENT_HANDLED; + } + } + else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_UP) { + int32_t keypress = 0; + unsigned char ascii = 0; + if ((keypress = key_a2fg[code]) && FETCH_WCB(*window, Special)) { + INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); + return EVENT_HANDLED; + } else if ((ascii = key_ascii(app, event)) && FETCH_WCB(*window, Keyboard)) { + INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); + return EVENT_HANDLED; + } + } + } + + int32_t source = AInputEvent_getSource(event); + if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION + && source == AINPUT_SOURCE_TOUCHSCREEN) { + int32_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; + /* Pointer ID for clicks * / + int32_t pidx = AMotionEvent_getAction(event) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + /* TODO: Handle multi-touch; also handle multiple sources/devices */ + /* cf. http://sourceforge.net/mailarchive/forum.php?thread_name=20120518071314.GA28061%40perso.beuc.net&forum_name=freeglut-developer * / + if (0) { + LOGI("motion action=%d index=%d source=%d", action, pidx, source); + int count = AMotionEvent_getPointerCount(event); + int i; + for (i = 0; i < count; i++) { + LOGI("multi(%d): %.01f,%.01f", + AMotionEvent_getPointerId(event, i), + AMotionEvent_getX(event, i), AMotionEvent_getY(event, i)); + } + } + float x = AMotionEvent_getX(event, 0); + float y = AMotionEvent_getY(event, 0); + + /* Virtual arrows PAD */ + /* Don't interfere with existing mouse move event * / + if (!touchscreen.in_mmotion) { + struct vpad_state prev_vpad = touchscreen.vpad; + touchscreen.vpad.left = touchscreen.vpad.right + = touchscreen.vpad.up = touchscreen.vpad.down = false; + + /* int32_t width = ANativeWindow_getWidth(window->Window.Handle); * / + int32_t height = ANativeWindow_getHeight(window->Window.Handle); + if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_MOVE) { + if ((x > 0 && x < 100) && (y > (height - 100) && y < height)) + touchscreen.vpad.left = true; + if ((x > 200 && x < 300) && (y > (height - 100) && y < height)) + touchscreen.vpad.right = true; + if ((x > 100 && x < 200) && (y > (height - 100) && y < height)) + touchscreen.vpad.down = true; + if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100))) + touchscreen.vpad.up = true; + } + if (action == AMOTION_EVENT_ACTION_DOWN && + (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) + touchscreen.vpad.on = true; + if (action == AMOTION_EVENT_ACTION_UP) + touchscreen.vpad.on = false; + if (prev_vpad.left != touchscreen.vpad.left + || prev_vpad.right != touchscreen.vpad.right + || prev_vpad.up != touchscreen.vpad.up + || prev_vpad.down != touchscreen.vpad.down + || prev_vpad.on != touchscreen.vpad.on) { + if (FETCH_WCB(*window, Special)) { + if (prev_vpad.left == false && touchscreen.vpad.left == true) + INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y)); + else if (prev_vpad.right == false && touchscreen.vpad.right == true) + INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y)); + else if (prev_vpad.up == false && touchscreen.vpad.up == true) + INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y)); + else if (prev_vpad.down == false && touchscreen.vpad.down == true) + INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y)); + } + if (FETCH_WCB(*window, SpecialUp)) { + if (prev_vpad.left == true && touchscreen.vpad.left == false) + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y)); + if (prev_vpad.right == true && touchscreen.vpad.right == false) + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y)); + if (prev_vpad.up == true && touchscreen.vpad.up == false) + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y)); + if (prev_vpad.down == true && touchscreen.vpad.down == false) + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y)); + } + return EVENT_HANDLED; + } + } + + /* Normal mouse events * / + if (!touchscreen.vpad.on) { + window->State.MouseX = x; + window->State.MouseY = y; + if (action == AMOTION_EVENT_ACTION_DOWN && FETCH_WCB(*window, Mouse)) { + touchscreen.in_mmotion = true; + INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, GLUT_DOWN, x, y)); + } else if (action == AMOTION_EVENT_ACTION_UP && FETCH_WCB(*window, Mouse)) { + touchscreen.in_mmotion = false; + INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, GLUT_UP, x, y)); + } else if (action == AMOTION_EVENT_ACTION_MOVE && FETCH_WCB(*window, Motion)) { + INVOKE_WCB(*window, Motion, (x, y)); + } + } + + return EVENT_HANDLED; + } + + /* Let Android handle other events (e.g. Back and Menu buttons) * / + return EVENT_NOT_HANDLED; +} +*/ + +/* * + * Process the next main command. + * / +void handle_cmd(struct android_app* app, int32_t cmd) { + SFG_Window* window = fgWindowByHandle(app->window); /* may be NULL * / + switch (cmd) { + /* App life cycle, in that order: * / + case APP_CMD_START: + LOGI("handle_cmd: APP_CMD_START"); + break; + case APP_CMD_RESUME: + LOGI("handle_cmd: APP_CMD_RESUME"); + /* Cf. fgPlatformProcessSingleEvent * / + break; + case APP_CMD_INIT_WINDOW: /* surfaceCreated * / + /* The window is being shown, get it ready. * / + LOGI("handle_cmd: APP_CMD_INIT_WINDOW %p", app->window); + fgDisplay.pDisplay.single_native_window = app->window; + /* start|resume: glPlatformOpenWindow was waiting for Handle to be + defined and will now continue processing * / + break; + case APP_CMD_GAINED_FOCUS: + LOGI("handle_cmd: APP_CMD_GAINED_FOCUS"); + break; + case APP_CMD_WINDOW_RESIZED: + LOGI("handle_cmd: APP_CMD_WINDOW_RESIZED"); + if (window->Window.pContext.egl.Surface != EGL_NO_SURFACE) + /* Make ProcessSingleEvent detect the new size, only available + after the next SwapBuffer * / + glutPostRedisplay(); + break; + + case APP_CMD_SAVE_STATE: /* onSaveInstanceState */ + /* The system has asked us to save our current state, when it + pauses the application without destroying it right after. * / + app->savedState = strdup("Detect me as non-NULL on next android_main"); + app->savedStateSize = strlen(app->savedState) + 1; + LOGI("handle_cmd: APP_CMD_SAVE_STATE"); + break; + case APP_CMD_PAUSE: + LOGI("handle_cmd: APP_CMD_PAUSE"); + /* Cf. fgPlatformProcessSingleEvent * / + break; + case APP_CMD_LOST_FOCUS: + LOGI("handle_cmd: APP_CMD_LOST_FOCUS"); + break; + case APP_CMD_TERM_WINDOW: /* surfaceDestroyed * / + /* The application is being hidden, but may be restored * / + LOGI("handle_cmd: APP_CMD_TERM_WINDOW"); + fghPlatformCloseWindowEGL(window); + fgDisplay.pDisplay.single_native_window = NULL; + break; + case APP_CMD_STOP: + LOGI("handle_cmd: APP_CMD_STOP"); + break; + case APP_CMD_DESTROY: /* Activity.onDestroy * / + LOGI("handle_cmd: APP_CMD_DESTROY"); + /* User closed the application for good, let's kill the window * / + { + /* Can't use fgWindowByHandle as app->window is NULL * / + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL) { + fgDestroyWindow(window); + } else { + LOGI("APP_CMD_DESTROY: No current window"); + } + } + /* glue has already set android_app->destroyRequested=1 * / + break; + + case APP_CMD_CONFIG_CHANGED: + /* Handle rotation / orientation change * / + LOGI("handle_cmd: APP_CMD_CONFIG_CHANGED"); + break; + case APP_CMD_LOW_MEMORY: + LOGI("handle_cmd: APP_CMD_LOW_MEMORY"); + break; + default: + LOGI("handle_cmd: unhandled cmd=%d", cmd); + } +} +*/ + +void fgPlatformOpenWindow( SFG_Window* window, const char* title, + GLboolean positionUse, int x, int y, + GLboolean sizeUse, int w, int h, + GLboolean gameMode, GLboolean isSubWindow ); + +void fgPlatformProcessSingleEvent ( void ) +{ + //TODO + //-------------------------------- + /* When the screen is resized, the window handle still points to the + old window until the next SwapBuffer, while it's crucial to set + the size (onShape) correctly before the next onDisplay callback. + Plus we don't know if the next SwapBuffer already occurred at the + time we process the event (e.g. during onDisplay). * / + /* So we do the check each time rather than on event. * / + /* Interestingly, on a Samsung Galaxy S/PowerVR SGX540 GPU/Android + 2.3, that next SwapBuffer is fake (but still necessary to get the + new size). * / + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL && window->Window.Handle != NULL) { + int32_t width = ANativeWindow_getWidth(window->Window.Handle); + int32_t height = ANativeWindow_getHeight(window->Window.Handle); + fghOnReshapeNotify(window,width,height,GL_FALSE); + } + + /* Read pending event. * / + int ident; + int events; + struct android_poll_source* source; + /* This is called "ProcessSingleEvent" but this means we'd only + process ~60 (screen Hz) mouse events per second, plus other ports + are processing all events already. So let's process all pending + events. */ + /* if ((ident=ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) { * / + while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { + /* Process this event. * / + if (source != NULL) { + source->process(source->app, source); + } + } + + /* If we're not in RESUME state, Android paused us, so wait * / + struct android_app* app = fgDisplay.pDisplay.app; + if (app->destroyRequested != 1 && app->activityState != APP_CMD_RESUME) { + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + + int FOREVER = -1; + while (app->destroyRequested != 1 && (app->activityState != APP_CMD_RESUME)) { + if ((ident=ALooper_pollOnce(FOREVER, NULL, &events, (void**)&source)) >= 0) { + /* Process this event. * / + if (source != NULL) { + source->process(source->app, source); + } + } + } + /* Coming back from a pause: * / + /* - Recreate window context and surface */ + /* - Call user-defined hook to restore resources (textures...) * / + /* - Exit pause loop * / + if (app->destroyRequested != 1) { + /* Android is full-screen only, simplified call.. * / + /* Ideally we'd have a fgPlatformReopenWindow() * / + /* If we're hidden by a non-fullscreen or translucent activity, + we'll be paused but not stopped, and keep the current + surface; in which case fgPlatformOpenWindow will no-op. * / + fgPlatformOpenWindow(window, "", GL_FALSE, 0, 0, GL_FALSE, 0, 0, GL_FALSE, GL_FALSE); + + /* TODO: should there be a whole GLUT_INIT_WORK forced? probably... + * Could queue that up in APP_CMD_TERM_WINDOW handler, but it'll + * be not possible to ensure InitContext CB gets called before + * Resume CB like that.. so maybe just force calling initContext CB + * here is best. Or we could force work on the window in question.. + * 1) save old work mask, 2) set mask to init only, 3) call fgProcessWork directly + * 4) set work mask back to the one saved in step 1. + / + if (!FETCH_WCB(*window, InitContext)) + fgWarning("Resuming application, but no callback to reload context resources (glutInitContextFunc)"); + } + + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + } + */ +} + +void fgPlatformMainLoopPreliminaryWork ( void ) +{ + LOGI("fgPlatformMainLoopPreliminaryWork\n", SLOG2_FA_END); + + key_init(); +} + + +/* deal with work list items */ +void fgPlatformInitWork(SFG_Window* window) +{ + /* notify windowStatus/visibility */ + INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) ); + + /* Position callback, always at 0,0 */ + fghOnPositionNotify(window, 0, 0, GL_TRUE); + + /* Size gets notified on window creation with size detection in mainloop above + * XXX CHECK: does this messages happen too early like on windows, + * so client code cannot have registered a callback yet and the message + * is thus never received by client? + */ +} + +void fgPlatformPosResZordWork(SFG_Window* window, unsigned int workMask) +{ + if (workMask & GLUT_FULL_SCREEN_WORK) + fgPlatformFullScreenToggle( window ); + if (workMask & GLUT_POSITION_WORK) + fgPlatformPositionWindow( window, window->State.DesiredXpos, window->State.DesiredYpos ); + if (workMask & GLUT_SIZE_WORK) + fgPlatformReshapeWindow ( window, window->State.DesiredWidth, window->State.DesiredHeight ); + if (workMask & GLUT_ZORDER_WORK) + { + if (window->State.DesiredZOrder < 0) + fgPlatformPushWindow( window ); + else + fgPlatformPopWindow( window ); + } +} + +void fgPlatformVisibilityWork(SFG_Window* window) +{ + /* Visibility status of window should get updated in the window message handlers + * For now, none of these functions called below do anything, so don't worry + * about it + */ + SFG_Window *win = window; + switch (window->State.DesiredVisibility) + { + case DesireHiddenState: + fgPlatformHideWindow( window ); + break; + case DesireIconicState: + /* Call on top-level window */ + while (win->Parent) + win = win->Parent; + fgPlatformIconifyWindow( win ); + break; + case DesireNormalState: + fgPlatformShowWindow( window ); + break; + } +} + diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h index 8febf36..d64a146 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h @@ -29,9 +29,9 @@ #include #include "fg_internal.h" -/*extern void fgPlatformProcessSingleEvent(void); -extern unsigned long fgPlatformSystemTime(void); +extern void fgPlatformProcessSingleEvent(void); +extern uint64_t fgPlatformSystemTime(void); extern void fgPlatformSleepForEvents(long msec); -extern void fgPlatformMainLoopPreliminaryWork(void);*/ +extern void fgPlatformMainLoopPreliminaryWork(void); #endif From f528ec0f25c6f6285167da6e4799aefba778cb99 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 4 Sep 2013 01:54:14 -0400 Subject: [PATCH 05/34] Implemented BlackBerry main (initial version) --- .../src/blackberry/fg_internal_blackberry.h | 2 + .../src/blackberry/fg_main_blackberry.c | 714 +++++++++--------- .../src/blackberry/fg_main_blackberry.h | 2 +- .../src/blackberry/fg_window_blackberry.c | 1 + 4 files changed, 344 insertions(+), 375 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 40e9fda..d6b0e3c 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -33,6 +33,7 @@ /* BlackBerry OpenGL ES is accessed through EGL */ #include "egl/fg_internal_egl.h" #include +#include /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */ /* The structure used by display initialization in freeglut_init.c */ @@ -49,6 +50,7 @@ struct tagSFG_PlatformContext { struct tagSFG_PlatformContextEGL egl; screen_context_t screenContext; + bps_event_t* event; }; diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index c61cddb..82a2705 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -35,6 +35,11 @@ #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__)) #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__)) #include +#include +#include +#include +#include +#include extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify); extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify); @@ -48,414 +53,375 @@ extern void fgPlatformIconifyWindow( SFG_Window *window ); extern void fgPlatformShowWindow( SFG_Window *window ); static struct touchscreen touchscreen; -static unsigned char key_a2fg[256]; -/** - * Initialize BlackBerry keycode to GLUT keycode mapping - */ -static void key_init() { - memset(key_a2fg, 0, sizeof(key_a2fg)); - - //XXX Any others? - - key_a2fg[KEYCODE_F1] = GLUT_KEY_F1; - key_a2fg[KEYCODE_F2] = GLUT_KEY_F2; - key_a2fg[KEYCODE_F3] = GLUT_KEY_F3; - key_a2fg[KEYCODE_F4] = GLUT_KEY_F4; - key_a2fg[KEYCODE_F5] = GLUT_KEY_F5; - key_a2fg[KEYCODE_F6] = GLUT_KEY_F6; - key_a2fg[KEYCODE_F7] = GLUT_KEY_F7; - key_a2fg[KEYCODE_F8] = GLUT_KEY_F8; - key_a2fg[KEYCODE_F9] = GLUT_KEY_F9; - key_a2fg[KEYCODE_F10] = GLUT_KEY_F10; - key_a2fg[KEYCODE_F11] = GLUT_KEY_F11; - key_a2fg[KEYCODE_F12] = GLUT_KEY_F12; - - key_a2fg[KEYCODE_PG_UP] = GLUT_KEY_PAGE_UP; - key_a2fg[KEYCODE_PG_DOWN] = GLUT_KEY_PAGE_DOWN; - key_a2fg[KEYCODE_HOME] = GLUT_KEY_HOME; - key_a2fg[KEYCODE_END] = GLUT_KEY_END; - key_a2fg[KEYCODE_INSERT] = GLUT_KEY_INSERT; - - key_a2fg[KEYCODE_UP] = GLUT_KEY_UP; - key_a2fg[KEYCODE_DOWN] = GLUT_KEY_DOWN; - key_a2fg[KEYCODE_LEFT] = GLUT_KEY_LEFT; - key_a2fg[KEYCODE_RIGHT] = GLUT_KEY_RIGHT; - - key_a2fg[KEYCODE_LEFT_ALT] = GLUT_KEY_ALT_L; - key_a2fg[KEYCODE_RIGHT_ALT] = GLUT_KEY_ALT_R; - key_a2fg[KEYCODE_LEFT_SHIFT] = GLUT_KEY_SHIFT_L; - key_a2fg[KEYCODE_RIGHT_SHIFT] = GLUT_KEY_SHIFT_R; - key_a2fg[KEYCODE_LEFT_CTRL] = GLUT_KEY_CTRL_L; - key_a2fg[KEYCODE_RIGHT_CTRL] = GLUT_KEY_CTRL_R; -} - -//XXX -/* * - * Convert an Android key event to ASCII. - * / -static unsigned char key_ascii(struct android_app* app, AInputEvent* event) { - int32_t code = AKeyEvent_getKeyCode(event); - - /* Handle a few special cases: * / - switch (code) { - case AKEYCODE_DEL: - return 8; - case AKEYCODE_FORWARD_DEL: - return 127; - case AKEYCODE_ESCAPE: - return 27; +unsigned int key_special(int qnxKeycode) +{ + switch(qnxKeycode) { + case KEYCODE_F1: + return GLUT_KEY_F1; + case KEYCODE_F2: + return GLUT_KEY_F2; + case KEYCODE_F3: + return GLUT_KEY_F3; + case KEYCODE_F4: + return GLUT_KEY_F4; + case KEYCODE_F5: + return GLUT_KEY_F5; + case KEYCODE_F6: + return GLUT_KEY_F6; + case KEYCODE_F7: + return GLUT_KEY_F7; + case KEYCODE_F8: + return GLUT_KEY_F8; + case KEYCODE_F9: + return GLUT_KEY_F9; + case KEYCODE_F10: + return GLUT_KEY_F10; + case KEYCODE_F11: + return GLUT_KEY_F11; + case KEYCODE_F12: + return GLUT_KEY_F12; + case KEYCODE_PG_UP: + return GLUT_KEY_PAGE_UP; + case KEYCODE_PG_DOWN: + return GLUT_KEY_PAGE_DOWN; + case KEYCODE_HOME: + return GLUT_KEY_HOME; + case KEYCODE_END: + return GLUT_KEY_END; + case KEYCODE_INSERT: + return GLUT_KEY_INSERT; + case KEYCODE_UP: + //case KEYCODE_KP_UP: + return GLUT_KEY_UP; + case KEYCODE_DOWN: + //case KEYCODE_KP_DOWN: + return GLUT_KEY_DOWN; + case KEYCODE_LEFT: + //case KEYCODE_KP_LEFT: + return GLUT_KEY_LEFT; + case KEYCODE_RIGHT: + //case KEYCODE_KP_RIGHT: + return GLUT_KEY_RIGHT; + case KEYCODE_NUM_LOCK: + return GLUT_KEY_NUM_LOCK; + case KEYCODE_LEFT_ALT: + return GLUT_KEY_ALT_L; + case KEYCODE_RIGHT_ALT: + return GLUT_KEY_ALT_R; + case KEYCODE_LEFT_SHIFT: + return GLUT_KEY_SHIFT_L; + case KEYCODE_RIGHT_SHIFT: + return GLUT_KEY_SHIFT_R; + case KEYCODE_LEFT_CTRL: + return GLUT_KEY_CTRL_L; + case KEYCODE_RIGHT_CTRL: + return GLUT_KEY_CTRL_R; } - - /* Get usable JNI context * / - JNIEnv* env = app->activity->env; - JavaVM* vm = app->activity->vm; - (*vm)->AttachCurrentThread(vm, &env, NULL); - - jclass KeyEventClass = (*env)->FindClass(env, "android/view/KeyEvent"); - jmethodID KeyEventConstructor = (*env)->GetMethodID(env, KeyEventClass, "", "(II)V"); - jobject keyEvent = (*env)->NewObject(env, KeyEventClass, KeyEventConstructor, - AKeyEvent_getAction(event), AKeyEvent_getKeyCode(event)); - jmethodID KeyEvent_getUnicodeChar = (*env)->GetMethodID(env, KeyEventClass, "getUnicodeChar", "(I)I"); - int ascii = (*env)->CallIntMethod(env, keyEvent, KeyEvent_getUnicodeChar, AKeyEvent_getMetaState(event)); - - /* LOGI("getUnicodeChar(%d) = %d ('%c')", AKeyEvent_getKeyCode(event), ascii, ascii); * / - (*vm)->DetachCurrentThread(vm); - - return ascii; + return 0; +} + +unsigned char key_ascii(int qnxKeycode) +{ + if (qnxKeycode >= KEYCODE_PC_KEYS && qnxKeycode <= UNICODE_PRIVATE_USE_AREA_LAST) { + switch (qnxKeycode) { + case KEYCODE_BACKSPACE: + return 0x0008; + case KEYCODE_TAB: + return 0x0009; + case KEYCODE_KP_ENTER: + case KEYCODE_RETURN: + return 0x000A; + case KEYCODE_ESCAPE: + return 0x001B; + } + } + return qnxKeycode; } -*/ uint64_t fgPlatformSystemTime ( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return now.tv_usec / 1000 + now.tv_sec * 1000; + struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); + return (1000 * now.tv_sec) + (now.tv_nsec / 1000000); } /* * Does the magic required to relinquish the CPU until something interesting * happens. */ -void fgPlatformSleepForEvents( long msec ) +void fgPlatformSleepForEvents( uint64_t msec ) { - //TODO + //XXX: Is this right? Is there a more direct way to access the context? + if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { + LOGW("BPS couldn't get event"); + } } -/* * - * Process the next input event. - * / -int32_t handle_input(struct android_app* app, AInputEvent* event) { - SFG_Window* window = fgWindowByHandle(app->window); - if (window == NULL) - return EVENT_NOT_HANDLED; +void handle_left_mouse(int x, int y, int height, int eventType, SFG_Window* window) +{ + bool handled = false; + /* Virtual arrows PAD */ + /* Don't interfere with existing mouse move event */ + if (!touchscreen.in_mmotion) { + struct vpad_state prev_vpad = touchscreen.vpad; + touchscreen.vpad.left = touchscreen.vpad.right = touchscreen.vpad.up = touchscreen.vpad.down = false; - /* FIXME: in Android, when a key is repeated, down - and up events happen most often at the exact same time. This - makes it impossible to animate based on key press time. * / - /* e.g. down/up/wait/down/up rather than down/wait/down/wait/up * / - /* This looks like a bug in the Android virtual keyboard system :/ - Real buttons such as the Back button appear to work correctly - (series of down events with proper getRepeatCount value). * / + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH || eventType == SCREEN_EVENT_MTOUCH_MOVE) { + if ((x > 0 && x < 100) && (y > (height - 100) && y < height)) + { + touchscreen.vpad.left = true; + } + if ((x > 200 && x < 300) && (y > (height - 100) && y < height)) + { + touchscreen.vpad.right = true; + } + if ((x > 100 && x < 200) && (y > (height - 100) && y < height)) + { + touchscreen.vpad.down = true; + } + if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100))) + { + touchscreen.vpad.up = true; + } + } - if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { - /* LOGI("action: %d", AKeyEvent_getAction(event)); */ - /* LOGI("keycode: %d", code); * / - int32_t code = AKeyEvent_getKeyCode(event); + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH && + (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) { + touchscreen.vpad.on = true; + } + if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { + touchscreen.vpad.on = false; + } - if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN) { - int32_t keypress = 0; - unsigned char ascii = 0; - if ((keypress = key_a2fg[code]) && FETCH_WCB(*window, Special)) { - INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); - return EVENT_HANDLED; - } else if ((ascii = key_ascii(app, event)) && FETCH_WCB(*window, Keyboard)) { - INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); - return EVENT_HANDLED; - } - } - else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_UP) { - int32_t keypress = 0; - unsigned char ascii = 0; - if ((keypress = key_a2fg[code]) && FETCH_WCB(*window, Special)) { - INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); - return EVENT_HANDLED; - } else if ((ascii = key_ascii(app, event)) && FETCH_WCB(*window, Keyboard)) { - INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); - return EVENT_HANDLED; - } - } - } - - int32_t source = AInputEvent_getSource(event); - if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION - && source == AINPUT_SOURCE_TOUCHSCREEN) { - int32_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; - /* Pointer ID for clicks * / - int32_t pidx = AMotionEvent_getAction(event) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; - /* TODO: Handle multi-touch; also handle multiple sources/devices */ - /* cf. http://sourceforge.net/mailarchive/forum.php?thread_name=20120518071314.GA28061%40perso.beuc.net&forum_name=freeglut-developer * / - if (0) { - LOGI("motion action=%d index=%d source=%d", action, pidx, source); - int count = AMotionEvent_getPointerCount(event); - int i; - for (i = 0; i < count; i++) { - LOGI("multi(%d): %.01f,%.01f", - AMotionEvent_getPointerId(event, i), - AMotionEvent_getX(event, i), AMotionEvent_getY(event, i)); - } - } - float x = AMotionEvent_getX(event, 0); - float y = AMotionEvent_getY(event, 0); - - /* Virtual arrows PAD */ - /* Don't interfere with existing mouse move event * / - if (!touchscreen.in_mmotion) { - struct vpad_state prev_vpad = touchscreen.vpad; - touchscreen.vpad.left = touchscreen.vpad.right - = touchscreen.vpad.up = touchscreen.vpad.down = false; - - /* int32_t width = ANativeWindow_getWidth(window->Window.Handle); * / - int32_t height = ANativeWindow_getHeight(window->Window.Handle); - if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_MOVE) { - if ((x > 0 && x < 100) && (y > (height - 100) && y < height)) - touchscreen.vpad.left = true; - if ((x > 200 && x < 300) && (y > (height - 100) && y < height)) - touchscreen.vpad.right = true; - if ((x > 100 && x < 200) && (y > (height - 100) && y < height)) - touchscreen.vpad.down = true; - if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100))) - touchscreen.vpad.up = true; - } - if (action == AMOTION_EVENT_ACTION_DOWN && - (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) - touchscreen.vpad.on = true; - if (action == AMOTION_EVENT_ACTION_UP) - touchscreen.vpad.on = false; - if (prev_vpad.left != touchscreen.vpad.left - || prev_vpad.right != touchscreen.vpad.right - || prev_vpad.up != touchscreen.vpad.up - || prev_vpad.down != touchscreen.vpad.down - || prev_vpad.on != touchscreen.vpad.on) { - if (FETCH_WCB(*window, Special)) { - if (prev_vpad.left == false && touchscreen.vpad.left == true) - INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y)); - else if (prev_vpad.right == false && touchscreen.vpad.right == true) - INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y)); - else if (prev_vpad.up == false && touchscreen.vpad.up == true) - INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y)); - else if (prev_vpad.down == false && touchscreen.vpad.down == true) - INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y)); + if (prev_vpad.left != touchscreen.vpad.left + || prev_vpad.right != touchscreen.vpad.right + || prev_vpad.up != touchscreen.vpad.up + || prev_vpad.down != touchscreen.vpad.down + || prev_vpad.on != touchscreen.vpad.on) { + if (FETCH_WCB(*window, Special)) { + if (prev_vpad.left == false && touchscreen.vpad.left == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y)); + } + else if (prev_vpad.right == false && touchscreen.vpad.right == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y)); + } + else if (prev_vpad.up == false && touchscreen.vpad.up == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y)); + } + else if (prev_vpad.down == false && touchscreen.vpad.down == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y)); + } + } + if (FETCH_WCB(*window, SpecialUp)) { + if (prev_vpad.left == true && touchscreen.vpad.left == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y)); + } + if (prev_vpad.right == true && touchscreen.vpad.right == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y)); + } + if (prev_vpad.up == true && touchscreen.vpad.up == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y)); + } + if (prev_vpad.down == true && touchscreen.vpad.down == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y)); + } + } + handled = true; + } } - if (FETCH_WCB(*window, SpecialUp)) { - if (prev_vpad.left == true && touchscreen.vpad.left == false) - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y)); - if (prev_vpad.right == true && touchscreen.vpad.right == false) - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y)); - if (prev_vpad.up == true && touchscreen.vpad.up == false) - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y)); - if (prev_vpad.down == true && touchscreen.vpad.down == false) - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y)); + + /* Normal mouse events */ + if (!handled && !touchscreen.vpad.on) { + window->State.MouseX = x; + window->State.MouseY = y; + + if(eventType == SCREEN_EVENT_MTOUCH_MOVE) { + INVOKE_WCB(*window, Motion, (x, y)); + } else if(FETCH_WCB(*window, Mouse)) { + touchscreen.in_mmotion = eventType == SCREEN_EVENT_MTOUCH_TOUCH; + int glutTouchType = eventType == SCREEN_EVENT_MTOUCH_TOUCH ? GLUT_DOWN : GLUT_UP; + INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, glutTouchType, x, y)); + } } - return EVENT_HANDLED; - } - } - - /* Normal mouse events * / - if (!touchscreen.vpad.on) { - window->State.MouseX = x; - window->State.MouseY = y; - if (action == AMOTION_EVENT_ACTION_DOWN && FETCH_WCB(*window, Mouse)) { - touchscreen.in_mmotion = true; - INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, GLUT_DOWN, x, y)); - } else if (action == AMOTION_EVENT_ACTION_UP && FETCH_WCB(*window, Mouse)) { - touchscreen.in_mmotion = false; - INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, GLUT_UP, x, y)); - } else if (action == AMOTION_EVENT_ACTION_MOVE && FETCH_WCB(*window, Motion)) { - INVOKE_WCB(*window, Motion, (x, y)); - } - } - - return EVENT_HANDLED; - } - - /* Let Android handle other events (e.g. Back and Menu buttons) * / - return EVENT_NOT_HANDLED; } -*/ - -/* * - * Process the next main command. - * / -void handle_cmd(struct android_app* app, int32_t cmd) { - SFG_Window* window = fgWindowByHandle(app->window); /* may be NULL * / - switch (cmd) { - /* App life cycle, in that order: * / - case APP_CMD_START: - LOGI("handle_cmd: APP_CMD_START"); - break; - case APP_CMD_RESUME: - LOGI("handle_cmd: APP_CMD_RESUME"); - /* Cf. fgPlatformProcessSingleEvent * / - break; - case APP_CMD_INIT_WINDOW: /* surfaceCreated * / - /* The window is being shown, get it ready. * / - LOGI("handle_cmd: APP_CMD_INIT_WINDOW %p", app->window); - fgDisplay.pDisplay.single_native_window = app->window; - /* start|resume: glPlatformOpenWindow was waiting for Handle to be - defined and will now continue processing * / - break; - case APP_CMD_GAINED_FOCUS: - LOGI("handle_cmd: APP_CMD_GAINED_FOCUS"); - break; - case APP_CMD_WINDOW_RESIZED: - LOGI("handle_cmd: APP_CMD_WINDOW_RESIZED"); - if (window->Window.pContext.egl.Surface != EGL_NO_SURFACE) - /* Make ProcessSingleEvent detect the new size, only available - after the next SwapBuffer * / - glutPostRedisplay(); - break; - - case APP_CMD_SAVE_STATE: /* onSaveInstanceState */ - /* The system has asked us to save our current state, when it - pauses the application without destroying it right after. * / - app->savedState = strdup("Detect me as non-NULL on next android_main"); - app->savedStateSize = strlen(app->savedState) + 1; - LOGI("handle_cmd: APP_CMD_SAVE_STATE"); - break; - case APP_CMD_PAUSE: - LOGI("handle_cmd: APP_CMD_PAUSE"); - /* Cf. fgPlatformProcessSingleEvent * / - break; - case APP_CMD_LOST_FOCUS: - LOGI("handle_cmd: APP_CMD_LOST_FOCUS"); - break; - case APP_CMD_TERM_WINDOW: /* surfaceDestroyed * / - /* The application is being hidden, but may be restored * / - LOGI("handle_cmd: APP_CMD_TERM_WINDOW"); - fghPlatformCloseWindowEGL(window); - fgDisplay.pDisplay.single_native_window = NULL; - break; - case APP_CMD_STOP: - LOGI("handle_cmd: APP_CMD_STOP"); - break; - case APP_CMD_DESTROY: /* Activity.onDestroy * / - LOGI("handle_cmd: APP_CMD_DESTROY"); - /* User closed the application for good, let's kill the window * / - { - /* Can't use fgWindowByHandle as app->window is NULL * / - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL) { - fgDestroyWindow(window); - } else { - LOGI("APP_CMD_DESTROY: No current window"); - } - } - /* glue has already set android_app->destroyRequested=1 * / - break; - - case APP_CMD_CONFIG_CHANGED: - /* Handle rotation / orientation change * / - LOGI("handle_cmd: APP_CMD_CONFIG_CHANGED"); - break; - case APP_CMD_LOW_MEMORY: - LOGI("handle_cmd: APP_CMD_LOW_MEMORY"); - break; - default: - LOGI("handle_cmd: unhandled cmd=%d", cmd); - } -} -*/ - -void fgPlatformOpenWindow( SFG_Window* window, const char* title, - GLboolean positionUse, int x, int y, - GLboolean sizeUse, int w, int h, - GLboolean gameMode, GLboolean isSubWindow ); void fgPlatformProcessSingleEvent ( void ) { - //TODO - //-------------------------------- - /* When the screen is resized, the window handle still points to the - old window until the next SwapBuffer, while it's crucial to set - the size (onShape) correctly before the next onDisplay callback. - Plus we don't know if the next SwapBuffer already occurred at the - time we process the event (e.g. during onDisplay). * / - /* So we do the check each time rather than on event. * / - /* Interestingly, on a Samsung Galaxy S/PowerVR SGX540 GPU/Android - 2.3, that next SwapBuffer is fake (but still necessary to get the - new size). * / - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL && window->Window.Handle != NULL) { - int32_t width = ANativeWindow_getWidth(window->Window.Handle); - int32_t height = ANativeWindow_getHeight(window->Window.Handle); - fghOnReshapeNotify(window,width,height,GL_FALSE); - } + int domain; + bps_event_t** eventPtr = &fgStructure.CurrentWindow->Window.pContext.event; //XXX Is there a more direct way to access the context? + bps_event_t* event; + do + { + if(*eventPtr != NULL) { + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL && window->Window.Handle != NULL) { + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); + } - /* Read pending event. * / - int ident; - int events; - struct android_poll_source* source; - /* This is called "ProcessSingleEvent" but this means we'd only - process ~60 (screen Hz) mouse events per second, plus other ports - are processing all events already. So let's process all pending - events. */ - /* if ((ident=ALooper_pollOnce(0, NULL, &events, (void**)&source)) >= 0) { * / - while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { - /* Process this event. * / - if (source != NULL) { - source->process(source->app, source); - } - } + event = *eventPtr; + domain = bps_event_get_domain(event); + if (domain == screen_get_domain()) { + int eventType; + screen_event_t screenEvent = screen_event_get_event(event); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); + switch (eventType) { - /* If we're not in RESUME state, Android paused us, so wait * / - struct android_app* app = fgDisplay.pDisplay.app; - if (app->destroyRequested != 1 && app->activityState != APP_CMD_RESUME) { - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + //Mostly from fg_main_android + case SCREEN_EVENT_MTOUCH_TOUCH: + case SCREEN_EVENT_MTOUCH_RELEASE: + case SCREEN_EVENT_MTOUCH_MOVE: + { + mtouch_event_t touchEvent; + screen_get_mtouch_event(screenEvent, &touchEvent, 0); + if(touchEvent.contact_id == 0) { //XXX Only support one contact for now + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); + } + break; + } - int FOREVER = -1; - while (app->destroyRequested != 1 && (app->activityState != APP_CMD_RESUME)) { - if ((ident=ALooper_pollOnce(FOREVER, NULL, &events, (void**)&source)) >= 0) { - /* Process this event. * / - if (source != NULL) { - source->process(source->app, source); - } - } - } - /* Coming back from a pause: * / - /* - Recreate window context and surface */ - /* - Call user-defined hook to restore resources (textures...) * / - /* - Exit pause loop * / - if (app->destroyRequested != 1) { - /* Android is full-screen only, simplified call.. * / - /* Ideally we'd have a fgPlatformReopenWindow() * / - /* If we're hidden by a non-fullscreen or translucent activity, - we'll be paused but not stopped, and keep the current - surface; in which case fgPlatformOpenWindow will no-op. * / - fgPlatformOpenWindow(window, "", GL_FALSE, 0, 0, GL_FALSE, 0, 0, GL_FALSE, GL_FALSE); + case SCREEN_EVENT_POINTER: + { + //Based off/part taken from GamePlay3d PlatformBlackBerry + static int mouse_pressed = 0; + int buttons; + int position[2]; + // A move event will be fired unless a button state changed. + bool move = true; + bool left_move = false; + // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - /* TODO: should there be a whole GLUT_INIT_WORK forced? probably... - * Could queue that up in APP_CMD_TERM_WINDOW handler, but it'll - * be not possible to ensure InitContext CB gets called before - * Resume CB like that.. so maybe just force calling initContext CB - * here is best. Or we could force work on the window in question.. - * 1) save old work mask, 2) set mask to init only, 3) call fgProcessWork directly - * 4) set work mask back to the one saved in step 1. - / - if (!FETCH_WCB(*window, InitContext)) - fgWarning("Resuming application, but no callback to reload context resources (glutInitContextFunc)"); - } + // Handle left mouse. Interpret as touch if the left mouse event is not consumed. + if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { + if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + left_move = true; + } else { + move = false; + mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); + } + } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); + } - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); - } - */ + // Handle right mouse. + if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { + move = false; + mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); + } + } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); + } + + // Handle middle mouse. + if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { + move = false; + mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); + } + } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); + } + + // Fire a move event if none of the buttons changed. + if (left_move || move) { + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); + } + break; + } + + //Based off fg_main_android + case SCREEN_EVENT_KEYBOARD: + { + int flags; + int value; + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_END); + // Suppress key repeats if desired + if (!fgStructure.CurrentWindow->State.IgnoreKeyRepeat && (flags & KEY_REPEAT) == 0) { + unsigned int keypress = 0; + unsigned char ascii = 0; + if ((keypress = key_special(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); + } else { + INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); + } + } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); + } else { + INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); + } + } + } + break; + } + } + } else if (domain == navigator_get_domain()) { + switch (bps_event_get_code(event)) { + + case NAVIGATOR_WINDOW_STATE: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE", SLOG2_FA_END); + navigator_window_state_t state = navigator_event_get_window_state(event); + switch (state) + { + case NAVIGATOR_WINDOW_FULLSCREEN: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN", SLOG2_FA_END); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + break; + case NAVIGATOR_WINDOW_THUMBNAIL: + case NAVIGATOR_WINDOW_INVISIBLE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE", SLOG2_FA_END); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + break; + } + break; + } + + case NAVIGATOR_EXIT: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT", SLOG2_FA_END); + /* User closed the application for good, let's kill the window */ + { + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL) { + fgDestroyWindow(window); + } else { + LOGI("NAVIGATOR_EXIT: No current window", SLOG2_FA_END); + } + } + break; + } + } + } + } while(bps_get_event(eventPtr, 1) == BPS_SUCCESS && *eventPtr != NULL); + + /* Reset event to reduce chances of triggering something */ + *eventPtr = NULL; } void fgPlatformMainLoopPreliminaryWork ( void ) { LOGI("fgPlatformMainLoopPreliminaryWork\n", SLOG2_FA_END); - - key_init(); } diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h index d64a146..4ccbc3d 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h @@ -31,7 +31,7 @@ extern void fgPlatformProcessSingleEvent(void); extern uint64_t fgPlatformSystemTime(void); -extern void fgPlatformSleepForEvents(long msec); +extern void fgPlatformSleepForEvents(uint64_t msec); extern void fgPlatformMainLoopPreliminaryWork(void); #endif diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 1f13b55..79d82f7 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -48,6 +48,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, fgWarning("You can't have more than one window on BlackBerry"); return; } + window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment /* Create window */ if (screen_create_context(&window->Window.pContext.screenContext, 0)) { From b9e26407cbfa4eeeeb06cfa1422a3d7dce24d1d2 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 4 Sep 2013 17:48:46 -0400 Subject: [PATCH 06/34] Minor change so that OpenGL ES 1.x can be used for BlackBerry --- freeglut/freeglut/src/blackberry/fg_window_blackberry.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 79d82f7..08f6643 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -65,10 +65,13 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Set window properties */ int screenFormat = SCREEN_FORMAT_RGBA8888; -#ifdef __X86__ +#ifdef GL_ES_VERSION_2_0 int screenUsage = SCREEN_USAGE_OPENGL_ES2; -#else - int screenUsage = SCREEN_USAGE_DISPLAY | SCREEN_USAGE_OPENGL_ES2; // Physical device copy directly into physical display +#elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 + int screenUsage = SCREEN_USAGE_OPENGL_ES1; +#endif +#ifndef __X86__ + screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display #endif if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { screen_destroy_window(sWindow); From 5ec6164f24328bcdd5499ff9bb7b4c835798b4c9 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Thu, 5 Sep 2013 01:58:34 -0400 Subject: [PATCH 07/34] Can use input devices from x11 (serial input... unlikely to ever be used, but you never know) Fixed bug in fg_window_egl:fgPlatformSetWindow where a NULL window may be passed and cause a segfault Fixed bug where navigator events were never started Take into account DisplayMode when creating window buffers Proper fgPlatformSystemTime implementation (from fg_main_x11) Added support for mutlitouch (from fg_main_windows) --- freeglut/freeglut/CMakeLists.txt | 3 +- .../src/blackberry/fg_init_blackberry.c | 6 +++ .../src/blackberry/fg_main_blackberry.c | 38 ++++++++++++++++--- .../src/blackberry/fg_main_blackberry.h | 1 - .../src/blackberry/fg_window_blackberry.c | 2 +- freeglut/freeglut/src/egl/fg_window_egl.c | 14 ++++--- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 428b6da..f2dd875 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -123,7 +123,6 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/fg_cursor_android.c src/android/fg_ext_android.c src/android/fg_gamemode_android.c - src/android/fg_input_devices_android.c src/android/fg_joystick_android.c src/android/fg_spaceball_android.c src/android/fg_structure_android.c @@ -134,6 +133,7 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/native_app_glue/android_native_app_glue.h src/android/fg_init_android.c src/android/fg_internal_android.h + src/android/fg_input_devices_android.c src/android/fg_main_android.c src/android/fg_main_android.h src/android/fg_runtime_android.c @@ -144,6 +144,7 @@ ELSEIF(ANDROID OR BLACKBERRY) LIST(APPEND FREEGLUT_SRCS src/blackberry/fg_init_blackberry.c src/blackberry/fg_internal_blackberry.h + src/x11/fg_input_devices_x11.c src/blackberry/fg_main_blackberry.c src/blackberry/fg_main_blackberry.h src/blackberry/fg_state_blackberry.c diff --git a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c index 4dee11d..40b1ed6 100644 --- a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c @@ -29,11 +29,15 @@ #include "fg_init.h" #include "egl/fg_init_egl.h" #include +#include void fgPlatformInitialize() { bps_initialize(); + navigator_request_events(0); + //XXX rotation lock? navigator_rotation_lock(true); + fghPlatformInitializeEGL(); /* Get start time */ @@ -46,6 +50,8 @@ void fgPlatformCloseDisplay() { fghPlatformCloseDisplayEGL(); + navigator_stop_events(0); + bps_shutdown(); } diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 82a2705..52b36f8 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -139,11 +139,18 @@ unsigned char key_ascii(int qnxKeycode) return qnxKeycode; } -uint64_t fgPlatformSystemTime ( void ) +//From fg_main_x11 +fg_time_t fgPlatformSystemTime ( void ) { - struct timespec now; - clock_gettime(CLOCK_REALTIME, &now); - return (1000 * now.tv_sec) + (now.tv_nsec / 1000000); +#ifdef CLOCK_MONOTONIC + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return now.tv_nsec/1000000 + now.tv_sec*1000; +#elif defined(HAVE_GETTIMEOFDAY) + struct timeval now; + gettimeofday( &now, NULL ); + return now.tv_usec/1000 + now.tv_sec*1000; +#endif } /* @@ -276,11 +283,23 @@ void fgPlatformProcessSingleEvent ( void ) { mtouch_event_t touchEvent; screen_get_mtouch_event(screenEvent, &touchEvent, 0); - if(touchEvent.contact_id == 0) { //XXX Only support one contact for now + if(touchEvent.contact_id == 0) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); } + + //Now handle mutlitouch (adapted from fg_main_windows) + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) { + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_ENTERED ) ); + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) ); + } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) { + INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) ); + //XXX No motion is performed without contact, thus MultiPassive is never used + } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); + } break; } @@ -290,15 +309,19 @@ void fgPlatformProcessSingleEvent ( void ) static int mouse_pressed = 0; int buttons; int position[2]; + int wheel; // A move event will be fired unless a button state changed. bool move = true; bool left_move = false; // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + //XXX Should multitouch be handled? + // Handle left mouse. Interpret as touch if the left mouse event is not consumed. if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { @@ -344,6 +367,11 @@ void fgPlatformProcessSingleEvent ( void ) if (left_move || move) { handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); } + + if (wheel) { + fgState.MouseWheelTicks -= wheel; + //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive) + } break; } diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h index 4ccbc3d..769e23d 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h @@ -30,7 +30,6 @@ #include "fg_internal.h" extern void fgPlatformProcessSingleEvent(void); -extern uint64_t fgPlatformSystemTime(void); extern void fgPlatformSleepForEvents(uint64_t msec); extern void fgPlatformMainLoopPreliminaryWork(void); diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 08f6643..7d2eb49 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -98,7 +98,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, }*/ /* Create window buffers */ - if (screen_create_window_buffers(sWindow, 2)) { + if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { screen_destroy_window(sWindow); screen_destroy_context(window->Window.pContext.screenContext); fgError("Could not create window buffers"); diff --git a/freeglut/freeglut/src/egl/fg_window_egl.c b/freeglut/freeglut/src/egl/fg_window_egl.c index 48eb748..6c4a7de 100644 --- a/freeglut/freeglut/src/egl/fg_window_egl.c +++ b/freeglut/freeglut/src/egl/fg_window_egl.c @@ -46,7 +46,7 @@ int fghChooseConfig(EGLConfig* config) { EGL_SAMPLES, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0, EGL_NONE }; - + EGLint num_config; if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, attribs, config, 1, &num_config)) { @@ -94,11 +94,13 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { void fgPlatformSetWindow ( SFG_Window *window ) { - if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, - window->Window.pContext.egl.Surface, - window->Window.pContext.egl.Surface, - window->Window.Context) == EGL_FALSE) - fgError("eglMakeCurrent: err=%x\n", eglGetError()); + if ( window != fgStructure.CurrentWindow && window) { + if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, + window->Window.pContext.egl.Surface, + window->Window.pContext.egl.Surface, + window->Window.Context) == EGL_FALSE) + fgError("eglMakeCurrent: err=%x\n", eglGetError()); + } } /* From 07555eb425e370e06b6a38864444ea6c76b7f938 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Thu, 5 Sep 2013 22:44:44 -0400 Subject: [PATCH 08/34] Made sure that windows created on BlackBerry are registered as fullscreen, for now. Added more logging in fgPlatformProcessSingleEvent on BlackBerry. Better handling of key repeats on BlackBerry by taking into account global and window settings. --- .../src/blackberry/fg_main_blackberry.c | 21 ++++++++++++++++--- .../src/blackberry/fg_window_blackberry.c | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 52b36f8..4c666f1 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -283,6 +283,7 @@ void fgPlatformProcessSingleEvent ( void ) { mtouch_event_t touchEvent; screen_get_mtouch_event(screenEvent, &touchEvent, 0); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_END); if(touchEvent.contact_id == 0) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); @@ -320,6 +321,8 @@ void fgPlatformProcessSingleEvent ( void ) int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_END); + //XXX Should multitouch be handled? // Handle left mouse. Interpret as touch if the left mouse event is not consumed. @@ -384,7 +387,7 @@ void fgPlatformProcessSingleEvent ( void ) screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_END); // Suppress key repeats if desired - if (!fgStructure.CurrentWindow->State.IgnoreKeyRepeat && (flags & KEY_REPEAT) == 0) { + if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) { unsigned int keypress = 0; unsigned char ascii = 0; if ((keypress = key_special(value))) { @@ -403,9 +406,14 @@ void fgPlatformProcessSingleEvent ( void ) } break; } + + default: + LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_END); + break; } } else if (domain == navigator_get_domain()) { - switch (bps_event_get_code(event)) { + int eventType = bps_event_get_code(event); + switch (eventType) { case NAVIGATOR_WINDOW_STATE: { @@ -422,6 +430,9 @@ void fgPlatformProcessSingleEvent ( void ) LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE", SLOG2_FA_END); INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); break; + default: + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state), SLOG2_FA_END); + break; } break; } @@ -434,10 +445,14 @@ void fgPlatformProcessSingleEvent ( void ) if (window != NULL) { fgDestroyWindow(window); } else { - LOGI("NAVIGATOR_EXIT: No current window", SLOG2_FA_END); + LOGW("NAVIGATOR_EXIT: No current window", SLOG2_FA_END); } } break; + + default: + LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_END); + break; } } } diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 7d2eb49..ff0c08f 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -108,9 +108,10 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Request window events */ screen_request_events(window->Window.pContext.screenContext); - /* Save window */ + /* Save window and set state */ window->Window.Handle = fgDisplay.pDisplay.single_native_window; window->State.WorkMask |= GLUT_INIT_WORK; + window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now /* Create context */ fghChooseConfig(&window->Window.pContext.egl.Config); From ea948775f9727e115a35d2c6fd530aa05162c2c3 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Thu, 5 Sep 2013 22:54:27 -0400 Subject: [PATCH 09/34] Removed fg_main_blackberry.h. It wasn't needed --- freeglut/freeglut/CMakeLists.txt | 1 - .../src/blackberry/fg_main_blackberry.c | 2 +- .../src/blackberry/fg_main_blackberry.h | 36 ------------------- 3 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 freeglut/freeglut/src/blackberry/fg_main_blackberry.h diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index f2dd875..527370a 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -146,7 +146,6 @@ ELSEIF(ANDROID OR BLACKBERRY) src/blackberry/fg_internal_blackberry.h src/x11/fg_input_devices_x11.c src/blackberry/fg_main_blackberry.c - src/blackberry/fg_main_blackberry.h src/blackberry/fg_state_blackberry.c src/blackberry/fg_window_blackberry.c ) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 4c666f1..65b5954 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -157,7 +157,7 @@ fg_time_t fgPlatformSystemTime ( void ) * Does the magic required to relinquish the CPU until something interesting * happens. */ -void fgPlatformSleepForEvents( uint64_t msec ) +void fgPlatformSleepForEvents( fg_time_t msec ) { //XXX: Is this right? Is there a more direct way to access the context? if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h b/freeglut/freeglut/src/blackberry/fg_main_blackberry.h deleted file mode 100644 index 769e23d..0000000 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * fg_main_blackberry.h - * - * The BlackBerry-specific windows message processing methods. - * - * Copyright (C) 2013 Vincent Simonetti - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef __FG_MAIN_BLACKBERRY_H__ -#define __FG_MAIN_BLACKBERRY_H__ - -#include -#include "fg_internal.h" - -extern void fgPlatformProcessSingleEvent(void); -extern void fgPlatformSleepForEvents(uint64_t msec); -extern void fgPlatformMainLoopPreliminaryWork(void); - -#endif From d584d991233e912dc9e0ce2d1152e3a78b2e1c38 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Fri, 6 Sep 2013 19:59:59 -0400 Subject: [PATCH 10/34] Added a couple event cases for BlackBerry that are common to prevent them being listed as unknown events. --- .../src/blackberry/fg_main_blackberry.c | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 65b5954..db3f5c6 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -32,8 +32,8 @@ #include "egl/fg_window_egl.h" #include -#define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__)) -#define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__)) +#define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) +#define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END)) #include #include #include @@ -283,7 +283,7 @@ void fgPlatformProcessSingleEvent ( void ) { mtouch_event_t touchEvent; screen_get_mtouch_event(screenEvent, &touchEvent, 0); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id)); if(touchEvent.contact_id == 0) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); @@ -321,7 +321,7 @@ void fgPlatformProcessSingleEvent ( void ) int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel)); //XXX Should multitouch be handled? @@ -385,7 +385,7 @@ void fgPlatformProcessSingleEvent ( void ) int value; screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value)); // Suppress key repeats if desired if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) { unsigned int keypress = 0; @@ -407,8 +407,12 @@ void fgPlatformProcessSingleEvent ( void ) break; } + case SCREEN_EVENT_PROPERTY: + case SCREEN_EVENT_IDLE: + break; + default: - LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_END); + LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); break; } } else if (domain == navigator_get_domain()) { @@ -417,41 +421,51 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_WINDOW_STATE: { - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE", SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); navigator_window_state_t state = navigator_event_get_window_state(event); switch (state) { case NAVIGATOR_WINDOW_FULLSCREEN: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN", SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); break; case NAVIGATOR_WINDOW_THUMBNAIL: case NAVIGATOR_WINDOW_INVISIBLE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE", SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE"); INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); break; default: - LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state), SLOG2_FA_END); + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); break; } break; } case NAVIGATOR_EXIT: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT", SLOG2_FA_END); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); /* User closed the application for good, let's kill the window */ { SFG_Window* window = fgStructure.CurrentWindow; if (window != NULL) { fgDestroyWindow(window); } else { - LOGW("NAVIGATOR_EXIT: No current window", SLOG2_FA_END); + LOGW("NAVIGATOR_EXIT: No current window"); } } break; + case NAVIGATOR_SWIPE_DOWN: + case NAVIGATOR_BACK: + case NAVIGATOR_WINDOW_ACTIVE: + case NAVIGATOR_DEVICE_LOCK_STATE: + case NAVIGATOR_WINDOW_COVER: + case NAVIGATOR_WINDOW_COVER_ENTER: + case NAVIGATOR_WINDOW_COVER_EXIT: + //XXX Should probably do something with these + break; + default: - LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_END); + LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); break; } } @@ -464,7 +478,7 @@ void fgPlatformProcessSingleEvent ( void ) void fgPlatformMainLoopPreliminaryWork ( void ) { - LOGI("fgPlatformMainLoopPreliminaryWork\n", SLOG2_FA_END); + LOGI("fgPlatformMainLoopPreliminaryWork"); } From 62fa02baf85310c7a80aaf61bb052da1cfffb058 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Fri, 6 Sep 2013 20:09:15 -0400 Subject: [PATCH 11/34] Minor order change in Android/BlackBerry CMake, one comment for BlackBerry window --- freeglut/freeglut/CMakeLists.txt | 4 ++-- freeglut/freeglut/src/blackberry/fg_window_blackberry.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 527370a..16661e6 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -131,8 +131,8 @@ ELSEIF(ANDROID OR BLACKBERRY) LIST(APPEND FREEGLUT_SRCS src/android/native_app_glue/android_native_app_glue.c src/android/native_app_glue/android_native_app_glue.h - src/android/fg_init_android.c src/android/fg_internal_android.h + src/android/fg_init_android.c src/android/fg_input_devices_android.c src/android/fg_main_android.c src/android/fg_main_android.h @@ -142,8 +142,8 @@ ELSEIF(ANDROID OR BLACKBERRY) ) ELSE() LIST(APPEND FREEGLUT_SRCS - src/blackberry/fg_init_blackberry.c src/blackberry/fg_internal_blackberry.h + src/blackberry/fg_init_blackberry.c src/x11/fg_input_devices_x11.c src/blackberry/fg_main_blackberry.c src/blackberry/fg_state_blackberry.c diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index ff0c08f..8c1a121 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -64,7 +64,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, fgDisplay.pDisplay.single_native_window = sWindow; /* Set window properties */ - int screenFormat = SCREEN_FORMAT_RGBA8888; + int screenFormat = SCREEN_FORMAT_RGBA8888; //XXX Should this be determined by config? #ifdef GL_ES_VERSION_2_0 int screenUsage = SCREEN_USAGE_OPENGL_ES2; #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 From 39eb9e3342ba8b0819f111f32e09a6d967fd0ce9 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Sat, 7 Sep 2013 02:08:47 -0400 Subject: [PATCH 12/34] Converted the odd double spaces into 4 space tabs --- .../src/blackberry/fg_init_blackberry.c | 20 +- .../src/blackberry/fg_internal_blackberry.h | 40 +- .../src/blackberry/fg_main_blackberry.c | 722 +++++++++--------- .../src/blackberry/fg_state_blackberry.c | 59 +- .../src/blackberry/fg_window_blackberry.c | 158 ++-- 5 files changed, 501 insertions(+), 498 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c index 40b1ed6..5a1a9d9 100644 --- a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c @@ -33,26 +33,26 @@ void fgPlatformInitialize() { - bps_initialize(); + bps_initialize(); - navigator_request_events(0); - //XXX rotation lock? navigator_rotation_lock(true); + navigator_request_events(0); + //XXX rotation lock? navigator_rotation_lock(true); - fghPlatformInitializeEGL(); + fghPlatformInitializeEGL(); - /* Get start time */ - fgState.Time = fgSystemTime(); + /* Get start time */ + fgState.Time = fgSystemTime(); - fgState.Initialised = GL_TRUE; + fgState.Initialised = GL_TRUE; } void fgPlatformCloseDisplay() { - fghPlatformCloseDisplayEGL(); + fghPlatformCloseDisplayEGL(); - navigator_stop_events(0); + navigator_stop_events(0); - bps_shutdown(); + bps_shutdown(); } /** diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index d6b0e3c..229ce05 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -40,17 +40,17 @@ typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay; struct tagSFG_PlatformDisplay { - struct tagSFG_PlatformDisplayEGL egl; - EGLNativeWindowType single_native_window; + struct tagSFG_PlatformDisplayEGL egl; + EGLNativeWindowType single_native_window; }; typedef struct tagSFG_PlatformContext SFG_PlatformContext; /* SFG_PlatformContext is used for SFG_Window.Window */ struct tagSFG_PlatformContext { - struct tagSFG_PlatformContextEGL egl; - screen_context_t screenContext; - bps_event_t* event; + struct tagSFG_PlatformContextEGL egl; + screen_context_t screenContext; + bps_event_t* event; }; @@ -76,34 +76,34 @@ struct touchscreen { * interspersed */ - /* - * We'll put these values in and that should - * allow the code to at least compile when there is - * no support. The JS open routine should error out - * and shut off all the code downstream anyway and if - * the application doesn't use a joystick we'll be fine. - */ +/* + * We'll put these values in and that should + * allow the code to at least compile when there is + * no support. The JS open routine should error out + * and shut off all the code downstream anyway and if + * the application doesn't use a joystick we'll be fine. + */ - struct JS_DATA_TYPE - { +struct JS_DATA_TYPE +{ int buttons; int x; int y; - }; +}; -# define JS_RETURN (sizeof(struct JS_DATA_TYPE)) +#define JS_RETURN (sizeof(struct JS_DATA_TYPE)) /* XXX It might be better to poll the operating system for the numbers of buttons and * XXX axes and then dynamically allocate the arrays. */ -# define _JS_MAX_AXES 16 +#define _JS_MAX_AXES 16 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick; struct tagSFG_PlatformJoystick { - struct JS_DATA_TYPE js; + struct JS_DATA_TYPE js; - char fname [ 128 ]; - int fd; + char fname [ 128 ]; + int fd; }; /* Window's state description. This structure should be kept portable. */ diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index db3f5c6..f7b8f66 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -56,87 +56,87 @@ static struct touchscreen touchscreen; unsigned int key_special(int qnxKeycode) { - switch(qnxKeycode) { - case KEYCODE_F1: - return GLUT_KEY_F1; - case KEYCODE_F2: - return GLUT_KEY_F2; - case KEYCODE_F3: - return GLUT_KEY_F3; - case KEYCODE_F4: - return GLUT_KEY_F4; - case KEYCODE_F5: - return GLUT_KEY_F5; - case KEYCODE_F6: - return GLUT_KEY_F6; - case KEYCODE_F7: - return GLUT_KEY_F7; - case KEYCODE_F8: - return GLUT_KEY_F8; - case KEYCODE_F9: - return GLUT_KEY_F9; - case KEYCODE_F10: - return GLUT_KEY_F10; - case KEYCODE_F11: - return GLUT_KEY_F11; - case KEYCODE_F12: - return GLUT_KEY_F12; - case KEYCODE_PG_UP: - return GLUT_KEY_PAGE_UP; - case KEYCODE_PG_DOWN: - return GLUT_KEY_PAGE_DOWN; - case KEYCODE_HOME: - return GLUT_KEY_HOME; - case KEYCODE_END: - return GLUT_KEY_END; - case KEYCODE_INSERT: - return GLUT_KEY_INSERT; - case KEYCODE_UP: - //case KEYCODE_KP_UP: - return GLUT_KEY_UP; - case KEYCODE_DOWN: - //case KEYCODE_KP_DOWN: - return GLUT_KEY_DOWN; - case KEYCODE_LEFT: - //case KEYCODE_KP_LEFT: - return GLUT_KEY_LEFT; - case KEYCODE_RIGHT: - //case KEYCODE_KP_RIGHT: - return GLUT_KEY_RIGHT; - case KEYCODE_NUM_LOCK: - return GLUT_KEY_NUM_LOCK; - case KEYCODE_LEFT_ALT: - return GLUT_KEY_ALT_L; - case KEYCODE_RIGHT_ALT: - return GLUT_KEY_ALT_R; - case KEYCODE_LEFT_SHIFT: - return GLUT_KEY_SHIFT_L; - case KEYCODE_RIGHT_SHIFT: - return GLUT_KEY_SHIFT_R; - case KEYCODE_LEFT_CTRL: - return GLUT_KEY_CTRL_L; - case KEYCODE_RIGHT_CTRL: - return GLUT_KEY_CTRL_R; - } - return 0; + switch(qnxKeycode) { + case KEYCODE_F1: + return GLUT_KEY_F1; + case KEYCODE_F2: + return GLUT_KEY_F2; + case KEYCODE_F3: + return GLUT_KEY_F3; + case KEYCODE_F4: + return GLUT_KEY_F4; + case KEYCODE_F5: + return GLUT_KEY_F5; + case KEYCODE_F6: + return GLUT_KEY_F6; + case KEYCODE_F7: + return GLUT_KEY_F7; + case KEYCODE_F8: + return GLUT_KEY_F8; + case KEYCODE_F9: + return GLUT_KEY_F9; + case KEYCODE_F10: + return GLUT_KEY_F10; + case KEYCODE_F11: + return GLUT_KEY_F11; + case KEYCODE_F12: + return GLUT_KEY_F12; + case KEYCODE_PG_UP: + return GLUT_KEY_PAGE_UP; + case KEYCODE_PG_DOWN: + return GLUT_KEY_PAGE_DOWN; + case KEYCODE_HOME: + return GLUT_KEY_HOME; + case KEYCODE_END: + return GLUT_KEY_END; + case KEYCODE_INSERT: + return GLUT_KEY_INSERT; + case KEYCODE_UP: + //case KEYCODE_KP_UP: + return GLUT_KEY_UP; + case KEYCODE_DOWN: + //case KEYCODE_KP_DOWN: + return GLUT_KEY_DOWN; + case KEYCODE_LEFT: + //case KEYCODE_KP_LEFT: + return GLUT_KEY_LEFT; + case KEYCODE_RIGHT: + //case KEYCODE_KP_RIGHT: + return GLUT_KEY_RIGHT; + case KEYCODE_NUM_LOCK: + return GLUT_KEY_NUM_LOCK; + case KEYCODE_LEFT_ALT: + return GLUT_KEY_ALT_L; + case KEYCODE_RIGHT_ALT: + return GLUT_KEY_ALT_R; + case KEYCODE_LEFT_SHIFT: + return GLUT_KEY_SHIFT_L; + case KEYCODE_RIGHT_SHIFT: + return GLUT_KEY_SHIFT_R; + case KEYCODE_LEFT_CTRL: + return GLUT_KEY_CTRL_L; + case KEYCODE_RIGHT_CTRL: + return GLUT_KEY_CTRL_R; + } + return 0; } unsigned char key_ascii(int qnxKeycode) { - if (qnxKeycode >= KEYCODE_PC_KEYS && qnxKeycode <= UNICODE_PRIVATE_USE_AREA_LAST) { - switch (qnxKeycode) { - case KEYCODE_BACKSPACE: - return 0x0008; - case KEYCODE_TAB: - return 0x0009; - case KEYCODE_KP_ENTER: - case KEYCODE_RETURN: - return 0x000A; - case KEYCODE_ESCAPE: - return 0x001B; - } - } - return qnxKeycode; + if (qnxKeycode >= KEYCODE_PC_KEYS && qnxKeycode <= UNICODE_PRIVATE_USE_AREA_LAST) { + switch (qnxKeycode) { + case KEYCODE_BACKSPACE: + return 0x0008; + case KEYCODE_TAB: + return 0x0009; + case KEYCODE_KP_ENTER: + case KEYCODE_RETURN: + return 0x000A; + case KEYCODE_ESCAPE: + return 0x001B; + } + } + return qnxKeycode; } //From fg_main_x11 @@ -159,326 +159,326 @@ fg_time_t fgPlatformSystemTime ( void ) */ void fgPlatformSleepForEvents( fg_time_t msec ) { - //XXX: Is this right? Is there a more direct way to access the context? - if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { - LOGW("BPS couldn't get event"); - } + //XXX: Is this right? Is there a more direct way to access the context? + if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { + LOGW("BPS couldn't get event"); + } } void handle_left_mouse(int x, int y, int height, int eventType, SFG_Window* window) { - bool handled = false; - /* Virtual arrows PAD */ - /* Don't interfere with existing mouse move event */ - if (!touchscreen.in_mmotion) { - struct vpad_state prev_vpad = touchscreen.vpad; - touchscreen.vpad.left = touchscreen.vpad.right = touchscreen.vpad.up = touchscreen.vpad.down = false; + bool handled = false; + /* Virtual arrows PAD */ + /* Don't interfere with existing mouse move event */ + if (!touchscreen.in_mmotion) { + struct vpad_state prev_vpad = touchscreen.vpad; + touchscreen.vpad.left = touchscreen.vpad.right = touchscreen.vpad.up = touchscreen.vpad.down = false; - if (eventType == SCREEN_EVENT_MTOUCH_TOUCH || eventType == SCREEN_EVENT_MTOUCH_MOVE) { - if ((x > 0 && x < 100) && (y > (height - 100) && y < height)) - { - touchscreen.vpad.left = true; - } - if ((x > 200 && x < 300) && (y > (height - 100) && y < height)) - { - touchscreen.vpad.right = true; - } - if ((x > 100 && x < 200) && (y > (height - 100) && y < height)) - { - touchscreen.vpad.down = true; - } - if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100))) - { - touchscreen.vpad.up = true; - } - } + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH || eventType == SCREEN_EVENT_MTOUCH_MOVE) { + if ((x > 0 && x < 100) && (y > (height - 100) && y < height)) + { + touchscreen.vpad.left = true; + } + if ((x > 200 && x < 300) && (y > (height - 100) && y < height)) + { + touchscreen.vpad.right = true; + } + if ((x > 100 && x < 200) && (y > (height - 100) && y < height)) + { + touchscreen.vpad.down = true; + } + if ((x > 100 && x < 200) && (y > (height - 200) && y < (height - 100))) + { + touchscreen.vpad.up = true; + } + } - if (eventType == SCREEN_EVENT_MTOUCH_TOUCH && - (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) { - touchscreen.vpad.on = true; - } - if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { - touchscreen.vpad.on = false; - } + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH && + (touchscreen.vpad.left || touchscreen.vpad.right || touchscreen.vpad.down || touchscreen.vpad.up)) { + touchscreen.vpad.on = true; + } + if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { + touchscreen.vpad.on = false; + } - if (prev_vpad.left != touchscreen.vpad.left - || prev_vpad.right != touchscreen.vpad.right - || prev_vpad.up != touchscreen.vpad.up - || prev_vpad.down != touchscreen.vpad.down - || prev_vpad.on != touchscreen.vpad.on) { - if (FETCH_WCB(*window, Special)) { - if (prev_vpad.left == false && touchscreen.vpad.left == true) { - INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y)); - } - else if (prev_vpad.right == false && touchscreen.vpad.right == true) { - INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y)); - } - else if (prev_vpad.up == false && touchscreen.vpad.up == true) { - INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y)); - } - else if (prev_vpad.down == false && touchscreen.vpad.down == true) { - INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y)); - } - } - if (FETCH_WCB(*window, SpecialUp)) { - if (prev_vpad.left == true && touchscreen.vpad.left == false) { - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y)); - } - if (prev_vpad.right == true && touchscreen.vpad.right == false) { - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y)); - } - if (prev_vpad.up == true && touchscreen.vpad.up == false) { - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y)); - } - if (prev_vpad.down == true && touchscreen.vpad.down == false) { - INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y)); - } - } - handled = true; - } - } + if (prev_vpad.left != touchscreen.vpad.left + || prev_vpad.right != touchscreen.vpad.right + || prev_vpad.up != touchscreen.vpad.up + || prev_vpad.down != touchscreen.vpad.down + || prev_vpad.on != touchscreen.vpad.on) { + if (FETCH_WCB(*window, Special)) { + if (prev_vpad.left == false && touchscreen.vpad.left == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_LEFT, x, y)); + } + else if (prev_vpad.right == false && touchscreen.vpad.right == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_RIGHT, x, y)); + } + else if (prev_vpad.up == false && touchscreen.vpad.up == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_UP, x, y)); + } + else if (prev_vpad.down == false && touchscreen.vpad.down == true) { + INVOKE_WCB(*window, Special, (GLUT_KEY_DOWN, x, y)); + } + } + if (FETCH_WCB(*window, SpecialUp)) { + if (prev_vpad.left == true && touchscreen.vpad.left == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_LEFT, x, y)); + } + if (prev_vpad.right == true && touchscreen.vpad.right == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_RIGHT, x, y)); + } + if (prev_vpad.up == true && touchscreen.vpad.up == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_UP, x, y)); + } + if (prev_vpad.down == true && touchscreen.vpad.down == false) { + INVOKE_WCB(*window, SpecialUp, (GLUT_KEY_DOWN, x, y)); + } + } + handled = true; + } + } - /* Normal mouse events */ - if (!handled && !touchscreen.vpad.on) { - window->State.MouseX = x; - window->State.MouseY = y; + /* Normal mouse events */ + if (!handled && !touchscreen.vpad.on) { + window->State.MouseX = x; + window->State.MouseY = y; - if(eventType == SCREEN_EVENT_MTOUCH_MOVE) { - INVOKE_WCB(*window, Motion, (x, y)); - } else if(FETCH_WCB(*window, Mouse)) { - touchscreen.in_mmotion = eventType == SCREEN_EVENT_MTOUCH_TOUCH; - int glutTouchType = eventType == SCREEN_EVENT_MTOUCH_TOUCH ? GLUT_DOWN : GLUT_UP; - INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, glutTouchType, x, y)); - } - } + if(eventType == SCREEN_EVENT_MTOUCH_MOVE) { + INVOKE_WCB(*window, Motion, (x, y)); + } else if(FETCH_WCB(*window, Mouse)) { + touchscreen.in_mmotion = eventType == SCREEN_EVENT_MTOUCH_TOUCH; + int glutTouchType = eventType == SCREEN_EVENT_MTOUCH_TOUCH ? GLUT_DOWN : GLUT_UP; + INVOKE_WCB(*window, Mouse, (GLUT_LEFT_BUTTON, glutTouchType, x, y)); + } + } } void fgPlatformProcessSingleEvent ( void ) { - int domain; - bps_event_t** eventPtr = &fgStructure.CurrentWindow->Window.pContext.event; //XXX Is there a more direct way to access the context? - bps_event_t* event; - do - { - if(*eventPtr != NULL) { - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL && window->Window.Handle != NULL) { - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); - } + int domain; + bps_event_t** eventPtr = &fgStructure.CurrentWindow->Window.pContext.event; //XXX Is there a more direct way to access the context? + bps_event_t* event; + do + { + if(*eventPtr != NULL) { + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL && window->Window.Handle != NULL) { + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); + } - event = *eventPtr; - domain = bps_event_get_domain(event); - if (domain == screen_get_domain()) { - int eventType; - screen_event_t screenEvent = screen_event_get_event(event); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); - switch (eventType) { + event = *eventPtr; + domain = bps_event_get_domain(event); + if (domain == screen_get_domain()) { + int eventType; + screen_event_t screenEvent = screen_event_get_event(event); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); + switch (eventType) { - //Mostly from fg_main_android - case SCREEN_EVENT_MTOUCH_TOUCH: - case SCREEN_EVENT_MTOUCH_RELEASE: - case SCREEN_EVENT_MTOUCH_MOVE: - { - mtouch_event_t touchEvent; - screen_get_mtouch_event(screenEvent, &touchEvent, 0); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id)); - if(touchEvent.contact_id == 0) { - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); - } + //Mostly from fg_main_android + case SCREEN_EVENT_MTOUCH_TOUCH: + case SCREEN_EVENT_MTOUCH_RELEASE: + case SCREEN_EVENT_MTOUCH_MOVE: + { + mtouch_event_t touchEvent; + screen_get_mtouch_event(screenEvent, &touchEvent, 0); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id)); + if(touchEvent.contact_id == 0) { + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); + } - //Now handle mutlitouch (adapted from fg_main_windows) - if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) { - INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_ENTERED ) ); - INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) ); - } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) { - INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) ); - //XXX No motion is performed without contact, thus MultiPassive is never used - } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { - INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); - INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); - } - break; - } + //Now handle mutlitouch (adapted from fg_main_windows) + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) { + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_ENTERED ) ); + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) ); + } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) { + INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) ); + //XXX No motion is performed without contact, thus MultiPassive is never used + } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); + } + break; + } - case SCREEN_EVENT_POINTER: - { - //Based off/part taken from GamePlay3d PlatformBlackBerry - static int mouse_pressed = 0; - int buttons; - int position[2]; - int wheel; - // A move event will be fired unless a button state changed. - bool move = true; - bool left_move = false; - // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + case SCREEN_EVENT_POINTER: + { + //Based off/part taken from GamePlay3d PlatformBlackBerry + static int mouse_pressed = 0; + int buttons; + int position[2]; + int wheel; + // A move event will be fired unless a button state changed. + bool move = true; + bool left_move = false; + // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel)); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel)); - //XXX Should multitouch be handled? + //XXX Should multitouch be handled? - // Handle left mouse. Interpret as touch if the left mouse event is not consumed. - if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { - if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { - left_move = true; - } else { - move = false; - mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); - } - } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { - move = false; - mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); - } + // Handle left mouse. Interpret as touch if the left mouse event is not consumed. + if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { + if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + left_move = true; + } else { + move = false; + mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); + } + } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); + } - // Handle right mouse. - if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { - if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { - move = false; - mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); - } - } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { - move = false; - mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); - } + // Handle right mouse. + if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { + move = false; + mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); + } + } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); + } - // Handle middle mouse. - if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { - if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { - move = false; - mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); - } - } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { - move = false; - mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); - } + // Handle middle mouse. + if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { + move = false; + mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); + } + } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); + } - // Fire a move event if none of the buttons changed. - if (left_move || move) { - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); - } + // Fire a move event if none of the buttons changed. + if (left_move || move) { + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); + } - if (wheel) { - fgState.MouseWheelTicks -= wheel; - //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive) - } - break; - } + if (wheel) { + fgState.MouseWheelTicks -= wheel; + //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive) + } + break; + } - //Based off fg_main_android - case SCREEN_EVENT_KEYBOARD: - { - int flags; - int value; - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value)); - // Suppress key repeats if desired - if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) { - unsigned int keypress = 0; - unsigned char ascii = 0; - if ((keypress = key_special(value))) { - if(flags & KEY_DOWN) { - INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); - } else { - INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); - } - } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { - if(flags & KEY_DOWN) { - INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); - } else { - INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); - } - } - } - break; - } + //Based off fg_main_android + case SCREEN_EVENT_KEYBOARD: + { + int flags; + int value; + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value)); + // Suppress key repeats if desired + if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) { + unsigned int keypress = 0; + unsigned char ascii = 0; + if ((keypress = key_special(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); + } else { + INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); + } + } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); + } else { + INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); + } + } + } + break; + } - case SCREEN_EVENT_PROPERTY: - case SCREEN_EVENT_IDLE: - break; + case SCREEN_EVENT_PROPERTY: + case SCREEN_EVENT_IDLE: + break; - default: - LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); - break; - } - } else if (domain == navigator_get_domain()) { - int eventType = bps_event_get_code(event); - switch (eventType) { + default: + LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); + break; + } + } else if (domain == navigator_get_domain()) { + int eventType = bps_event_get_code(event); + switch (eventType) { - case NAVIGATOR_WINDOW_STATE: - { - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); - navigator_window_state_t state = navigator_event_get_window_state(event); - switch (state) - { - case NAVIGATOR_WINDOW_FULLSCREEN: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); - break; - case NAVIGATOR_WINDOW_THUMBNAIL: - case NAVIGATOR_WINDOW_INVISIBLE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); - break; - default: - LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); - break; - } - break; - } + case NAVIGATOR_WINDOW_STATE: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); + navigator_window_state_t state = navigator_event_get_window_state(event); + switch (state) + { + case NAVIGATOR_WINDOW_FULLSCREEN: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + break; + case NAVIGATOR_WINDOW_THUMBNAIL: + case NAVIGATOR_WINDOW_INVISIBLE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + break; + default: + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); + break; + } + break; + } - case NAVIGATOR_EXIT: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); - /* User closed the application for good, let's kill the window */ - { - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL) { - fgDestroyWindow(window); - } else { - LOGW("NAVIGATOR_EXIT: No current window"); - } - } - break; + case NAVIGATOR_EXIT: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); + /* User closed the application for good, let's kill the window */ + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL) { + fgDestroyWindow(window); + } else { + LOGW("NAVIGATOR_EXIT: No current window"); + } + break; + } - case NAVIGATOR_SWIPE_DOWN: - case NAVIGATOR_BACK: - case NAVIGATOR_WINDOW_ACTIVE: - case NAVIGATOR_DEVICE_LOCK_STATE: - case NAVIGATOR_WINDOW_COVER: - case NAVIGATOR_WINDOW_COVER_ENTER: - case NAVIGATOR_WINDOW_COVER_EXIT: - //XXX Should probably do something with these - break; + case NAVIGATOR_SWIPE_DOWN: + case NAVIGATOR_BACK: + case NAVIGATOR_WINDOW_ACTIVE: + case NAVIGATOR_DEVICE_LOCK_STATE: + case NAVIGATOR_WINDOW_COVER: + case NAVIGATOR_WINDOW_COVER_ENTER: + case NAVIGATOR_WINDOW_COVER_EXIT: + //XXX Should probably do something with these + break; - default: - LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); - break; - } - } - } - } while(bps_get_event(eventPtr, 1) == BPS_SUCCESS && *eventPtr != NULL); + default: + LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); + break; + } + } + } + } while(bps_get_event(eventPtr, 1) == BPS_SUCCESS && *eventPtr != NULL); - /* Reset event to reduce chances of triggering something */ - *eventPtr = NULL; + /* Reset event to reduce chances of triggering something */ + *eventPtr = NULL; } void fgPlatformMainLoopPreliminaryWork ( void ) { - LOGI("fgPlatformMainLoopPreliminaryWork"); + LOGI("fgPlatformMainLoopPreliminaryWork"); } diff --git a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c index a6955e2..27f4968 100644 --- a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c @@ -62,38 +62,39 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat ) int fgPlatformGlutGet ( GLenum eWhat ) { - switch (eWhat) { - /* One full-screen window only */ - case GLUT_WINDOW_X: - case GLUT_WINDOW_Y: - case GLUT_WINDOW_BORDER_WIDTH: - case GLUT_WINDOW_HEADER_HEIGHT: - return 0; + switch (eWhat) { + /* One full-screen window only */ + case GLUT_WINDOW_X: + case GLUT_WINDOW_Y: + case GLUT_WINDOW_BORDER_WIDTH: + case GLUT_WINDOW_HEADER_HEIGHT: + return 0; - case GLUT_WINDOW_WIDTH: - case GLUT_WINDOW_HEIGHT: + case GLUT_WINDOW_WIDTH: + case GLUT_WINDOW_HEIGHT: { - if ( fgStructure.CurrentWindow == NULL ) - return 0; - int size[2]; - if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0 ) - return 0; - switch ( eWhat ) - { - case GLUT_WINDOW_WIDTH: - return size[0]; - case GLUT_WINDOW_HEIGHT: - return size[1]; - } + if ( fgStructure.CurrentWindow == NULL ) + return 0; + int size[2]; + if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0 ) + return 0; + switch ( eWhat ) + { + case GLUT_WINDOW_WIDTH: + return size[0]; + case GLUT_WINDOW_HEIGHT: + return size[1]; + } + break; } - case GLUT_WINDOW_COLORMAP_SIZE: - /* 0 for RGBA/non-indexed mode */ - /* Under BlackBerry and GLES more generally, no indexed-mode */ - return 0; + case GLUT_WINDOW_COLORMAP_SIZE: + /* 0 for RGBA/non-indexed mode */ + /* Under BlackBerry and GLES more generally, no indexed-mode */ + return 0; - default: - return fghPlatformGlutGetEGL(eWhat); - } - return -1; + default: + return fghPlatformGlutGetEGL(eWhat); + } + return -1; } diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 8c1a121..d435dfb 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -43,84 +43,84 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isSubWindow ) { - /* TODO: only one full-screen window possible? */ - if (fgDisplay.pDisplay.single_native_window != NULL) { - fgWarning("You can't have more than one window on BlackBerry"); - return; - } - window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment + /* TODO: only one full-screen window possible? */ + if (fgDisplay.pDisplay.single_native_window != NULL) { + fgWarning("You can't have more than one window on BlackBerry"); + return; + } + window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment - /* Create window */ - if (screen_create_context(&window->Window.pContext.screenContext, 0)) { - fgError("Could not create screen context"); - return; - } - screen_window_t sWindow; - if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) { - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not create window"); - return; - } - fgDisplay.pDisplay.single_native_window = sWindow; + /* Create window */ + if (screen_create_context(&window->Window.pContext.screenContext, 0)) { + fgError("Could not create screen context"); + return; + } + screen_window_t sWindow; + if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) { + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not create window"); + return; + } + fgDisplay.pDisplay.single_native_window = sWindow; - /* Set window properties */ - int screenFormat = SCREEN_FORMAT_RGBA8888; //XXX Should this be determined by config? + /* Set window properties */ + int screenFormat = SCREEN_FORMAT_RGBA8888; //XXX Should this be determined by config? #ifdef GL_ES_VERSION_2_0 - int screenUsage = SCREEN_USAGE_OPENGL_ES2; + int screenUsage = SCREEN_USAGE_OPENGL_ES2; #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 - int screenUsage = SCREEN_USAGE_OPENGL_ES1; + int screenUsage = SCREEN_USAGE_OPENGL_ES1; #endif #ifndef __X86__ - screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display + screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display #endif - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not set window format"); - return; - } - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not set window usage"); - return; - } + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not set window format"); + return; + } + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not set window usage"); + return; + } - /* Could set size based on what is specified for window. Work on another time - int size[2]; - size[0] = w; - size[1] = h; - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not set window buffer size"); - return; - }*/ + /* Could set size based on what is specified for window. Work on another time + int size[2]; + size[0] = w; + size[1] = h; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not set window buffer size"); + return; + }*/ - /* Create window buffers */ - if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { - screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); - fgError("Could not create window buffers"); - return; - } + /* Create window buffers */ + if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { + screen_destroy_window(sWindow); + screen_destroy_context(window->Window.pContext.screenContext); + fgError("Could not create window buffers"); + return; + } - /* Request window events */ - screen_request_events(window->Window.pContext.screenContext); + /* Request window events */ + screen_request_events(window->Window.pContext.screenContext); - /* Save window and set state */ - window->Window.Handle = fgDisplay.pDisplay.single_native_window; - window->State.WorkMask |= GLUT_INIT_WORK; - window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now + /* Save window and set state */ + window->Window.Handle = fgDisplay.pDisplay.single_native_window; + window->State.WorkMask |= GLUT_INIT_WORK; + window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now - /* Create context */ - fghChooseConfig(&window->Window.pContext.egl.Config); - window->Window.Context = fghCreateNewContextEGL(window); + /* Create context */ + fghChooseConfig(&window->Window.pContext.egl.Config); + window->Window.Context = fghCreateNewContextEGL(window); - /* Create EGL window */ - fghPlatformOpenWindowEGL(window); + /* Create EGL window */ + fghPlatformOpenWindowEGL(window); - window->State.Visible = GL_TRUE; + window->State.Visible = GL_TRUE; } /* @@ -128,7 +128,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, */ void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height ) { - fprintf(stderr, "fgPlatformReshapeWindow: STUB\n"); + fprintf(stderr, "fgPlatformReshapeWindow: STUB\n"); } /* @@ -136,13 +136,13 @@ void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height ) */ void fgPlatformCloseWindow( SFG_Window* window ) { - fghPlatformCloseWindowEGL(window); + fghPlatformCloseWindowEGL(window); - screen_stop_events(window->Window.pContext.screenContext); + screen_stop_events(window->Window.pContext.screenContext); - screen_destroy_window((screen_window_t)window->Window.Handle); + screen_destroy_window((screen_window_t)window->Window.Handle); - screen_destroy_context(window->Window.pContext.screenContext); + screen_destroy_context(window->Window.pContext.screenContext); } /* @@ -150,7 +150,7 @@ void fgPlatformCloseWindow( SFG_Window* window ) */ void fgPlatformShowWindow( void ) { - fprintf(stderr, "fgPlatformShowWindow: STUB\n"); + fprintf(stderr, "fgPlatformShowWindow: STUB\n"); } /* @@ -158,7 +158,7 @@ void fgPlatformShowWindow( void ) */ void fgPlatformHideWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformHideWindow: STUB\n"); + fprintf(stderr, "fgPlatformHideWindow: STUB\n"); } /* @@ -166,7 +166,8 @@ void fgPlatformHideWindow( SFG_Window *window ) */ void fgPlatformIconifyWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n"); + //XXX This is possible via Cascades, but can't seem to find a C-level API + fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n"); } /* @@ -174,7 +175,7 @@ void fgPlatformIconifyWindow( SFG_Window *window ) */ void fgPlatformGlutSetWindowTitle( const char* title ) { - fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n"); + fprintf(stderr, "fgPlatformGlutSetWindowTitle: STUB\n"); } /* @@ -182,14 +183,15 @@ void fgPlatformGlutSetWindowTitle( const char* title ) */ void fgPlatformGlutSetIconTitle( const char* title ) { - fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n");} + fprintf(stderr, "fgPlatformGlutSetIconTitle: STUB\n"); +} /* * Change the specified window's position */ void fgPlatformPositionWindow( SFG_Window *window, int x, int y ) { - fprintf(stderr, "fgPlatformPositionWindow: STUB\n"); + fprintf(stderr, "fgPlatformPositionWindow: STUB\n"); } /* @@ -197,7 +199,7 @@ void fgPlatformPositionWindow( SFG_Window *window, int x, int y ) */ void fgPlatformPushWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformPushWindow: STUB\n"); + fprintf(stderr, "fgPlatformPushWindow: STUB\n"); } /* @@ -205,7 +207,7 @@ void fgPlatformPushWindow( SFG_Window *window ) */ void fgPlatformPopWindow( SFG_Window *window ) { - fprintf(stderr, "fgPlatformPopWindow: STUB\n"); + fprintf(stderr, "fgPlatformPopWindow: STUB\n"); } /* @@ -213,5 +215,5 @@ void fgPlatformPopWindow( SFG_Window *window ) */ void fgPlatformFullScreenToggle( SFG_Window *win ) { - fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n"); + fprintf(stderr, "fgPlatformFullScreenToggle: STUB\n"); } From ae7fc0ad83b98771d073ee54e8bfadbd7579c33b Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 9 Sep 2013 00:43:31 -0400 Subject: [PATCH 13/34] Prevented case where no window was set when waiting for events. --- freeglut/freeglut/src/blackberry/fg_main_blackberry.c | 2 +- freeglut/freeglut/src/blackberry/fg_window_blackberry.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index f7b8f66..e347703 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -160,7 +160,7 @@ fg_time_t fgPlatformSystemTime ( void ) void fgPlatformSleepForEvents( fg_time_t msec ) { //XXX: Is this right? Is there a more direct way to access the context? - if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { + if(fgStructure.CurrentWindow && bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } } diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index d435dfb..5201eb5 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -106,7 +106,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, } /* Request window events */ - screen_request_events(window->Window.pContext.screenContext); + screen_request_events(window->Window.pContext.screenContext); //XXX When multiple screens are supported, this needs to be moved to wherever the screen context is actually created /* Save window and set state */ window->Window.Handle = fgDisplay.pDisplay.single_native_window; From ed6b434516268b300ced580a50277083ad3f17db Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 9 Sep 2013 00:54:48 -0400 Subject: [PATCH 14/34] Added two more navigator states (that might be implemented) for BlackBerry --- freeglut/freeglut/src/blackberry/fg_main_blackberry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index e347703..dfc7044 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -457,10 +457,12 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_SWIPE_DOWN: case NAVIGATOR_BACK: case NAVIGATOR_WINDOW_ACTIVE: + case NAVIGATOR_WINDOW_INACTIVE: case NAVIGATOR_DEVICE_LOCK_STATE: case NAVIGATOR_WINDOW_COVER: case NAVIGATOR_WINDOW_COVER_ENTER: case NAVIGATOR_WINDOW_COVER_EXIT: + case NAVIGATOR_APP_STATE: //XXX Should probably do something with these break; From 8c2c8d138c6e5b1672aadffd0441a53dd8103d23 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 9 Sep 2013 01:18:27 -0400 Subject: [PATCH 15/34] Added keyboard states for BlackBerry --- freeglut/freeglut/src/blackberry/fg_main_blackberry.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index dfc7044..d16f315 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -458,6 +458,8 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_BACK: case NAVIGATOR_WINDOW_ACTIVE: case NAVIGATOR_WINDOW_INACTIVE: + case NAVIGATOR_KEYBOARD_STATE: + case NAVIGATOR_KEYBOARD_POSITION: case NAVIGATOR_DEVICE_LOCK_STATE: case NAVIGATOR_WINDOW_COVER: case NAVIGATOR_WINDOW_COVER_ENTER: From 9f930856ab6222e1a6f0b7c6204399388fc5cefe Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 9 Sep 2013 12:31:04 -0400 Subject: [PATCH 16/34] Restructuring of when screen context and events are started stopped, created and destroyed --- .../src/blackberry/fg_init_blackberry.c | 18 ++++++--- .../src/blackberry/fg_internal_blackberry.h | 4 +- .../src/blackberry/fg_main_blackberry.c | 39 +++++++++++++------ .../src/blackberry/fg_window_blackberry.c | 19 +-------- 4 files changed, 43 insertions(+), 37 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c index 5a1a9d9..aaef2cb 100644 --- a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c @@ -29,17 +29,24 @@ #include "fg_init.h" #include "egl/fg_init_egl.h" #include -#include +#include void fgPlatformInitialize() { bps_initialize(); - navigator_request_events(0); - //XXX rotation lock? navigator_rotation_lock(true); - fghPlatformInitializeEGL(); + /* Prepare for screen events */ + fgDisplay.pDisplay.event = NULL; + fgDisplay.pDisplay.screenContext = NULL; + + /* Create window */ + if (screen_create_context(&fgDisplay.pDisplay.screenContext, 0)) { + fgError("Could not create screen context"); + return; + } + /* Get start time */ fgState.Time = fgSystemTime(); @@ -50,7 +57,8 @@ void fgPlatformCloseDisplay() { fghPlatformCloseDisplayEGL(); - navigator_stop_events(0); + screen_destroy_context(fgDisplay.pDisplay.screenContext); + fgDisplay.pDisplay.screenContext = NULL; bps_shutdown(); } diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 229ce05..795ff5d 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -41,6 +41,8 @@ typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay; struct tagSFG_PlatformDisplay { struct tagSFG_PlatformDisplayEGL egl; + screen_context_t screenContext; + bps_event_t* event; EGLNativeWindowType single_native_window; }; @@ -49,8 +51,6 @@ typedef struct tagSFG_PlatformContext SFG_PlatformContext; struct tagSFG_PlatformContext { struct tagSFG_PlatformContextEGL egl; - screen_context_t screenContext; - bps_event_t* event; }; diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index d16f315..9c22184 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -51,6 +51,7 @@ extern void fgPlatformPopWindow( SFG_Window *window ); extern void fgPlatformHideWindow( SFG_Window *window ); extern void fgPlatformIconifyWindow( SFG_Window *window ); extern void fgPlatformShowWindow( SFG_Window *window ); +extern void fgPlatformMainLoopPostWork ( void ); static struct touchscreen touchscreen; @@ -160,7 +161,7 @@ fg_time_t fgPlatformSystemTime ( void ) void fgPlatformSleepForEvents( fg_time_t msec ) { //XXX: Is this right? Is there a more direct way to access the context? - if(fgStructure.CurrentWindow && bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) { + if(fgStructure.CurrentWindow && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } } @@ -256,11 +257,9 @@ void handle_left_mouse(int x, int y, int height, int eventType, SFG_Window* wind void fgPlatformProcessSingleEvent ( void ) { int domain; - bps_event_t** eventPtr = &fgStructure.CurrentWindow->Window.pContext.event; //XXX Is there a more direct way to access the context? - bps_event_t* event; do { - if(*eventPtr != NULL) { + if(fgDisplay.pDisplay.event != NULL) { SFG_Window* window = fgStructure.CurrentWindow; if (window != NULL && window->Window.Handle != NULL) { int size[2]; @@ -268,11 +267,10 @@ void fgPlatformProcessSingleEvent ( void ) fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); } - event = *eventPtr; - domain = bps_event_get_domain(event); + domain = bps_event_get_domain(fgDisplay.pDisplay.event); if (domain == screen_get_domain()) { int eventType; - screen_event_t screenEvent = screen_event_get_event(event); + screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); switch (eventType) { @@ -416,13 +414,13 @@ void fgPlatformProcessSingleEvent ( void ) break; } } else if (domain == navigator_get_domain()) { - int eventType = bps_event_get_code(event); + int eventType = bps_event_get_code(fgDisplay.pDisplay.event); switch (eventType) { case NAVIGATOR_WINDOW_STATE: { LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); - navigator_window_state_t state = navigator_event_get_window_state(event); + navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event); switch (state) { case NAVIGATOR_WINDOW_FULLSCREEN: @@ -444,6 +442,9 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_EXIT: { LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); + + fgPlatformMainLoopPostWork(); + /* User closed the application for good, let's kill the window */ SFG_Window* window = fgStructure.CurrentWindow; if (window != NULL) { @@ -474,17 +475,32 @@ void fgPlatformProcessSingleEvent ( void ) } } } - } while(bps_get_event(eventPtr, 1) == BPS_SUCCESS && *eventPtr != NULL); + } while(bps_get_event(&fgDisplay.pDisplay.event, 1) == BPS_SUCCESS && fgDisplay.pDisplay.event != NULL); /* Reset event to reduce chances of triggering something */ - *eventPtr = NULL; + fgDisplay.pDisplay.event = NULL; } void fgPlatformMainLoopPreliminaryWork ( void ) { LOGI("fgPlatformMainLoopPreliminaryWork"); + + /* Request navigator events */ + navigator_request_events(0); + //XXX rotation lock? navigator_rotation_lock(true); + + /* Request window events */ + screen_request_events(fgDisplay.pDisplay.screenContext); } +void fgPlatformMainLoopPostWork ( void ) +{ + LOGI("fgPlatformMainLoopPostWork"); + + screen_stop_events(fgDisplay.pDisplay.screenContext); + + navigator_stop_events(0); +} /* deal with work list items */ void fgPlatformInitWork(SFG_Window* window) @@ -542,4 +558,3 @@ void fgPlatformVisibilityWork(SFG_Window* window) break; } } - diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 5201eb5..e6876cf 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -48,16 +48,10 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, fgWarning("You can't have more than one window on BlackBerry"); return; } - window->Window.pContext.event = NULL; //XXX Should probably be done elsewhere. Done here so there is no event at the moment /* Create window */ - if (screen_create_context(&window->Window.pContext.screenContext, 0)) { - fgError("Could not create screen context"); - return; - } screen_window_t sWindow; - if (screen_create_window(&sWindow, window->Window.pContext.screenContext)) { - screen_destroy_context(window->Window.pContext.screenContext); + if (screen_create_window(&sWindow, fgDisplay.pDisplay.screenContext)) { fgError("Could not create window"); return; } @@ -75,13 +69,11 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, #endif if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); fgError("Could not set window format"); return; } if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_USAGE, &screenUsage)) { screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); fgError("Could not set window usage"); return; } @@ -92,7 +84,6 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, size[1] = h; if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); fgError("Could not set window buffer size"); return; }*/ @@ -100,14 +91,10 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Create window buffers */ if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { screen_destroy_window(sWindow); - screen_destroy_context(window->Window.pContext.screenContext); fgError("Could not create window buffers"); return; } - /* Request window events */ - screen_request_events(window->Window.pContext.screenContext); //XXX When multiple screens are supported, this needs to be moved to wherever the screen context is actually created - /* Save window and set state */ window->Window.Handle = fgDisplay.pDisplay.single_native_window; window->State.WorkMask |= GLUT_INIT_WORK; @@ -138,11 +125,7 @@ void fgPlatformCloseWindow( SFG_Window* window ) { fghPlatformCloseWindowEGL(window); - screen_stop_events(window->Window.pContext.screenContext); - screen_destroy_window((screen_window_t)window->Window.Handle); - - screen_destroy_context(window->Window.pContext.screenContext); } /* From 315007b4d48737d0337d763ae8c3c474b54e24b7 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 10 Sep 2013 15:24:22 -0400 Subject: [PATCH 17/34] Added ability to get screen size of display --- .../src/blackberry/fg_init_blackberry.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c index aaef2cb..ed1b1c9 100644 --- a/freeglut/freeglut/src/blackberry/fg_init_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_init_blackberry.c @@ -47,6 +47,39 @@ void fgPlatformInitialize() return; } + /* Get screen size */ + int displayCount; + screen_display_t* displays; + int vals[2]; + if(screen_get_context_property_iv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount)) { + fgWarning("Could not get display count. Screen size not determined and will be left at default values"); + } else if(displayCount >= 1) { + displays = (screen_display_t*)calloc(displayCount, sizeof(screen_display_t)); + if(screen_get_context_property_pv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DISPLAYS, (void**)displays)) { + fgWarning("Could not get displays. Screen size not determined and will be left at default values"); + } else { + /* We only care about the first one, which is the device display */ + if(screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_SIZE, vals)) { + fgWarning("Could not get display size. Values will be left at default"); + } else { + if(screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_ROTATION, &displayCount) || (displayCount == 0 || displayCount == 180)) { + fgDisplay.ScreenWidth = vals[0]; + fgDisplay.ScreenHeight = vals[1]; + } else { + fgDisplay.ScreenWidth = vals[1]; + fgDisplay.ScreenHeight = vals[0]; + } + } + if(screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_PHYSICAL_SIZE, vals)) { + fgWarning("Could not get physical display size. Values will be left at default"); + } else { + fgDisplay.ScreenWidthMM = vals[0]; + fgDisplay.ScreenHeightMM = vals[1]; + } + } + free(displays); + } + /* Get start time */ fgState.Time = fgSystemTime(); From 6293d84f0f61cefef553a4f0d71348fd7e01465f Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 10 Sep 2013 17:01:20 -0400 Subject: [PATCH 18/34] Added ability to get mouse button count or touch ID count. --- .../src/blackberry/fg_state_blackberry.c | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c index 27f4968..f16aea6 100644 --- a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c @@ -35,6 +35,9 @@ //From fg_state_android.c int fgPlatformGlutDeviceGet ( GLenum eWhat ) { + int deviceCount, i, value; + screen_device_t* devices; + switch( eWhat ) { case GLUT_HAS_KEYBOARD: @@ -42,13 +45,36 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat ) return 1; case GLUT_HAS_MOUSE: - /* BlackBerry has a touchscreen; until we get proper touchscreen - support, consider it as a mouse. */ + /* BlackBerry has a touchscreen. Consider it as a mouse since we have no guarantee + that a mouse will be used (in which case it's a simulator). */ return 1 ; case GLUT_NUM_MOUSE_BUTTONS: - /* BlackBerry has a touchscreen; until we get proper touchscreen - support, consider it as a 1-button mouse. */ + /* BlackBerry has a touchscreen, which we can consider a 1-button mouse at min. + Otherwise check for an actual mouse, else get max touch points */ + if(!screen_get_context_property_iv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount)) { + devices = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); + if(!screen_get_context_property_pv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DEVICES, (void**)devices)) { + /* Check for a pointer */ + for(i = 0; i < deviceCount; i++) { + if(!screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &value) && + value == SCREEN_EVENT_POINTER && + !screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_BUTTON_COUNT, &value)) { + return value; + } + } + /* Check for mtouch */ + for(i = 0; i < deviceCount; i++) { + if(!screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &value) && + value == SCREEN_EVENT_MTOUCH_TOUCH && + !screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_MAXIMUM_TOUCH_ID, &value)) { + return value; + } + } + } + free(devices); + } + /* Backup, pretend it's a 1-button mouse */ return 1; default: From 13e00879cf92b240d273705209dc0b4170c1a0e1 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 10 Sep 2013 18:25:02 -0400 Subject: [PATCH 19/34] Added support for key modifiers --- .../src/blackberry/fg_main_blackberry.c | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 9c22184..6fc6e7c 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -254,6 +254,16 @@ void handle_left_mouse(int x, int y, int height, int eventType, SFG_Window* wind } } +/* + * Determine a GLUT modifier mask based on BlackBerry modifier info. + */ +int fgPlatformGetModifiers (int mod) +{ + return (((mod & KEYMOD_SHIFT) ? GLUT_ACTIVE_SHIFT : 0) | + ((mod & KEYMOD_CTRL) ? GLUT_ACTIVE_CTRL : 0) | + ((mod & KEYMOD_ALT) ? GLUT_ACTIVE_ALT : 0)); +} + void fgPlatformProcessSingleEvent ( void ) { int domain; @@ -270,6 +280,7 @@ void fgPlatformProcessSingleEvent ( void ) domain = bps_event_get_domain(fgDisplay.pDisplay.event); if (domain == screen_get_domain()) { int eventType; + int mod; screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); switch (eventType) { @@ -281,7 +292,13 @@ void fgPlatformProcessSingleEvent ( void ) { mtouch_event_t touchEvent; screen_get_mtouch_event(screenEvent, &touchEvent, 0); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id)); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod)); + + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); + if(touchEvent.contact_id == 0) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); @@ -316,13 +333,17 @@ void fgPlatformProcessSingleEvent ( void ) screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel)); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod)); //XXX Should multitouch be handled? + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); + // Handle left mouse. Interpret as touch if the left mouse event is not consumed. if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { @@ -383,11 +404,19 @@ void fgPlatformProcessSingleEvent ( void ) int value; screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value)); - // Suppress key repeats if desired - if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) { + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X, Mod: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_SIGNED(mod)); + + /* Suppress key repeats if desired. Based off fg_main_mswin */ + if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_OFF && fgStructure.CurrentWindow->State.IgnoreKeyRepeat == GL_TRUE)) { unsigned int keypress = 0; unsigned char ascii = 0; + + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); + + /* Process keys */ if ((keypress = key_special(value))) { if(flags & KEY_DOWN) { INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); @@ -400,6 +429,8 @@ void fgPlatformProcessSingleEvent ( void ) } else { INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); } + } else { + LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event"); } } break; @@ -487,7 +518,7 @@ void fgPlatformMainLoopPreliminaryWork ( void ) /* Request navigator events */ navigator_request_events(0); - //XXX rotation lock? navigator_rotation_lock(true); + //XXX rotation lock? navigator_rotation_lock(true); /* Request window events */ screen_request_events(fgDisplay.pDisplay.screenContext); @@ -495,11 +526,11 @@ void fgPlatformMainLoopPreliminaryWork ( void ) void fgPlatformMainLoopPostWork ( void ) { - LOGI("fgPlatformMainLoopPostWork"); + LOGI("fgPlatformMainLoopPostWork"); - screen_stop_events(fgDisplay.pDisplay.screenContext); + screen_stop_events(fgDisplay.pDisplay.screenContext); - navigator_stop_events(0); + navigator_stop_events(0); } /* deal with work list items */ From 1fa4c3f5cfde1078c14786aa25b2200135e239bb Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 10 Sep 2013 18:34:07 -0400 Subject: [PATCH 20/34] Forgot to reset modifiers once done with modifiers. --- freeglut/freeglut/src/blackberry/fg_main_blackberry.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 6fc6e7c..3314002 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -316,6 +316,8 @@ void fgPlatformProcessSingleEvent ( void ) INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); } + + fgState.Modifiers = INVALID_MODIFIERS; break; } @@ -394,6 +396,8 @@ void fgPlatformProcessSingleEvent ( void ) fgState.MouseWheelTicks -= wheel; //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive) } + + fgState.Modifiers = INVALID_MODIFIERS; break; } @@ -432,6 +436,8 @@ void fgPlatformProcessSingleEvent ( void ) } else { LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event"); } + + fgState.Modifiers = INVALID_MODIFIERS; } break; } From e01c7955c6fdfbc6e389fda4eb68fc9e324ca8ec Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 11 Sep 2013 01:47:12 -0400 Subject: [PATCH 21/34] Added support for the scroll wheel when using the simulator --- .../src/blackberry/fg_internal_blackberry.h | 3 ++ .../src/blackberry/fg_main_blackberry.c | 40 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 795ff5d..90b11fe 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -69,6 +69,9 @@ struct touchscreen { bool in_mmotion; }; +/* -- INPUT DEFINITIONS ---------------------------------------------------- */ +#define WHEEL_DELTA 120 //This is taken from http://msdn.microsoft.com/en-us/library/windows/desktop/ms646254(v=vs.85).aspx + /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */ /* diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 3314002..827365b 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -393,8 +393,46 @@ void fgPlatformProcessSingleEvent ( void ) } if (wheel) { + /* Very slightly modified from fg_main_mswin. + * Because we don't want MouseWheel to be called every. single. time. + * That the action occurs, we mimic the Windows version with "wheel deltas" + * XXX Do we even want this? + * XXX If we want this, it's possible to get horizontal scroll as well. + * XXX -Vertical scroll=wheel 0, horizontal=wheel 1? */ fgState.MouseWheelTicks -= wheel; - //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive) + if (abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) + { + int wheel_number = 0; + int direction = (fgState.MouseWheelTicks > 0) ? -1 : 1; + + if (!FETCH_WCB(*window, MouseWheel) && !FETCH_WCB(*window, Mouse)) + break; + + //XXX fgSetWindow(window); + + while(abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) + { + if (FETCH_WCB(*window, MouseWheel)) + INVOKE_WCB(*window, MouseWheel, (wheel_number, direction, window->State.MouseX, window->State.MouseY)); + else /* No mouse wheel, call the mouse button callback twice */ + { + /* + * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4 + * " " one +1 to 5, -1 to 6, ... + * + * XXX The below assumes that you have no more than 3 mouse + * XXX buttons. Sorry. + */ + int button = wheel_number * 2 + 3; + if (direction < 0) + ++button; + INVOKE_WCB(*window, Mouse, (button, GLUT_DOWN, window->State.MouseX, window->State.MouseY)); + INVOKE_WCB(*window, Mouse, (button, GLUT_UP, window->State.MouseX, window->State.MouseY)); + } + + fgState.MouseWheelTicks -= WHEEL_DELTA * direction; + } + } } fgState.Modifiers = INVALID_MODIFIERS; From 84f5249b6e5e79f9e660c45ab5924d2116a5b4c7 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 11 Sep 2013 14:33:34 -0400 Subject: [PATCH 22/34] Implemented a small work around for no current window being set while executing the event handler --- freeglut/freeglut/src/blackberry/fg_main_blackberry.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 827365b..60218a0 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -161,7 +161,7 @@ fg_time_t fgPlatformSystemTime ( void ) void fgPlatformSleepForEvents( fg_time_t msec ) { //XXX: Is this right? Is there a more direct way to access the context? - if(fgStructure.CurrentWindow && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { + if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } } @@ -266,12 +266,17 @@ int fgPlatformGetModifiers (int mod) void fgPlatformProcessSingleEvent ( void ) { + if(fgStructure.CurrentWindow == NULL) + //XXX Is this right? Would this just cause a whole lot of busy looping while we wait for events? + LOGW("fgPlatformProcessSingleEvent: Missing current window. Skipping event processing"); + return; + int domain; do { if(fgDisplay.pDisplay.event != NULL) { SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL && window->Window.Handle != NULL) { + if (window->Window.Handle != NULL) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); From e8c0cc0f713b1d40638dfaf9b1074b039f6b672c Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 11 Sep 2013 14:39:25 -0400 Subject: [PATCH 23/34] Fixed bug where if statement didn't have parenthesis, causing it to just exit --- freeglut/freeglut/src/blackberry/fg_main_blackberry.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 60218a0..73b9f41 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -266,10 +266,11 @@ int fgPlatformGetModifiers (int mod) void fgPlatformProcessSingleEvent ( void ) { - if(fgStructure.CurrentWindow == NULL) + if(fgStructure.CurrentWindow == NULL) { //XXX Is this right? Would this just cause a whole lot of busy looping while we wait for events? - LOGW("fgPlatformProcessSingleEvent: Missing current window. Skipping event processing"); + LOGW("fgPlatformProcessSingleEvent: Missing current window. Skipping event processing"); return; + } int domain; do From 67354250fc0624526317bf81ad84e400ad4ba6eb Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 11 Sep 2013 15:48:14 -0400 Subject: [PATCH 24/34] Added full support for WindowStatus App status is now based on actual app status instead of window visibility --- .../src/blackberry/fg_main_blackberry.c | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 73b9f41..0932248 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -506,12 +506,18 @@ void fgPlatformProcessSingleEvent ( void ) { case NAVIGATOR_WINDOW_FULLSCREEN: LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); break; case NAVIGATOR_WINDOW_THUMBNAIL: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL"); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); + break; case NAVIGATOR_WINDOW_INVISIBLE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE"); + window->State.Visible = GL_FALSE; + INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); //XXX Should this be GLUT_FULLY_COVERED? break; default: LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); @@ -537,17 +543,40 @@ void fgPlatformProcessSingleEvent ( void ) } case NAVIGATOR_SWIPE_DOWN: + /* XXX Open app menu */ + break; + case NAVIGATOR_BACK: + /* XXX Should this be a Special/SpecialUp event? */ + break; + case NAVIGATOR_WINDOW_ACTIVE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_ACTIVE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + break; + case NAVIGATOR_WINDOW_INACTIVE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_INACTIVE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + break; + case NAVIGATOR_KEYBOARD_STATE: case NAVIGATOR_KEYBOARD_POSITION: + /* TODO Something needs to be done with this. Not sure what */ + break; + case NAVIGATOR_DEVICE_LOCK_STATE: + break; + case NAVIGATOR_WINDOW_COVER: case NAVIGATOR_WINDOW_COVER_ENTER: case NAVIGATOR_WINDOW_COVER_EXIT: + /* BlackBerry specific. Let app status and window status take care of everything */ + break; + case NAVIGATOR_APP_STATE: - //XXX Should probably do something with these + /* Can do the same as NAVIGATOR_WINDOW_ACTIVE/NAVIGATOR_WINDOW_INACTIVE but + seems less likely to work when the app comes to the foreground. Might be a bug */ break; default: @@ -586,8 +615,7 @@ void fgPlatformMainLoopPostWork ( void ) /* deal with work list items */ void fgPlatformInitWork(SFG_Window* window) { - /* notify windowStatus/visibility */ - INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) ); + LOGI("fgPlatformInitWork"); /* Position callback, always at 0,0 */ fghOnPositionNotify(window, 0, 0, GL_TRUE); From 80ef2bca8fe2e02b520d0020e4c9ab6fad71338c Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 11 Sep 2013 21:31:54 -0400 Subject: [PATCH 25/34] Placeholder for window sizes Prevent navigator event 0x0 to show as unknown (though it is unknown... it's not defined in navigator.h) --- .../freeglut/src/blackberry/fg_main_blackberry.c | 3 +++ .../freeglut/src/blackberry/fg_window_blackberry.c | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 0932248..71f7b6d 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -579,6 +579,9 @@ void fgPlatformProcessSingleEvent ( void ) seems less likely to work when the app comes to the foreground. Might be a bug */ break; + case 0: //Doesn't exist in header, but shows up when keyboard shows and resizes + break; + default: LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); break; diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index e6876cf..9f35750 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -80,12 +80,14 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Could set size based on what is specified for window. Work on another time int size[2]; - size[0] = w; - size[1] = h; - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { - screen_destroy_window(sWindow); - fgError("Could not set window buffer size"); - return; + if(sizeUse) { + size[0] = w; + size[1] = h; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { + screen_destroy_window(sWindow); + fgError("Could not set window buffer size"); + return; + } }*/ /* Create window buffers */ From 147414033acaf887675c5d3b4a6c100134096fb0 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Thu, 12 Sep 2013 00:24:25 -0400 Subject: [PATCH 26/34] Added (though commented out) support for setting window position --- .../src/blackberry/fg_window_blackberry.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 9f35750..61bd58d 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -78,12 +78,22 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, return; } - /* Could set size based on what is specified for window. Work on another time - int size[2]; + /* Uncomment when multiple windows are supported + int value[2]; + if(positionUse) { + value[0] = x; + value[1] = y; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_POSITION, value)) { + screen_destroy_window(sWindow); + fgError("Could not set window position"); + return; + } + } + if(sizeUse) { - size[0] = w; - size[1] = h; - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, size)) { + value[0] = w; + value[1] = h; + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { screen_destroy_window(sWindow); fgError("Could not set window buffer size"); return; From d97003f08fb96cacf832fb9d61cda2e8d7fd5be0 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Thu, 12 Sep 2013 20:06:22 -0400 Subject: [PATCH 27/34] Added support for rotation so an app can be rotated and FG will resize and manage the window in the background Additional documentation explaining why certain functions are implemented in the manner they are Changed QNX macro to a non deprecated one --- freeglut/freeglut/AUTHORS | 6 +- freeglut/freeglut/CMakeLists.txt | 3 + .../src/blackberry/fg_internal_blackberry.h | 3 +- .../src/blackberry/fg_main_blackberry.c | 595 ++++++++++-------- .../src/blackberry/fg_window_blackberry.c | 89 ++- freeglut/freeglut/src/fg_internal.h | 2 +- 6 files changed, 414 insertions(+), 284 deletions(-) diff --git a/freeglut/freeglut/AUTHORS b/freeglut/freeglut/AUTHORS index 972e662..62db946 100644 --- a/freeglut/freeglut/AUTHORS +++ b/freeglut/freeglut/AUTHORS @@ -32,9 +32,6 @@ John Tsiombikas Sylvain Beucler support for Android, X11/EGL, OpenGL(ES) 2.x, misc fixes -Vincent Simonetti - support for BlackBerry - Diederick C. Niehorster Chris Marshall Clive McCarthy @@ -42,4 +39,7 @@ Eero Pajarre Florian Echtler Matti Lehtonen +Vincent Simonetti + support for BlackBerry + ...and all the opengl-gamedev-l people that made Pawel start this project :) diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 16661e6..946ac6d 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -119,6 +119,9 @@ IF(WIN32) ENDIF() ELSEIF(ANDROID OR BLACKBERRY) + # BlackBerry and Android share some similar design concepts and ideas, as with many mobile devices. + # As such, some classes can be shared between the two. XXX: Possibly rename shareable classes to + # a more generic name. *_stub? *_mobile? LIST(APPEND FREEGLUT_SRCS src/android/fg_cursor_android.c src/android/fg_ext_android.c diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 90b11fe..63cca30 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -113,7 +113,8 @@ struct tagSFG_PlatformJoystick typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState; struct tagSFG_PlatformWindowState { - char unused; + int newWidth; + int newHeight; }; /* Menu font and color definitions */ diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 71f7b6d..6d2d03c 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -52,6 +52,7 @@ extern void fgPlatformHideWindow( SFG_Window *window ); extern void fgPlatformIconifyWindow( SFG_Window *window ); extern void fgPlatformShowWindow( SFG_Window *window ); extern void fgPlatformMainLoopPostWork ( void ); +extern void fgPlatformRotateWindow( SFG_Window *window, int rotation ); static struct touchscreen touchscreen; @@ -272,320 +273,364 @@ void fgPlatformProcessSingleEvent ( void ) return; } + if(fgDisplay.pDisplay.event == NULL) + /* Nothing to do */ + return; + int domain; do { - if(fgDisplay.pDisplay.event != NULL) { - SFG_Window* window = fgStructure.CurrentWindow; - if (window->Window.Handle != NULL) { - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); - } + SFG_Window* window = fgStructure.CurrentWindow; + domain = bps_event_get_domain(fgDisplay.pDisplay.event); + if (domain == screen_get_domain()) { + int eventType; + int mod; + screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); + switch (eventType) { - domain = bps_event_get_domain(fgDisplay.pDisplay.event); - if (domain == screen_get_domain()) { - int eventType; - int mod; - screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); - switch (eventType) { + //Mostly from fg_main_android + case SCREEN_EVENT_MTOUCH_TOUCH: + case SCREEN_EVENT_MTOUCH_RELEASE: + case SCREEN_EVENT_MTOUCH_MOVE: + { + mtouch_event_t touchEvent; + screen_get_mtouch_event(screenEvent, &touchEvent, 0); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); - //Mostly from fg_main_android - case SCREEN_EVENT_MTOUCH_TOUCH: - case SCREEN_EVENT_MTOUCH_RELEASE: - case SCREEN_EVENT_MTOUCH_MOVE: - { - mtouch_event_t touchEvent; - screen_get_mtouch_event(screenEvent, &touchEvent, 0); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod)); - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod)); + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); - /* Remember the current modifiers state so user can query it from their callback */ - fgState.Modifiers = fgPlatformGetModifiers(mod); - - if(touchEvent.contact_id == 0) { - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); - } - - //Now handle mutlitouch (adapted from fg_main_windows) - if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) { - INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_ENTERED ) ); - INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) ); - } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) { - INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) ); - //XXX No motion is performed without contact, thus MultiPassive is never used - } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { - INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); - INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); - } - - fgState.Modifiers = INVALID_MODIFIERS; - break; - } - - case SCREEN_EVENT_POINTER: - { - //Based off/part taken from GamePlay3d PlatformBlackBerry - static int mouse_pressed = 0; - int buttons; - int position[2]; - int wheel; - // A move event will be fired unless a button state changed. - bool move = true; - bool left_move = false; - // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + if(touchEvent.contact_id == 0) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); + } - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod)); + //Now handle mutlitouch (adapted from fg_main_windows) + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) { + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_ENTERED ) ); + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) ); + } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) { + INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) ); + //XXX No motion is performed without contact, thus MultiPassive is never used + } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); + } - //XXX Should multitouch be handled? + fgState.Modifiers = INVALID_MODIFIERS; + break; + } + + case SCREEN_EVENT_POINTER: + { + //Based off/part taken from GamePlay3d PlatformBlackBerry + static int mouse_pressed = 0; + int buttons; + int position[2]; + int wheel; + // A move event will be fired unless a button state changed. + bool move = true; + bool left_move = false; + // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod)); + + //XXX Should multitouch be handled? + + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); + + // Handle left mouse. Interpret as touch if the left mouse event is not consumed. + if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { + if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + left_move = true; + } else { + move = false; + mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); + } + } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); + } + + // Handle right mouse. + if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { + move = false; + mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); + } + } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); + } + + // Handle middle mouse. + if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { + move = false; + mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); + } + } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); + } + + // Fire a move event if none of the buttons changed. + if (left_move || move) { + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); + } + + if (wheel) { + /* Very slightly modified from fg_main_mswin. + * Because we don't want MouseWheel to be called every. single. time. + * That the action occurs, we mimic the Windows version with "wheel deltas" + * XXX Do we even want this? + * XXX If we want this, it's possible to get horizontal scroll as well. + * XXX -Vertical scroll=wheel 0, horizontal=wheel 1? */ + fgState.MouseWheelTicks -= wheel; + if (abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) + { + int wheel_number = 0; + int direction = (fgState.MouseWheelTicks > 0) ? -1 : 1; + + if (!FETCH_WCB(*window, MouseWheel) && !FETCH_WCB(*window, Mouse)) + break; + + //XXX fgSetWindow(window); + + while(abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) + { + if (FETCH_WCB(*window, MouseWheel)) + INVOKE_WCB(*window, MouseWheel, (wheel_number, direction, window->State.MouseX, window->State.MouseY)); + else /* No mouse wheel, call the mouse button callback twice */ + { + /* + * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4 + * " " one +1 to 5, -1 to 6, ... + * + * XXX The below assumes that you have no more than 3 mouse + * XXX buttons. Sorry. + */ + int button = wheel_number * 2 + 3; + if (direction < 0) + ++button; + INVOKE_WCB(*window, Mouse, (button, GLUT_DOWN, window->State.MouseX, window->State.MouseY)); + INVOKE_WCB(*window, Mouse, (button, GLUT_UP, window->State.MouseX, window->State.MouseY)); + } + + fgState.MouseWheelTicks -= WHEEL_DELTA * direction; + } + } + } + + fgState.Modifiers = INVALID_MODIFIERS; + break; + } + + //Based off fg_main_android + case SCREEN_EVENT_KEYBOARD: + { + int flags; + int value; + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X, Mod: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_SIGNED(mod)); + + /* Suppress key repeats if desired. Based off fg_main_mswin */ + if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_OFF && fgStructure.CurrentWindow->State.IgnoreKeyRepeat == GL_TRUE)) { + unsigned int keypress = 0; + unsigned char ascii = 0; /* Remember the current modifiers state so user can query it from their callback */ fgState.Modifiers = fgPlatformGetModifiers(mod); - // Handle left mouse. Interpret as touch if the left mouse event is not consumed. - if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { - if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { - left_move = true; + /* Process keys */ + if ((keypress = key_special(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); } else { - move = false; - mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); + INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); } - } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { - move = false; - mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); - } - - // Handle right mouse. - if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { - if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { - move = false; - mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); - } - } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { - move = false; - mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); - } - - // Handle middle mouse. - if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { - if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { - move = false; - mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); - } - } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { - move = false; - mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); - } - - // Fire a move event if none of the buttons changed. - if (left_move || move) { - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); - } - - if (wheel) { - /* Very slightly modified from fg_main_mswin. - * Because we don't want MouseWheel to be called every. single. time. - * That the action occurs, we mimic the Windows version with "wheel deltas" - * XXX Do we even want this? - * XXX If we want this, it's possible to get horizontal scroll as well. - * XXX -Vertical scroll=wheel 0, horizontal=wheel 1? */ - fgState.MouseWheelTicks -= wheel; - if (abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) - { - int wheel_number = 0; - int direction = (fgState.MouseWheelTicks > 0) ? -1 : 1; - - if (!FETCH_WCB(*window, MouseWheel) && !FETCH_WCB(*window, Mouse)) - break; - - //XXX fgSetWindow(window); - - while(abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) - { - if (FETCH_WCB(*window, MouseWheel)) - INVOKE_WCB(*window, MouseWheel, (wheel_number, direction, window->State.MouseX, window->State.MouseY)); - else /* No mouse wheel, call the mouse button callback twice */ - { - /* - * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4 - * " " one +1 to 5, -1 to 6, ... - * - * XXX The below assumes that you have no more than 3 mouse - * XXX buttons. Sorry. - */ - int button = wheel_number * 2 + 3; - if (direction < 0) - ++button; - INVOKE_WCB(*window, Mouse, (button, GLUT_DOWN, window->State.MouseX, window->State.MouseY)); - INVOKE_WCB(*window, Mouse, (button, GLUT_UP, window->State.MouseX, window->State.MouseY)); - } - - fgState.MouseWheelTicks -= WHEEL_DELTA * direction; - } + } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); + } else { + INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); } + } else { + LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event"); } fgState.Modifiers = INVALID_MODIFIERS; - break; } + break; + } - //Based off fg_main_android - case SCREEN_EVENT_KEYBOARD: + case SCREEN_EVENT_PROPERTY: + case SCREEN_EVENT_IDLE: + break; + + default: + LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); + break; + } + } else if (domain == navigator_get_domain()) { + int eventType = bps_event_get_code(fgDisplay.pDisplay.event); + switch (eventType) { + + case NAVIGATOR_WINDOW_STATE: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); + navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event); + switch (state) { - int flags; - int value; - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); - - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X, Mod: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_SIGNED(mod)); - - /* Suppress key repeats if desired. Based off fg_main_mswin */ - if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_OFF && fgStructure.CurrentWindow->State.IgnoreKeyRepeat == GL_TRUE)) { - unsigned int keypress = 0; - unsigned char ascii = 0; - - /* Remember the current modifiers state so user can query it from their callback */ - fgState.Modifiers = fgPlatformGetModifiers(mod); - - /* Process keys */ - if ((keypress = key_special(value))) { - if(flags & KEY_DOWN) { - INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); - } else { - INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); - } - } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { - if(flags & KEY_DOWN) { - INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); - } else { - INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); - } - } else { - LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event"); - } - - fgState.Modifiers = INVALID_MODIFIERS; - } + case NAVIGATOR_WINDOW_FULLSCREEN: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); break; - } - - case SCREEN_EVENT_PROPERTY: - case SCREEN_EVENT_IDLE: + case NAVIGATOR_WINDOW_THUMBNAIL: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL"); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_INVISIBLE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE"); + window->State.Visible = GL_FALSE; + INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); //XXX Should this be GLUT_FULLY_COVERED? break; - default: - LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); break; } - } else if (domain == navigator_get_domain()) { - int eventType = bps_event_get_code(fgDisplay.pDisplay.event); - switch (eventType) { + break; + } - case NAVIGATOR_WINDOW_STATE: - { - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); - navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event); - switch (state) - { - case NAVIGATOR_WINDOW_FULLSCREEN: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); - window->State.Visible = GL_TRUE; - INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); - break; - case NAVIGATOR_WINDOW_THUMBNAIL: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL"); - window->State.Visible = GL_TRUE; - INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); - break; - case NAVIGATOR_WINDOW_INVISIBLE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE"); - window->State.Visible = GL_FALSE; - INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); //XXX Should this be GLUT_FULLY_COVERED? - break; - default: - LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); - break; - } - break; + case NAVIGATOR_EXIT: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); + + fgPlatformMainLoopPostWork(); + + /* User closed the application for good, let's kill the window */ + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL) { + fgDestroyWindow(window); + } else { + LOGW("NAVIGATOR_EXIT: No current window"); } + break; + } - case NAVIGATOR_EXIT: - { - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); + case NAVIGATOR_SWIPE_DOWN: + /* XXX Open app menu */ + break; - fgPlatformMainLoopPostWork(); + /* Orientation is a bunch of handshakes. + - First the app get's asked if it wants to rotate (NAVIGATOR_ORIENTATION_CHECK) + - If the app wants to rotate, then it will be told what size it will be after rotate (NAVIGATOR_ORIENTATION_SIZE). + - Once the OS confirms that it's ready to rotate, it tells the app to handle rotation (NAVIGATOR_ORIENTATION). + - Once rotation is complete, the OS tells the app it's done (NAVIGATOR_ORIENTATION_DONE) */ + case NAVIGATOR_ORIENTATION_CHECK: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_CHECK"); - /* User closed the application for good, let's kill the window */ - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL) { - fgDestroyWindow(window); - } else { - LOGW("NAVIGATOR_EXIT: No current window"); - } - break; - } + /* Reset sizes */ + window->State.pWState.newWidth = 0; + window->State.pWState.newHeight = 0; - case NAVIGATOR_SWIPE_DOWN: - /* XXX Open app menu */ - break; + /* Notify that we want to rotate */ + navigator_orientation_check_response(fgDisplay.pDisplay.event, true); + break; - case NAVIGATOR_BACK: - /* XXX Should this be a Special/SpecialUp event? */ - break; + case NAVIGATOR_ORIENTATION: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION"); - case NAVIGATOR_WINDOW_ACTIVE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_ACTIVE"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); - break; + /* Rotate and resize the window */ + fgPlatformRotateWindow(window, navigator_event_get_orientation_angle(fgDisplay.pDisplay.event)); + fghOnReshapeNotify(window, window->State.pWState.newWidth, window->State.pWState.newHeight, GL_FALSE); - case NAVIGATOR_WINDOW_INACTIVE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_INACTIVE"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); - break; + /* Reset sizes */ + window->State.pWState.newWidth = 0; + window->State.pWState.newHeight = 0; - case NAVIGATOR_KEYBOARD_STATE: - case NAVIGATOR_KEYBOARD_POSITION: - /* TODO Something needs to be done with this. Not sure what */ - break; + /* Done rotating */ + navigator_done_orientation(fgDisplay.pDisplay.event); + break; - case NAVIGATOR_DEVICE_LOCK_STATE: - break; + case NAVIGATOR_BACK: + /* XXX Should this be a Special/SpecialUp event? */ + break; - case NAVIGATOR_WINDOW_COVER: - case NAVIGATOR_WINDOW_COVER_ENTER: - case NAVIGATOR_WINDOW_COVER_EXIT: - /* BlackBerry specific. Let app status and window status take care of everything */ - break; + case NAVIGATOR_WINDOW_ACTIVE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_ACTIVE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + break; - case NAVIGATOR_APP_STATE: - /* Can do the same as NAVIGATOR_WINDOW_ACTIVE/NAVIGATOR_WINDOW_INACTIVE but - seems less likely to work when the app comes to the foreground. Might be a bug */ - break; + case NAVIGATOR_WINDOW_INACTIVE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_INACTIVE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + break; - case 0: //Doesn't exist in header, but shows up when keyboard shows and resizes - break; + case NAVIGATOR_ORIENTATION_DONE: + case NAVIGATOR_ORIENTATION_RESULT: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_DONE\NAVIGATOR_ORIENTATION_RESULT"); + break; - default: - LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); - break; - } + case NAVIGATOR_KEYBOARD_STATE: + /* XXX Should something be done with this? */ + break; + + case NAVIGATOR_KEYBOARD_POSITION: + /* TODO Invoke resize with the modified screen size (((y + height) - keyboardPos) - y). + * If result is less then zero then window is covered. If == height, then no change in size. Else, change in size */ + break; + + case NAVIGATOR_DEVICE_LOCK_STATE: + break; + + case NAVIGATOR_WINDOW_COVER: + case NAVIGATOR_WINDOW_COVER_ENTER: + case NAVIGATOR_WINDOW_COVER_EXIT: + /* BlackBerry specific. Let app status and window status take care of everything */ + break; + + case NAVIGATOR_APP_STATE: + /* Can do the same as NAVIGATOR_WINDOW_ACTIVE/NAVIGATOR_WINDOW_INACTIVE but + seems less likely to work when the app comes to the foreground. Might be a bug */ + break; + + case NAVIGATOR_ORIENTATION_SIZE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_SIZE"); + + /* Get new window size */ + window->State.pWState.newWidth = navigator_event_get_orientation_size_width(fgDisplay.pDisplay.event); + window->State.pWState.newHeight = navigator_event_get_orientation_size_height(fgDisplay.pDisplay.event); + break; + + case 0: //Doesn't exist in header, but shows up when keyboard shows and resizes + break; + + default: + LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); + break; } } } while(bps_get_event(&fgDisplay.pDisplay.event, 1) == BPS_SUCCESS && fgDisplay.pDisplay.event != NULL); @@ -600,7 +645,9 @@ void fgPlatformMainLoopPreliminaryWork ( void ) /* Request navigator events */ navigator_request_events(0); - //XXX rotation lock? navigator_rotation_lock(true); + + /* Allow rotation */ + navigator_rotation_lock(false); /* Request window events */ screen_request_events(fgDisplay.pDisplay.screenContext); @@ -610,6 +657,7 @@ void fgPlatformMainLoopPostWork ( void ) { LOGI("fgPlatformMainLoopPostWork"); + /* Stop all events */ screen_stop_events(fgDisplay.pDisplay.screenContext); navigator_stop_events(0); @@ -623,6 +671,11 @@ void fgPlatformInitWork(SFG_Window* window) /* Position callback, always at 0,0 */ fghOnPositionNotify(window, 0, 0, GL_TRUE); + /* Get window size */ + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + fghOnReshapeNotify(window, size[0], size[1], GL_FALSE); + /* Size gets notified on window creation with size detection in mainloop above * XXX CHECK: does this messages happen too early like on windows, * so client code cannot have registered a callback yet and the message diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 61bd58d..f18512e 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -58,11 +58,12 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, fgDisplay.pDisplay.single_native_window = sWindow; /* Set window properties */ + int orientation = atoi(getenv("ORIENTATION")); int screenFormat = SCREEN_FORMAT_RGBA8888; //XXX Should this be determined by config? #ifdef GL_ES_VERSION_2_0 - int screenUsage = SCREEN_USAGE_OPENGL_ES2; + int screenUsage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 - int screenUsage = SCREEN_USAGE_OPENGL_ES1; + int screenUsage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION; #endif #ifndef __X86__ screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display @@ -78,8 +79,8 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, return; } - /* Uncomment when multiple windows are supported int value[2]; + /* Uncomment when multiple windows are supported if(positionUse) { value[0] = x; value[1] = y; @@ -88,17 +89,83 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, fgError("Could not set window position"); return; } - } + }*/ if(sizeUse) { + /* Uncomment when multiple windows are supported value[0] = w; value[1] = h; - if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { + */ + //TEMP until ^^ is uncommented + if (screen_get_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { screen_destroy_window(sWindow); - fgError("Could not set window buffer size"); + fgError("Could not get window mode"); return; } - }*/ + } else { + /* From PlatformBlackBerry in GamePlay3d */ + screen_display_t display; + if (screen_get_window_property_pv(sWindow, SCREEN_PROPERTY_DISPLAY, (void**)&display)) { + screen_destroy_window(sWindow); + fgError("Could not get window display"); + return; + } + + screen_display_mode_t displayMode; + if (screen_get_display_property_pv(display, SCREEN_PROPERTY_MODE, (void**)&displayMode)) { + screen_destroy_window(sWindow); + fgError("Could not get display mode"); + return; + } + + if (screen_get_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { + screen_destroy_window(sWindow); + fgError("Could not get window mode"); + return; + } + + /* Adjust buffer sizes based on rotation */ + if ((orientation == 0) || (orientation == 180)) + { + if (((displayMode.width > displayMode.height) && (value[0] < value[1])) || + ((displayMode.width < displayMode.height) && (value[0] > value[1]))) + { + int tmp = value[1]; + value[1] = value[0]; + value[0] = tmp; + } + } + else if ((orientation == 90) || (orientation == 270)) + { + if (((displayMode.width > displayMode.height) && (value[0] > value[1])) || + ((displayMode.width < displayMode.height) && (value[0] < value[1]))) + { + int tmp = value[1]; + value[1] = value[0]; + value[0] = tmp; + } + } + else + { + screen_destroy_window(sWindow); + fgError("Unexpected rotation angle"); + return; + } + } + + /* Set rotation if usage allows it */ + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_ROTATION, &orientation)) { + screen_destroy_window(sWindow); + fgError("Could not set window rotation"); + return; + } + + /* Set buffer sizes */ + if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { + screen_destroy_window(sWindow); + fgError("Could not set window buffer size"); + return; + } /* Create window buffers */ if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { @@ -108,7 +175,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, } /* Save window and set state */ - window->Window.Handle = fgDisplay.pDisplay.single_native_window; + window->Window.Handle = sWindow; window->State.WorkMask |= GLUT_INIT_WORK; window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now @@ -122,6 +189,11 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, window->State.Visible = GL_TRUE; } +void fgPlatformRotateWindow(SFG_Window* window, int rotation) +{ + screen_set_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_ROTATION, &rotation); +} + /* * Request a window resize */ @@ -162,6 +234,7 @@ void fgPlatformHideWindow( SFG_Window *window ) void fgPlatformIconifyWindow( SFG_Window *window ) { //XXX This is possible via Cascades, but can't seem to find a C-level API + //XXX bb::Application::instance()->minimize(); fprintf(stderr, "fgPlatformGlutIconifyWindow: STUB\n"); } diff --git a/freeglut/freeglut/src/fg_internal.h b/freeglut/freeglut/src/fg_internal.h index 4792ad8..6c1060f 100644 --- a/freeglut/freeglut/src/fg_internal.h +++ b/freeglut/freeglut/src/fg_internal.h @@ -45,7 +45,7 @@ #elif defined (__ANDROID__) # define TARGET_HOST_ANDROID 1 -#elif defined (__QNX__) +#elif defined (__QNXNTO__) # define TARGET_HOST_BLACKBERRY 1 #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun) From 241be47c45c344c743642ee2b0e1899e8215253b Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Sat, 14 Sep 2013 01:23:59 -0400 Subject: [PATCH 28/34] Made glutGet, for window width and height, return width and height determined by device rotation Now handles keyboard open/close (along wit device rotation while the keyboard is open) and resize The "back" operation now returns an ESCAPE key --- freeglut/freeglut/CMakeLists.txt | 3 +- .../src/blackberry/fg_internal_blackberry.h | 4 + .../src/blackberry/fg_main_blackberry.c | 159 +++++++++++++++--- .../src/blackberry/fg_state_blackberry.c | 10 ++ .../src/blackberry/fg_structure_blackberry.c | 40 +++++ .../src/blackberry/fg_window_blackberry.c | 12 +- 6 files changed, 198 insertions(+), 30 deletions(-) create mode 100644 freeglut/freeglut/src/blackberry/fg_structure_blackberry.c diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 946ac6d..28bab9d 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -128,7 +128,6 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/fg_gamemode_android.c src/android/fg_joystick_android.c src/android/fg_spaceball_android.c - src/android/fg_structure_android.c ) IF(ANDROID) LIST(APPEND FREEGLUT_SRCS @@ -141,6 +140,7 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/fg_main_android.h src/android/fg_runtime_android.c src/android/fg_state_android.c + src/android/fg_structure_android.c src/android/fg_window_android.c ) ELSE() @@ -150,6 +150,7 @@ ELSEIF(ANDROID OR BLACKBERRY) src/x11/fg_input_devices_x11.c src/blackberry/fg_main_blackberry.c src/blackberry/fg_state_blackberry.c + src/blackberry/fg_structure_blackberry.c src/blackberry/fg_window_blackberry.c ) ENDIF() diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 63cca30..0756219 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -34,6 +34,7 @@ #include "egl/fg_internal_egl.h" #include #include +#include /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */ /* The structure used by display initialization in freeglut_init.c */ @@ -115,6 +116,9 @@ struct tagSFG_PlatformWindowState { int newWidth; int newHeight; + int originalRotation; + navigator_window_state_t windowState; + GLboolean windowCovered; }; /* Menu font and color definitions */ diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 6d2d03c..20c3d1b 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -40,6 +40,7 @@ #include #include #include +#include extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify); extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify); @@ -53,9 +54,12 @@ extern void fgPlatformIconifyWindow( SFG_Window *window ); extern void fgPlatformShowWindow( SFG_Window *window ); extern void fgPlatformMainLoopPostWork ( void ); extern void fgPlatformRotateWindow( SFG_Window *window, int rotation ); +extern void fgPlatformFlushCommands ( void ); static struct touchscreen touchscreen; +#define ESCAPE_BUTTON_KEY 0x001B + unsigned int key_special(int qnxKeycode) { switch(qnxKeycode) { @@ -135,7 +139,7 @@ unsigned char key_ascii(int qnxKeycode) case KEYCODE_RETURN: return 0x000A; case KEYCODE_ESCAPE: - return 0x001B; + return ESCAPE_BUTTON_KEY; } } return qnxKeycode; @@ -161,7 +165,6 @@ fg_time_t fgPlatformSystemTime ( void ) */ void fgPlatformSleepForEvents( fg_time_t msec ) { - //XXX: Is this right? Is there a more direct way to access the context? if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } @@ -265,6 +268,57 @@ int fgPlatformGetModifiers (int mod) ((mod & KEYMOD_ALT) ? GLUT_ACTIVE_ALT : 0)); } +void fgPlatformHandleKeyboardHeight(SFG_Window* window, int height) +{ + int size[2]; + int screenHeight; + int nScreenHeight = -1; + + screenHeight = glutGet(GLUT_WINDOW_HEIGHT); //Using this takes rotation into account + if(height == 0) { + nScreenHeight = screenHeight; + } + else if(!screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_POSITION, size)) { + /* Calculate the new screen size */ //XXX Make sure to use display size instead of screen size + nScreenHeight = ((size[1] + screenHeight) - height) - size[1]; + } + + if(nScreenHeight != -1) { + /* If nScreenHeight is less then zero then window is covered. If nScreenHeight == height, then no change in size. Else, change in size */ + + int screenWidth = glutGet(GLUT_WINDOW_WIDTH); + if(nScreenHeight < 0) { + LOGI("fgPlatformHandleKeyboardHeight: Covered window state"); + window->State.Visible = GL_FALSE; + window->State.pWState.windowCovered = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_COVERED)); + fghOnReshapeNotify(window, screenWidth, 0, GL_FALSE); + } else { + if(window->State.pWState.windowCovered == GL_TRUE) { + LOGI("fgPlatformHandleKeyboardHeight: Resetting window state"); + + /* Reset window status if it was previously covered */ + switch(window->State.pWState.windowState) { + case NAVIGATOR_WINDOW_FULLSCREEN: + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_THUMBNAIL: + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_INVISIBLE: + window->State.Visible = GL_FALSE; + INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); + break; + } + window->State.pWState.windowCovered = GL_FALSE; + } + fghOnReshapeNotify(window, screenWidth, nScreenHeight, GL_FALSE); + } + } +} + void fgPlatformProcessSingleEvent ( void ) { if(fgStructure.CurrentWindow == NULL) { @@ -345,7 +399,7 @@ void fgPlatformProcessSingleEvent ( void ) LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod)); - //XXX Should multitouch be handled? + //XXX Is multitouch be handled in a good way? /* Remember the current modifiers state so user can query it from their callback */ fgState.Modifiers = fgPlatformGetModifiers(mod); @@ -499,28 +553,37 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_WINDOW_STATE: { LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); + + /* Covered only happens due to keyboard. When the app is minimized, the keyboard is closed. + When the keyboard is open, and the app is fullscreened, the keyboard is also closed. + If a window is covered and the app is minimized, the state will be set and the keyboard event + will adjust the screen size and change window status. */ navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event); - switch (state) + if(window->State.pWState.windowCovered == GL_FALSE) { - case NAVIGATOR_WINDOW_FULLSCREEN: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); - window->State.Visible = GL_TRUE; - INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); - break; - case NAVIGATOR_WINDOW_THUMBNAIL: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL"); - window->State.Visible = GL_TRUE; - INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); - break; - case NAVIGATOR_WINDOW_INVISIBLE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE"); - window->State.Visible = GL_FALSE; - INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); //XXX Should this be GLUT_FULLY_COVERED? - break; - default: - LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); - break; + switch (state) + { + case NAVIGATOR_WINDOW_FULLSCREEN: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_THUMBNAIL: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL"); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_INVISIBLE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE"); + window->State.Visible = GL_FALSE; + INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); + break; + default: + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); + break; + } } + window->State.pWState.windowState = state; break; } @@ -563,8 +626,11 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_ORIENTATION: LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION"); + /* NAVIGATOR_ORIENTATION occurs before NAVIGATOR_KEYBOARD_POSITION */ + /* Rotate and resize the window */ fgPlatformRotateWindow(window, navigator_event_get_orientation_angle(fgDisplay.pDisplay.event)); + fgPlatformFlushCommands(); fghOnReshapeNotify(window, window->State.pWState.newWidth, window->State.pWState.newHeight, GL_FALSE); /* Reset sizes */ @@ -576,7 +642,9 @@ void fgPlatformProcessSingleEvent ( void ) break; case NAVIGATOR_BACK: - /* XXX Should this be a Special/SpecialUp event? */ + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_BACK"); + INVOKE_WCB(*window, Keyboard, (ESCAPE_BUTTON_KEY, window->State.MouseX, window->State.MouseY)); + INVOKE_WCB(*window, KeyboardUp, (ESCAPE_BUTTON_KEY, window->State.MouseX, window->State.MouseY)); break; case NAVIGATOR_WINDOW_ACTIVE: @@ -591,17 +659,52 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_ORIENTATION_DONE: case NAVIGATOR_ORIENTATION_RESULT: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_DONE\NAVIGATOR_ORIENTATION_RESULT"); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_DONE/NAVIGATOR_ORIENTATION_RESULT"); break; case NAVIGATOR_KEYBOARD_STATE: - /* XXX Should something be done with this? */ + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE"); + + navigator_keyboard_state_t state = navigator_event_get_keyboard_state(fgDisplay.pDisplay.event); + switch (state) + { + case NAVIGATOR_KEYBOARD_CLOSED: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE-NAVIGATOR_KEYBOARD_CLOSED"); + /* NAVIGATOR_KEYBOARD_POSITION only occurs on open, so on keyboard close we need to reset the keyboard height */ + fgPlatformHandleKeyboardHeight(window, 0); + break; + case NAVIGATOR_KEYBOARD_OPENING: + case NAVIGATOR_KEYBOARD_OPENED: + case NAVIGATOR_KEYBOARD_CLOSING: + break; + case NAVIGATOR_KEYBOARD_UNRECOGNIZED: + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE-NAVIGATOR_KEYBOARD_UNRECOGNIZED"); + break; + default: + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); + break; + } break; + } case NAVIGATOR_KEYBOARD_POSITION: - /* TODO Invoke resize with the modified screen size (((y + height) - keyboardPos) - y). - * If result is less then zero then window is covered. If == height, then no change in size. Else, change in size */ + { + /* Occurs only when keyboard has opened or resizes */ + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_POSITION"); + + int keyboardOffset = navigator_event_get_keyboard_position(fgDisplay.pDisplay.event); + if(keyboardOffset == BPS_FAILURE) { + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_POSITION: getting keyboard offset failed"); + } else { + /* keyboardOffset is the offset from the top of the screen to the top of the keyboard, AKA the size of the uncovered screen + We want the height of the keyboard. So instead of determining the orientation, getting the right display size, and subtracting; + we just get the keyboard height which may be slower but easier to understand and work with */ + virtualkeyboard_get_height(&keyboardOffset); + fgPlatformHandleKeyboardHeight(window, keyboardOffset); + } break; + } case NAVIGATOR_DEVICE_LOCK_STATE: break; @@ -614,7 +717,7 @@ void fgPlatformProcessSingleEvent ( void ) case NAVIGATOR_APP_STATE: /* Can do the same as NAVIGATOR_WINDOW_ACTIVE/NAVIGATOR_WINDOW_INACTIVE but - seems less likely to work when the app comes to the foreground. Might be a bug */ + seems like it doesn't work when the app comes to the foreground. Might be a bug */ break; case NAVIGATOR_ORIENTATION_SIZE: diff --git a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c index f16aea6..c7991a9 100644 --- a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c @@ -102,8 +102,18 @@ int fgPlatformGlutGet ( GLenum eWhat ) if ( fgStructure.CurrentWindow == NULL ) return 0; int size[2]; + int orientation; if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0 ) return 0; + if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_ROTATION, &orientation) != 0 ) + return 0; + int orientationDif = abs(orientation - fgStructure.CurrentWindow->State.pWState.originalRotation); + if (orientationDif == 90 || orientationDif == 270) { + /* Swap dim. if screen is rotated */ + int tmp = size[0]; + size[0] = size[1]; + size[1] = tmp; + } switch ( eWhat ) { case GLUT_WINDOW_WIDTH: diff --git a/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c b/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c new file mode 100644 index 0000000..3fe233e --- /dev/null +++ b/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c @@ -0,0 +1,40 @@ +/* + * fg_structure_blackberry.c + * + * Windows and menus need tree structure + * + * Copyright (C) 2012 Sylvain Beucler + * Copyright (C) 2013 Vincent Simonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include "fg_internal.h" +#include "egl/fg_structure_egl.h" + +/** + * Initialize default platform-specific fields in SFG_Window + */ +void fgPlatformCreateWindow ( SFG_Window *window ) +{ + fghPlatformCreateWindowEGL(window); + + memset(&(window->State.pWState), 0, sizeof(SFG_PlatformWindowState)); + window->State.pWState.windowCovered = GL_FALSE; +} diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index f18512e..0cc14c9 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -159,6 +159,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, fgError("Could not set window rotation"); return; } + window->State.pWState.originalRotation = orientation; /* Set buffer sizes */ if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_BUFFER_SIZE, value)) { @@ -189,9 +190,18 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, window->State.Visible = GL_TRUE; } +void fgPlatformFlushCommands() +{ + if(screen_flush_context(fgDisplay.pDisplay.screenContext, 0)) { + fgWarning("Could not flush screen context"); + } +} + void fgPlatformRotateWindow(SFG_Window* window, int rotation) { - screen_set_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_ROTATION, &rotation); + if(screen_set_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_ROTATION, &rotation)) { + fgWarning("Could not set window rotation"); + } } /* From b241816870ee0fe5c87147d0db61885ec6519d01 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Sat, 14 Sep 2013 14:11:36 -0400 Subject: [PATCH 29/34] Hardcoded the RGB bitdepths for EGL surface creation. --- freeglut/freeglut/src/blackberry/fg_window_blackberry.c | 2 +- freeglut/freeglut/src/egl/fg_window_egl.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 0cc14c9..5689394 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -59,7 +59,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Set window properties */ int orientation = atoi(getenv("ORIENTATION")); - int screenFormat = SCREEN_FORMAT_RGBA8888; //XXX Should this be determined by config? + int screenFormat = SCREEN_FORMAT_RGBA8888; //Only SCREEN_FORMAT_RGBA8888 and SCREEN_FORMAT_RGB565 are supported. See fg_window_egl for more info #ifdef GL_ES_VERSION_2_0 int screenUsage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 diff --git a/freeglut/freeglut/src/egl/fg_window_egl.c b/freeglut/freeglut/src/egl/fg_window_egl.c index 6c4a7de..0e06233 100644 --- a/freeglut/freeglut/src/egl/fg_window_egl.c +++ b/freeglut/freeglut/src/egl/fg_window_egl.c @@ -36,9 +36,18 @@ int fghChooseConfig(EGLConfig* config) { #else EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, #endif +#ifdef TARGET_HOST_BLACKBERRY + /* Only 888 and 565 seem to work. Based on + http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp + That's all that is used, and that's what BlackBerry uses for their own internal OpenGL setup, so unless something else is determined, use it */ + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, +#else EGL_BLUE_SIZE, 1, EGL_GREEN_SIZE, 1, EGL_RED_SIZE, 1, +#endif EGL_ALPHA_SIZE, (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0, EGL_DEPTH_SIZE, (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0, EGL_STENCIL_SIZE, (fgState.DisplayMode & GLUT_STENCIL) ? 1 : 0, From 468e13e95863fe00721744d534978aa27b65496a Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Sat, 14 Sep 2013 19:24:32 -0400 Subject: [PATCH 30/34] Info logging only shows in debug compilation Added support for UseCurrentContext flag Updated fghPlatformCloseWindowEGL for performance so that eglMakeCurrent isn't invoked unless it's the current window and that the EGL context isn't destroyed unless no other windows uses --- .../src/blackberry/fg_main_blackberry.c | 7 +++- .../src/blackberry/fg_window_blackberry.c | 6 +++- freeglut/freeglut/src/egl/fg_window_egl.c | 35 ++++++++++++++----- freeglut/freeglut/src/fg_init.c | 14 ++++---- freeglut/freeglut/src/fg_window.c | 10 +++--- 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 20c3d1b..89474d0 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -32,7 +32,11 @@ #include "egl/fg_window_egl.h" #include +#ifdef NDEBUG +#define LOGI(...) +#else #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) +#endif #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END)) #include #include @@ -165,7 +169,8 @@ fg_time_t fgPlatformSystemTime ( void ) */ void fgPlatformSleepForEvents( fg_time_t msec ) { - if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { + if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && + bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } } diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 5689394..0b7d80b 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -182,7 +182,11 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, /* Create context */ fghChooseConfig(&window->Window.pContext.egl.Config); - window->Window.Context = fghCreateNewContextEGL(window); + window->Window.Context = EGL_NO_CONTEXT; + if( fgState.UseCurrentContext == GL_TRUE ) + window->Window.Context = eglGetCurrentContext(); + if( window->Window.Context == EGL_NO_CONTEXT ) + window->Window.Context = fghCreateNewContextEGL(window); /* Create EGL window */ fghPlatformOpenWindowEGL(window); diff --git a/freeglut/freeglut/src/egl/fg_window_egl.c b/freeglut/freeglut/src/egl/fg_window_egl.c index 0e06233..2141c5c 100644 --- a/freeglut/freeglut/src/egl/fg_window_egl.c +++ b/freeglut/freeglut/src/egl/fg_window_egl.c @@ -41,8 +41,8 @@ int fghChooseConfig(EGLConfig* config) { http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp That's all that is used, and that's what BlackBerry uses for their own internal OpenGL setup, so unless something else is determined, use it */ EGL_BLUE_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, #else EGL_BLUE_SIZE, 1, EGL_GREEN_SIZE, 1, @@ -58,7 +58,7 @@ int fghChooseConfig(EGLConfig* config) { EGLint num_config; if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, - attribs, config, 1, &num_config)) { + attribs, config, 1, &num_config)) { fgWarning("eglChooseConfig: error %x\n", eglGetError()); return 0; } @@ -105,9 +105,9 @@ void fgPlatformSetWindow ( SFG_Window *window ) { if ( window != fgStructure.CurrentWindow && window) { if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, - window->Window.pContext.egl.Surface, - window->Window.pContext.egl.Surface, - window->Window.Context) == EGL_FALSE) + window->Window.pContext.egl.Surface, + window->Window.pContext.egl.Surface, + window->Window.Context) == EGL_FALSE) fgError("eglMakeCurrent: err=%x\n", eglGetError()); } } @@ -138,9 +138,28 @@ void fghPlatformOpenWindowEGL( SFG_Window* window ) */ void fghPlatformCloseWindowEGL( SFG_Window* window ) { - eglMakeCurrent(fgDisplay.pDisplay.egl.Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + /* Based on fg_window_mswin fgPlatformCloseWindow */ + if( fgStructure.CurrentWindow == window ) + eglMakeCurrent(fgDisplay.pDisplay.egl.Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (window->Window.Context != EGL_NO_CONTEXT) { - eglDestroyContext(fgDisplay.pDisplay.egl.Display, window->Window.Context); + /* Step through the list of windows. If the rendering context is not being used by another window, then delete it */ + { + GLboolean used = GL_FALSE; + SFG_Window *iter; + + for( iter = (SFG_Window*)fgStructure.Windows.First; + iter && used == GL_FALSE; + iter = (SFG_Window*)iter->Node.Next) + { + if( (iter->Window.Context == window->Window.Context) && + (iter != window) ) + used = GL_TRUE; + } + + if( !used ) + eglDestroyContext(fgDisplay.pDisplay.egl.Display, window->Window.Context); + } window->Window.Context = EGL_NO_CONTEXT; } diff --git a/freeglut/freeglut/src/fg_init.c b/freeglut/freeglut/src/fg_init.c index 0b6e29d..4061836 100644 --- a/freeglut/freeglut/src/fg_init.c +++ b/freeglut/freeglut/src/fg_init.c @@ -110,7 +110,7 @@ void fghParseCommandLineArguments ( int* pargc, char** argv, char **pDisplayName int i, j, argc = *pargc; { - /* check if GLUT_FPS env var is set */ + /* check if GLUT_FPS env var is set */ const char *fps = getenv( "GLUT_FPS" ); if( fps ) @@ -229,7 +229,7 @@ void fgDeinitialize( void ) return; } - /* If we're in game mode, we want to leave game mode */ + /* If we're in game mode, we want to leave game mode */ if( fgStructure.GameModeWindow ) { glutLeaveGameMode(); } @@ -237,7 +237,7 @@ void fgDeinitialize( void ) /* If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { - fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext ); + fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext ); free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } @@ -256,9 +256,9 @@ void fgDeinitialize( void ) free( timer ); } - fgPlatformDeinitialiseInputDevices (); + fgPlatformDeinitialiseInputDevices (); - fgState.MouseWheelTicks = 0; + fgState.MouseWheelTicks = 0; fgState.MajorVersion = 1; fgState.MinorVersion = 0; @@ -310,7 +310,7 @@ void fgDeinitialize( void ) fgState.ProgramName = NULL; } - fgPlatformCloseDisplay (); + fgPlatformCloseDisplay (); fgState.Initialised = GL_FALSE; } @@ -342,7 +342,7 @@ void FGAPIENTRY glutInit( int* pargc, char** argv ) fgCreateStructure( ); - fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry ); + fghParseCommandLineArguments ( pargc, argv, &displayName, &geometry ); /* * Have the display created now. If there wasn't a "-display" diff --git a/freeglut/freeglut/src/fg_window.c b/freeglut/freeglut/src/fg_window.c index d61be0d..cf1dff8 100644 --- a/freeglut/freeglut/src/fg_window.c +++ b/freeglut/freeglut/src/fg_window.c @@ -106,7 +106,7 @@ void fghContextCreationError( void ) */ void fgSetWindow ( SFG_Window *window ) { - fgPlatformSetWindow ( window ); + fgPlatformSetWindow ( window ); fgStructure.CurrentWindow = window; } @@ -158,7 +158,7 @@ void fgCloseWindow( SFG_Window* window ) if (fgStructure.GameModeWindow != NULL && fgStructure.GameModeWindow->ID==window->ID) glutLeaveGameMode(); - fgPlatformCloseWindow ( window ); + fgPlatformCloseWindow ( window ); } @@ -335,7 +335,7 @@ void FGAPIENTRY glutSetWindowTitle( const char* title ) FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSetWindowTitle" ); if( ! fgStructure.CurrentWindow->Parent ) { - fgPlatformGlutSetWindowTitle ( title ); + fgPlatformGlutSetWindowTitle ( title ); } } @@ -349,7 +349,7 @@ void FGAPIENTRY glutSetIconTitle( const char* title ) if( ! fgStructure.CurrentWindow->Parent ) { - fgPlatformGlutSetIconTitle ( title ); + fgPlatformGlutSetIconTitle ( title ); } } @@ -445,7 +445,7 @@ void FGAPIENTRY glutFullScreen( void ) } if (!win->State.IsFullscreen) - win->State.WorkMask |= GLUT_FULL_SCREEN_WORK; + win->State.WorkMask |= GLUT_FULL_SCREEN_WORK; } /* From 325873c14e9738aea72eb93b2f2df2d32c47fe86 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Tue, 17 Sep 2013 01:50:15 -0400 Subject: [PATCH 31/34] Added BlackBerry PlayBook support Bug memleak when getting the number of mouse buttons on a non-PlayBook where an appropriate device is found and the value is returned --- freeglut/freeglut/CMakeLists.txt | 26 ++++++-- freeglut/freeglut/blackberry.toolchain.cmake | 31 ++++++++-- .../src/blackberry/fg_main_blackberry.c | 60 ++++++++++++++++++- .../src/blackberry/fg_state_blackberry.c | 20 +++++-- .../src/blackberry/fg_window_blackberry.c | 3 +- freeglut/freeglut/src/fg_internal.h | 10 +++- 6 files changed, 128 insertions(+), 22 deletions(-) diff --git a/freeglut/freeglut/CMakeLists.txt b/freeglut/freeglut/CMakeLists.txt index 28bab9d..6feb753 100644 --- a/freeglut/freeglut/CMakeLists.txt +++ b/freeglut/freeglut/CMakeLists.txt @@ -269,10 +269,16 @@ IF(ANDROID) # -llog for native Android logging LIST(APPEND LIBS android log) ELSEIF(BLACKBERRY) - # -lbps for event loop - # -lslog2 for logging - # -screen for native screen - LIST(APPEND LIBS bps slog2 screen) + if(PLAYBOOK) + # -lbps for event loop + # -screen for native screen + LIST(APPEND LIBS bps screen) + ELSE() + # -lbps for event loop + # -lslog2 for logging + # -screen for native screen + LIST(APPEND LIBS bps slog2 screen) + ENDIF() ENDIF() INCLUDE(CheckFunctionExists) @@ -487,7 +493,11 @@ ELSEIF(FREEGLUT_GLES2) IF(ANDROID) SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm") ELSEIF(BLACKBERRY) - SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lEGL -lm") + IF(PLAYBOOK) + SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv2 -lEGL -lm") + ELSE() + SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lEGL -lm") + ENDIF() ELSE() SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lEGL -lm") ENDIF() @@ -495,7 +505,11 @@ ELSEIF(FREEGLUT_GLES1) IF(ANDROID) SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv1_CM -lEGL -lm") ELSEIF(BLACKBERRY) - SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv1_CM -lEGL -lm") + IF(PLAYBOOK) + SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv1_CM -lEGL -lm") + ELSE() + SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv1_CM -lEGL -lm") + ENDIF() ELSE() SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv1_CM -lEGL -lm") ENDIF() diff --git a/freeglut/freeglut/blackberry.toolchain.cmake b/freeglut/freeglut/blackberry.toolchain.cmake index 4c9d264..47198f9 100644 --- a/freeglut/freeglut/blackberry.toolchain.cmake +++ b/freeglut/freeglut/blackberry.toolchain.cmake @@ -32,6 +32,11 @@ set( BLACKBERRY_TARGET_ROOT "$ENV{QNX_TARGET}" ) set( CMAKE_SYSTEM_NAME Linux ) set( CMAKE_SYSTEM_VERSION 1 ) +# Check for PlayBook +if( EXISTS "${BLACKBERRY_TARGET_ROOT}/usr/include" ) +set( PLAYBOOK True ) +endif() + # STL version: by default gnustl_static will be used set( BLACKBERRY_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static") mark_as_advanced( BLACKBERRY_USE_STLPORT ) @@ -91,15 +96,29 @@ else() endif() # Includes -list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" ) +if( PLAYBOOK ) + list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/usr/include" ) +else() + list( APPEND BLACKBERRY_SYSTEM_INCLUDE_DIRS "${BLACKBERRY_TARGET_ROOT}/qnx6/usr/include" ) +endif() # Flags and preprocessor definitions if( BLACKBERRY_ARCHITECTURE STREQUAL "arm" ) - set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntoarmv7le -D__QNX__" ) - set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntoarmv7le -Y_gpp -D__QNX__" ) + if( PLAYBOOK ) + set( BLACKBERRY_CC_FLAGS " -V4.4.2,gcc_ntoarmv7le -D__PLAYBOOK__" ) + set( BLACKBERRY_CXX_FLAGS " -V4.4.2,gcc_ntoarmv7le -Y_gpp -D__PLAYBOOK__" ) + else() + set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntoarmv7le -D__QNX__" ) + set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntoarmv7le -Y_gpp -D__QNX__" ) + endif() else() - set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntox86 -D__QNX__" ) - set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntox86 -Y_gpp -D__QNX__" ) + if( PLAYBOOK ) + set( BLACKBERRY_CC_FLAGS " -V4.4.2,gcc_ntox86 -D__PLAYBOOK__" ) + set( BLACKBERRY_CXX_FLAGS " -V4.4.2,gcc_ntox86 -Y_gpp -D__PLAYBOOK__" ) + else() + set( BLACKBERRY_CC_FLAGS " -V4.6.3,gcc_ntox86 -D__QNX__" ) + set( BLACKBERRY_CXX_FLAGS " -V4.6.3,gcc_ntox86 -Y_gpp -D__QNX__" ) + endif() endif() set( BLACKBERRY 1 ) @@ -131,7 +150,7 @@ set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" ) SET( CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" CACHE STRING "linker flags") SET( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" CACHE STRING "linker flags") set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" ) -set( CMAKE_EXE_LINKER_FLAGS "-lstdc++ -lm -lEGL -lGLESv2 -lbps -lscreen" CACHE STRING "linker flags" ) +set( CMAKE_EXE_LINKER_FLAGS "-lstdc++" CACHE STRING "linker flags" ) # Finish flags set( BLACKBERRY_CXX_FLAGS "${BLACKBERRY_CXX_FLAGS}" CACHE INTERNAL "Extra BlackBerry compiler flags") diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 89474d0..4aa6759 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -31,6 +31,18 @@ #include "fg_internal.h" #include "egl/fg_window_egl.h" +#ifdef __PLAYBOOK__ +#include +#ifdef NDEBUG +#define LOGI(...) +#else +#define LOGI(...) ((void)slogf(1337, _SLOG_INFO, __VA_ARGS__)) +#endif +#define LOGW(...) ((void)slogf(1337, _SLOG_WARNING, __VA_ARGS__)) +#ifndef SLOG2_FA_SIGNED +#define SLOG2_FA_SIGNED(x) (x) +#endif +#else #include #ifdef NDEBUG #define LOGI(...) @@ -38,6 +50,7 @@ #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) #endif #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END)) +#endif #include #include #include @@ -355,7 +368,11 @@ void fgPlatformProcessSingleEvent ( void ) { mtouch_event_t touchEvent; screen_get_mtouch_event(screenEvent, &touchEvent, 0); +#ifndef __PLAYBOOK__ screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); +#else + mod = 0; +#endif LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod)); @@ -397,8 +414,12 @@ void fgPlatformProcessSingleEvent ( void ) // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); +#ifndef __PLAYBOOK__ screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); +#else + wheel = mod = 0; +#endif int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); @@ -552,7 +573,7 @@ void fgPlatformProcessSingleEvent ( void ) break; } } else if (domain == navigator_get_domain()) { - int eventType = bps_event_get_code(fgDisplay.pDisplay.event); + unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event); switch (eventType) { case NAVIGATOR_WINDOW_STATE: @@ -636,6 +657,11 @@ void fgPlatformProcessSingleEvent ( void ) /* Rotate and resize the window */ fgPlatformRotateWindow(window, navigator_event_get_orientation_angle(fgDisplay.pDisplay.event)); fgPlatformFlushCommands(); +#ifdef __PLAYBOOK__ + /* PlayBook doesn't indicate what the new size will be, so we need to retrieve it from the window itself */ + window->State.pWState.newWidth = glutGet(GLUT_WINDOW_WIDTH); + window->State.pWState.newHeight = glutGet(GLUT_WINDOW_HEIGHT); +#endif fghOnReshapeNotify(window, window->State.pWState.newWidth, window->State.pWState.newHeight, GL_FALSE); /* Reset sizes */ @@ -667,6 +693,7 @@ void fgPlatformProcessSingleEvent ( void ) LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_DONE/NAVIGATOR_ORIENTATION_RESULT"); break; +#ifndef __PLAYBOOK__ case NAVIGATOR_KEYBOARD_STATE: { LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE"); @@ -732,6 +759,7 @@ void fgPlatformProcessSingleEvent ( void ) window->State.pWState.newWidth = navigator_event_get_orientation_size_width(fgDisplay.pDisplay.event); window->State.pWState.newHeight = navigator_event_get_orientation_size_height(fgDisplay.pDisplay.event); break; +#endif case 0: //Doesn't exist in header, but shows up when keyboard shows and resizes break; @@ -741,6 +769,29 @@ void fgPlatformProcessSingleEvent ( void ) break; } } +#ifdef __PLAYBOOK__ + else if(domain == virtualkeyboard_get_domain()) { + unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event); + switch (eventType) { + case VIRTUALKEYBOARD_EVENT_VISIBLE: + break; + + case VIRTUALKEYBOARD_EVENT_HIDDEN: + LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_HIDDEN"); + fgPlatformHandleKeyboardHeight(window, 0); + break; + + case VIRTUALKEYBOARD_EVENT_INFO: + LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_INFO"); + fgPlatformHandleKeyboardHeight(window, virtualkeyboard_event_get_height(fgDisplay.pDisplay.event)); + break; + + default: + LOGW("fgPlatformProcessSingleEvent: unknown virtualkeyboard event: 0x%X", eventType); + break; + } + } +#endif } while(bps_get_event(&fgDisplay.pDisplay.event, 1) == BPS_SUCCESS && fgDisplay.pDisplay.event != NULL); /* Reset event to reduce chances of triggering something */ @@ -757,6 +808,11 @@ void fgPlatformMainLoopPreliminaryWork ( void ) /* Allow rotation */ navigator_rotation_lock(false); +#ifdef __PLAYBOOK__ + /* Request keyboard events */ + virtualkeyboard_request_events(0); +#endif + /* Request window events */ screen_request_events(fgDisplay.pDisplay.screenContext); } @@ -768,7 +824,9 @@ void fgPlatformMainLoopPostWork ( void ) /* Stop all events */ screen_stop_events(fgDisplay.pDisplay.screenContext); +#ifndef __PLAYBOOK__ navigator_stop_events(0); +#endif } /* deal with work list items */ diff --git a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c index c7991a9..246ba04 100644 --- a/freeglut/freeglut/src/blackberry/fg_state_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_state_blackberry.c @@ -35,8 +35,10 @@ //From fg_state_android.c int fgPlatformGlutDeviceGet ( GLenum eWhat ) { +#ifndef __PLAYBOOK__ int deviceCount, i, value; screen_device_t* devices; +#endif switch( eWhat ) { @@ -51,7 +53,8 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat ) case GLUT_NUM_MOUSE_BUTTONS: /* BlackBerry has a touchscreen, which we can consider a 1-button mouse at min. - Otherwise check for an actual mouse, else get max touch points */ + Otherwise check for an actual mouse, else get max touch points. PlayBook does not support this. */ +#ifndef __PLAYBOOK__ if(!screen_get_context_property_iv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount)) { devices = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t)); if(!screen_get_context_property_pv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DEVICES, (void**)devices)) { @@ -60,6 +63,7 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat ) if(!screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &value) && value == SCREEN_EVENT_POINTER && !screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_BUTTON_COUNT, &value)) { + free(devices); return value; } } @@ -68,12 +72,14 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat ) if(!screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &value) && value == SCREEN_EVENT_MTOUCH_TOUCH && !screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_MAXIMUM_TOUCH_ID, &value)) { + free(devices); return value; } } } free(devices); } +#endif /* Backup, pretend it's a 1-button mouse */ return 1; @@ -101,18 +107,20 @@ int fgPlatformGlutGet ( GLenum eWhat ) { if ( fgStructure.CurrentWindow == NULL ) return 0; + int size[2]; int orientation; if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0 ) return 0; if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_ROTATION, &orientation) != 0 ) - return 0; + return 0; + int orientationDif = abs(orientation - fgStructure.CurrentWindow->State.pWState.originalRotation); if (orientationDif == 90 || orientationDif == 270) { - /* Swap dim. if screen is rotated */ - int tmp = size[0]; - size[0] = size[1]; - size[1] = tmp; + /* Swap dim. if screen is rotated */ + int tmp = size[0]; + size[0] = size[1]; + size[1] = tmp; } switch ( eWhat ) { diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index 0b7d80b..e88653c 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -32,7 +32,6 @@ #include "fg_internal.h" #include "egl/fg_window_egl.h" #include -#include /* * Opens a window. Requires a SFG_Window object created and attached @@ -65,7 +64,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 int screenUsage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION; #endif -#ifndef __X86__ +#if !defined(__X86__) && !defined(__PLAYBOOK__) screenUsage |= SCREEN_USAGE_DISPLAY; // Physical device copy directly into physical display #endif if (screen_set_window_property_iv(sWindow, SCREEN_PROPERTY_FORMAT, &screenFormat)) { diff --git a/freeglut/freeglut/src/fg_internal.h b/freeglut/freeglut/src/fg_internal.h index 6c1060f..6698865 100644 --- a/freeglut/freeglut/src/fg_internal.h +++ b/freeglut/freeglut/src/fg_internal.h @@ -45,7 +45,7 @@ #elif defined (__ANDROID__) # define TARGET_HOST_ANDROID 1 -#elif defined (__QNXNTO__) +#elif defined (__QNXNTO__) || defined (__PLAYBOOK__) # define TARGET_HOST_BLACKBERRY 1 #elif defined(__posix__) || defined(__unix__) || defined(__linux__) || defined(__sun) @@ -71,6 +71,14 @@ # define TARGET_HOST_MS_WINDOWS 0 #endif +#ifndef TARGET_HOST_ANDROID +# define TARGET_HOST_ANDROID 0 +#endif + +#ifndef TARGET_HOST_BLACKBERRY +# define TARGET_HOST_BLACKBERRY 0 +#endif + #ifndef TARGET_HOST_POSIX_X11 # define TARGET_HOST_POSIX_X11 0 #endif From 447b1167d007b72452543dc3bd2bf5be591fa632 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Wed, 18 Sep 2013 02:00:26 -0400 Subject: [PATCH 32/34] Updated toolchain so that it does a more exact check if this is for PlayBook or BlackBerry 10 Fixed bug with keyboard on PlayBook where keyboard heights only occurred on rotation, and resize would occur twice because of it and resize wouldn't happen for keyboard --- freeglut/freeglut/blackberry.toolchain.cmake | 2 +- .../src/blackberry/fg_internal_blackberry.h | 16 +++++--- .../src/blackberry/fg_main_blackberry.c | 41 +++++++++++++++---- .../src/blackberry/fg_structure_blackberry.c | 3 ++ 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/freeglut/freeglut/blackberry.toolchain.cmake b/freeglut/freeglut/blackberry.toolchain.cmake index 47198f9..958e4ba 100644 --- a/freeglut/freeglut/blackberry.toolchain.cmake +++ b/freeglut/freeglut/blackberry.toolchain.cmake @@ -33,7 +33,7 @@ set( CMAKE_SYSTEM_NAME Linux ) set( CMAKE_SYSTEM_VERSION 1 ) # Check for PlayBook -if( EXISTS "${BLACKBERRY_TARGET_ROOT}/usr/include" ) +if( EXISTS "${BLACKBERRY_TARGET_ROOT}/x86/lib/gcc/4.4.2" ) set( PLAYBOOK True ) endif() diff --git a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h index 0756219..d06f9e1 100644 --- a/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h +++ b/freeglut/freeglut/src/blackberry/fg_internal_blackberry.h @@ -43,7 +43,7 @@ struct tagSFG_PlatformDisplay { struct tagSFG_PlatformDisplayEGL egl; screen_context_t screenContext; - bps_event_t* event; + bps_event_t* event; EGLNativeWindowType single_native_window; }; @@ -114,11 +114,15 @@ struct tagSFG_PlatformJoystick typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState; struct tagSFG_PlatformWindowState { - int newWidth; - int newHeight; - int originalRotation; - navigator_window_state_t windowState; - GLboolean windowCovered; + int newWidth; + int newHeight; + int originalRotation; + navigator_window_state_t windowState; + GLboolean windowCovered; +#ifdef __PLAYBOOK__ + int keyboardHeight; + GLboolean keyboardOpen; +#endif }; /* Menu font and color definitions */ diff --git a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c index 4aa6759..07ec16c 100644 --- a/freeglut/freeglut/src/blackberry/fg_main_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_main_blackberry.c @@ -31,11 +31,13 @@ #include "fg_internal.h" #include "egl/fg_window_egl.h" -#ifdef __PLAYBOOK__ -#include #ifdef NDEBUG #define LOGI(...) -#else +#endif + +#ifdef __PLAYBOOK__ +#include +#ifndef LOGI #define LOGI(...) ((void)slogf(1337, _SLOG_INFO, __VA_ARGS__)) #endif #define LOGW(...) ((void)slogf(1337, _SLOG_WARNING, __VA_ARGS__)) @@ -44,9 +46,7 @@ #endif #else #include -#ifdef NDEBUG -#define LOGI(...) -#else +#ifndef LOGI #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) #endif #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END)) @@ -353,6 +353,12 @@ void fgPlatformProcessSingleEvent ( void ) do { SFG_Window* window = fgStructure.CurrentWindow; +#ifdef __PLAYBOOK__ + /* Get the keyboard height before doing anything since we otherwise don't get it until it changes */ + if(window->State.pWState.keyboardHeight == 0) { + virtualkeyboard_get_height(&window->State.pWState.keyboardHeight); + } +#endif domain = bps_event_get_domain(fgDisplay.pDisplay.event); if (domain == screen_get_domain()) { int eventType; @@ -626,6 +632,8 @@ void fgPlatformProcessSingleEvent ( void ) } else { LOGW("NAVIGATOR_EXIT: No current window"); } + + //XXX Should this be a bit more "forceful" so that it doesn't continue to loop through events? break; } @@ -645,6 +653,11 @@ void fgPlatformProcessSingleEvent ( void ) window->State.pWState.newWidth = 0; window->State.pWState.newHeight = 0; +#ifdef __PLAYBOOK__ + /* On rotation, the keyboard is closed. This prevents two resize calls */ + window->State.pWState.keyboardOpen = GL_FALSE; +#endif + /* Notify that we want to rotate */ navigator_orientation_check_response(fgDisplay.pDisplay.event, true); break; @@ -770,20 +783,32 @@ void fgPlatformProcessSingleEvent ( void ) } } #ifdef __PLAYBOOK__ + /* While this could be used for non-PlayBook, BlackBerry 10 will still get navigator events, so use those. They are a bit more exact. */ else if(domain == virtualkeyboard_get_domain()) { unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event); switch (eventType) { case VIRTUALKEYBOARD_EVENT_VISIBLE: + LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_VISIBLE"); + if(window->State.pWState.keyboardOpen != GL_TRUE) { + window->State.pWState.keyboardOpen = GL_TRUE; + fgPlatformHandleKeyboardHeight(window, window->State.pWState.keyboardHeight); + } break; case VIRTUALKEYBOARD_EVENT_HIDDEN: LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_HIDDEN"); - fgPlatformHandleKeyboardHeight(window, 0); + if(window->State.pWState.keyboardOpen != GL_FALSE) { + window->State.pWState.keyboardOpen = GL_FALSE; + fgPlatformHandleKeyboardHeight(window, 0); + } break; case VIRTUALKEYBOARD_EVENT_INFO: LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_INFO"); - fgPlatformHandleKeyboardHeight(window, virtualkeyboard_event_get_height(fgDisplay.pDisplay.event)); + window->State.pWState.keyboardHeight = virtualkeyboard_event_get_height(fgDisplay.pDisplay.event); + if(window->State.pWState.keyboardOpen == GL_TRUE) { + fgPlatformHandleKeyboardHeight(window, window->State.pWState.keyboardHeight); + } break; default: diff --git a/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c b/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c index 3fe233e..d6eab8f 100644 --- a/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_structure_blackberry.c @@ -37,4 +37,7 @@ void fgPlatformCreateWindow ( SFG_Window *window ) memset(&(window->State.pWState), 0, sizeof(SFG_PlatformWindowState)); window->State.pWState.windowCovered = GL_FALSE; +#ifdef __PLAYBOOK__ + window->State.pWState.keyboardOpen = GL_FALSE; +#endif } From 2083d8cbe6ab05426a7df2f22c72d30ea0bba210 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Mon, 18 Nov 2013 11:37:43 -0500 Subject: [PATCH 33/34] BlackBerry and Android -Added ability for developer to choose OpenGL ES version (2.0 or 3.0) via glutInitContextVersion (only the major version is used) BlackBerry specific -Added better documentation on required window bit depth for BlackBerry. -Modified screen format picking so it will choose either RGBA8888 or RGB565 instead of always using RGBA8888 --- .../freeglut/src/blackberry/fg_window_blackberry.c | 13 +++++++++++-- freeglut/freeglut/src/egl/fg_window_egl.c | 12 ++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c index e88653c..c0e2ce4 100644 --- a/freeglut/freeglut/src/blackberry/fg_window_blackberry.c +++ b/freeglut/freeglut/src/blackberry/fg_window_blackberry.c @@ -56,9 +56,19 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, } fgDisplay.pDisplay.single_native_window = sWindow; + /* Choose config and screen format */ + fghChooseConfig(&window->Window.pContext.egl.Config); + int screenFormat = SCREEN_FORMAT_RGBA8888; //Only SCREEN_FORMAT_RGBA8888 and SCREEN_FORMAT_RGB565 are supported. See fg_window_egl for more info + int configAttri; +#define EGL_QUERY_COMP(att, comp) (eglGetConfigAttrib(fgDisplay.pDisplay.egl.Display, window->Window.pContext.egl.Config, att, &configAttri) == GL_TRUE && (configAttri comp)) + if(EGL_QUERY_COMP(EGL_ALPHA_SIZE, <= 0) && EGL_QUERY_COMP(EGL_RED_SIZE, <= 5) && + EGL_QUERY_COMP(EGL_GREEN_SIZE, <= 6) && EGL_QUERY_COMP(EGL_BLUE_SIZE, <= 5)) { + screenFormat = SCREEN_FORMAT_RGB565; + } +#undef EGL_QUERY_COMP + /* Set window properties */ int orientation = atoi(getenv("ORIENTATION")); - int screenFormat = SCREEN_FORMAT_RGBA8888; //Only SCREEN_FORMAT_RGBA8888 and SCREEN_FORMAT_RGB565 are supported. See fg_window_egl for more info #ifdef GL_ES_VERSION_2_0 int screenUsage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION; #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 @@ -180,7 +190,6 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, window->State.IsFullscreen = GL_TRUE; //XXX Always fullscreen for now /* Create context */ - fghChooseConfig(&window->Window.pContext.egl.Config); window->Window.Context = EGL_NO_CONTEXT; if( fgState.UseCurrentContext == GL_TRUE ) window->Window.Context = eglGetCurrentContext(); diff --git a/freeglut/freeglut/src/egl/fg_window_egl.c b/freeglut/freeglut/src/egl/fg_window_egl.c index 2141c5c..4bfbd72 100644 --- a/freeglut/freeglut/src/egl/fg_window_egl.c +++ b/freeglut/freeglut/src/egl/fg_window_egl.c @@ -38,8 +38,8 @@ int fghChooseConfig(EGLConfig* config) { #endif #ifdef TARGET_HOST_BLACKBERRY /* Only 888 and 565 seem to work. Based on - http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp - That's all that is used, and that's what BlackBerry uses for their own internal OpenGL setup, so unless something else is determined, use it */ + http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp and + https://twitter.com/BlackBerryDev/status/380720927475912706 */ EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, @@ -76,7 +76,7 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { EGLConfig eglConfig = window->Window.pContext.egl.Config; /* Ensure OpenGLES 2.0 context */ - static const EGLint ctx_attribs[] = { + static EGLint ctx_attribs[] = { #ifdef GL_ES_VERSION_2_0 EGL_CONTEXT_CLIENT_VERSION, 2, #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 @@ -84,6 +84,10 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { #endif EGL_NONE }; +#ifdef GL_ES_VERSION_2_0 + int gles2Ver = fgState.MajorVersion <= 2 ? 2 : fgState.MajorVersion; + ctx_attribs[1] = gles2Ver; +#endif context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, ctx_attribs); if (context == EGL_NO_CONTEXT) { fgWarning("Cannot initialize EGL context, err=%x\n", eglGetError()); @@ -92,7 +96,7 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { EGLint ver = -1; eglQueryContext(fgDisplay.pDisplay.egl.Display, context, EGL_CONTEXT_CLIENT_VERSION, &ver); #ifdef GL_ES_VERSION_2_0 - if (ver != 2) + if (ver != gles2Ver) #else if (ver != 1) #endif From a6f0764bd1f4df311835d72f0000ae77142ebdc6 Mon Sep 17 00:00:00 2001 From: Rcmaniac25 Date: Thu, 2 Jan 2014 01:08:34 -0500 Subject: [PATCH 34/34] Added comments about GLES 3.0 support with 2.0 references. --- freeglut/freeglut/src/egl/fg_window_egl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/freeglut/freeglut/src/egl/fg_window_egl.c b/freeglut/freeglut/src/egl/fg_window_egl.c index 4bfbd72..2f78a65 100644 --- a/freeglut/freeglut/src/egl/fg_window_egl.c +++ b/freeglut/freeglut/src/egl/fg_window_egl.c @@ -30,6 +30,11 @@ int fghChooseConfig(EGLConfig* config) { const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, #ifdef GL_ES_VERSION_2_0 + /* + * Khronos does not specify a EGL_OPENGL_ES3_BIT outside of the OpenGL extension "EGL_KHR_create_context". There are numerous references on the internet that + * say to use EGL_OPENGL_ES3_BIT, followed by many saying they can't find it in any headers. In fact, the offical updated specification for EGL does not have + * any references to OpenGL ES 3.0. Tests have shown that EGL_OPENGL_ES2_BIT will work with ES 3.0. + */ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, @@ -85,6 +90,10 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { EGL_NONE }; #ifdef GL_ES_VERSION_2_0 + /* + * As GLES 3.0 is backwards compatible with GLES 2.0, we set 2.0 as default unless the user states a different version. + * This updates the context attributes and lets us check that the correct version was set when we query it after creation. + */ int gles2Ver = fgState.MajorVersion <= 2 ? 2 : fgState.MajorVersion; ctx_attribs[1] = gles2Ver; #endif