Skip to content

Commit

Permalink
SDL2 experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed Dec 10, 2024
1 parent bcf087f commit b83a826
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 502 deletions.
18 changes: 18 additions & 0 deletions cmake/yup_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ endfunction()

#==============================================================================

function (_yup_fetch_sdl2)
FetchContent_Declare (sdl
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-2.30.10
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)

set (BUILD_SHARED_LIBS OFF)
set (SDL_SHARED OFF)
set (SDL_STATIC ON)

FetchContent_MakeAvailable (sdl)

set_target_properties (SDL2-static PROPERTIES FOLDER "Thirdparty")
endfunction()

#==============================================================================

function (_yup_fetch_perfetto)
FetchContent_Declare (Perfetto
GIT_REPOSITORY https://android.googlesource.com/platform/external/perfetto
Expand Down
4 changes: 2 additions & 2 deletions cmake/yup_standalone.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function (yup_standalone_app)

# ==== Find dependencies
if (NOT "${yup_platform}" MATCHES "^(emscripten|ios)$")
_yup_fetch_glfw3()
list (APPEND additional_libraries glfw)
_yup_fetch_sdl2()
list (APPEND additional_libraries SDL2-static)
endif()

# ==== Enable profiling
Expand Down
4 changes: 2 additions & 2 deletions examples/render/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class CustomWindow
}

yup::OwnedArray<yup::Artboard> artboards;
int totalRows = 4;
int totalColumns = 4;
int totalRows = 1;
int totalColumns = 2;
};

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_events/juce_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

//==============================================================================
#if JUCE_MAC || JUCE_IOS
#include "native/juce_MessageQueue_mac.h"
#include "native/juce_MessageQueue_apple.h"
#if JUCE_MAC
#include "native/juce_MessageManager_mac.mm"
#else
Expand Down
7 changes: 5 additions & 2 deletions modules/juce_events/messages/juce_MessageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class JUCE_API MessageManager final
*/
void stopDispatchLoop();

/** Returns true if the stopDispatchLoop() method has been called.
*/
/** Returns true if the stopDispatchLoop() method has been called. */
bool hasStopMessageBeenSent() const noexcept { return quitMessagePosted.get() != 0; }

#if JUCE_MODAL_LOOPS_PERMITTED
Expand All @@ -104,6 +103,10 @@ class JUCE_API MessageManager final
bool runDispatchLoopUntil (int millisecondsToRunFor);
#endif

//==============================================================================
/** Register an event loop callback that will be processed in the event loop. */
void registerEventLoopCallback (std::function<void()> loopCallbackToSet);

//==============================================================================
/** Asynchronously invokes a function or C++11 lambda on the message thread.
Expand Down
10 changes: 8 additions & 2 deletions modules/juce_events/native/juce_MessageManager_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@
#endif

//==============================================================================
static std::unique_ptr<MessageQueue> messageQueue;
static std::unique_ptr<InternalMessageQueue> messageQueue;

void MessageManager::doPlatformSpecificInitialisation()
{
if (messageQueue == nullptr)
messageQueue.reset(new MessageQueue());
messageQueue.reset(new InternalMessageQueue());
}

void MessageManager::doPlatformSpecificShutdown()
Expand All @@ -116,4 +116,10 @@
// N/A on current iOS
}

void MessageManager::registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
jassert (messageQueue);
messageQueue->registerEventLoopCallback (std::move (loopCallbackToSet));
}

} // namespace juce
8 changes: 7 additions & 1 deletion modules/juce_events/native/juce_MessageManager_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static String quotedIfContainsSpaces(NSString* file)
return juceStringToNS("juce_" + String::toHexString(File::getSpecialLocation(File::currentExecutableFile).hashCode64()));
}

MessageQueue messageQueue;
InternalMessageQueue messageQueue;
id delegate;
};

Expand Down Expand Up @@ -448,6 +448,12 @@ void initialiseNSApplication()
userInfo:info];
}

void MessageManager::registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
jassert(appDelegate != nil);
appDelegate->messageQueue.registerEventLoopCallback (std::move (loopCallbackToSet));
}

//==============================================================================
#if JUCE_MAC
struct MountedVolumeListChangeDetector::Pimpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ namespace juce
{

//==============================================================================
/* An internal message pump class used in OSX and iOS. */
class MessageQueue
class InternalMessageQueue
{
public:
MessageQueue()
InternalMessageQueue()
{
#if JUCE_IOS
runLoop = CFRunLoopGetCurrent();
Expand All @@ -61,12 +60,17 @@ class MessageQueue
CFRunLoopAddSource (runLoop, runLoopSource.get(), kCFRunLoopCommonModes);
}

~MessageQueue() noexcept
~InternalMessageQueue() noexcept
{
CFRunLoopRemoveSource (runLoop, runLoopSource.get(), kCFRunLoopCommonModes);
CFRunLoopSourceInvalidate (runLoopSource.get());
}

void registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
loopCallback = std::move (loopCallbackToSet);
}

