diff --git a/android/jni/com/mapswithme/maps/Lifecycle.cpp b/android/jni/com/mapswithme/maps/Lifecycle.cpp index df6f3d43d4..1d95ee5898 100644 --- a/android/jni/com/mapswithme/maps/Lifecycle.cpp +++ b/android/jni/com/mapswithme/maps/Lifecycle.cpp @@ -5,18 +5,9 @@ * Author: siarheirachytski */ -#include - -#include -#include -#include -#include #include #include -#include -#include "../../../nv_time/nv_time.hpp" #include "../../../nv_event/nv_event.hpp" -#include "../../../nv_thread/nv_thread.hpp" #include "../../../../../base/logging.hpp" #include "../../../../../graphics/opengl/opengl.hpp" #include "Framework.hpp" @@ -25,27 +16,11 @@ #define MODULE "MapsWithMe" #define NVDEBUG(args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, ## args) -static float s_aspect = 1.0f; static int32_t s_winWidth = 1; static int32_t s_winHeight = 1; static int32_t s_densityDpi = 1; -static unsigned int s_swapCount = 0; static bool s_glesLoaded = false; -static bool s_glesAutopaused = false; -static bool shouldLoadState = true; - -static bool renderGameplay() -{ - g_framework->DrawFrame(); - - return true; //return true to update screen -} - -static bool renderPauseScreen() -{ - return true; -} bool SetupGLESResources() { @@ -124,30 +99,8 @@ bool renderFrame(bool allocateIfNeeded) return false; } - // If we're not paused, "animate" the scene - if (!s_glesAutopaused) - { - // clock ticks, so animate something. - } - - // For this simple app, we render the gameplay every time - // we render, even if it is paused. When we are paused, the - /// gameplay is not animated and the pause "screen" is on top g_framework->DrawFrame(); -// // If we're paused, draw the pause screen on top -// if (s_glesAutopaused) -// renderPauseScreen(); - -// NVEventSwapBuffersEGL(); - - // A debug printout every 256 frames so we can see when we're - // actively rendering and swapping - /*if (!(s_swapCount++ & 0x00ff)) - { - NVDEBUG("Swap count is %d", s_swapCount); - }*/ - return true; } @@ -156,20 +109,11 @@ bool renderFrame(bool allocateIfNeeded) // as listed in the docs) int32_t NVEventAppInit(int32_t argc, char** argv) { - /*if (!g_framework) - { - android::Platform::Instance().Initialize(env, apkPath, storagePath); - g_framework = new android::Framework(g_jvm); - }*/ - -// nv_shader_init(); - return 0; } int32_t NVEventAppMain(int32_t argc, char** argv) { - s_swapCount = 0; s_glesLoaded = false; NVDEBUG("Application entering main loop"); @@ -187,7 +131,7 @@ int32_t NVEventAppMain(int32_t argc, char** argv) 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)/* && !s_glesAutopaused*/) + if ((ev->m_data.m_key.m_code == NV_KEYCODE_BACK)) { renderFrame(false); NVEventDoneWithEvent(true); @@ -205,7 +149,6 @@ int32_t NVEventAppMain(int32_t argc, char** argv) NVEventDoneWithEvent(false); break; case NV_EVENT_LONG_CLICK: - break; case NV_EVENT_TOUCH: { @@ -244,9 +187,6 @@ int32_t NVEventAppMain(int32_t argc, char** argv) g_framework->NativeFramework()->Invalidate(true); NVDEBUG( "Surface create/resize event: %d x %d", s_winWidth, s_winHeight); - - if ((s_winWidth > 0) && (s_winHeight > 0)) - s_aspect = (float)s_winWidth / (float)s_winHeight; break; case NV_EVENT_SURFACE_DESTROYED: diff --git a/android/jni/nv_event/nv_event.cpp b/android/jni/nv_event/nv_event.cpp index 46d295d338..18ce33da2a 100644 --- a/android/jni/nv_event/nv_event.cpp +++ b/android/jni/nv_event/nv_event.cpp @@ -1,6 +1,6 @@ //---------------------------------------------------------------------------------- // File: libs\jni\nv_event\nv_event.cpp -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// Samples Version: NVIDIA Android Lifecycle samples 1_0beta // Email: tegradev@nvidia.com // Web: http://developer.nvidia.com/category/zone/mobile-development // @@ -39,12 +39,6 @@ #include "nv_keycode_mapping.hpp" #include "nv_event_queue.hpp" -// TODO TBD - this should be done in NVTimeInit(), but we use a different -// class than most apps. Need to clean this up, as it is fragile w.r.t. -// changes in nv_time -extern void nvAcquireTimeExtensionJNI(JNIEnv*, jobject); -extern jlong nvGetSystemTimeJNI(JNIEnv*, jobject); - #define CT_ASSERT(tag,cond) \ enum { COMPILE_TIME_ASSERT__ ## tag = 1/(cond) } @@ -77,27 +71,27 @@ enum 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; } @@ -231,7 +225,7 @@ bool NVEventStatusIsFocused() return QueryAppFlag(NVEVENT_STATUS_FOCUSED); } -// True when the app's SurfaceHolder points to a +// True when the app's SurfaceHolder points to a // valid, nonzero-sized window bool NVEventStatusHasRealSurface() { @@ -441,7 +435,7 @@ bool NVEventSwapBuffersEGL() RESET_PROFILING(); return true; } - + int NVEventGetErrorEGL() { return s_GetErrorEGL.CallInt(); @@ -505,7 +499,7 @@ void NVEventOnRenderingInitialized() // Input event-related Java to Native callback functions -static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action, +static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action, jboolean hasFirst, jboolean hasSecond, jint mx1, jint my1, jint mx2, jint my2) { { @@ -521,7 +515,7 @@ static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action, maskOnly |= 0x2; ev.m_type = NV_EVENT_MULTITOUCH; - + if (actionOnly == NVEVENT_ACTION_UP) { ev.m_data.m_multi.m_action = NV_MULTITOUCH_UP; @@ -784,8 +778,8 @@ static jboolean onDestroyNative(JNIEnv* env, jobject thiz) return JNI_TRUE; } -static jboolean postUserEvent(JNIEnv* env, jobject thiz, - jint u0, jint u1, jint u2, jint u3, +static jboolean postUserEvent(JNIEnv* env, jobject thiz, + jint u0, jint u1, jint u2, jint u3, jboolean blocking) { NVEvent ev; @@ -915,7 +909,7 @@ void InitNVEvent(JavaVM* vm) jclass k; k = (env)->FindClass ("com/nvidia/devtech/NvEventQueueActivity"); (env)->RegisterNatives(k, methods, dimof(methods)); - + s_InitEGL.QueryID(env, k); s_CleanupEGL.QueryID(env, k); s_CreateSurfaceEGL.QueryID(env, k); diff --git a/android/jni/nv_event/nv_event.hpp b/android/jni/nv_event/nv_event.hpp index 59d1f2c8fa..8d5e132c4f 100644 --- a/android/jni/nv_event/nv_event.hpp +++ b/android/jni/nv_event/nv_event.hpp @@ -1,6 +1,6 @@ //---------------------------------------------------------------------------------- // File: libs\jni\nv_event\nv_event.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// Samples Version: NVIDIA Android Lifecycle samples 1_0beta // Email: tegradev@nvidia.com // Web: http://developer.nvidia.com/category/zone/mobile-development // @@ -23,7 +23,6 @@ #define _NV_EVENT_H #include #include -//#include /** @file nv_event.h Contains a framework for event loop-based applications. This library replaces @@ -31,7 +30,7 @@ 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 +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 @@ -49,7 +48,7 @@ typedef jobject NVEventPlatformAppHandle; #else // unknown platform -typedef void* NVEventPlatformAppHandle; +typedef void * NVEventPlatformAppHandle; #endif @@ -124,7 +123,7 @@ typedef enum NVTouchEventType NV_TOUCHACTION_FORCE_32BITS = 0x7fffffff } NVTouchEventType; -/** Multitouch event flags +/** Multitouch event flags */ typedef enum NVMultiTouchEventType { @@ -336,9 +335,9 @@ typedef struct NVEventMWM void * m_pFn; } NVEventMWM; -/** All-encompassing event structure +/** All-encompassing event structure */ -typedef struct NVEvent +typedef struct NVEvent { /** The type of the event, which also indicates which m_data union holds the data */ NVEventType m_type; @@ -367,58 +366,58 @@ typedef struct NVEvent @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); +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 +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". +@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. + 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 +@see NVEvent +@see NVEventDoneWithEvent */ -const NVEvent* NVEventGetNextEvent(int waitMSecs = 0); +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 +/** 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 +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 +@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 +@see NVEvent +@see NVEventGetNextEvent */ void NVEventDoneWithEvent(bool handled); -/** The app-supplied "callback" for initialization during JNI_OnLoad. +/** 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 +@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. +/** 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 +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); @@ -435,8 +434,8 @@ bool NVEventInitEGL(); */ 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 +/** 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 */ @@ -462,26 +461,26 @@ bool NVEventUnbindSurfaceAndContextEGL(); @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. + 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. + 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 +/** 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 +@return true if the application is between onCreate and onDestroy and false after an onDestroy event has been delivered. */ bool NVEventStatusIsRunning(); @@ -499,33 +498,33 @@ bool NVEventStatusIsActive(); */ bool NVEventStatusIsFocused(); -/** Convenience conditional function to determine if the app has a surface and that surface +/** 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 +@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 +/** 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, +@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, +/** 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) +/** 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 +/** 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(); diff --git a/android/jni/nv_event/nv_event_queue.cpp b/android/jni/nv_event/nv_event_queue.cpp index b759284101..4172040dd7 100644 --- a/android/jni/nv_event/nv_event_queue.cpp +++ b/android/jni/nv_event/nv_event_queue.cpp @@ -4,7 +4,7 @@ // Email: tegradev@nvidia.com // Web: http://developer.nvidia.com/category/zone/mobile-development // -// Copyright 2009-2011 NVIDIA® Corporation +// 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. @@ -33,14 +33,14 @@ #define NVPrevWrapped(index) (((index) - 1) & QUEUE_MASK) /* you must be inside a m_accessLock lock to invoke this! */ -static void unlockAll(NVEventSync* sem) +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) +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? @@ -59,29 +59,29 @@ static int32_t wait(NVEventSync* sem, pthread_mutex_t* mutex, int waitMS) } } -static void signal(NVEventSync* sem) +static void signal(NVEventSync * sem) { pthread_cond_signal(&sem->m_cond); } -static void broadcast(NVEventSync* sem) +static void broadcast(NVEventSync * sem) { pthread_cond_broadcast(&sem->m_cond); } -static void syncInit( NVEventSync* sync ) +static void syncInit(NVEventSync * sync) { - pthread_cond_init(&(sync->m_cond), NULL); + pthread_cond_init(&sync->m_cond, NULL); sync->m_block = true; } -static void syncDestroy( NVEventSync* sync ) +static void syncDestroy(NVEventSync * sync) { - pthread_cond_destroy( &sync->m_cond ); + pthread_cond_destroy(&sync->m_cond); } /* you must be inside a m_accessLock lock to invoke this! */ -bool NVEventQueue::insert(const NVEvent* ev) +bool NVEventQueue::insert(NVEvent const * ev) { // Is the queue full? int32_t nextNext = NVNextWrapped(m_nextInsertIndex); @@ -91,7 +91,7 @@ bool NVEventQueue::insert(const NVEvent* ev) return false; } - NVEvent* evDest = m_events + m_nextInsertIndex; + NVEvent * evDest = m_events + m_nextInsertIndex; memcpy(evDest, ev, sizeof(NVEvent)); m_nextInsertIndex = nextNext; @@ -102,7 +102,7 @@ void NVEventQueue::Init() { m_nextInsertIndex = 0; m_headIndex = 0; - pthread_mutex_init(&(m_accessLock), NULL); + pthread_mutex_init(&m_accessLock, NULL); syncInit(&m_consumerSync); syncInit(&m_blockerSync); @@ -113,13 +113,13 @@ void NVEventQueue::Init() void NVEventQueue::Shutdown() { - pthread_mutex_destroy(&(m_accessLock)); + pthread_mutex_destroy(&m_accessLock); // free everyone... unlockAll(&m_consumerSync); unlockAll(&m_blockerSync); - syncDestroy(&(m_consumerSync)); - syncDestroy(&(m_blockerSync)); + syncDestroy(&m_consumerSync); + syncDestroy(&m_blockerSync); } void NVEventQueue::Flush() @@ -130,32 +130,32 @@ void NVEventQueue::Flush() void NVEventQueue::UnblockConsumer() { - unlockAll(&(m_consumerSync)); + unlockAll(&m_consumerSync); } void NVEventQueue::UnblockProducer() { - unlockAll(&(m_blockerSync)); + unlockAll(&m_blockerSync); } void NVEventQueue::Insert(const NVEvent* ev) { - pthread_mutex_lock(&(m_accessLock)); + pthread_mutex_lock(&m_accessLock); // insert the event and unblock a waiter insert(ev); signal(&m_consumerSync); - pthread_mutex_unlock(&(m_accessLock)); + 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)); + pthread_mutex_lock(&m_accessLock); while (m_blocker) { - if (wait(&(m_blockerSync), &(m_accessLock), NV_EVENT_WAIT_FOREVER)) + if (wait(&m_blockerSync, &m_accessLock, NV_EVENT_WAIT_FOREVER)) return false; } @@ -168,7 +168,7 @@ bool NVEventQueue::InsertBlocking(const NVEvent* ev) m_blockerState = PENDING_BLOCKER; // Release the consumer, as we just posted a new event - signal(&(m_consumerSync)); + signal(&m_consumerSync); // Loop on the condition variable until we find out that // there is a return value waiting for us. Since only we @@ -176,7 +176,7 @@ bool NVEventQueue::InsertBlocking(const NVEvent* ev) // else start to post a blocking event while (m_blockerState != RETURNED_BLOCKER) { - if (wait(&(m_blockerSync), &(m_accessLock), NV_EVENT_WAIT_FOREVER)) + if (wait(&m_blockerSync, &m_accessLock, NV_EVENT_WAIT_FOREVER)) return false; } @@ -188,8 +188,8 @@ bool NVEventQueue::InsertBlocking(const NVEvent* ev) // 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)); + signal(&m_blockerSync); + pthread_mutex_unlock(&m_accessLock); return handled; } @@ -197,7 +197,7 @@ bool NVEventQueue::InsertBlocking(const NVEvent* ev) const NVEvent* NVEventQueue::RemoveOldest(int waitMSecs) { - pthread_mutex_lock(&(m_accessLock)); + pthread_mutex_lock(&m_accessLock); // Hmm - the last event we got from RemoveOldest was a // blocker, and DoneWithEvent not called. @@ -206,7 +206,7 @@ const NVEvent* NVEventQueue::RemoveOldest(int waitMSecs) { m_blockerReturnVal = false; m_blockerState = RETURNED_BLOCKER; - broadcast(&(m_blockerSync)); + broadcast(&m_blockerSync); } // Blocker is waiting - return it @@ -215,7 +215,7 @@ const NVEvent* NVEventQueue::RemoveOldest(int waitMSecs) { m_blockerState = PROCESSING_BLOCKER; const NVEvent* ev = m_blocker; - pthread_mutex_unlock(&(m_accessLock)); + pthread_mutex_unlock(&m_accessLock); return ev; } @@ -229,7 +229,7 @@ const NVEvent* NVEventQueue::RemoveOldest(int waitMSecs) else { // wait for the specified time - wait(&(m_consumerSync), &(m_accessLock), (unsigned)waitMSecs); + wait(&m_consumerSync, &m_accessLock, (unsigned)waitMSecs); } // check again after exiting cond waits, either we had a timeout @@ -249,15 +249,15 @@ const NVEvent* NVEventQueue::RemoveOldest(int waitMSecs) { // One way or another, we have an event... - const NVEvent* ev = m_events + m_headIndex; + NVEvent const * ev = m_events + m_headIndex; m_headIndex = NVNextWrapped(m_headIndex); - pthread_mutex_unlock(&(m_accessLock)); + pthread_mutex_unlock(&m_accessLock); return ev; } no_event: - pthread_mutex_unlock(&(m_accessLock)); + pthread_mutex_unlock(&m_accessLock); return NULL; } @@ -265,12 +265,12 @@ void NVEventQueue::DoneWithEvent(bool ret) { // We only care about blockers for now. // All other events just NOP - pthread_mutex_lock(&(m_accessLock)); + pthread_mutex_lock(&m_accessLock); if (m_blockerState == PROCESSING_BLOCKER) { m_blockerReturnVal = ret; m_blockerState = RETURNED_BLOCKER; - broadcast(&(m_blockerSync)); + broadcast(&m_blockerSync); } - pthread_mutex_unlock(&(m_accessLock)); + 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 index 4c08b8ba01..b6d0c113c4 100644 --- a/android/jni/nv_event/nv_event_queue.hpp +++ b/android/jni/nv_event/nv_event_queue.hpp @@ -4,7 +4,7 @@ // Email: tegradev@nvidia.com // Web: http://developer.nvidia.com/category/zone/mobile-development // -// Copyright 2009-2011 NVIDIA® Corporation +// 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. @@ -41,10 +41,10 @@ public: void UnblockConsumer(); void UnblockProducer(); // Events are copied, so caller can reuse ev immediately - void Insert(const NVEvent* ev); + void Insert(NVEvent const * ev); // Waits until the event is consumed. Returns whether the // consumer indicates handling the event or ignoring it - bool InsertBlocking(const NVEvent* ev); + bool InsertBlocking(NVEvent const * ev); // Returned event is valid only until the next call to // RemoveOldest or until a call to DoneWithEvent @@ -60,7 +60,7 @@ public: void DoneWithEvent(bool ret); protected: - bool insert(const NVEvent* ev); + bool insert(NVEvent const * ev); enum { QUEUE_ELEMS = 256 }; enum { QUEUE_MASK = 0x000000ff }; @@ -74,7 +74,7 @@ protected: NVEventSync m_consumerSync; NVEvent m_events[QUEUE_ELEMS]; - const NVEvent* m_blocker; + NVEvent const * m_blocker; enum BlockerState { NO_BLOCKER, @@ -86,7 +86,4 @@ protected: bool m_blockerReturnVal; }; - - - #endif // #ifndef NV_EVENT_QUEUE diff --git a/android/jni/nv_thread/nv_thread.cpp b/android/jni/nv_thread/nv_thread.cpp index 26a891d6ea..f7d1a87d39 100644 --- a/android/jni/nv_thread/nv_thread.cpp +++ b/android/jni/nv_thread/nv_thread.cpp @@ -42,45 +42,14 @@ void NVThreadInit(JavaVM* vm) JNIEnv* NVThreadGetCurrentJNIEnv() { return jni::GetEnv(); - -// JNIEnv* env = NULL; -// if (s_jniEnvKey) -// { -// env = (JNIEnv*)pthread_getspecific(s_jniEnvKey); -// } -// else -// { -// pthread_key_create(&s_jniEnvKey, NULL); -// } -// -// if (!env) -// { -// // do we have a VM cached? -// if (!s_vm) -// { -// __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error - could not find JVM!"); -// return NULL; -// } -// -// // Hmm - no env for this thread cached yet -// int error = s_vm->AttachCurrentThread(&env, NULL); -// __android_log_print(ANDROID_LOG_DEBUG, MODULE, "AttachCurrentThread: %d, 0x%p", error, env); -// if (error || !env) -// { -// __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error - could not attach thread to JVM!"); -// return NULL; -// } -// -// pthread_setspecific(s_jniEnvKey, env); -// } -// -// return env; } +typedef void * (*StartRoutine)(void *); + typedef struct NVThreadInitStruct { void* m_arg; - void *(*m_startRoutine)(void *); + StartRoutine m_startRoutine; } NVThreadInitStruct; // Implementations are in PThreadImpl.cpp @@ -89,33 +58,33 @@ typedef struct NVThreadInitStruct void AndroidThreadAttachToJVM(); void AndroidThreadDetachFromJVM(); -static void* NVThreadSpawnProc(void* arg) +static void * NVThreadSpawnProc(void* arg) { - NVThreadInitStruct* init = (NVThreadInitStruct*)arg; - void *(*start_routine)(void *) = init->m_startRoutine; - void* data = init->m_arg; - void* ret; + NVThreadInitStruct * init = (NVThreadInitStruct *)arg; + StartRoutine startRoutine = init->m_startRoutine; + void * data = init->m_arg; + void * ret; free(arg); AndroidThreadAttachToJVM(); - ret = start_routine(data); + ret = startRoutine(data); AndroidThreadDetachFromJVM(); return ret; } -int NVThreadSpawnJNIThread(pthread_t *thread, pthread_attr_t const * attr, - void *(*start_routine)(void *), void * arg) +int NVThreadSpawnJNIThread(pthread_t * thread, pthread_attr_t const * attr, + StartRoutine startRoutine, void * arg) { - if (!start_routine) + if (!startRoutine) return -1; NVThreadInitStruct * initData = new NVThreadInitStruct; - initData->m_startRoutine = start_routine; + initData->m_startRoutine = startRoutine; initData->m_arg = arg; int err = pthread_create(thread, attr, NVThreadSpawnProc, initData); diff --git a/android/jni/nv_time/nv_time.cpp b/android/jni/nv_time/nv_time.cpp index a2d421ccca..441d4442da 100644 --- a/android/jni/nv_time/nv_time.cpp +++ b/android/jni/nv_time/nv_time.cpp @@ -1,10 +1,10 @@ //---------------------------------------------------------------------------------- // File: libs\jni\nv_time\nv_time.cpp -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// 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 +// 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. @@ -22,114 +22,18 @@ #include "nv_time.hpp" #include "../nv_thread/nv_thread.hpp" -/*#include -#include -#include */ #include #include #include #include #include -/*#ifndef EGL_NV_system_time -#define EGL_NV_system_time 1 -typedef khronos_uint64_t EGLuint64NV; -#ifdef EGL_EGLEXT_PROTOTYPES -EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV(void); -EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV(void); -#endif -typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC)(void); -typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC)(void); -#endif -*/ - -void nvAcquireTimeExtensionJNI(JNIEnv*, jobject) -{ - nvAcquireTimeExtension(); -} - -jlong nvGetSystemTimeJNI(JNIEnv*, jobject) -{ - return (jlong)nvGetSystemTime(); -} - -/*static PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC eglGetSystemTimeFrequencyNVProc = NULL; -static PFNEGLGETSYSTEMTIMENVPROC eglGetSystemTimeNVProc = NULL; -static EGLuint64NV eglSystemTimeFrequency = 0; -static bool timeExtensionQueried = false;*/ - -void nvAcquireTimeExtension() -{ -/* if (timeExtensionQueried) - return; - timeExtensionQueried = true; - - eglGetSystemTimeFrequencyNVProc = (PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) eglGetProcAddress("eglGetSystemTimeFrequencyNV"); - eglGetSystemTimeNVProc = (PFNEGLGETSYSTEMTIMENVPROC) eglGetProcAddress("eglGetSystemTimeNV"); - - // now, we'll proceed through a series of sanity checking. - // if they all succeed, we'll return. - // if any fail, we fall out of conditional tests to end of function, null pointers, and return. - if (eglGetSystemTimeFrequencyNVProc && - eglGetSystemTimeNVProc) - { - eglSystemTimeFrequency = eglGetSystemTimeFrequencyNVProc(); - if (eglSystemTimeFrequency>0) // assume okay. quick-check it works. - { - EGLuint64NV time1, time2; - time1 = eglGetSystemTimeNVProc(); - usleep(2000); // 2ms should be MORE than sufficient, right? - time2 = eglGetSystemTimeNVProc(); - if (time1 != time2) // quick sanity only... - { - // we've sanity checked: - // - fn pointers non-null - // - freq non-zero - // - two calls to time sep'd by sleep non-equal - // safe to return now. - return; - } - } - } - - // fall back if we've not returned already. - eglGetSystemTimeFrequencyNVProc = (PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) NULL; - eglGetSystemTimeNVProc = (PFNEGLGETSYSTEMTIMENVPROC) NULL;*/ -} - -bool nvValidTimeExtension() -{ -/* if (NULL == eglGetSystemTimeFrequencyNVProc || - NULL == eglGetSystemTimeNVProc) - return false; - else - return true;*/ - return false; -} - long nvGetSystemTime() { static struct timeval start_time, end_time; static int isinit = 0; jlong curr_time = 0; -/* if(eglGetSystemTimeNVProc) - { - EGLuint64NV egltime; - EGLuint64NV egltimequot; - EGLuint64NV egltimerem; - - egltime = eglGetSystemTimeNVProc(); - - egltimequot = egltime / eglSystemTimeFrequency; - egltimerem = egltime - (eglSystemTimeFrequency * egltimequot); - egltimequot *= 1000; - egltimerem *= 1000; - egltimerem /= eglSystemTimeFrequency; - egltimequot += egltimerem; - return (jlong) egltimequot; - } -*/ if (!isinit) { gettimeofday(&start_time, 0); @@ -141,25 +45,3 @@ long nvGetSystemTime() return curr_time; } - -void NVTimeInit() -{ - JNIEnv* env = NVThreadGetCurrentJNIEnv(); - - JNINativeMethod methods_time[] = - { - { - "nvAcquireTimeExtension", - "()V", - (void *) nvAcquireTimeExtension - }, - { - "nvGetSystemTime", - "()J", - (void *) nvGetSystemTime - }, - }; - jclass k_time; - k_time = (env)->FindClass ("com/nvidia/devtech/NvActivity"); - (env)->RegisterNatives(k_time, methods_time, 2); -} diff --git a/android/jni/nv_time/nv_time.hpp b/android/jni/nv_time/nv_time.hpp index 88a01d2a37..f1b16a45ef 100644 --- a/android/jni/nv_time/nv_time.hpp +++ b/android/jni/nv_time/nv_time.hpp @@ -1,10 +1,10 @@ //---------------------------------------------------------------------------------- // File: libs\jni\nv_time\nv_time.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// 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 +// 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. @@ -25,10 +25,6 @@ #include -void NVTimeInit(); - -void nvAcquireTimeExtension(); -bool nvValidTimeExtension(); long nvGetSystemTime(); #endif