diff --git a/android/assets/colors.txt b/android/assets/colors.txt new file mode 120000 index 0000000000..ab5dad0420 --- /dev/null +++ b/android/assets/colors.txt @@ -0,0 +1 @@ +../../data/colors.txt \ No newline at end of file diff --git a/android/assets/patterns.txt b/android/assets/patterns.txt new file mode 120000 index 0000000000..ca0c3453a9 --- /dev/null +++ b/android/assets/patterns.txt @@ -0,0 +1 @@ +../../data/patterns.txt \ No newline at end of file diff --git a/android/jni/com/mapswithme/maps/Lifecycle.cpp b/android/jni/com/mapswithme/maps/Lifecycle.cpp deleted file mode 100644 index 59ae344c58..0000000000 --- a/android/jni/com/mapswithme/maps/Lifecycle.cpp +++ /dev/null @@ -1,290 +0,0 @@ -#include -#include -#include "../../../nv_event/nv_event.hpp" -#include "base/logging.hpp" -#include "graphics/opengl/opengl.hpp" -#include "Framework.hpp" -#include "../platform/Platform.hpp" - -#define MODULE "MapsWithMe" -#define NVDEBUG(args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, ## args) - -static int32_t s_winWidth = 1; -static int32_t s_winHeight = 1; -static int32_t s_densityDpi = 1; - -static bool s_glesLoaded = false; - -bool SetupGLESResources() -{ - if (s_glesLoaded) - return true; - - if (!g_framework->InitRenderPolicy(s_densityDpi, s_winWidth, s_winHeight)) - { - NVEventReportUnsupported(); - return false; - } - else - NVEventOnRenderingInitialized(); - - s_glesLoaded = true; - - return true; -} - -bool ShutdownGLESResources() -{ - if (!s_glesLoaded) - return true; - - // We cannot use GLES calls to release the resources if the context is - // not bound. In that case, we simply shut down EGL, which has code to - // explicitly delete the context - if (!NVEventStatusEGLIsBound()) - { - NVDEBUG("ShutdownGLESResources: GLES not bound, shutting down EGL to release"); - - graphics::gl::g_hasContext = false; - - g_framework->DeleteRenderPolicy(); - - graphics::gl::g_hasContext = true; - - NVDEBUG("Cleaning up EGL"); - - if (NVEventCleanupEGL()) - { - s_glesLoaded = false; - return true; - } - else - { - return false; - } - } - - NVDEBUG("ShutdownGLESResources event: GLES bound, manually deleting GLES resources"); - - g_framework->DeleteRenderPolicy(); - - s_glesLoaded = false; - - return true; -} - -bool renderFrame(bool allocateIfNeeded) -{ - if (!NVEventReadyToRenderEGL(allocateIfNeeded)) - return false; - - // We've gotten this far, so EGL is ready for us. Have we loaded our assets? - // Note that we cannot use APP_STATUS_GLES_LOADED to imply that EGL is - // ready to render. We can have a valid context with all GLES resources loaded - // into it but no surface and thus the context not bound. These are semi- - // independent states. - if (!s_glesLoaded) - { - if (!allocateIfNeeded) - return false; - - if (!SetupGLESResources()) - return false; - } - - g_framework->DrawFrame(); - - return true; -} - -namespace -{ - -const int32_t TIMEOUT_FOREGROUND_IN_FOCUS = 1; // msec -const int32_t TIMEOUT_FOREGROUND_NOT_IN_FOCUS = 100; // msec - -int32_t GetEventQueueTimeout(bool isAppInBackground) -{ - if (isAppInBackground) - return NV_EVENT_WAIT_FOREVER; - else - return (NVEventStatusIsFocused() ? TIMEOUT_FOREGROUND_IN_FOCUS : TIMEOUT_FOREGROUND_NOT_IN_FOCUS); -} - -} // namespace - -// Add any initialization that requires the app Java classes -// to be accessible (such as nv_shader_init, NvAPKInit, etc, -// as listed in the docs) -int32_t NVEventAppInit(int32_t argc, char** argv) -{ - return 0; -} - -int32_t NVEventAppMain(int32_t argc, char** argv) -{ - s_glesLoaded = false; - - bool isAppInBackground = true; - - NVDEBUG("Application entering main loop"); - - while (NVEventStatusIsRunning()) - { - const NVEvent* ev = NULL; - while (NVEventStatusIsRunning() && - (ev = NVEventGetNextEvent(GetEventQueueTimeout(isAppInBackground)))) - { - switch (ev->m_type) - { - case NV_EVENT_KEY: - NVDEBUG( "Key event: 0x%02x %s", - ev->m_data.m_key.m_code, - (ev->m_data.m_key.m_action == NV_KEYACTION_DOWN) ? "down" : "up"); - - if ((ev->m_data.m_key.m_code == NV_KEYCODE_BACK)) - { - renderFrame(false); - NVEventDoneWithEvent(true); - } - else - { - NVEventDoneWithEvent(false); - } - ev = NULL; - break; - - case NV_EVENT_CHAR: - NVDEBUG("Char event: 0x%02x", ev->m_data.m_char.m_unichar); - ev = NULL; - NVEventDoneWithEvent(false); - break; - case NV_EVENT_LONG_CLICK: - break; - case NV_EVENT_TOUCH: - { - switch (ev->m_data.m_touch.m_action) - { - case NV_TOUCHACTION_DOWN: - g_framework->Move(0, ev->m_data.m_touch.m_x, ev->m_data.m_touch.m_y); - break; - case NV_TOUCHACTION_MOVE: - g_framework->Move(1, ev->m_data.m_touch.m_x, ev->m_data.m_touch.m_y); - break; - case NV_TOUCHACTION_UP: - g_framework->Move(2, ev->m_data.m_touch.m_x, ev->m_data.m_touch.m_y); - break; - } - } - break; - - case NV_EVENT_MULTITOUCH: - { - int maskOnly = (ev->m_data.m_multi.m_action & NV_MULTITOUCH_POINTER_MASK) >> (NV_MULTITOUCH_POINTER_SHIFT); - int action = ev->m_data.m_multi.m_action & NV_MULTITOUCH_ACTION_MASK; - - g_framework->Touch(action, maskOnly, ev->m_data.m_multi.m_x1, ev->m_data.m_multi.m_y1, - ev->m_data.m_multi.m_x2, ev->m_data.m_multi.m_y2); - } - break; - - case NV_EVENT_SURFACE_CREATED: - case NV_EVENT_SURFACE_SIZE: - s_winWidth = ev->m_data.m_size.m_w; - s_winHeight = ev->m_data.m_size.m_h; - s_densityDpi = ev->m_data.m_size.m_density; - - g_framework->Resize(s_winWidth, s_winHeight); - g_framework->NativeFramework()->Invalidate(true); - - NVDEBUG( "Surface create/resize event: %d x %d", s_winWidth, s_winHeight); - break; - - case NV_EVENT_SURFACE_DESTROYED: - NVDEBUG("Surface destroyed event"); - NVEventDestroySurfaceEGL(); - break; - - case NV_EVENT_FOCUS_LOST: - NVDEBUG("Focus lost event"); - - renderFrame(false); - break; - - case NV_EVENT_PAUSE: - NVDEBUG("Pause event"); - - renderFrame(false); - break; - - case NV_EVENT_STOP: - NVDEBUG("Stop event"); - - // As per Google's recommendation, we release GLES resources here - ShutdownGLESResources(); - isAppInBackground = true; - break; - - case NV_EVENT_QUIT: - NVDEBUG("Quit event"); - - break; - - case NV_EVENT_START: - case NV_EVENT_RESTART: - NVDEBUG("Start/restart event: %s", NVEventGetEventStr(ev->m_type)); - isAppInBackground = false; - break; - - case NV_EVENT_ACCEL: - case NV_EVENT_RESUME: - case NV_EVENT_FOCUS_GAINED: - NVDEBUG("%s event: no specific app action", NVEventGetEventStr(ev->m_type)); - break; - - case NV_EVENT_MWM: - { - typedef function FnT; - FnT * pFn = reinterpret_cast(ev->m_data.m_mwm.m_pFn); - (*pFn)(); - delete pFn; - break; - } - - default: - NVDEBUG("UNKNOWN event"); - break; - }; - - // if we do not NULL out the event, then we return that - // we handled it by default - if (ev) - NVEventDoneWithEvent(true); - } - - // Do not bother to initialize _any_ of EGL, much less go ahead - // and render to the screen unless we have all we need to go - // ahead and do our thing. In many cases, - // devices will bring us part-way up and then take us down. - // So, before we bother to init EGL (much less the rendering - // surface, check that: - // - we are focused - // - we have a rendering surface - // - the surface size is not 0x0 - // - we are resumed, not paused - if (NVEventStatusIsInteractable()) - { - // This will try to set up EGL if it isn't set up - // When we first set up EGL completely, we also load our GLES resources - // If these are already set up or we succeed at setting them all up now, then - // we go ahead and render. - renderFrame(true); - } - } - - NVDEBUG("cleanup!!!"); - - NVEventCleanupEGL(); - - return 0; -} diff --git a/android/jni/nv_debug/nv_debug.hpp b/android/jni/nv_debug/nv_debug.hpp deleted file mode 100644 index f404c212ca..0000000000 --- a/android/jni/nv_debug/nv_debug.hpp +++ /dev/null @@ -1,77 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_debug.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- -#ifndef __INCLUDED_NV_DEBUG_H -#define __INCLUDED_NV_DEBUG_H - -#define CT_ASSERT(tag,cond) \ -enum { COMPILE_TIME_ASSERT__ ## tag = 1/(cond) } - -#define dimof( x ) ( sizeof(x) / sizeof(x[0]) ) -#include - -#define DBG_DETAILED 0 - -#if 0 - - // the detailed prefix can be customised by setting DBG_DETAILED_PREFIX. See - // below as a reference. - // NOTE: fmt is the desired format string and must be in the prefix. - //#ifndef DBG_DETAILED_PREFIX - // #define DBG_DETAILED_PREFIX "%s, %s, line %d: " fmt, __FILE__, __FUNCTION__, __LINE__, - //#endif - //#define DEBUG_D_(fmt, args...) - //#define DEBUG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, (DBG_DETAILED_PREFIX) ## args) - -#else - - #ifdef STRINGIFY - #pragma push_macro("STRINGIFY") - #undef STRINGIFY - #define STRINGIFYPUSHED_____ - #endif - #define STRINGIFY(x) #x - - // debug macro, includes file name function name and line number - #define TO(x) typeof(x) - #define DEBUG_D_(file, line, fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, file ", %s, line(" STRINGIFY(line) "): " fmt, __FUNCTION__, ## args) - #define DEBUG_D(fmt, args...) DEBUG_D_( __FILE__ , __LINE__ , fmt, ## args) - - #ifdef STRINGIFYPUSHED_____ - #undef STRINGIFYPUSHED_____ - #pragma pop_macro("STRINGIFY") - #endif - -#endif - -// basic debug macro -#define NVDEBUG_(fmt, args...) (__android_log_print(ANDROID_LOG_DEBUG, MODULE, fmt, ## args)) - -// Debug macro that can be switched to spew a file name, -// function and line number using DEBUG_DETAILED -#if DBG_DETAILED == 1 - #define NVDEBUG(fmt, args...) NVDEBUG_D(fmt, ## args) -#else - #define NVDEBUG(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, fmt, ## args) -#endif - - -#endif diff --git a/android/jni/nv_event/nv_event.cpp b/android/jni/nv_event/nv_event.cpp deleted file mode 100644 index 23355e7018..0000000000 --- a/android/jni/nv_event/nv_event.cpp +++ /dev/null @@ -1,925 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_event.cpp -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA� Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#define MODULE "NVEvent" -#define DBG_DETAILED 0 - -#include "nv_event.hpp" - -#include -#include -#include -#include -#include -//#include - -#include "../nv_time/nv_time.hpp" -#include "../nv_thread/nv_thread.hpp" -#include "../nv_debug/nv_debug.hpp" -#include "scoped_profiler.hpp" -#include "nv_keycode_mapping.hpp" -#include "nv_event_queue.hpp" - -#define CT_ASSERT(tag,cond) \ -enum { COMPILE_TIME_ASSERT__ ## tag = 1/(cond) } - -enum -{ - // Android lifecycle status flags. Not app-specific - // Set between onCreate and onDestroy - NVEVENT_STATUS_RUNNING = 0x00000001, - // Set between onResume and onPause - NVEVENT_STATUS_ACTIVE = 0x00000002, - // Set between onWindowFocusChanged(true) and (false) - NVEVENT_STATUS_FOCUSED = 0x00000004, - // Set when the app's SurfaceHolder points to a - // valid, nonzero-sized surface - NVEVENT_STATUS_HAS_REAL_SURFACE = 0x00000008, - - // Mask of all app lifecycle status flags, useful for checking when is it - // a reasonable time to be setting up EGL and rendering - NVEVENT_STATUS_INTERACTABLE = 0x0000000f, - - // NvEvent EGL status flags. Not app-specific - // Set between calls to NVEventInitEGL and NVEventCleanupEGL - NVEVENT_STATUS_EGL_INITIALIZED = 0x00000010, - // Set when the EGL surface is allocated - NVEVENT_STATUS_EGL_HAS_SURFACE = 0x00000020, - // Set when a surface and context are available and bound - NVEVENT_STATUS_EGL_BOUND = 0x00000040, -}; - -static unsigned int s_appStatus = 0; - -static void ZeroAppFlags() -{ - s_appStatus = 0; -} - -static void SetAppFlag(unsigned int status) -{ - s_appStatus |= status; -} - -static void ClearAppFlag(unsigned int status) -{ - s_appStatus &= ~status; -} - -static bool QueryAppFlag(unsigned int status) -{ - return (s_appStatus & status) ? true : false; -} - -static bool QueryAppFlagsEqualMasked(unsigned int status, unsigned int mask) -{ - return ((s_appStatus & mask) == status) ? true : false; -} - -static NVKeyCodeMapping s_keyMapping; -static NVEventQueue s_eventQueue; -static jobject s_globalThiz; -static jfieldID s_lengthId; -static jfieldID s_dataId; -static jfieldID s_widthId; -static jfieldID s_heightId; -static jfieldID s_texDataId; -static pthread_t s_mainThread; -static bool s_appThreadExited = false; -static bool s_javaPostedQuit = false; - -static int NVEVENT_ACTION_DOWN = 0; -static int NVEVENT_ACTION_UP = 0; -static int NVEVENT_ACTION_CANCEL = 0; -static int NVEVENT_ACTION_POINTER_INDEX_MASK = 0; -static int NVEVENT_ACTION_POINTER_INDEX_SHIFT = 0; -static int NVEVENT_ACTION_KEY_UP = 0; - -class MethodRef -{ -public: - MethodRef(const char* name, - const char* signature) : - m_name(name), - m_signature(signature), - m_index(NULL) - {} - - bool QueryID(JNIEnv *env, jclass k) - { - m_index = env->GetMethodID(k, m_name, m_signature); - return true; - } - - bool CallBoolean() - { - JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); - - if (!jniEnv || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); - return false; - } - if (!m_index) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); - return false; - } -// __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling JNI up to %s", m_name); - return jniEnv->CallBooleanMethod(s_globalThiz, m_index); - } - - bool CallInt() - { - JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); - - if (!jniEnv || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); - return 0; - } - - if (!m_index) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); - return false; - } - - return (int)jniEnv->CallIntMethod(s_globalThiz, m_index); - } - - void CallVoid() - { - JNIEnv * jniEnv = NVThreadGetCurrentJNIEnv(); - - if (!jniEnv || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); - return; - } - - if (!m_index) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); - return; - } - - jniEnv->CallVoidMethod(s_globalThiz, m_index); - } - - const char* m_name; - const char* m_signature; - jmethodID m_index; - -}; - -static MethodRef s_InitEGL("InitEGL", "()Z"); -static MethodRef s_CleanupEGL("CleanupEGL", "()Z"); -static MethodRef s_CreateSurfaceEGL("CreateSurfaceEGL", "()Z"); -static MethodRef s_DestroySurfaceEGL("DestroySurfaceEGL", "()Z"); -static MethodRef s_SwapBuffersEGL("SwapBuffersEGL", "()Z"); -static MethodRef s_BindSurfaceAndContextEGL("BindSurfaceAndContextEGL", "()Z"); -static MethodRef s_UnbindSurfaceAndContextEGL("UnbindSurfaceAndContextEGL", "()Z"); -static MethodRef s_GetErrorEGL("GetErrorEGL", "()I"); -static MethodRef s_finish("finish", "()V"); -static MethodRef s_ReportUnsupported("ReportUnsupported", "()V"); -static MethodRef s_OnRenderingInitialized("OnRenderingInitialized", "()V"); - -// True between onCreate and onDestroy -bool NVEventStatusIsRunning() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_RUNNING); -} - -// True between onResume and onPause -bool NVEventStatusIsActive() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_ACTIVE); -} - -// True between onWindowFocusChanged(true) and (false) -bool NVEventStatusIsFocused() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_FOCUSED); -} - -// True when the app's SurfaceHolder points to a -// valid, nonzero-sized window -bool NVEventStatusHasRealSurface() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); -} - -// True when all of IsRunning, IsActive, IsFocused, HasRealSurface are true -// useful for checking when is it a reasonable time to be setting up EGL and rendering -bool NVEventStatusIsInteractable() -{ - // TBD - need to lock a mutex? - return QueryAppFlagsEqualMasked(NVEVENT_STATUS_INTERACTABLE, NVEVENT_STATUS_INTERACTABLE); -} - -// True between calls to NVEventInitEGL and NVEventCleanupEGL -bool NVEventStatusEGLInitialized() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); -} - -// True when the EGL surface is allocated -bool NVEventStatusEGLHasSurface() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); -} - -// True when a surface and context are available and bound -bool NVEventStatusEGLIsBound() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_EGL_BOUND); -} - -static void NVEventInitInputFields(JNIEnv *env) -{ - jclass Motion_class = env->FindClass("android/view/MotionEvent"); - jfieldID ACTION_DOWN_id = env->GetStaticFieldID(Motion_class, "ACTION_DOWN", "I"); - jfieldID ACTION_UP_id = env->GetStaticFieldID(Motion_class, "ACTION_UP", "I"); - jfieldID ACTION_CANCEL_id = env->GetStaticFieldID(Motion_class, "ACTION_CANCEL", "I"); - jfieldID ACTION_POINTER_INDEX_SHIFT_id = env->GetStaticFieldID(Motion_class, "ACTION_POINTER_ID_SHIFT", "I"); - jfieldID ACTION_POINTER_INDEX_MASK_id = env->GetStaticFieldID(Motion_class, "ACTION_POINTER_ID_MASK", "I"); - NVEVENT_ACTION_DOWN = env->GetStaticIntField(Motion_class, ACTION_DOWN_id); - NVEVENT_ACTION_UP = env->GetStaticIntField(Motion_class, ACTION_UP_id); - NVEVENT_ACTION_CANCEL = env->GetStaticIntField(Motion_class, ACTION_CANCEL_id); - NVEVENT_ACTION_POINTER_INDEX_MASK = env->GetStaticIntField(Motion_class, ACTION_POINTER_INDEX_MASK_id); - NVEVENT_ACTION_POINTER_INDEX_SHIFT = env->GetStaticIntField(Motion_class, ACTION_POINTER_INDEX_SHIFT_id); - - jclass KeyCode_class = env->FindClass("android/view/KeyEvent"); - jfieldID ACTION_KEY_UP_id = env->GetStaticFieldID(KeyCode_class, "ACTION_UP", "I"); - NVEVENT_ACTION_KEY_UP = env->GetStaticIntField(KeyCode_class, ACTION_KEY_UP_id); -} - -static void* NVEventMainLoopThreadFunc(void*) -{ - NVEventAppMain(0, NULL); - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NvEvent native app Main returned"); - - // signal the condition variable to unblock - // java from waiting on pause or quit - s_eventQueue.UnblockProducer(); - - s_appThreadExited = true; - - // IF that app main returned because we posted a QUIT, then Java knows what to - // do regarding lifecycle. But, if the app returned from main of its own accord, - // we need to call finish. - if (!s_javaPostedQuit) - { - JNIEnv* env = NVThreadGetCurrentJNIEnv(); - env->CallVoidMethod(s_globalThiz, s_finish.m_index); - } - - return NULL; -} - -NVEventPlatformAppHandle NVEventGetPlatformAppHandle() -{ - return s_globalThiz; -} - -/////////////////////////////////////////////////////////////////////////////// -// Native event-handling functions - -const char* NVEventGetEventStr(NVEventType eventType) -{ - switch(eventType) - { - case NV_EVENT_KEY: return "NV_EVENT_KEY"; - case NV_EVENT_CHAR: return "NV_EVENT_CHAR"; - case NV_EVENT_TOUCH: return "NV_EVENT_TOUCH"; - case NV_EVENT_MULTITOUCH: return "NV_EVENT_MULTITOUCH"; - case NV_EVENT_ACCEL: return "NV_EVENT_ACCEL"; - case NV_EVENT_START: return "NV_EVENT_START"; - case NV_EVENT_RESTART: return "NV_EVENT_RESTART"; - case NV_EVENT_RESUME: return "NV_EVENT_RESUME"; - case NV_EVENT_FOCUS_GAINED: return "NV_EVENT_FOCUS_GAINED"; - case NV_EVENT_SURFACE_CREATED: return "NV_EVENT_SURFACE_CREATED"; - case NV_EVENT_SURFACE_SIZE: return "NV_EVENT_SURFACE_SIZE"; - case NV_EVENT_SURFACE_DESTROYED: return "NV_EVENT_SURFACE_DESTROYED"; - case NV_EVENT_FOCUS_LOST: return "NV_EVENT_FOCUS_LOST"; - case NV_EVENT_PAUSE: return "NV_EVENT_PAUSE"; - case NV_EVENT_STOP: return "NV_EVENT_STOP"; - case NV_EVENT_QUIT: return "NV_EVENT_QUIT"; - case NV_EVENT_USER: return "NV_EVENT_USER"; - case NV_EVENT_LONG_CLICK: return "NV_EVENT_LONG_CLICK"; - case NV_EVENT_MWM: return "NV_EVENT_MWM"; - } - - // update this if you end up having to edit something. - CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 19); - return "unknown event type!"; -} - -const NVEvent* NVEventGetNextEvent(int waitMSecs) -{ - return s_eventQueue.RemoveOldest(waitMSecs); -} - -void NVEventDoneWithEvent(bool handled) -{ - return s_eventQueue.DoneWithEvent(handled); -} - -static void NVEventInsert(NVEvent* ev) -{ - if(!s_appThreadExited) - s_eventQueue.Insert(ev); -} - -static bool NVEventInsertBlocking(NVEvent* ev) -{ - if(!s_appThreadExited) - return s_eventQueue.InsertBlocking(ev); - - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -// Native to Java EGL call-up functions - -bool NVEventInitEGL() -{ - if(s_InitEGL.CallBoolean()) - { - SetAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); - return true; - } - else - return false; -} - -bool NVEventCleanupEGL() -{ - ClearAppFlag(NVEVENT_STATUS_EGL_BOUND); - ClearAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); - ClearAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); - return s_CleanupEGL.CallBoolean(); -} - -bool NVEventCreateSurfaceEGL() -{ - if (s_CreateSurfaceEGL.CallBoolean()) - { - SetAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); - return true; - } - else - return false; -} - -bool NVEventDestroySurfaceEGL() -{ - if (!QueryAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE)) - return true; - - if (QueryAppFlag(NVEVENT_STATUS_EGL_BOUND)) - NVEventUnbindSurfaceAndContextEGL(); - - ClearAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); - return s_DestroySurfaceEGL.CallBoolean(); -} - -bool NVEventBindSurfaceAndContextEGL() -{ - if (s_BindSurfaceAndContextEGL.CallBoolean()) - { - SetAppFlag(NVEVENT_STATUS_EGL_BOUND); - return true; - } - else - return false; -} - -bool NVEventUnbindSurfaceAndContextEGL() -{ - ClearAppFlag(NVEVENT_STATUS_EGL_BOUND); - return s_UnbindSurfaceAndContextEGL.CallBoolean(); -} - -bool NVEventSwapBuffersEGL() -{ - if (!s_SwapBuffersEGL.CallBoolean()) - return false; - RESET_PROFILING(); - return true; -} - -int NVEventGetErrorEGL() -{ - return s_GetErrorEGL.CallInt(); -} - -bool NVEventReadyToRenderEGL(bool allocateIfNeeded) -{ - // If we have a bound context and surface, then EGL is ready - if (!NVEventStatusEGLIsBound()) - { - if (!allocateIfNeeded) - return false; - - // If we have not bound the context and surface, do we even _have_ a surface? - if (!NVEventStatusEGLHasSurface()) - { - // No surface, so we need to check if EGL is set up at all - if (!NVEventStatusEGLInitialized()) - { - if (!NVEventInitEGL()) - return false; - } - - // Create the rendering surface now that we have a context - if (!NVEventCreateSurfaceEGL()) - return false; - - } - - // We have a surface and context, so bind them - if (NVEventBindSurfaceAndContextEGL()) - return false; - } - - return true; -} - -bool NVEventRepaint() -{ - NVEvent ev; - ev.m_type = NV_EVENT_USER; - ev.m_data.m_user.m_u0 = 1; - NVEventInsert(&ev); - - return true; -} - -void NVEventReportUnsupported() -{ - /// to prevent from rendering - ClearAppFlag(NVEVENT_STATUS_FOCUSED); - s_ReportUnsupported.CallVoid(); -} - -void NVEventOnRenderingInitialized() -{ - s_OnRenderingInitialized.CallVoid(); -} - -/////////////////////////////////////////////////////////////////////////////// -// Input event-related Java to Native callback functions - - -static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action, - jboolean hasFirst, jboolean hasSecond, jint mx1, jint my1, jint mx2, jint my2) -{ - { - NVEvent ev; - - int actionOnly = action & (~NVEVENT_ACTION_POINTER_INDEX_MASK); - - int maskOnly = 0; - - if (hasFirst) - maskOnly |= 0x1; - if (hasSecond) - maskOnly |= 0x2; - - ev.m_type = NV_EVENT_MULTITOUCH; - - if (actionOnly == NVEVENT_ACTION_UP) - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_UP; - } - else if (actionOnly == NVEVENT_ACTION_DOWN) - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_DOWN; - } - else if (actionOnly == NVEVENT_ACTION_CANCEL) - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_CANCEL; - } - else - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_MOVE; - } - ev.m_data.m_multi.m_action = - (NVMultiTouchEventType)(ev.m_data.m_multi.m_action | (maskOnly << NV_MULTITOUCH_POINTER_SHIFT)); - ev.m_data.m_multi.m_x1 = mx1; - ev.m_data.m_multi.m_y1 = my1; - ev.m_data.m_multi.m_x2 = mx2; - ev.m_data.m_multi.m_y2 = my2; - NVEventInsert(&ev); - } - - return JNI_TRUE; -} - -static jboolean NVEventKeyEvent(JNIEnv* env, jobject thiz, jint action, jint keycode, jint unichar) -{ - // TBD - remove these or make them resettable for safety... - static int lastKeyAction = 0; - static int lastKeyCode = 0; - bool ret = false; - - NVKeyCode code = NV_KEYCODE_NULL; - - if (s_keyMapping.MapKey((int)keycode, code)) - { - if ((code != NV_KEYCODE_NULL) && - ((code != lastKeyCode) || (action != lastKeyAction))) - { - NVEvent ev; - ev.m_type = NV_EVENT_KEY; - ev.m_data.m_key.m_action = (NVEVENT_ACTION_UP == action) - ? NV_KEYACTION_UP : NV_KEYACTION_DOWN; - ev.m_data.m_key.m_code = code; - ret = NVEventInsertBlocking(&ev); - } - - lastKeyAction = action; - lastKeyCode = code; - } - - if (unichar && (NVEVENT_ACTION_UP != action)) - { - NVEvent ev; - ev.m_type = NV_EVENT_CHAR; - ev.m_data.m_char.m_unichar = unichar; - NVEventInsert(&ev); - } - - return ret; -} - -static jboolean NVEventAccelerometerEvent(JNIEnv* env, jobject thiz, jfloat values0, jfloat values1, jfloat values2) -{ - NVEvent ev; - ev.m_type = NV_EVENT_ACCEL; - ev.m_data.m_accel.m_x = values0; - ev.m_data.m_accel.m_y = values1; - ev.m_data.m_accel.m_z = values2; - NVEventInsert(&ev); - return JNI_TRUE; -} - -/////////////////////////////////////////////////////////////////////////////// -// Java to Native app lifecycle callback functions - -static jboolean onDestroyNative(JNIEnv* env, jobject thiz); - - - -static jboolean onCreateNative(JNIEnv* env, jobject thiz) -{ - if (s_globalThiz) - onDestroyNative(env, thiz); - - ZeroAppFlags(); - - if (!s_globalThiz) - { - s_globalThiz = env->NewGlobalRef(thiz); - if (!s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: Thiz NewGlobalRef failed!"); - } - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Thiz NewGlobalRef: 0x%p", s_globalThiz); - } - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Init KeyCode Map"); - s_keyMapping.Init(env, thiz); - - NVEventInitInputFields(env); - - s_eventQueue.Init(); - - s_javaPostedQuit = false; - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling NVEventAppInit"); - - if (NVEventAppInit(0, NULL)) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NVEventAppInit error"); - return JNI_FALSE; - } - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "spawning thread"); - - s_appThreadExited = false; - SetAppFlag(NVEVENT_STATUS_RUNNING); - - /* Launch thread with main loop */ - NVThreadSpawnJNIThread(&s_mainThread, NULL, NVEventMainLoopThreadFunc, NULL); - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "thread spawned"); - - return JNI_TRUE; -} - -static jboolean onStartNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_START; - return NVEventInsertBlocking(&ev); -} - -static jboolean onRestartNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_RESTART; - return NVEventInsertBlocking(&ev); -} - -static jboolean onResumeNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_RESUME; - SetAppFlag(NVEVENT_STATUS_ACTIVE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onSurfaceCreatedNative(JNIEnv* env, jobject thiz, int w, int h, int density) -{ - NVEvent ev; - ev.m_type = NV_EVENT_SURFACE_CREATED; - ev.m_data.m_size.m_w = w; - ev.m_data.m_size.m_h = h; - ev.m_data.m_size.m_density = density; - if ((w > 0) && (h > 0)) - SetAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - else - ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onFocusChangedNative(JNIEnv* env, jobject thiz, jboolean focused) -{ - NVEvent ev; - ev.m_type = (focused == JNI_TRUE) ? NV_EVENT_FOCUS_GAINED : NV_EVENT_FOCUS_LOST; - if (focused) - SetAppFlag(NVEVENT_STATUS_FOCUSED); - else - ClearAppFlag(NVEVENT_STATUS_FOCUSED); - return NVEventInsertBlocking(&ev); -} - -static jboolean onSurfaceChangedNative(JNIEnv* env, jobject thiz, int w, int h, int density) -{ - NVEvent ev; - ev.m_type = NV_EVENT_SURFACE_SIZE; - ev.m_data.m_size.m_w = w; - ev.m_data.m_size.m_h = h; - ev.m_data.m_size.m_density = density; - if (w * h) - SetAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - else - ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onSurfaceDestroyedNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_SURFACE_DESTROYED; - ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onPauseNative(JNIEnv* env, jobject thiz) -{ - // TODO: we could selectively flush here to - // improve responsiveness to the pause - s_eventQueue.Flush(); - NVEvent ev; - ev.m_type = NV_EVENT_PAUSE; - ClearAppFlag(NVEVENT_STATUS_ACTIVE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onStopNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_STOP; - return NVEventInsertBlocking(&ev); -} - -static jboolean onDestroyNative(JNIEnv* env, jobject thiz) -{ - if (!env || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: DestroyingRegisteredObjectInstance no TLS data!"); - } - - if (!s_appThreadExited) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Posting quit event"); - - // flush ALL events - s_eventQueue.Flush(); - - NVEvent ev; - ev.m_type = NV_EVENT_QUIT; - ClearAppFlag(NVEVENT_STATUS_RUNNING); - - // We're posting quit, so we need to mark that; when the main loop - // thread exits, we check this flag to ensure that we only call "finish" - // if the app returned of its own accord, not if we posted it - s_javaPostedQuit = true; - NVEventInsert(&ev); - - // ensure that the native side - // isn't blocked waiting for an event -- since we've flushed - // all the events save quit, we must artificially unblock native - s_eventQueue.UnblockConsumer(); - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Waiting for main loop exit"); - pthread_join(s_mainThread, NULL); - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Main loop exited"); - } - - env->DeleteGlobalRef(s_globalThiz); - s_globalThiz = NULL; - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Released global thiz!"); - - s_eventQueue.Shutdown(); - - return JNI_TRUE; -} - -static jboolean postUserEvent(JNIEnv* env, jobject thiz, - jint u0, jint u1, jint u2, jint u3, - jboolean blocking) -{ - NVEvent ev; - ev.m_type = NV_EVENT_USER; - ev.m_data.m_user.m_u0 = u0; - ev.m_data.m_user.m_u1 = u1; - ev.m_data.m_user.m_u2 = u2; - ev.m_data.m_user.m_u3 = u3; - if (blocking == JNI_TRUE) - { - return NVEventInsertBlocking(&ev); - } - else - { - NVEventInsert(&ev); - return true; - } -} - -void postMWMEvent(void * pFn, bool blocking) -{ - NVEvent ev; - ev.m_type = NV_EVENT_MWM; - ev.m_data.m_mwm.m_pFn = pFn; - - if (blocking) - (void) NVEventInsertBlocking(&ev); - else - NVEventInsert(&ev); -} - -/////////////////////////////////////////////////////////////////////////////// -// File and APK handling functions - -char* NVEventLoadFile(const char* file) -{ - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "loadFile is not implemented"); - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// JVM Initialization functions - -void InitNVEvent(JavaVM* vm) -{ - JNIEnv *env; - - NVThreadInit(vm); - - NVDEBUG("InitNVEvent called"); - - if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) - { - NVDEBUG("Failed to get the environment using GetEnv()"); - return; - } - - JNINativeMethod methods[] = - { - { - "onCreateNative", - "()Z", - (void *) onCreateNative - }, - { - "onStartNative", - "()Z", - (void *) onStartNative - }, - { - "onRestartNative", - "()Z", - (void *) onRestartNative - }, - { - "onResumeNative", - "()Z", - (void *) onResumeNative - }, - { - "onSurfaceCreatedNative", - "(III)Z", - (void *) onSurfaceCreatedNative - }, - { - "onFocusChangedNative", - "(Z)Z", - (void *) onFocusChangedNative - }, - { - "onSurfaceChangedNative", - "(III)Z", - (void *) onSurfaceChangedNative - }, - { - "onSurfaceDestroyedNative", - "()Z", - (void *) onSurfaceDestroyedNative - }, - { - "onPauseNative", - "()Z", - (void *) onPauseNative - }, - { - "onStopNative", - "()Z", - (void *) onStopNative - }, - { - "onDestroyNative", - "()Z", - (void *) onDestroyNative - }, - { - "multiTouchEvent", - "(IZZIIIILandroid/view/MotionEvent;)Z", - (void *) NVEventMultiTouchEvent - }/*, - { - "onLongClickNative", - "(II)Z", - (void *) NVEventLongClickEvent - }*/ - }; - - jclass k; - k = (env)->FindClass ("com/nvidia/devtech/NvEventQueueFragment"); - (env)->RegisterNatives(k, methods, dimof(methods)); - - s_InitEGL.QueryID(env, k); - s_CleanupEGL.QueryID(env, k); - s_CreateSurfaceEGL.QueryID(env, k); - s_DestroySurfaceEGL.QueryID(env, k); - s_SwapBuffersEGL.QueryID(env, k); - s_BindSurfaceAndContextEGL.QueryID(env, k); - s_UnbindSurfaceAndContextEGL.QueryID(env, k); - s_GetErrorEGL.QueryID(env, k); - s_finish.QueryID(env, k); - s_ReportUnsupported.QueryID(env, k); - s_OnRenderingInitialized.QueryID(env, k); -} - diff --git a/android/jni/nv_event/nv_event.hpp b/android/jni/nv_event/nv_event.hpp deleted file mode 100644 index eea19d3bc1..0000000000 --- a/android/jni/nv_event/nv_event.hpp +++ /dev/null @@ -1,547 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_event.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- -#ifndef _NV_EVENT_H -#define _NV_EVENT_H -#include -#include - -/** @file nv_event.h -Contains a framework for event loop-based applications. This library replaces -most or all of the normally-required JNI code for Android NDK applications, -presenting the application developer with two callbacks into which they can -write their application. The framework runs in a natively-created thread, -allowing the application to implement a classic "event loop and render" structure -without having to return to Java code to avoid ANR warnings. The library -includes support for input and system event passing as well as JNI initialization -and exposes basic EGL functionality to native as well. Put together, the library -can form the basis of a simple interactive 3D application. All applications that -are based on this library must also be subclassed on the Java side from the -provided NvEventQueueActivity. Additional external documentation on the use of -this library, the related Java code and the tool provided to create a template -application based on the library are provided with the SDK. -@see NvEventQueueActivity -*/ - -#ifdef ANDROID - -#include -typedef jobject NVEventPlatformAppHandle; - -#else // unknown platform - -typedef void * NVEventPlatformAppHandle; - -#endif - - -enum -{ - /** Timeout argument to NVEventGetNextEvent() that indicates the function should - block until there is an event pending or the app exits - @see NVEventGetNextEvent() - */ - NV_EVENT_WAIT_FOREVER = -1 -}; - -/** Event type values -*/ -typedef enum NVEventType -{ - /** Key up/down events */ - NV_EVENT_KEY = 1, - /** Translated character events */ - NV_EVENT_CHAR, - /** Single-touch pointer events */ - NV_EVENT_TOUCH, - /** Multi-touch events */ - NV_EVENT_MULTITOUCH, - /** Long Click Event */ - NV_EVENT_LONG_CLICK, - /** Accelerometer events */ - NV_EVENT_ACCEL, - /** onStart lifecycle events */ - NV_EVENT_START, - /** onRestart lifecycle events */ - NV_EVENT_RESTART, - /** onResume lifecycle events */ - NV_EVENT_RESUME, - /** onWindowFocusChanged(TRUE) lifecycle events */ - NV_EVENT_FOCUS_GAINED, - /** Surface created events */ - NV_EVENT_SURFACE_CREATED, - /** Surface size changed events */ - NV_EVENT_SURFACE_SIZE, - /** Surface destroyed events */ - NV_EVENT_SURFACE_DESTROYED, - /** onWindowFocusChanged(FALSE) lifecycle events */ - NV_EVENT_FOCUS_LOST, - /** onPause lifecycle events */ - NV_EVENT_PAUSE, - /** onStop lifecycle events */ - NV_EVENT_STOP, - /** (onDestroy) Quit request events */ - NV_EVENT_QUIT, - /** App-specific events */ - NV_EVENT_USER, - NV_EVENT_MWM, - /* a dummy enum value used to compute num_events */ - NV_EVENT_NUM_EVENT_DUMMY_DONTUSEME, - /* total number of events */ - NV_EVENT_NUM_EVENTS = NV_EVENT_NUM_EVENT_DUMMY_DONTUSEME - 1, - NV_EVENT_FORCE_32BITS = 0x7fffffff -} NVEventType; - -/** Touch event actions -*/ -typedef enum NVTouchEventType -{ - /** Pointer has just left the screen */ - NV_TOUCHACTION_UP, - /** Pointer has just gone down onto the screen */ - NV_TOUCHACTION_DOWN, - /** Pointer is moving on the screen */ - NV_TOUCHACTION_MOVE, - NV_TOUCHACTION_FORCE_32BITS = 0x7fffffff -} NVTouchEventType; - -/** Multitouch event flags -*/ -typedef enum NVMultiTouchEventType -{ - /** Indicated pointers are leaving the screen */ - NV_MULTITOUCH_UP = 0x00000001, - /** Indicated pointers have just touched the screen */ - NV_MULTITOUCH_DOWN = 0x00000002, - /** Indicated pointers are moving on the screen */ - NV_MULTITOUCH_MOVE = 0x00000003, - /** Indicated pointers have halted the current gesture - app should cancel any actions implied by the gesture */ - NV_MULTITOUCH_CANCEL = 0x00000004, - /** Mask to be AND'ed with the flag value - to get the active pointer bits */ - NV_MULTITOUCH_POINTER_MASK = 0x0000ff00, - /** Number of bits to right-shift the masked value - to get the active pointer bits */ - NV_MULTITOUCH_POINTER_SHIFT = 0x00000008, - /** Mask to be AND'ed with the flag value - to get the event action */ - NV_MULTITOUCH_ACTION_MASK = 0x000000ff, - NV_MULTITOUCH_FORCE_32BITS = 0x7fffffff -} NVMultiTouchEventType; - -/** Key event types -*/ -typedef enum NVKeyEventType -{ - /** Key has just been pressed (no repeats) */ - NV_KEYACTION_UP, - /** Key has just been released */ - NV_KEYACTION_DOWN, - NV_KEYACTION_FORCE_32BITS = 0x7fffffff -} NVKeyEventType; - -/** Key event key codes -*/ -#define NV_MAX_KEYCODE 256 -typedef enum NVKeyCode -{ - NV_KEYCODE_NULL = 0, - NV_KEYCODE_BACK, - NV_KEYCODE_TAB, - NV_KEYCODE_ENTER, - NV_KEYCODE_DEL, - NV_KEYCODE_SPACE, - NV_KEYCODE_ENDCALL, - NV_KEYCODE_HOME, - - NV_KEYCODE_STAR, - NV_KEYCODE_PLUS, - NV_KEYCODE_MINUS, - NV_KEYCODE_NUM, - - NV_KEYCODE_DPAD_LEFT, - NV_KEYCODE_DPAD_UP, - NV_KEYCODE_DPAD_RIGHT, - NV_KEYCODE_DPAD_DOWN, - - NV_KEYCODE_0, - NV_KEYCODE_1, - NV_KEYCODE_2, - NV_KEYCODE_3, - NV_KEYCODE_4, - NV_KEYCODE_5, - NV_KEYCODE_6, - NV_KEYCODE_7, - NV_KEYCODE_8, - NV_KEYCODE_9, - - NV_KEYCODE_A, - NV_KEYCODE_B, - NV_KEYCODE_C, - NV_KEYCODE_D, - NV_KEYCODE_E, - NV_KEYCODE_F, - NV_KEYCODE_G, - NV_KEYCODE_H, - NV_KEYCODE_I, - NV_KEYCODE_J, - NV_KEYCODE_K, - NV_KEYCODE_L, - NV_KEYCODE_M, - NV_KEYCODE_N, - NV_KEYCODE_O, - NV_KEYCODE_P, - NV_KEYCODE_Q, - NV_KEYCODE_R, - NV_KEYCODE_S, - NV_KEYCODE_T, - NV_KEYCODE_U, - NV_KEYCODE_V, - NV_KEYCODE_W, - NV_KEYCODE_X, - NV_KEYCODE_Y, - NV_KEYCODE_Z, - - NV_KEYCODE_ALT_LEFT, - NV_KEYCODE_ALT_RIGHT, - - NV_KEYCODE_SHIFT_LEFT, - NV_KEYCODE_SHIFT_RIGHT, - - NV_KEYCODE_APOSTROPHE, - NV_KEYCODE_SEMICOLON, - NV_KEYCODE_EQUALS, - NV_KEYCODE_COMMA, - NV_KEYCODE_PERIOD, - NV_KEYCODE_SLASH, - NV_KEYCODE_GRAVE, - NV_KEYCODE_BACKSLASH, - - NV_KEYCODE_LEFT_BRACKET, - NV_KEYCODE_RIGHT_BRACKET, - - NV_KEYCODE_FORCE_32BIT = 0x7fffffff -} NVKeyCode; - -/** Single-touch event data -*/ -typedef struct NVEventTouch -{ - /** The action code */ - NVTouchEventType m_action; - /** The window-relative X position (in pixels) */ - float m_x; - /** The window-relative Y position (in pixels) */ - float m_y; -} NVEventTouch; - -/** Multi-touch event data -*/ -typedef struct NVEventMultiTouch -{ - /** The action flags */ - NVMultiTouchEventType m_action; - /** The window-relative X position of the first pointer (in pixels) - only valid if bit 0 of the pointer bits is set */ - float m_x1; - /** The window-relative Y position of the first pointer (in pixels) - only valid if bit 0 of the pointer bits is set */ - float m_y1; - /** The window-relative X position of the second pointer (in pixels) - only valid if bit 1 of the pointer bits is set */ - float m_x2; - /** The window-relative Y position of the second pointer (in pixels) - only valid if bit 1 of the pointer bits is set */ - float m_y2; -} NVEventMultiTouch; - -/** Key down/up event data -*/ -typedef struct NVEventKey -{ - /** The action flags */ - NVKeyEventType m_action; - /** The code of the key pressed or released */ - NVKeyCode m_code; -} NVEventKey; - -/** Translated character event data -*/ -typedef struct NVEventChar -{ - /** The UNICODE character represented */ - int32_t m_unichar; -} NVEventChar; - -/** Accelerometer event data -*/ -typedef struct NVEventAccel -{ - /** Signed X magnitude of the force vector */ - float m_x; - /** Signed Y magnitude of the force vector */ - float m_y; - /** Signed Z magnitude of the force vector */ - float m_z; -} NVEventAccel; - -/** Surface size change event data -*/ -typedef struct NVEventSurfaceSize -{ - /** New surface client area width (in pixels) */ - int32_t m_w; - /** New surface client area height (in pixels) */ - int32_t m_h; - /** Screen density for the screen at which this surface was created*/ - int32_t m_density; -} NVEventSurfaceSize; - -/** User/App-specific event data -*/ -typedef struct NVEventUser -{ - /** First 32-bit user data item */ - int32_t m_u0; - /** Second 32-bit user data item */ - int32_t m_u1; - /** Third 32-bit user data item */ - int32_t m_u2; - /** Fourth 32-bit user data item */ - int32_t m_u3; -} NVEventUser; - -typedef struct NVEventMWM -{ - void * m_pFn; -} NVEventMWM; - -/** All-encompassing event structure -*/ -typedef struct NVEvent -{ - /** The type of the event, which also indicates which m_data union holds the data */ - NVEventType m_type; - /** Union containing all possible event type data */ - union NVEventData - { - /** Data for single-touch events */ - NVEventTouch m_touch; - /** Data for multi-touch events */ - NVEventMultiTouch m_multi; - /** Data for key up/down events */ - NVEventKey m_key; - /** Data for charcter events */ - NVEventChar m_char; - /** Data for accelerometer events */ - NVEventAccel m_accel; - /** Data for surface size events */ - NVEventSurfaceSize m_size; - /** Data for user/app events */ - NVEventUser m_user; - NVEventMWM m_mwm; - } m_data; -} NVEvent; - -/** Returns a string describing the event -@param eventType The event type -@return Returns a string containing a description of the event. Do not free or delete this memory. -@see NVEvent */ -const char * NVEventGetEventStr(NVEventType eventType); - -/** Returns the next pending event for the application to process. Can return immediately if there -is no event, or can wait a fixed number of milisecs (or "forever") if desired. -The application should always pair calls to this function that return non-NULL events with calls -to NVEventDoneWithEvent() -@param waitMSecs The maximum time (in milisecs) to wait for an event before returning "no event". - Pass NV_EVENT_WAIT_FOREVER to wait indefinitely for an event. Note that NV_EVENT_WAIT_FOREVER - does not guarantee an event on return. The function can still return on error or if the - app is exiting. Default is to return immediately, event or not. -@return Non-NULL pointer to a constant event structure if an event was pending, NULL if no event was - pending in the requested timeout period -@see NVEvent -@see NVEventDoneWithEvent -*/ -const NVEvent * NVEventGetNextEvent(int waitMSecs = 0); - -/** Indicates that the application has finished handling the event returned from the last -call to NVEventGetNextEvent. This function should always be called prior to the next call -to NVEventGetNextEvent. If the current event is a blocking event, this call will unblock -the posting thread (normally in Java). This is particularly important for application -lifecycle events like onPause, as calling this function indicates that the native code has -completed the handling of the lifecycle callback. Failure to call this function promptly -for all events can lead to Application Not Responding errors. -@param handled The return value that should be passed back to Java for blocking events. For non-blocking -events, this parameter is discard. -@see NVEvent -@see NVEventGetNextEvent -*/ -void NVEventDoneWithEvent(bool handled); - -/** The app-supplied "callback" for initialization during JNI_OnLoad. -Declares the application's pre-main initialization function. Does not define the -function. The app must define this in its own code, even if the function is empty. -JNI init code can be safely called from here, as it WILL be called from -within a JNI function thread -@parm argc Passes the number of command line arguments. - This is currently unsupported and is always passed 0 -@parm argv Passes the array of command line arguments. - This is currently unsupported and is always passed NULL -@return The function should return 0 on success and nonzero on failure. -*/ -extern int32_t NVEventAppInit(int32_t argc, char** argv); - -/** The app-supplied "callback" for running the application's main loop. -Declares the application's main loop function. Does not define the -function. The app must define this in its own code -This function will be spawned in its own thread. -@parm argc Passes the number of command line arguments. - This is currently unsupported and is always passed 0 -@parm argv Passes the array of command line arguments. - This is currently unsupported and is always passed NULL -@return The function should return 0 on success and nonzero on failure. -*/ -extern int32_t NVEventAppMain(int32_t argc, char** argv); - - -/** Initializes EGL, queries a valid ES1 config and creates (but does not bind) - an ES1-compatible EGLContext -@return true on success, false on failure -*/ -bool NVEventInitEGL(); - -/** Releases any existing EGLSurface and EGLContext and terminates EGL -@return true on success, false on failure -*/ -bool NVEventCleanupEGL(); - -/** Creates an EGLSurface for the current Android surface. Will attempt to initialize - EGL and an EGLContext if not already done. Fails if there is no valid Android surface - or if there is an EGL error. -@return true on success, false on failure -*/ -bool NVEventCreateSurfaceEGL(); - -/** Unbinds (if needed) and releases the app's EGLSurface -@return true on success, false on failure -*/ -bool NVEventDestroySurfaceEGL(); - -/** Binds the app's EGLSurface and EGLContext to the calling thread. The EGLSurface and - EGLContext must both exist already, or else the function will fail. -@return true on success, false on failure -*/ -bool NVEventBindSurfaceAndContextEGL(); - -/** Un-binds the app's EGLSurface and EGLContext from the calling thread. -@return true on success, false on failure -*/ -bool NVEventUnbindSurfaceAndContextEGL(); - -/** Swaps the currently-bound EGLSurface -@return true on success, false on failure -*/ -bool NVEventSwapBuffersEGL(); - -/** Accessor for the last EGL error -@return the EGL error -*/ -int NVEventGetErrorEGL(); - -/** Utility function: checks if EGl is completely ready to render, including - initialization, surface creation and context/surface binding. -@parm allocateIfNeeded If the parameter is false, then the function immediately returns if any - part of the requirements have not already been satisfied. If the parameter is - true, then the function attempts to initialize any of the steps needed, failing - and returning false only if a step cannot be completed at this time. -@return The function returns true if EGL/GLES is ready to render/load content (i.e. - a context and surface are bound) and false it not -*/ -bool NVEventReadyToRenderEGL(bool allocateIfNeeded); - -/** Convenience conditional function to determine if the app is between onCreate - and onDestroy callbacks (i.e. the app is in a running state). -@return true if the application is between onCreate and onDestroy and false after - an onDestroy event has been delivered. -*/ -bool NVEventStatusIsRunning(); - -/** Convenience conditional function to determine if the app is between onResume and onPause - callbacks (i.e. the app is in a "resumed" state). -@return true if the application is between onResume and onPause and false if the application - has not yet been resumed, or is currently paused. -*/ -bool NVEventStatusIsActive(); - -/** Convenience conditional function to determine if the app's window is focused (between - calls to onWindowFocusChanged(true) and onWindowFocusChanged(false)) -@return true between onWindowFocusChanged(true) and onWindowFocusChanged(false) -*/ -bool NVEventStatusIsFocused(); - -/** Convenience conditional function to determine if the app has a surface and that surface - has non-zero area -@return true if the app is between surfaceCreated and surfaceDestroyed callbacks and - the surface has non-zero pixel area (not 0x0 pixels) -*/ -bool NVEventStatusHasRealSurface(); - -/** Convenience conditional function to determine if the app is in a fully-focused, visible - state. This is a logical "AND" of IsRunning, IsActive, IsFocused and HasRealSurface -@return true if IsRunning, IsActive, IsFocused and HasRealSurface are all currently true, -false otherwise -*/ -bool NVEventStatusIsInteractable(); - -/** Convenience conditional function to determine if the app has active EGL -@return true between successful calls to NVEventInitEGL and NVEventCleanupEGL, -false otherwise -*/ -bool NVEventStatusEGLInitialized(); - -/** Convenience conditional function to determine if the app has an EGLSurface (need not be bound) -@return true if the EGLSurface for the app is allocated, false otherwise -*/ -bool NVEventStatusEGLHasSurface(); - -/** Convenience conditional function to determine if the app has an EGLSurface and EGLContext - and they are bound -@return true if the EGLSurface and EGLContext for the app are allocated and bound, false otherwise -*/ -bool NVEventStatusEGLIsBound(); - -bool NVEventRepaint(); - -void NVEventReportUnsupported(); - -void NVEventOnRenderingInitialized(); - -/** Returns the platform-specific handle to the application instance, if supported. This -function is, by definition platform-specific. -@return A platform-specific handle to the application. */ -NVEventPlatformAppHandle NVEventGetPlatformAppHandle(); - -void InitNVEvent(JavaVM * jvm); - -void postMWMEvent(void * pFn, bool blocking); - -#endif diff --git a/android/jni/nv_event/nv_event_queue.cpp b/android/jni/nv_event/nv_event_queue.cpp deleted file mode 100644 index 4172040dd7..0000000000 --- a/android/jni/nv_event/nv_event_queue.cpp +++ /dev/null @@ -1,276 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_event_queue.cpp -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA� Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- -#define MODULE "NVEventQueue" -#include "../nv_debug/nv_debug.hpp" - -#include "nv_event_queue.hpp" -#include -#include -#include -#include -#include - -#define NVNextWrapped(index) (((index) + 1) & QUEUE_MASK) -#define NVPrevWrapped(index) (((index) - 1) & QUEUE_MASK) - -/* you must be inside a m_accessLock lock to invoke this! */ -static void unlockAll(NVEventSync * sem) -{ - sem->m_block = false; - pthread_cond_broadcast(&(sem->m_cond)); -} - -/* you must be inside mutex lock to invoke this! */ -static int32_t wait(NVEventSync * sem, pthread_mutex_t * mutex, int waitMS) -{ - // TBD - spec is dodgy; do we definitely release the mutex even if - // wait fails? - if(sem->m_block) - { - if( waitMS < 0 ) - return pthread_cond_wait(&sem->m_cond, mutex); - else - return pthread_cond_timeout_np(&sem->m_cond, mutex, (unsigned)waitMS); - } - else - { - // must release this, as failure assumes no lock - pthread_mutex_unlock(mutex); - return 1; // do not return 0 - we do not own the lock! - } -} - -static void signal(NVEventSync * sem) -{ - pthread_cond_signal(&sem->m_cond); -} - -static void broadcast(NVEventSync * sem) -{ - pthread_cond_broadcast(&sem->m_cond); -} - -static void syncInit(NVEventSync * sync) -{ - pthread_cond_init(&sync->m_cond, NULL); - sync->m_block = true; -} - -static void syncDestroy(NVEventSync * sync) -{ - pthread_cond_destroy(&sync->m_cond); -} - -/* you must be inside a m_accessLock lock to invoke this! */ -bool NVEventQueue::insert(NVEvent const * ev) -{ - // Is the queue full? - int32_t nextNext = NVNextWrapped(m_nextInsertIndex); - if (nextNext == m_headIndex) - { - // TBD - what to do when we cannot insert (full queue) - return false; - } - - NVEvent * evDest = m_events + m_nextInsertIndex; - memcpy(evDest, ev, sizeof(NVEvent)); - - m_nextInsertIndex = nextNext; - return true; -} - -void NVEventQueue::Init() -{ - m_nextInsertIndex = 0; - m_headIndex = 0; - pthread_mutex_init(&m_accessLock, NULL); - syncInit(&m_consumerSync); - syncInit(&m_blockerSync); - - m_blocker = NULL; - m_blockerState = NO_BLOCKER; - m_blockerReturnVal = false; -} - -void NVEventQueue::Shutdown() -{ - pthread_mutex_destroy(&m_accessLock); - - // free everyone... - unlockAll(&m_consumerSync); - unlockAll(&m_blockerSync); - syncDestroy(&m_consumerSync); - syncDestroy(&m_blockerSync); -} - -void NVEventQueue::Flush() -{ - // TBD: Lock the mutex???? - m_headIndex = m_nextInsertIndex; -} - -void NVEventQueue::UnblockConsumer() -{ - unlockAll(&m_consumerSync); -} - -void NVEventQueue::UnblockProducer() -{ - unlockAll(&m_blockerSync); -} - -void NVEventQueue::Insert(const NVEvent* ev) -{ - pthread_mutex_lock(&m_accessLock); - - // insert the event and unblock a waiter - insert(ev); - signal(&m_consumerSync); - pthread_mutex_unlock(&m_accessLock); -} - -bool NVEventQueue::InsertBlocking(const NVEvent* ev) -{ - // TBD - how to handle the destruction of these mutexes - - pthread_mutex_lock(&m_accessLock); - while (m_blocker) - { - if (wait(&m_blockerSync, &m_accessLock, NV_EVENT_WAIT_FOREVER)) - return false; - } - - assert(!m_blocker); - assert(m_blockerState == NO_BLOCKER); - - // we have the mutex _and_ the blocking event is NULL - // So now we can push a new one - m_blocker = ev; - m_blockerState = PENDING_BLOCKER; - - // Release the consumer, as we just posted a new event - signal(&m_consumerSync); - - // Loop on the condition variable until we find out that - // there is a return value waiting for us. Since only we - // will null the blocker pointer, we will not let anyone - // else start to post a blocking event - while (m_blockerState != RETURNED_BLOCKER) - { - if (wait(&m_blockerSync, &m_accessLock, NV_EVENT_WAIT_FOREVER)) - return false; - } - - bool handled = m_blockerReturnVal; - m_blocker = NULL; - m_blockerState = NO_BLOCKER; - - NVDEBUG("producer unblocking from consumer handling blocking event (%s)", handled ? "true" : "false"); - - // We've handled the event, so the producer can release the - // next thread to potentially post a blocking event - signal(&m_blockerSync); - pthread_mutex_unlock(&m_accessLock); - - return handled; -} - - -const NVEvent* NVEventQueue::RemoveOldest(int waitMSecs) -{ - pthread_mutex_lock(&m_accessLock); - - // Hmm - the last event we got from RemoveOldest was a - // blocker, and DoneWithEvent not called. - // Default to "false" as a return value - if (m_blockerState == PROCESSING_BLOCKER) - { - m_blockerReturnVal = false; - m_blockerState = RETURNED_BLOCKER; - broadcast(&m_blockerSync); - } - - // Blocker is waiting - return it - // And push the blocker pipeline forward - if(m_blockerState == PENDING_BLOCKER) - { - m_blockerState = PROCESSING_BLOCKER; - const NVEvent* ev = m_blocker; - pthread_mutex_unlock(&m_accessLock); - - return ev; - } - else if (m_nextInsertIndex == m_headIndex) - { - // We're empty - so what do we do? - if (waitMSecs == 0) - { - goto no_event; - } - else - { - // wait for the specified time - wait(&m_consumerSync, &m_accessLock, (unsigned)waitMSecs); - } - - // check again after exiting cond waits, either we had a timeout - if(m_blockerState == PENDING_BLOCKER) - { - m_blockerState = PROCESSING_BLOCKER; - const NVEvent* ev = m_blocker; - pthread_mutex_unlock(&(m_accessLock)); - - return ev; - } - else if (m_nextInsertIndex == m_headIndex) - { - goto no_event; - } - } - - { - // One way or another, we have an event... - NVEvent const * ev = m_events + m_headIndex; - m_headIndex = NVNextWrapped(m_headIndex); - - pthread_mutex_unlock(&m_accessLock); - return ev; - } - -no_event: - pthread_mutex_unlock(&m_accessLock); - return NULL; -} - -void NVEventQueue::DoneWithEvent(bool ret) -{ - // We only care about blockers for now. - // All other events just NOP - pthread_mutex_lock(&m_accessLock); - if (m_blockerState == PROCESSING_BLOCKER) - { - m_blockerReturnVal = ret; - m_blockerState = RETURNED_BLOCKER; - broadcast(&m_blockerSync); - } - pthread_mutex_unlock(&m_accessLock); -} diff --git a/android/jni/nv_event/nv_event_queue.hpp b/android/jni/nv_event/nv_event_queue.hpp deleted file mode 100644 index b6d0c113c4..0000000000 --- a/android/jni/nv_event/nv_event_queue.hpp +++ /dev/null @@ -1,89 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_event_queue.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA� Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#ifndef NV_EVENT_QUEUE -#define NV_EVENT_QUEUE - -#include "nv_event.hpp" -#include - -class NVEventSync -{ -public: - pthread_cond_t m_cond; - bool m_block; -}; - -class NVEventQueue { -public: - void Init(); - void Shutdown(); - void Flush(); - void UnblockConsumer(); - void UnblockProducer(); - // Events are copied, so caller can reuse ev immediately - void Insert(NVEvent const * ev); - // Waits until the event is consumed. Returns whether the - // consumer indicates handling the event or ignoring it - bool InsertBlocking(NVEvent const * ev); - - // Returned event is valid only until the next call to - // RemoveOldest or until a call to DoneWithEvent - // Calling RemoveOldest again without calling DoneWithEvent - // indicates that the last event returned was NOT handled, and - // thus InsertNewestAndWait for that even would return false - const NVEvent* RemoveOldest(int waitMSecs); - - // Indicates that all processing of the last event returned - // from RemoveOldest is complete. Also allows the app to indicate - // whether it handled the event or not. - // Do not dereference the last event pointer after calling this function - void DoneWithEvent(bool ret); - -protected: - bool insert(NVEvent const * ev); - - enum { QUEUE_ELEMS = 256 }; - enum { QUEUE_MASK = 0x000000ff }; - - int32_t m_nextInsertIndex; - int32_t m_headIndex; - - pthread_mutex_t m_accessLock; - - NVEventSync m_blockerSync; - NVEventSync m_consumerSync; - - NVEvent m_events[QUEUE_ELEMS]; - NVEvent const * m_blocker; - enum BlockerState - { - NO_BLOCKER, - PENDING_BLOCKER, - PROCESSING_BLOCKER, - RETURNED_BLOCKER - }; - BlockerState m_blockerState; - bool m_blockerReturnVal; -}; - -#endif // #ifndef NV_EVENT_QUEUE diff --git a/android/jni/nv_event/nv_keycode_mapping.hpp b/android/jni/nv_event/nv_keycode_mapping.hpp deleted file mode 100644 index 0434240c39..0000000000 --- a/android/jni/nv_event/nv_keycode_mapping.hpp +++ /dev/null @@ -1,147 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_keycode_mapping.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -class NVKeyCodeMapping -{ -public: - NVKeyCodeMapping() - { - memset(m_keyMapping, 0, sizeof(NVKeyCode) * NV_MAX_KEYCODE); - } - - void Init(JNIEnv* env, jobject thiz); - - bool MapKey(int key, NVKeyCode& code); - -protected: - void AddKeyMapping(JNIEnv* env, jobject thiz, jclass KeyCode_class, const char* name, NVKeyCode value); - NVKeyCode m_keyMapping[NV_MAX_KEYCODE]; -}; - -/* Init the mapping array, set up the event queue */ -void NVKeyCodeMapping::AddKeyMapping(JNIEnv* env, jobject thiz, jclass KeyCode_class, const char* name, NVKeyCode value) -{ - // Add a new mapping... - jfieldID id = env->GetStaticFieldID(KeyCode_class, name, "I"); - int keyID = env->GetStaticIntField(KeyCode_class, id); - - if (keyID < NV_MAX_KEYCODE) - { - /* TODO TBD Should check for collision */ - m_keyMapping[keyID] = value; - } -} - -#define AddKeymappingMacro(name, value) \ - AddKeyMapping(env, thiz, KeyCode_class, name, value) - -void NVKeyCodeMapping::Init(JNIEnv* env, jobject thiz) -{ - jclass KeyCode_class = env->FindClass("android/view/KeyEvent"); - - AddKeymappingMacro("KEYCODE_BACK",NV_KEYCODE_BACK); - AddKeymappingMacro("KEYCODE_TAB",NV_KEYCODE_TAB); - AddKeymappingMacro("KEYCODE_ENTER",NV_KEYCODE_ENTER); - - AddKeymappingMacro("KEYCODE_SPACE",NV_KEYCODE_SPACE); - AddKeymappingMacro("KEYCODE_ENDCALL",NV_KEYCODE_ENDCALL); - AddKeymappingMacro("KEYCODE_HOME",NV_KEYCODE_HOME); - - AddKeymappingMacro("KEYCODE_DPAD_LEFT",NV_KEYCODE_DPAD_LEFT); - AddKeymappingMacro("KEYCODE_DPAD_UP",NV_KEYCODE_DPAD_UP); - AddKeymappingMacro("KEYCODE_DPAD_RIGHT",NV_KEYCODE_DPAD_RIGHT); - AddKeymappingMacro("KEYCODE_DPAD_DOWN",NV_KEYCODE_DPAD_DOWN); - - AddKeymappingMacro("KEYCODE_DEL",NV_KEYCODE_DEL); - - AddKeymappingMacro("KEYCODE_0",NV_KEYCODE_0); - AddKeymappingMacro("KEYCODE_1",NV_KEYCODE_1); - AddKeymappingMacro("KEYCODE_2",NV_KEYCODE_2); - AddKeymappingMacro("KEYCODE_3",NV_KEYCODE_3); - AddKeymappingMacro("KEYCODE_4",NV_KEYCODE_4); - AddKeymappingMacro("KEYCODE_5",NV_KEYCODE_5); - AddKeymappingMacro("KEYCODE_6",NV_KEYCODE_6); - AddKeymappingMacro("KEYCODE_7",NV_KEYCODE_7); - AddKeymappingMacro("KEYCODE_8",NV_KEYCODE_8); - AddKeymappingMacro("KEYCODE_9",NV_KEYCODE_9); - - AddKeymappingMacro("KEYCODE_A",NV_KEYCODE_A); - AddKeymappingMacro("KEYCODE_B",NV_KEYCODE_B); - AddKeymappingMacro("KEYCODE_C",NV_KEYCODE_C); - AddKeymappingMacro("KEYCODE_D",NV_KEYCODE_D); - AddKeymappingMacro("KEYCODE_E",NV_KEYCODE_E); - AddKeymappingMacro("KEYCODE_F",NV_KEYCODE_F); - AddKeymappingMacro("KEYCODE_G",NV_KEYCODE_G); - AddKeymappingMacro("KEYCODE_H",NV_KEYCODE_H); - AddKeymappingMacro("KEYCODE_I",NV_KEYCODE_I); - AddKeymappingMacro("KEYCODE_J",NV_KEYCODE_J); - AddKeymappingMacro("KEYCODE_K",NV_KEYCODE_K); - AddKeymappingMacro("KEYCODE_L",NV_KEYCODE_L); - AddKeymappingMacro("KEYCODE_M",NV_KEYCODE_M); - AddKeymappingMacro("KEYCODE_N",NV_KEYCODE_N); - AddKeymappingMacro("KEYCODE_O",NV_KEYCODE_O); - AddKeymappingMacro("KEYCODE_P",NV_KEYCODE_P); - AddKeymappingMacro("KEYCODE_Q",NV_KEYCODE_Q); - AddKeymappingMacro("KEYCODE_R",NV_KEYCODE_R); - AddKeymappingMacro("KEYCODE_S",NV_KEYCODE_S); - AddKeymappingMacro("KEYCODE_T",NV_KEYCODE_T); - AddKeymappingMacro("KEYCODE_U",NV_KEYCODE_U); - AddKeymappingMacro("KEYCODE_V",NV_KEYCODE_V); - AddKeymappingMacro("KEYCODE_W",NV_KEYCODE_W); - AddKeymappingMacro("KEYCODE_X",NV_KEYCODE_X); - AddKeymappingMacro("KEYCODE_Y",NV_KEYCODE_Y); - AddKeymappingMacro("KEYCODE_Z",NV_KEYCODE_Z); - - AddKeymappingMacro("KEYCODE_STAR",NV_KEYCODE_STAR); - AddKeymappingMacro("KEYCODE_PLUS",NV_KEYCODE_PLUS); - AddKeymappingMacro("KEYCODE_MINUS",NV_KEYCODE_MINUS); - - AddKeymappingMacro("KEYCODE_NUM",NV_KEYCODE_NUM); - - AddKeymappingMacro("KEYCODE_ALT_LEFT",NV_KEYCODE_ALT_LEFT); - AddKeymappingMacro("KEYCODE_ALT_RIGHT",NV_KEYCODE_ALT_RIGHT); - - AddKeymappingMacro("KEYCODE_SHIFT_LEFT",NV_KEYCODE_SHIFT_LEFT); - AddKeymappingMacro("KEYCODE_SHIFT_RIGHT",NV_KEYCODE_SHIFT_RIGHT); - - AddKeymappingMacro("KEYCODE_APOSTROPHE",NV_KEYCODE_APOSTROPHE); - AddKeymappingMacro("KEYCODE_SEMICOLON",NV_KEYCODE_SEMICOLON); - AddKeymappingMacro("KEYCODE_EQUALS",NV_KEYCODE_EQUALS); - AddKeymappingMacro("KEYCODE_COMMA",NV_KEYCODE_COMMA); - AddKeymappingMacro("KEYCODE_PERIOD",NV_KEYCODE_PERIOD); - AddKeymappingMacro("KEYCODE_SLASH",NV_KEYCODE_SLASH); - AddKeymappingMacro("KEYCODE_GRAVE",NV_KEYCODE_GRAVE); - AddKeymappingMacro("KEYCODE_LEFT_BRACKET",NV_KEYCODE_LEFT_BRACKET); - AddKeymappingMacro("KEYCODE_BACKSLASH",NV_KEYCODE_BACKSLASH); - AddKeymappingMacro("KEYCODE_RIGHT_BRACKET",NV_KEYCODE_RIGHT_BRACKET); -} - -bool NVKeyCodeMapping::MapKey(int key, NVKeyCode& code) -{ - if (key < NV_MAX_KEYCODE) - { - code = m_keyMapping[key]; - return true; - } - else - return false; -} diff --git a/android/jni/nv_event/scoped_profiler.hpp b/android/jni/nv_event/scoped_profiler.hpp deleted file mode 100644 index 1c3d2f2aae..0000000000 --- a/android/jni/nv_event/scoped_profiler.hpp +++ /dev/null @@ -1,82 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\scoped_profiler.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#ifndef SCOPED_PROFILER_H -#define SCOPED_PROFILER_H - -#define PERF_STMTS 0 -#if PERF_STMTS == 1 -#include "../nv_time/nv_time.hpp" -#include "stdio.h" -#include "stdlib.h" - -static char s_bigString[4096]; -static int s_bigStringSize; - -static char s_tmpBuf[1024]; - -class ScopedProfiler -{ -public: - ScopedProfiler(const char* text) - { - _text = text; - _startTime = nvGetSystemTime(); - __last = this; - } - ~ScopedProfiler() - { - stop(); - } - inline void stop() - { - if(_text) - { - int size = snprintf(s_tmpBuf, dimof(s_tmpBuf)-1, "%d ms spent in %s" , (int)(nvGetSystemTime() - _startTime), _text); - strcat(s_bigString + s_bigStringSize, s_tmpBuf); - s_bigStringSize += size; - _text = 0; - } - static void stopLast() - { - if(__last) - __last->stop(); - __last = 0; - } - const char* _text; - long _startTime; - static ScopedProfiler* __last; -}; -ScopedProfiler* ScopedProfiler::__last = 0; - -#define STRINGIFIER(s) #s -#define CONCAT_(a,b) a ## b -#define CONCAT(a,b) CONCAT_(a,b) -#define PERFBLURB(s) static const char CONCAT(___str,__LINE__)[] = s "\n"; ScopedProfiler CONCAT(SCOPED_PROFILER,__LINE__)(CONCAT(___str,__LINE__)); -#define RESET_PROFILING() { DEBUG_D("%s", s_bigString); s_bigString[0] = 0; s_bigStringSize = 0; } -#else -#define PERFBLURB(s) -#define RESET_PROFILING() -#endif - -#endif // SCOPED_PROFILER_H - diff --git a/android/jni/nv_thread/nv_thread.cpp b/android/jni/nv_thread/nv_thread.cpp deleted file mode 100644 index f7d1a87d39..0000000000 --- a/android/jni/nv_thread/nv_thread.cpp +++ /dev/null @@ -1,136 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_thread\nv_thread.c -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA� Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#include - -#include "nv_thread.hpp" -#include -#include - -static JavaVM* s_vm = NULL; -static pthread_key_t s_jniEnvKey = 0; - -#define MODULE "NVThread" - -#include "../nv_debug/nv_debug.hpp" -#include "../com/mapswithme/core/jni_helper.hpp" - -void NVThreadInit(JavaVM* vm) -{ - s_vm = vm; -} - -JNIEnv* NVThreadGetCurrentJNIEnv() -{ - return jni::GetEnv(); -} - -typedef void * (*StartRoutine)(void *); - -typedef struct NVThreadInitStruct -{ - void* m_arg; - StartRoutine m_startRoutine; -} NVThreadInitStruct; - -// Implementations are in PThreadImpl.cpp -// They're used automatically if thread is created with base/thread.hpp -// @TODO: refactor and remove -void AndroidThreadAttachToJVM(); -void AndroidThreadDetachFromJVM(); - -static void * NVThreadSpawnProc(void* arg) -{ - NVThreadInitStruct * init = (NVThreadInitStruct *)arg; - StartRoutine startRoutine = init->m_startRoutine; - void * data = init->m_arg; - void * ret; - - free(arg); - - AndroidThreadAttachToJVM(); - - ret = startRoutine(data); - - AndroidThreadDetachFromJVM(); - - return ret; -} - -int NVThreadSpawnJNIThread(pthread_t * thread, pthread_attr_t const * attr, - StartRoutine startRoutine, void * arg) -{ - if (!startRoutine) - return -1; - - NVThreadInitStruct * initData = new NVThreadInitStruct; - - initData->m_startRoutine = startRoutine; - initData->m_arg = arg; - - int err = pthread_create(thread, attr, NVThreadSpawnProc, initData); - - // If the thread was not started, then we need to delete the init data ourselves - if (err) - free(initData); - - return err; -} - -// on linuces, signals can interrupt sleep functions, so you might need to -// retry to get the full sleep going. I'm not entirely sure this is necessary -// *here* clients could retry themselves when the exposed function returns -// nonzero -inline int __sleep(const struct timespec *req, struct timespec *rem) -{ - int ret = 1; - int i; - static const int sleepTries = 2; - - struct timespec req_tmp={0}, rem_tmp={0}; - - rem_tmp = *req; - for(i = 0; i < sleepTries; ++i) - { - req_tmp = rem_tmp; - int ret = nanosleep(&req_tmp, &rem_tmp); - if(ret == 0) - { - ret = 0; - break; - } - } - if(rem) - *rem = rem_tmp; - return ret; -} - -int NVThreadSleep(unsigned long millisec) -{ - struct timespec req={0},rem={0}; - time_t sec =(int)(millisec/1000); - - millisec = millisec-(sec*1000); - req.tv_sec = sec; - req.tv_nsec = millisec*1000000L; - return __sleep(&req,&rem); -} diff --git a/android/jni/nv_thread/nv_thread.hpp b/android/jni/nv_thread/nv_thread.hpp deleted file mode 100644 index 20e03f5a4a..0000000000 --- a/android/jni/nv_thread/nv_thread.hpp +++ /dev/null @@ -1,97 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_thread\nv_thread.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#ifndef __INCLUDED_NV_THREAD_H -#define __INCLUDED_NV_THREAD_H - -#include -#include -#include - -#if defined(__cplusplus) -extern "C" -{ -#endif - -/** @file nv_thread.h - The NVThread library makes it easy to create native threads that can acess - JNI objects. By default, pthreads created in the Android NDK are NOT connected - to the JVM and JNI calls will fail. This library wraps thread creation in - such a way that pthreads created using it will connect to and disconnect from - the JVM as appropriate. Applications creating all of their threads with these - interfaces can use the provided NVThreadGetCurrentJNIEnv() function to - get the current thread's JNI context at any time. - - Note that native-created threads still have JNI limitations over threads - that are calls down to native from Java. The JNI function FindClass will - NOT find application-specific classes when called from native threads. - Native code that needs to call FindClass and record the indices of Java - class members for later access must call FindClass and Get*FieldID/Get*MethodID - in threads calling from Java, such as JNI_OnLoad - */ - -/** - Initializes the nv_thread system by connecting it to the JVM. This - function must be called as early as possible in the native code's - JNI_OnLoad function, so that the thread system is prepared for any - JNI-dependent library initialization calls. - @param vm The VM pointer - should be the JavaVM pointer sent to JNI_OnLoad. - */ -void NVThreadInit(JavaVM* vm); - -/** - Retrieves the JNIEnv object associated with the current thread, allowing - any thread that was creating with NVThreadSpawnJNIThread() to access the - JNI at will. This JNIEnv is NOT usable across multiple calls or threads - The function should be called in each function that requires a JNIEnv - @return The current thread's JNIEnv, or NULL if the thread was not created - by NVThreadSpawnJNIThread - @see NVThreadSpawnJNIThread - */ -JNIEnv* NVThreadGetCurrentJNIEnv(); - -/** - Spwans a new native thread that is registered for use with JNI. Threads - created with this function will have access to JNI data via the JNIEnv - available from NVThreadGetCurrentJNIEnv(). - @param thread is the same as in pthread_create - @param attr is the same as in pthread_create - @param start_routine is the same as in pthread_create - @param arg is the same as in pthread_create - @return 0 on success, -1 on failure - @see NVThreadGetCurrentJNIEnv -*/ -int NVThreadSpawnJNIThread(pthread_t *thread, pthread_attr_t const * attr, - void *(*start_routine)(void *), void * arg); - -/** - Sleeps the current thread for the specified number of milliseconds - @param millisec Sleep time in ms - @return 0 on success, -1 on failure -*/ -int NVThreadSleep(unsigned long millisec); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/android/jni/nv_time/nv_time.cpp b/android/jni/nv_time/nv_time.cpp deleted file mode 100644 index 441d4442da..0000000000 --- a/android/jni/nv_time/nv_time.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_time\nv_time.cpp -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#include "nv_time.hpp" -#include "../nv_thread/nv_thread.hpp" -#include -#include -#include -#include -#include - -long nvGetSystemTime() -{ - static struct timeval start_time, end_time; - static int isinit = 0; - jlong curr_time = 0; - - if (!isinit) - { - gettimeofday(&start_time, 0); - isinit = 1; - } - gettimeofday(&end_time, 0); - curr_time = (end_time.tv_sec - start_time.tv_sec) * 1000; - curr_time += (end_time.tv_usec - start_time.tv_usec) / 1000; - - return curr_time; -} diff --git a/android/jni/nv_time/nv_time.hpp b/android/jni/nv_time/nv_time.hpp deleted file mode 100644 index f1b16a45ef..0000000000 --- a/android/jni/nv_time/nv_time.hpp +++ /dev/null @@ -1,30 +0,0 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_time\nv_time.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIA® Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//---------------------------------------------------------------------------------- - -#ifndef __INCLUDED_NV_TIME_H -#define __INCLUDED_NV_TIME_H - -#include - -long nvGetSystemTime(); - -#endif diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index 99796b54ca..44c9b4e865 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -87,7 +87,7 @@ public class Framework public native static MapObject nativeGetMapObjectForPoint(double lat, double lon); - public native static void nativeConnectBalloonListeners(OnBalloonListener listener); + public native static void nativeSetBalloonListener(OnBalloonListener listener); public native static void nativeRemoveBalloonListener(); diff --git a/drape/drape_global.hpp b/drape/drape_global.hpp index 1031f891ce..e5bb35497f 100644 --- a/drape/drape_global.hpp +++ b/drape/drape_global.hpp @@ -14,7 +14,7 @@ enum TextureFormat UNSPECIFIED }; -uint8_t GetBytesPerPixel(TextureFormat format) +inline uint8_t GetBytesPerPixel(TextureFormat format) { uint8_t result = 0; switch (format)