Browse Source

Android fixes. OSX fix for old SDKs.

tags/2021-05-28
jules 13 years ago
parent
commit
53c0436d71
7 changed files with 61 additions and 73 deletions
  1. +1
    -0
      modules/juce_core/maths/juce_BigInteger.cpp
  2. +1
    -1
      modules/juce_core/native/juce_android_JNIHelpers.h
  3. +4
    -1
      modules/juce_events/messages/juce_MessageManager.cpp
  4. +10
    -11
      modules/juce_events/native/juce_android_Messaging.cpp
  5. +7
    -16
      modules/juce_gui_basics/native/juce_android_Windowing.cpp
  6. +1
    -1
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm
  7. +37
    -43
      modules/juce_opengl/native/juce_OpenGL_android.h

+ 1
- 0
modules/juce_core/maths/juce_BigInteger.cpp View File

@@ -118,6 +118,7 @@ BigInteger& BigInteger::operator= (const BigInteger& other)
if (this != &other) if (this != &other)
{ {
highestBit = other.getHighestBit(); highestBit = other.getHighestBit();
jassert (other.numValues >= 4);
numValues = (size_t) jmax ((size_t) 4, bitToIndex (highestBit) + 1); numValues = (size_t) jmax ((size_t) 4, bitToIndex (highestBit) + 1);
negative = other.negative; negative = other.negative;
values.malloc (numValues + 1); values.malloc (numValues + 1);


+ 1
- 1
modules/juce_core/native/juce_android_JNIHelpers.h View File

@@ -270,7 +270,7 @@ public:
JNIEnv* attach() JNIEnv* attach()
{ {
JNIEnv* env = nullptr; JNIEnv* env = nullptr;
jvm->AttachCurrentThread (&env, 0);
jvm->AttachCurrentThread (&env, nullptr);
if (env != nullptr) if (env != nullptr)
addEnv (env); addEnv (env);


+ 4
- 1
modules/juce_events/messages/juce_MessageManager.cpp View File

@@ -158,9 +158,12 @@ private:
void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* const func, void* const parameter) void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* const func, void* const parameter)
{ {
if (MessageManager::getInstance()->isThisTheMessageThread())
if (isThisTheMessageThread())
return func (parameter); return func (parameter);
// If this thread has the message manager locked, then this will deadlock!
jassert (! currentThreadHasLockedMessageManager());
const ReferenceCountedObjectPtr<AsyncFunctionCallback> message (new AsyncFunctionCallback (func, parameter)); const ReferenceCountedObjectPtr<AsyncFunctionCallback> message (new AsyncFunctionCallback (func, parameter));
message->post(); message->post();
message->finished.wait(); message->finished.wait();


+ 10
- 11
modules/juce_events/native/juce_android_Messaging.cpp View File

@@ -39,7 +39,7 @@ bool MessageManager::dispatchNextMessageOnSystemQueue (const bool returnIfNoPend
bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* const message) bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* const message)
{ {
message->incReferenceCount(); message->incReferenceCount();
getEnv()->CallVoidMethod (android.activity, JuceAppActivity.postMessage, (jlong) (pointer_sized_uint) message);
android.activity.callVoidMethod (JuceAppActivity.postMessage, (jlong) (pointer_sized_uint) message);
return true; return true;
} }
@@ -63,19 +63,18 @@ void MessageManager::runDispatchLoop()
{ {
} }
class QuitCallback : public CallbackMessage
void MessageManager::stopDispatchLoop()
{ {
public:
QuitCallback() {}
void messageCallback()
struct QuitCallback : public CallbackMessage
{ {
android.activity.callVoidMethod (JuceAppActivity.finish);
}
};
QuitCallback() {}
void messageCallback()
{
android.activity.callVoidMethod (JuceAppActivity.finish);
}
};
void MessageManager::stopDispatchLoop()
{
(new QuitCallback())->post(); (new QuitCallback())->post();
quitMessagePosted = true; quitMessagePosted = true;
} }

+ 7
- 16
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -111,14 +111,9 @@ public:
} }
else else
{ {
class ViewDeleter : public CallbackMessage
struct ViewDeleter : public CallbackMessage
{ {
public:
ViewDeleter (const GlobalRef& view_)
: view (view_)
{
post();
}
ViewDeleter (const GlobalRef& view_) : view (view_) {}
void messageCallback() void messageCallback()
{ {
@@ -129,7 +124,7 @@ public:
GlobalRef view; GlobalRef view;
}; };
new ViewDeleter (view);
(new ViewDeleter (view))->post();
} }
view.clear(); view.clear();
@@ -148,14 +143,11 @@ public:
} }
else else
{ {
class VisibilityChanger : public CallbackMessage
struct VisibilityChanger : public CallbackMessage
{ {
public:
VisibilityChanger (const GlobalRef& view_, bool shouldBeVisible_) VisibilityChanger (const GlobalRef& view_, bool shouldBeVisible_)
: view (view_), shouldBeVisible (shouldBeVisible_) : view (view_), shouldBeVisible (shouldBeVisible_)
{
post();
}
{}
void messageCallback() void messageCallback()
{ {
@@ -167,7 +159,7 @@ public:
bool shouldBeVisible; bool shouldBeVisible;
}; };
new VisibilityChanger (view, shouldBeVisible);
(new VisibilityChanger (view, shouldBeVisible))->post();
} }
} }
@@ -714,8 +706,7 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, setScreenSize, void, (JNIEnv
android.screenWidth = screenWidth; android.screenWidth = screenWidth;
android.screenHeight = screenHeight; android.screenHeight = screenHeight;
if (isSystemInitialised)
Desktop::getInstance().refreshMonitorSizes();
Desktop::getInstance().refreshMonitorSizes();
} }
//============================================================================== //==============================================================================


