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

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1674 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2014-01-24 10:35:05 +00:00
parent e8cc20621f
commit 4c37b66f1e
6 changed files with 128 additions and 22 deletions

View File

@ -269,11 +269,17 @@ IF(ANDROID)
# -llog for native Android logging
LIST(APPEND LIBS android log)
ELSEIF(BLACKBERRY)
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)
INCLUDE(CheckTypeSize)
@ -487,7 +493,11 @@ ELSEIF(FREEGLUT_GLES2)
IF(ANDROID)
SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm")
ELSEIF(BLACKBERRY)
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)
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()

View File

@ -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,16 +96,30 @@ else()
endif()
# Includes
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" )
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()
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 )
# NDK flags
@ -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")

View File

@ -31,6 +31,18 @@
#include "fg_internal.h"
#include "egl/fg_window_egl.h"
#ifdef __PLAYBOOK__
#include <sys/slog.h>
#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 <slog2.h>
#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 <sys/keycodes.h>
#include <input/screen_helpers.h>
#include <bps/bps.h>
@ -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 */

View File

@ -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,12 +107,14 @@ 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 */

View File

@ -32,7 +32,6 @@
#include "fg_internal.h"
#include "egl/fg_window_egl.h"
#include <screen/screen.h>
#include <bps/screen.h>
/*
* 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)) {

View File

@ -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