void post (MessageManager::MessageBase* const message)
{
messages.add (message);
Expand All @@ -77,6 +81,7 @@ class MessageQueue
ReferenceCountedArray<MessageManager::MessageBase, CriticalSection> messages;
CFRunLoopRef runLoop;
CFUniquePtr<CFRunLoopSourceRef> runLoopSource;
std::function<void()> loopCallback;

void wakeUp() noexcept
{
Expand Down Expand Up @@ -105,6 +110,9 @@ class MessageQueue

void runLoopCallback() noexcept
{
if (loopCallback)
loopCallback();

for (int i = 4; --i >= 0;)
if (! deliverNextMessage())
return;
Expand All @@ -114,7 +122,7 @@ class MessageQueue

static void runLoopSourceCallback (void* info) noexcept
{
static_cast<MessageQueue*> (info)->runLoopCallback();
static_cast<InternalMessageQueue*> (info)->runLoopCallback();
}
};

Expand Down
15 changes: 14 additions & 1 deletion modules/juce_events/native/juce_Messaging_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class InternalMessageQueue
clearSingletonInstance();
}

//==============================================================================
void registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
loopCallback = std::move (loopCallbackToSet);
}

//==============================================================================
void postMessage (MessageManager::MessageBase* const msg) noexcept
{
Expand All @@ -65,7 +71,8 @@ class InternalMessageQueue

for (;;)
{
glfwPollEvents();
if (loopCallback)
loopCallback();

{
const ScopedLock sl (lock);
Expand Down Expand Up @@ -102,6 +109,7 @@ class InternalMessageQueue
private:
CriticalSection lock;
ReferenceCountedArray<MessageManager::MessageBase> queue;
std::function<void()> loopCallback;
};

JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue)
Expand Down Expand Up @@ -136,6 +144,11 @@ void MessageManager::broadcastMessage (const String&)
{
}

void MessageManager::registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
InternalMessageQueue::getInstance()->registerEventLoopCallback (std::move (loopCallbackToSet));
}

//==============================================================================
void juce_juceEventsAndroidStartApp()
{
Expand Down
14 changes: 14 additions & 0 deletions modules/juce_events/native/juce_Messaging_emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class InternalMessageQueue
clearSingletonInstance();
}

//==============================================================================
void registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
loopCallback = std::move (loopCallbackToSet);
}