+ 1
- 1
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -906,7 +906,7 @@ void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
{ {
if ([NSEvent respondsToSelector: @selector (modifierFlags)]) if ([NSEvent respondsToSelector: @selector (modifierFlags)])
NSViewComponentPeer::updateModifiers ([NSEvent modifierFlags]);
NSViewComponentPeer::updateModifiers ((NSUInteger) [NSEvent modifierFlags]);
return NSViewComponentPeer::currentModifiers; return NSViewComponentPeer::currentModifiers;
} }


+ 37
- 43
modules/juce_opengl/native/juce_OpenGL_android.h View File

@@ -42,11 +42,10 @@ public:
: component (component_), : component (component_),
isInsideGLCallback (false) isInsideGLCallback (false)
{ {
glView = GlobalRef (createOpenGLView (component.getPeer()));
{ {
const ScopedLock sl (getContextListLock());
getContextList().add (this);
const ScopedLock sl (contextListLock);
glView = GlobalRef (createOpenGLView (component.getPeer()));
contextList.add (this);
} }
updateWindowPosition (component.getTopLevelComponent() updateWindowPosition (component.getTopLevelComponent()
@@ -56,8 +55,8 @@ public:
~NativeContext() ~NativeContext()
{ {
{ {
const ScopedLock sl (getContextListLock());
getContextList().removeValue (this);
const ScopedLock sl (contextListLock);
contextList.removeValue (this);
} }
android.activity.callVoidMethod (JuceAppActivity.deleteView, glView.get()); android.activity.callVoidMethod (JuceAppActivity.deleteView, glView.get());
@@ -95,6 +94,10 @@ public:
} }
} }
void contextChangedSize()
{
}
void triggerRepaint() void triggerRepaint()
{ {
glView.callVoidMethod (OpenGLView.requestRender); glView.callVoidMethod (OpenGLView.requestRender);
@@ -107,12 +110,11 @@ public:
//============================================================================== //==============================================================================
static NativeContext* findContextFor (JNIEnv* env, jobject glView) static NativeContext* findContextFor (JNIEnv* env, jobject glView)
{ {
const ScopedLock sl (getContextListLock());
const ContextArray& contexts = getContextList();
const ScopedLock sl (contextListLock);
for (int i = contexts.size(); --i >= 0;)
for (int i = contextList.size(); --i >= 0;)
{ {
NativeContext* const c = contexts.getUnchecked(i);
NativeContext* const c = contextList.getUnchecked(i);
if (env->IsSameObject (c->glView.get(), glView)) if (env->IsSameObject (c->glView.get(), glView))
return c; return c;
@@ -123,12 +125,11 @@ public:
static NativeContext* getActiveContext() noexcept static NativeContext* getActiveContext() noexcept
{ {
const ScopedLock sl (getContextListLock());
const ContextArray& contexts = getContextList();
const ScopedLock sl (contextListLock);
for (int i = contexts.size(); --i >= 0;)
for (int i = contextList.size(); --i >= 0;)
{ {
NativeContext* const c = contexts.getUnchecked(i);
NativeContext* const c = contextList.getUnchecked(i);
if (c->isInsideGLCallback) if (c->isInsideGLCallback)
return c; return c;
@@ -144,23 +145,16 @@ private:
Rectangle<int> lastBounds; Rectangle<int> lastBounds;
bool isInsideGLCallback; bool isInsideGLCallback;
static CriticalSection& getContextListLock()
{
static CriticalSection lock;
return lock;
}
typedef Array<NativeContext*> ContextArray; typedef Array<NativeContext*> ContextArray;
static ContextArray& getContextList()
{
static ContextArray contexts;
return contexts;
}
static CriticalSection contextListLock;
static ContextArray contextList;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext);
}; };
CriticalSection OpenGLContext::NativeContext::contextListLock;
OpenGLContext::NativeContext::ContextArray OpenGLContext::NativeContext::contextList;
//============================================================================== //==============================================================================
bool OpenGLHelpers::isContextActive() bool OpenGLHelpers::isContextActive()
{ {
@@ -168,34 +162,34 @@ bool OpenGLHelpers::isContextActive()
} }
//============================================================================== //==============================================================================
JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024OpenGLView), contextCreated, void, (JNIEnv* env, jobject view))
#define GL_VIEW_CLASS_NAME JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024OpenGLView)
JUCE_JNI_CALLBACK (GL_VIEW_CLASS_NAME, contextCreated, void, (JNIEnv* env, jobject view))
{ {
threadLocalJNIEnvHolder.getOrAttach(); threadLocalJNIEnvHolder.getOrAttach();
JUCE_CHECK_OPENGL_ERROR
OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view);
for (int i = 100; --i >= 0;)
if (context != nullptr)
{ {
OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view);
if (context != nullptr)
{
context->contextCreatedCallback();
JUCE_CHECK_OPENGL_ERROR
return;
}
Thread::sleep (20);
context->contextCreatedCallback();
JUCE_CHECK_OPENGL_ERROR
}
else
{
jassertfalse;
} }
jassertfalse;
} }
JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024OpenGLView), contextChangedSize, void, (JNIEnv* env, jobject view))
JUCE_JNI_CALLBACK (GL_VIEW_CLASS_NAME, contextChangedSize, void, (JNIEnv* env, jobject view))
{ {
OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view);
if (context != nullptr)
context->contextChangedSize();
} }
JUCE_JNI_CALLBACK (JUCE_JOIN_MACRO (JUCE_ANDROID_ACTIVITY_CLASSNAME, _00024OpenGLView), render, void, (JNIEnv* env, jobject view))
JUCE_JNI_CALLBACK (GL_VIEW_CLASS_NAME, render, void, (JNIEnv* env, jobject view))
{ {
OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view); OpenGLContext::NativeContext* const context = OpenGLContext::NativeContext::findContextFor (env, view);


Loading…
Cancel
Save