From d2a4173ab418c376c440575c97e2d4f677284079 Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 23 Feb 2012 17:34:46 +0000 Subject: [PATCH] Android: better logging, more GL work. --- .../jucer_ProjectExport_Android.h | 8 ++++++ .../Builds/Android/AndroidManifest.xml | 1 + extras/JuceDemo/Builds/Android/jni/Android.mk | 4 +-- .../Builds/Android/src/com/juce/JuceDemo.java | 25 +++---------------- modules/juce_core/juce_core.cpp | 5 ++++ .../native/java/JuceAppActivity.java | 25 +++---------------- .../native/juce_android_JNIHelpers.h | 1 - .../juce_core/native/juce_android_Misc.cpp | 6 +---- .../native/juce_android_OpenGLComponent.cpp | 17 +++++++++---- .../opengl/juce_OpenGLComponent.cpp | 12 +++++++++ 10 files changed, 49 insertions(+), 55 deletions(-) diff --git a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h index dd1558b9db..5011a5ff92 100644 --- a/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h +++ b/extras/Introjucer/Source/Project Saving/jucer_ProjectExport_Android.h @@ -243,6 +243,13 @@ private: manifest->createNewChildElement ("uses-permission")->setAttribute ("android:name", permissions[i]); } + if (project.isModuleEnabled ("juce_opengl")) + { + XmlElement* feature = manifest->createNewChildElement ("uses-feature"); + feature->setAttribute ("android:glEsVersion", "0x00020000"); + feature->setAttribute ("android:required", "true"); + } + XmlElement* app = manifest->createNewChildElement ("application"); app->setAttribute ("android:label", "@string/app_name"); app->setAttribute ("android:icon", "@drawable/icon"); @@ -422,6 +429,7 @@ private: { StringArray libs; + libs.add ("log"); libs.add ("GLESv1_CM"); libs.add ("GLESv2"); diff --git a/extras/JuceDemo/Builds/Android/AndroidManifest.xml b/extras/JuceDemo/Builds/Android/AndroidManifest.xml index 5aa57ea37e..11a3c874bb 100644 --- a/extras/JuceDemo/Builds/Android/AndroidManifest.xml +++ b/extras/JuceDemo/Builds/Android/AndroidManifest.xml @@ -6,6 +6,7 @@ + diff --git a/extras/JuceDemo/Builds/Android/jni/Android.mk b/extras/JuceDemo/Builds/Android/jni/Android.mk index c838b2f94d..bcc5c43abe 100644 --- a/extras/JuceDemo/Builds/Android/jni/Android.mk +++ b/extras/JuceDemo/Builds/Android/jni/Android.mk @@ -48,11 +48,11 @@ LOCAL_SRC_FILES := \ ifeq ($(CONFIG),Debug) LOCAL_CPPFLAGS += -fsigned-char -fexceptions -frtti -g -I "../../JuceLibraryCode" -O0 -D "JUCE_ANDROID=1" -D "JUCE_ANDROID_ACTIVITY_CLASSNAME=com_juce_JuceDemo" -D JUCE_ANDROID_ACTIVITY_CLASSPATH=\"com/juce/JuceDemo\" -D "DEBUG=1" -D "_DEBUG=1" -D "JUCE_UNIT_TESTS=1" -D "JUCER_ANDROID_7F0E4A25=1" APP_ABI := armeabi - LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 + LOCAL_LDLIBS := -llog -lGLESv1_CM -lGLESv2 else LOCAL_CPPFLAGS += -fsigned-char -fexceptions -frtti -I "../../JuceLibraryCode" -Os -D "JUCE_ANDROID=1" -D "JUCE_ANDROID_ACTIVITY_CLASSNAME=com_juce_JuceDemo" -D JUCE_ANDROID_ACTIVITY_CLASSPATH=\"com/juce/JuceDemo\" -D "NDEBUG=1" -D "JUCE_UNIT_TESTS=1" -D "JUCER_ANDROID_7F0E4A25=1" APP_ABI := armeabi armeabi-v7a - LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 + LOCAL_LDLIBS := -llog -lGLESv1_CM -lGLESv2 endif include $(BUILD_SHARED_LIBRARY) diff --git a/extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java b/extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java index e47178e08a..535a5bf86e 100644 --- a/extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java +++ b/extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java @@ -347,43 +347,26 @@ public final class JuceDemo extends Activity OpenGLView (Context context) { super (context); - setEGLContextClientVersion (2); - getHolder().setFormat(PixelFormat.TRANSLUCENT); - setVisibility (VISIBLE); setRenderer (this); - - //setRenderMode (RENDERMODE_CONTINUOUSLY); - //requestRender(); } @Override public void onSurfaceCreated (GL10 unused, EGLConfig config) { - // contextCreated(); - } - - @Override - public void onDrawFrame (GL10 unused) - { - //GLES20.glClearColor (1.0f, 0.5f, 0.0f, 1.0f); - //GLES20.glClear (GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); - - // render(); + contextCreated(); } @Override public void onSurfaceChanged (GL10 unused, int width, int height) { - //GLES20.glViewport (0, 0, width, height); + contextCreated(); } @Override - protected void onLayout (boolean changed, int left, int top, int right, int bottom) + public void onDrawFrame (GL10 unused) { - super.onLayout (changed, left, top, right, bottom); - requestLayout(); - ((ViewGroup) getParent()).requestTransparentRegion (this); + render(); } private native void contextCreated(); diff --git a/modules/juce_core/juce_core.cpp b/modules/juce_core/juce_core.cpp index 7f8ca996da..cf67e0dccf 100644 --- a/modules/juce_core/juce_core.cpp +++ b/modules/juce_core/juce_core.cpp @@ -74,6 +74,11 @@ #include #endif +#if JUCE_ANDROID + #include +#endif + + //============================================================================== namespace juce { diff --git a/modules/juce_core/native/java/JuceAppActivity.java b/modules/juce_core/native/java/JuceAppActivity.java index d59c53f601..ddb1fe8585 100644 --- a/modules/juce_core/native/java/JuceAppActivity.java +++ b/modules/juce_core/native/java/JuceAppActivity.java @@ -347,43 +347,26 @@ public final class JuceAppActivity extends Activity OpenGLView (Context context) { super (context); - setEGLContextClientVersion (2); - getHolder().setFormat(PixelFormat.TRANSLUCENT); - setVisibility (VISIBLE); setRenderer (this); - - //setRenderMode (RENDERMODE_CONTINUOUSLY); - //requestRender(); } @Override public void onSurfaceCreated (GL10 unused, EGLConfig config) { - // contextCreated(); - } - - @Override - public void onDrawFrame (GL10 unused) - { - //GLES20.glClearColor (1.0f, 0.5f, 0.0f, 1.0f); - //GLES20.glClear (GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); - - // render(); + contextCreated(); } @Override public void onSurfaceChanged (GL10 unused, int width, int height) { - //GLES20.glViewport (0, 0, width, height); + contextCreated(); } @Override - protected void onLayout (boolean changed, int left, int top, int right, int bottom) + public void onDrawFrame (GL10 unused) { - super.onLayout (changed, left, top, right, bottom); - requestLayout(); - ((ViewGroup) getParent()).requestTransparentRegion (this); + render(); } private native void contextCreated(); diff --git a/modules/juce_core/native/juce_android_JNIHelpers.h b/modules/juce_core/native/juce_android_JNIHelpers.h index 411312cd4a..70ded199b5 100644 --- a/modules/juce_core/native/juce_android_JNIHelpers.h +++ b/modules/juce_core/native/juce_android_JNIHelpers.h @@ -333,7 +333,6 @@ extern ThreadLocalJNIEnvHolder threadLocalJNIEnvHolder; //============================================================================== #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ - STATICMETHOD (printToConsole, "printToConsole", "(Ljava/lang/String;)V") \ METHOD (createNewView, "createNewView", "(Z)L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$ComponentPeerView;") \ METHOD (deleteView, "deleteView", "(L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$ComponentPeerView;)V") \ METHOD (postMessage, "postMessage", "(J)V") \ diff --git a/modules/juce_core/native/juce_android_Misc.cpp b/modules/juce_core/native/juce_android_Misc.cpp index b3942f7e27..36c1685ba2 100644 --- a/modules/juce_core/native/juce_android_Misc.cpp +++ b/modules/juce_core/native/juce_android_Misc.cpp @@ -25,9 +25,5 @@ void Logger::outputDebugString (const String& text) { - JNIEnv* const env = getEnv(); - - if (env != nullptr) - env->CallStaticVoidMethod (JuceAppActivity, JuceAppActivity.printToConsole, - javaString (text).get()); + __android_log_print (ANDROID_LOG_INFO, "JUCE", text.toUTF8()); } diff --git a/modules/juce_opengl/native/juce_android_OpenGLComponent.cpp b/modules/juce_opengl/native/juce_android_OpenGLComponent.cpp index 9998bab2d0..2dade202dc 100644 --- a/modules/juce_opengl/native/juce_android_OpenGLComponent.cpp +++ b/modules/juce_opengl/native/juce_android_OpenGLComponent.cpp @@ -25,8 +25,8 @@ #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ - METHOD (layout, "layout", "(IIII)V") \ - METHOD (invalidate, "invalidate", "(IIII)V") \ + METHOD (layout, "layout", "(IIII)V") \ + METHOD (requestRender, "requestRender", "()V") \ DECLARE_JNI_CLASS (OpenGLView, JUCE_ANDROID_ACTIVITY_CLASSPATH "$OpenGLView"); #undef JNI_CLASS_MEMBERS @@ -47,9 +47,8 @@ public: isGLES2 (isGLES2_), isInsideGLCallback (false) { - getContextList().add (this); - jassert (peer != nullptr); + getContextList().add (this); glView = GlobalRef (createOpenGLView (peer)); } @@ -71,7 +70,7 @@ public: void swapBuffers() {} - void* getRawContext() const noexcept { return 0; } + void* getRawContext() const noexcept { return glView.get(); } unsigned int getFrameBufferID() const { return 0; } int getWidth() const { return lastWidth; } @@ -191,6 +190,14 @@ bool OpenGLHelpers::isContextActive() return AndroidGLContext::isAnyContextActive(); } +void triggerAndroidOpenGLRepaint (OpenGLContext* context) +{ + AndroidGLContext* c = dynamic_cast (context); + + if (c != nullptr) + c->glView.callVoidMethod (OpenGLView.requestRender); +} + //============================================================================== JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024OpenGLView), contextCreated, void, (JNIEnv* env, jobject view)) { diff --git a/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp b/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp index 15ef8fa106..27422d135f 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLComponent.cpp @@ -23,6 +23,10 @@ ============================================================================== */ +#if JUCE_ANDROID + void triggerAndroidOpenGLRepaint (OpenGLContext*); +#endif + class OpenGLComponent::OpenGLCachedComponentImage : public CachedComponentImage, public Timer // N.B. using a Timer rather than an AsyncUpdater // to avoid scheduling problems on Windows @@ -54,8 +58,12 @@ public: { owner.updateContext(); + #if JUCE_ANDROID + triggerAndroidOpenGLRepaint (owner.getCurrentContext()); + #else if (isTimerRunning()) timerCallback(); + #endif } } @@ -90,8 +98,12 @@ public: { owner.needToRepaint = true; + #if JUCE_ANDROID + triggerAndroidOpenGLRepaint (owner.getCurrentContext()); + #else if (! owner.isUsingDedicatedThread()) startTimer (1000 / 70); + #endif } OpenGLFrameBuffer& getFrameBuffer (int width, int height)