//==============================================================================
bool postMessage (MessageManager::MessageBase* const msg)
{
Expand Down Expand Up @@ -93,6 +99,9 @@ class InternalMessageQueue
{
Timer::callPendingTimersSynchronously();

if (loopCallback)
loopCallback();

ReferenceCountedArray<MessageManager::MessageBase> currentEvents;

{
Expand All @@ -111,6 +120,7 @@ class InternalMessageQueue

CriticalSection lock;
ReferenceCountedArray<MessageManager::MessageBase> eventQueue;
std::function<void()> loopCallback;
};

JUCE_IMPLEMENT_SINGLETON (InternalMessageQueue)
Expand Down Expand Up @@ -157,4 +167,8 @@ void MessageManager::stopDispatchLoop()
quitMessagePosted = true;
}

void MessageManager::registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
InternalMessageQueue::getInstance()->registerEventLoopCallback (std::move (loopCallbackToSet));
}
} // namespace juce
12 changes: 12 additions & 0 deletions modules/juce_events/native/juce_Messaging_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ struct InternalRunLoop

void removeListener (LinuxEventLoopInternal::Listener& listener) { listeners.remove (&listener); }

void registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
loopCallback = std::move (loopCallbackToSet);
}

//==============================================================================
JUCE_DECLARE_SINGLETON (InternalRunLoop, false)

Expand Down Expand Up @@ -299,6 +304,8 @@ struct InternalRunLoop
std::vector<pollfd> pfds;

ListenerList<LinuxEventLoopInternal::Listener> listeners;

std::function<void()> loopCallback;
};

JUCE_IMPLEMENT_SINGLETON (InternalRunLoop)
Expand Down Expand Up @@ -358,6 +365,11 @@ void MessageManager::broadcastMessage (const String&)
// TODO
}

void MessageManager::registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
InternalRunLoop::getInstance()->registerEventLoopCallback (std::move (loopCallbackToSet));
}

namespace detail
{
// this function expects that it will NEVER be called simultaneously for two concurrent threads
Expand Down
15 changes: 15 additions & 0 deletions modules/juce_events/native/juce_Messaging_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class InternalMessageQueue

JUCE_DECLARE_SINGLETON (InternalMessageQueue, false)

//==============================================================================
void registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
loopCallback = std::move (loopCallbackToSet);
}

//==============================================================================
void broadcastMessage (const String& message)
{
Expand Down Expand Up @@ -235,6 +241,9 @@ class InternalMessageQueue
{
ReferenceCountedArray<MessageManager::MessageBase> messagesToDispatch;

if (loopCallback)
loopCallback();

{
const ScopedLock sl (lock);

Expand All @@ -261,6 +270,7 @@ class InternalMessageQueue

CriticalSection lock;
ReferenceCountedArray<MessageManager::MessageBase> messageQueue;
std::function<void()> loopCallback;

//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InternalMessageQueue)
Expand Down Expand Up @@ -301,6 +311,11 @@ void MessageManager::broadcastMessage (const String& value)
queue->broadcastMessage (value);
}

void MessageManager::registerEventLoopCallback (std::function<void()> loopCallbackToSet)
{
InternalMessageQueue::getInstance()->registerEventLoopCallback (std::move (loopCallbackToSet));
}

//==============================================================================
void MessageManager::doPlatformSpecificInitialisation()
{
Expand Down
1 change: 1 addition & 0 deletions modules/yup_gui/component/yup_Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class JUCE_API Component

friend class ComponentNative;
friend class GLFWComponentNative;
friend class SDL2ComponentNative;
friend class WeakReference<Component>;

using MouseListenerList = ListenerList<MouseListener, Array<WeakReference<MouseListener>>>;
Expand Down
3 changes: 2 additions & 1 deletion modules/yup_gui/keyboard/yup_KeyModifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ class JUCE_API KeyModifiers
return ! (*this == other);
}

private:
//==============================================================================
static constexpr int shiftMask = 0x0001;
static constexpr int controlMask = 0x0002;
static constexpr int altMask = 0x0004;
static constexpr int superMask = 0x0008;
static constexpr int capsLockMask = 0x0010;
static constexpr int numLockMask = 0x0020;

private:
int32_t modifiers = 0;
};

Expand Down
Loading

0 comments on commit b83a826

Please sign in to comment.