src/core/android/SDL_android.cpp
changeset 6650 d36232135316
parent 6642 b716011e53ce
child 6653 b73f8ee5f033
     1.1 --- a/src/core/android/SDL_android.cpp	Sun Nov 04 09:45:18 2012 -0800
     1.2 +++ b/src/core/android/SDL_android.cpp	Sun Nov 04 13:49:32 2012 -0800
     1.3 @@ -21,6 +21,7 @@
     1.4  #include "SDL_config.h"
     1.5  #include "SDL_stdinc.h"
     1.6  #include "SDL_assert.h"
     1.7 +#include "SDL_log.h"
     1.8  
     1.9  #ifdef __ANDROID__
    1.10  
    1.11 @@ -41,6 +42,8 @@
    1.12  #define LOGI(...) do {} while (false)
    1.13  #define LOGE(...) do {} while (false)
    1.14  
    1.15 +/* Uncomment this to log messages entering and exiting methods in this file */
    1.16 +//#define DEBUG_JNI
    1.17  
    1.18  /* Implemented in audio/android/SDL_androidaudio.c */
    1.19  extern void Android_RunAudioThread();
    1.20 @@ -259,8 +262,15 @@
    1.21      }
    1.22  
    1.23  public:
    1.24 -    LocalReferenceHolder() : m_env(NULL) { }
    1.25 +    LocalReferenceHolder(const char *func) : m_env(NULL), m_func(func) {
    1.26 +#ifdef DEBUG_JNI
    1.27 +        SDL_Log("Entering function %s", m_func);
    1.28 +#endif
    1.29 +    }
    1.30      ~LocalReferenceHolder() {
    1.31 +#ifdef DEBUG_JNI
    1.32 +        SDL_Log("Leaving function %s", m_func);
    1.33 +#endif
    1.34          if (m_env) {
    1.35              m_env->PopLocalFrame(NULL);
    1.36              --s_active;
    1.37 @@ -279,6 +289,7 @@
    1.38  
    1.39  protected:
    1.40      JNIEnv *m_env;
    1.41 +    const char *m_func;
    1.42  };
    1.43  int LocalReferenceHolder::s_active;
    1.44  
    1.45 @@ -497,7 +508,7 @@
    1.46  
    1.47  static int Android_JNI_FileOpen(SDL_RWops* ctx)
    1.48  {
    1.49 -    LocalReferenceHolder refs;
    1.50 +    LocalReferenceHolder refs(__FUNCTION__);
    1.51      int result = 0;
    1.52  
    1.53      jmethodID mid;
    1.54 @@ -592,7 +603,7 @@
    1.55  extern "C" int Android_JNI_FileOpen(SDL_RWops* ctx,
    1.56          const char* fileName, const char*)
    1.57  {
    1.58 -    LocalReferenceHolder refs;
    1.59 +    LocalReferenceHolder refs(__FUNCTION__);
    1.60      JNIEnv *mEnv = Android_JNI_GetEnv();
    1.61  
    1.62      if (!refs.init(mEnv)) {
    1.63 @@ -615,7 +626,7 @@
    1.64  extern "C" size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
    1.65          size_t size, size_t maxnum)
    1.66  {
    1.67 -    LocalReferenceHolder refs;
    1.68 +    LocalReferenceHolder refs(__FUNCTION__);
    1.69      jlong bytesRemaining = (jlong) (size * maxnum);
    1.70      jlong bytesMax = (jlong) (ctx->hidden.androidio.size -  ctx->hidden.androidio.position);
    1.71      int bytesRead = 0;
    1.72 @@ -661,7 +672,7 @@
    1.73  
    1.74  static int Android_JNI_FileClose(SDL_RWops* ctx, bool release)
    1.75  {
    1.76 -    LocalReferenceHolder refs;
    1.77 +    LocalReferenceHolder refs(__FUNCTION__);
    1.78      int result = 0;
    1.79      JNIEnv *mEnv = Android_JNI_GetEnv();
    1.80  
    1.81 @@ -731,7 +742,7 @@
    1.82  
    1.83      Sint64 movement = newPosition - ctx->hidden.androidio.position;
    1.84      if (movement > 0) {
    1.85 -        unsigned char buffer[1024];
    1.86 +        unsigned char buffer[4096];
    1.87  
    1.88          // The easy case where we're seeking forwards
    1.89          while (movement > 0) {
    1.90 @@ -767,7 +778,7 @@
    1.91  // returns a new global reference which needs to be released later
    1.92  static jobject Android_JNI_GetSystemServiceObject(const char* name)
    1.93  {
    1.94 -    LocalReferenceHolder refs;
    1.95 +    LocalReferenceHolder refs(__FUNCTION__);
    1.96      JNIEnv* env = Android_JNI_GetEnv();
    1.97      if (!refs.init(env)) {
    1.98          return NULL;
    1.99 @@ -789,7 +800,7 @@
   1.100  }
   1.101  
   1.102  #define SETUP_CLIPBOARD(error) \
   1.103 -    LocalReferenceHolder refs; \
   1.104 +    LocalReferenceHolder refs(__FUNCTION__); \
   1.105      JNIEnv* env = Android_JNI_GetEnv(); \
   1.106      if (!refs.init(env)) { \
   1.107          return error; \
   1.108 @@ -847,7 +858,7 @@
   1.109  // returns the value in seconds and percent or -1 if not available
   1.110  extern "C" int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent)
   1.111  {
   1.112 -    LocalReferenceHolder refs;
   1.113 +    LocalReferenceHolder refs(__FUNCTION__);
   1.114      JNIEnv* env = Android_JNI_GetEnv();
   1.115      if (!refs.init(env)) {
   1.116          return -1;
   1.117 @@ -993,7 +1004,7 @@
   1.118  
   1.119  extern "C" void *SDL_AndroidGetActivity()
   1.120  {
   1.121 -    LocalReferenceHolder refs;
   1.122 +    LocalReferenceHolder refs(__FUNCTION__);
   1.123      jmethodID mid;
   1.124  
   1.125      JNIEnv *env = Android_JNI_GetEnv();
   1.126 @@ -1012,7 +1023,7 @@
   1.127      static char *s_AndroidInternalFilesPath = NULL;
   1.128  
   1.129      if (!s_AndroidInternalFilesPath) {
   1.130 -        LocalReferenceHolder refs;
   1.131 +        LocalReferenceHolder refs(__FUNCTION__);
   1.132          jmethodID mid;
   1.133          jobject context;
   1.134          jobject fileObject;
   1.135 @@ -1052,7 +1063,7 @@
   1.136  
   1.137  extern "C" int SDL_AndroidGetExternalStorageState()
   1.138  {
   1.139 -    LocalReferenceHolder refs;
   1.140 +    LocalReferenceHolder refs(__FUNCTION__);
   1.141      jmethodID mid;
   1.142      jclass cls;
   1.143      jstring stateString;
   1.144 @@ -1092,7 +1103,7 @@
   1.145      static char *s_AndroidExternalFilesPath = NULL;
   1.146  
   1.147      if (!s_AndroidExternalFilesPath) {
   1.148 -        LocalReferenceHolder refs;
   1.149 +        LocalReferenceHolder refs(__FUNCTION__);
   1.150          jmethodID mid;
   1.151          jobject context;
   1.152          jobject fileObject;