Skip to content

Commit

Permalink
Improved sdl display handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed Dec 16, 2024
1 parent f22910b commit 0938320
Show file tree
Hide file tree
Showing 15 changed files with 603 additions and 397 deletions.
29 changes: 27 additions & 2 deletions examples/render/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ class CustomWindow

//==============================================================================

class CustomWindow2
: public yup::DocumentWindow
{
public:
CustomWindow2()
: yup::DocumentWindow (yup::ComponentNative::Options(), {})
{
setTitle ("secondary");
}

void userTriedToCloseWindow() override
{
setVisible (false);
}
};

//==============================================================================

struct Application : yup::YUPApplication
{
Application() = default;
Expand All @@ -198,14 +216,18 @@ struct Application : yup::YUPApplication
yup::Logger::outputDebugString ("Starting app " + commandLineParameters);

window = std::make_unique<CustomWindow>();

#if JUCE_IOS || JUCE_ANDROID
window->centreWithSize ({ 1080, 2400 });
#else
window->centreWithSize ({ 1280, 866 });
#endif

window->setVisible (true);
window->toFront();

window2 = std::make_unique<CustomWindow2>();
window2->centreWithSize ({ 300, 300 });
window2->setVisible (true);
window2->toFront();
}

void shutdown() override
Expand All @@ -214,11 +236,14 @@ struct Application : yup::YUPApplication

window.reset();

window2.reset();

YUP_PROFILE_STOP();
}

private:
std::unique_ptr<CustomWindow> window;
std::unique_ptr<CustomWindow2> window2;
};

START_JUCE_APPLICATION (Application)
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ default:
clean:
rm -Rf build/*

osx:
cmake -G Xcode -B build -DYUP_ENABLE_PROFILING=OFF
osx PROFILING="OFF":
cmake -G Xcode -B build -DYUP_ENABLE_PROFILING={{PROFILING}}
-open build/yup.xcodeproj

ios:
Expand Down
14 changes: 14 additions & 0 deletions modules/juce_core/juce_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@
#define JUCE_ENABLE_ALLOCATION_HOOKS 0
#endif

/** Config: JUCE_PROFILING_CATEGORIES
If enabled, this will add global profiling categories to the profiler. The "yup" category should
always be defined, only additional categories should be provided (note the first comma).
Format of the categories is like:
```
#define JUCE_PROFILING_CATEGORIES \
, perfetto::Category ("custom1") \
, perfetto::Category ("custom2")
```
*/
#ifndef JUCE_PROFILING_CATEGORIES
#define JUCE_PROFILING_CATEGORIES
#endif

#ifndef JUCE_STRING_UTF_TYPE
#define JUCE_STRING_UTF_TYPE 8
#endif
Expand Down
20 changes: 17 additions & 3 deletions modules/juce_core/profiling/juce_Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#if JUCE_ENABLE_PROFILING

PERFETTO_DEFINE_CATEGORIES (
perfetto::Category ("rendering"),
perfetto::Category ("network"));
perfetto::Category ("yup")
JUCE_PROFILING_CATEGORIES);

