Browse Source

Message leak fix. Android repaint fix. Minor clean-ups.

tags/2021-05-28
jules 13 years ago
parent
commit
87d3acf19f
9 changed files with 51 additions and 78 deletions
  1. +3
    -3
      modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h
  2. +12
    -12
      modules/juce_core/memory/juce_HeapBlock.h
  3. +2
    -3
      modules/juce_core/native/juce_android_JNIHelpers.h
  4. +2
    -2
      modules/juce_core/native/juce_win32_SystemStats.cpp
  5. +0
    -1
      modules/juce_core/system/juce_StandardHeader.h
  6. +1
    -0
      modules/juce_events/messages/juce_MessageManager.cpp
  7. +4
    -8
      modules/juce_graphics/image_formats/juce_PNGLoader.cpp
  8. +18
    -16
      modules/juce_graphics/native/juce_android_Fonts.cpp
  9. +9
    -33
      modules/juce_gui_basics/native/juce_android_Windowing.cpp

+ 3
- 3
modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h View File

@@ -169,8 +169,8 @@ private:
static VstEvent* allocateVSTEvent()
{
VstEvent* const e = (VstEvent*) ::calloc (1, sizeof (VstMidiEvent) > sizeof (VstMidiSysexEvent) ? sizeof (VstMidiEvent)
: sizeof (VstMidiSysexEvent));
VstEvent* const e = (VstEvent*) std::calloc (1, sizeof (VstMidiEvent) > sizeof (VstMidiSysexEvent) ? sizeof (VstMidiEvent)
: sizeof (VstMidiSysexEvent));
e->type = kVstMidiType;
e->byteSize = sizeof (VstMidiEvent);
return e;
@@ -181,7 +181,7 @@ private:
if (e->type == kVstSysExType)
delete[] (((VstMidiSysexEvent*) e)->sysexDump);
::free (e);
std::free (e);
}
};


+ 12
- 12
modules/juce_core/memory/juce_HeapBlock.h View File

@@ -105,7 +105,7 @@ public:
If you want an array of zero values, you can use the calloc() method instead.
*/
explicit HeapBlock (const size_t numElements)
: data (static_cast <ElementType*> (::malloc (numElements * sizeof (ElementType))))
: data (static_cast <ElementType*> (std::malloc (numElements * sizeof (ElementType))))
{
throwOnAllocationFailure();
}
@@ -116,7 +116,7 @@ public:
*/
~HeapBlock()
{
::free (data);
std::free (data);
}
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
@@ -203,8 +203,8 @@ public:
*/
void malloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType))
{
::free (data);
data = static_cast <ElementType*> (::malloc (newNumElements * elementSize));
std::free (data);
data = static_cast <ElementType*> (std::malloc (newNumElements * elementSize));
throwOnAllocationFailure();
}
@@ -213,8 +213,8 @@ public:
*/
void calloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType))
{
::free (data);
data = static_cast <ElementType*> (::calloc (newNumElements, elementSize));
std::free (data);
data = static_cast <ElementType*> (std::calloc (newNumElements, elementSize));
throwOnAllocationFailure();
}
@@ -224,12 +224,12 @@ public:
*/
void allocate (const size_t newNumElements, const bool initialiseToZero)
{
::free (data);
std::free (data);
if (initialiseToZero)
data = static_cast <ElementType*> (::calloc (newNumElements, sizeof (ElementType)));
data = static_cast <ElementType*> (std::calloc (newNumElements, sizeof (ElementType)));
else
data = static_cast <ElementType*> (::malloc (newNumElements * sizeof (ElementType)));
data = static_cast <ElementType*> (std::malloc (newNumElements * sizeof (ElementType)));
throwOnAllocationFailure();
}
@@ -242,9 +242,9 @@ public:
void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType))
{
if (data == nullptr)
data = static_cast <ElementType*> (::malloc (newNumElements * elementSize));
data = static_cast <ElementType*> (std::malloc (newNumElements * elementSize));
else
data = static_cast <ElementType*> (::realloc (data, newNumElements * elementSize));
data = static_cast <ElementType*> (std::realloc (data, newNumElements * elementSize));
throwOnAllocationFailure();
}
@@ -254,7 +254,7 @@ public:
*/
void free()
{
::free (data);
std::free (data);
data = nullptr;
}


+ 2
- 3
modules/juce_core/native/juce_android_JNIHelpers.h View File