namespace juce
{
Expand Down Expand Up @@ -153,6 +153,7 @@ constexpr auto Profiler::compileTimePrettierFunction (F func)
*/
#define YUP_PROFILE_STOP(...) ::juce::Profiler::getInstance()->stopTracing()

#if ! YUP_PROFILE_DISABLE_TRACE
/** Records a profiling trace event.
This macro is used to trace events for profiling purposes.
Expand All @@ -162,18 +163,31 @@ constexpr auto Profiler::compileTimePrettierFunction (F func)
@param category The category for the trace event.
@param ... Optional additional arguments for the trace event.
*/
#if ! YUP_PROFILE_DISABLE_TRACE
#define YUP_PROFILE_TRACE(category, ...) \
constexpr auto JUCE_JOIN_MACRO (juce_pfn_, __LINE__) = ::juce::Profiler::compileTimePrettierFunction ([] { return PERFETTO_DEBUG_FUNCTION_IDENTIFIER(); }); \
TRACE_EVENT (category, ::perfetto::StaticString (JUCE_JOIN_MACRO (juce_pfn_, __LINE__).data()), ##__VA_ARGS__)

/** Records a profiling internal trace event.
This macro is used internally by the yup framework to trace events for profiling purposes.
@param ... Optional additional arguments for the trace event.
*/
#define YUP_PROFILE_INTERNAL_TRACE(...) \
constexpr auto JUCE_JOIN_MACRO (juce_pfn_, __LINE__) = ::juce::Profiler::compileTimePrettierFunction ([] { return PERFETTO_DEBUG_FUNCTION_IDENTIFIER(); }); \
TRACE_EVENT ("yup", ::perfetto::StaticString (JUCE_JOIN_MACRO (juce_pfn_, __LINE__).data()), ##__VA_ARGS__)

#else
#define YUP_PROFILE_TRACE(category, ...)
#define YUP_PROFILE_INTERNAL_TRACE(...)

#endif
// clang-format on

#else
#define YUP_PROFILE_START(...)
#define YUP_PROFILE_STOP(...)
#define YUP_PROFILE_TRACE(category, ...)
#define YUP_PROFILE_INTERNAL_TRACE(...)

#endif
1 change: 1 addition & 0 deletions modules/juce_events/native/juce_MessageManager_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ static String quotedIfContainsSpaces(NSString* file)
static void shutdownNSApp()
{
[NSApp stop:nil];
[NSEvent stopPeriodicEvents];
[NSEvent startPeriodicEventsAfterDelay:0 withPeriod:0.1];
}

Expand Down
1 change: 1 addition & 0 deletions modules/yup_gui/component/yup_ComponentNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class JUCE_API ComponentNative
virtual void enableWireframe (bool shouldBeEnabld) = 0;

//==============================================================================
virtual void repaint() = 0;
virtual void repaint (const Rectangle<float>& rect) = 0;
virtual Rectangle<float> getRepaintArea() const = 0;

Expand Down
24 changes: 22 additions & 2 deletions modules/yup_gui/desktop/yup_Desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,39 @@ int Desktop::getNumDisplays() const
return displays.size();
}

Display* Desktop::getDisplay (int displayIndex) const
Display::Ptr Desktop::getDisplay (int displayIndex) const
{
if (isPositiveAndBelow (displayIndex, displays.size()))
return displays.getUnchecked (displayIndex);

return nullptr;
}

Display* Desktop::getPrimaryDisplay() const
Display::Ptr Desktop::getPrimaryDisplay() const
{
return ! displays.isEmpty() ? getDisplay (0) : nullptr;
}

void Desktop::handleDisplayConnected (int displayIndex)
{
updateDisplays();
}

void Desktop::handleDisplayDisconnected (int displayIndex)
{
updateDisplays();
}

void Desktop::handleDisplayMoved (int displayIndex)
{
updateDisplays();
}

void Desktop::handleDisplayOrientationChanged (int displayIndex)
{
updateDisplays();
}

JUCE_IMPLEMENT_SINGLETON (Desktop)

} // namespace yup
16 changes: 13 additions & 3 deletions modules/yup_gui/desktop/yup_Desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class JUCE_API Desktop
@return A pointer to the `Display` object, or nullptr if the index is out of range.
*/
Display* getDisplay (int displayIndex) const;
Display::Ptr getDisplay (int displayIndex) const;

/** Retrieves a pointer to the primary `Display` object.
The primary display is typically the main screen of the system where applications are initially displayed.
@return A pointer to the primary `Display` object.
*/
Display* getPrimaryDisplay() const;
Display::Ptr getPrimaryDisplay() const;

//==============================================================================
// TODO - doxygen
Expand All @@ -65,12 +65,22 @@ class JUCE_API Desktop
//==============================================================================
JUCE_DECLARE_SINGLETON (Desktop, false)

//==============================================================================
/** @internal */
void handleDisplayConnected (int displayIndex);
/** @internal */
void handleDisplayDisconnected (int displayIndex);
/** @internal */
void handleDisplayMoved (int displayIndex);
/** @internal */
void handleDisplayOrientationChanged (int displayIndex);

private:
friend class YUPApplication;

Desktop();

OwnedArray<Display> displays;
ReferenceCountedArray<Display> displays;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Desktop)
};
Expand Down
4 changes: 3 additions & 1 deletion modules/yup_gui/desktop/yup_Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
namespace yup
{

class JUCE_API Display
class JUCE_API Display : public ReferenceCountedObject
{
public:
using Ptr = ReferenceCountedObjectPtr<Display>;

Display() {}

Size<int> physicalSizeMillimeters;
Expand Down
2 changes: 1 addition & 1 deletion modules/yup_gui/native/yup_Windowing_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
==============================================================================
This file is part of the YUP library.
Copyright (c): return { KeyPress::xxx, modifiers, sc }; - [email protected]
Copyright (c) 2024 - [email protected]
YUP is an open source library subject to open-source licensing.
Expand Down
Loading

0 comments on commit 0938320

Please sign in to comment.