@@ -108,7 +108,7 @@ template <typename JavaType>
class LocalRef
{
public:
explicit inline LocalRef (JavaType obj_) noexcept : obj (obj_){}
explicit inline LocalRef (JavaType obj_) noexcept : obj (obj_) {}
inline LocalRef (const LocalRef& other) noexcept : obj (retain (other.obj)) {}
~LocalRef() { clear(); }
@@ -143,8 +143,7 @@ namespace
{
String juceString (JNIEnv* env, jstring s)
{
jboolean isCopy;
const char* const utf8 = env->GetStringUTFChars (s, &isCopy);
const char* const utf8 = env->GetStringUTFChars (s, nullptr);
CharPointer_UTF8 utf8CP (utf8);
const String result (utf8CP);
env->ReleaseStringUTFChars (s, utf8);


+ 2
- 2
modules/juce_core/native/juce_win32_SystemStats.cpp View File

@@ -30,8 +30,8 @@ void Logger::outputDebugString (const String& text)
//==============================================================================
#ifdef JUCE_DLL
JUCE_API void* juceDLL_malloc (size_t sz) { return ::malloc (sz); }
JUCE_API void juceDLL_free (void* block) { ::free (block); }
JUCE_API void* juceDLL_malloc (size_t sz) { return std::malloc (sz); }
JUCE_API void juceDLL_free (void* block) { std::free (block); }
#endif
//==============================================================================


+ 0
- 1
modules/juce_core/system/juce_StandardHeader.h View File

@@ -104,7 +104,6 @@
#endif
#if JUCE_MSVC
#include <malloc.h>
#pragma warning (pop)
#endif


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

@@ -103,6 +103,7 @@ void MessageManager::runDispatchLoop()
void MessageManager::stopDispatchLoop()
{
(new QuitMessage())->post();
quitMessagePosted = true;
}
bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)


+ 4
- 8
modules/juce_graphics/image_formats/juce_PNGLoader.cpp View File

@@ -50,12 +50,12 @@ namespace pnglibNamespace
#if JUCE_INCLUDE_PNGLIB_CODE || ! defined (JUCE_INCLUDE_PNGLIB_CODE)
#if _MSC_VER != 1310
using ::calloc; // (causes conflict in VS.NET 2003)
using ::malloc;
using ::free;
using std::calloc; // (causes conflict in VS.NET 2003)
using std::malloc;
using std::free;
#endif
using ::abs;
using std::abs;
#define PNG_INTERNAL
#define NO_DUMMY_DECL
#define PNG_SETJMP_NOT_SUPPORTED
@@ -95,10 +95,6 @@ namespace pnglibNamespace
#pragma warning (pop)
#endif
using ::calloc;
using ::malloc;
using ::free;
//==============================================================================
namespace PNGHelpers
{


+ 18
- 16
modules/juce_graphics/native/juce_android_Fonts.cpp View File

@@ -180,28 +180,30 @@ public:
const Rectangle<int> bounds (left, top, right - left, bottom - top);
if (bounds.isEmpty())
return nullptr;
EdgeTable* et = nullptr;
jint* const maskDataElements = env->GetIntArrayElements (maskData, 0);
if (! bounds.isEmpty())
{
et = new EdgeTable (bounds);
EdgeTable* et = new EdgeTable (bounds);
jint* const maskDataElements = env->GetIntArrayElements (maskData, 0);
const jint* mask = maskDataElements;
const jint* mask = maskDataElements;
for (int y = top; y < bottom; ++y)
{
#if JUCE_LITTLE_ENDIAN
const uint8* const lineBytes = ((const uint8*) mask) + 3;
#else
const uint8* const lineBytes = (const uint8*) mask;
#endif
for (int y = top; y < bottom; ++y)
{
#if JUCE_LITTLE_ENDIAN
const uint8* const lineBytes = ((const uint8*) mask) + 3;
#else
const uint8* const lineBytes = (const uint8*) mask;
#endif
et->clipLineToMask (left, y, lineBytes, 4, bounds.getWidth());
mask += bounds.getWidth();
et->clipLineToMask (left, y, lineBytes, 4, bounds.getWidth());
mask += bounds.getWidth();
}
env->ReleaseIntArrayElements (maskData, maskDataElements, 0);
}
env->ReleaseIntArrayElements (maskData, maskDataElements, 0);
env->DeleteLocalRef (maskData);
return et;
}


+ 9
- 33
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -45,6 +45,8 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* en
JUCEApplication* app = dynamic_cast <JUCEApplication*> (JUCEApplicationBase::createInstance());
if (! app->initialiseApp (String::empty))
exit (0);
jassert (MessageManager::getInstance()->isThisTheMessageThread());
}
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, quitApp, void, (JNIEnv* env, jobject activity))
@@ -386,7 +388,7 @@ public:
jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), 0);
if (dest != 0)
if (dest != nullptr)
{
{
Image temp (new PreallocatedImage (clip.getWidth(), clip.getHeight(),
@@ -415,26 +417,23 @@ public:
}
else
{
class ViewRepainter : public CallbackMessage
struct ViewRepainter : public CallbackMessage
{
public:
ViewRepainter (const GlobalRef& view_, const Rectangle<int>& area_)
: view (view_), area (area_)
{
post();
}
: view (view_), area (area_) {}
void messageCallback()
{
view.callVoidMethod (ComponentPeerView.invalidate, area.getX(), area.getY(), area.getRight(), area.getBottom());
view.callVoidMethod (ComponentPeerView.invalidate, area.getX(), area.getY(),
area.getRight(), area.getBottom());
}
private:
GlobalRef view;
const Rectangle<int>& area;
const Rectangle<int> area;
};
new ViewRepainter (view, area);
(new ViewRepainter (view, area))->post();
}
}
@@ -448,29 +447,6 @@ public:
// TODO
}
#if USE_ANDROID_CANVAS
StringArray getAvailableRenderingEngines()
{
StringArray s (ComponentPeer::getAvailableRenderingEngines());
s.add ("Android Canvas Renderer");
return s;
}
int getCurrentRenderingEngine() const
{
return usingAndroidGraphics ? 1 : 0;
}
void setCurrentRenderingEngine (int index)
{
if (usingAndroidGraphics != (index > 0))
{
usingAndroidGraphics = index > 0;
component->repaint();
}
}
#endif
//==============================================================================
static AndroidComponentPeer* findPeerForJavaView (JNIEnv* env, jobject viewToFind)
{


Loading…
Cancel
Save