Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved SDL <> Juce Message Manager handling #38

Merged
merged 5 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ IndentWidth: 4
IndentWrappedFunctionNames: true
IndentPPDirectives: BeforeHash
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
LambdaBodyIndentation: OuterScope
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PackConstructorInitializers: Never
Expand Down
12 changes: 6 additions & 6 deletions examples/render/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ struct Application : yup::YUPApplication
window->setVisible (true);
window->toFront();

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

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

window.reset();

window2.reset();
//window2.reset();

YUP_PROFILE_STOP();
}

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

START_JUCE_APPLICATION (Application)
7 changes: 7 additions & 0 deletions modules/juce_core/juce_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@
#define JUCE_PROFILING_CATEGORIES
#endif

/** Config: JUCE_PROFILING_FILE_PREFIX
If provided, it will be used as prefix for profilation files generated. By default it will use "yup-profile".
*/
#ifndef JUCE_PROFILING_FILE_PREFIX
#define JUCE_PROFILING_FILE_PREFIX "yup-profile"
#endif

#ifndef JUCE_STRING_UTF_TYPE
#define JUCE_STRING_UTF_TYPE 8
#endif
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/memory/juce_ReferenceCountedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class JUCE_API ReferenceCountedObject
/** Resets the reference count to zero without deleting the object.
You should probably never need to use this!
*/
void resetReferenceCount() noexcept
void resetReferenceCount() const noexcept
{
refCount = 0;
}
Expand Down
69 changes: 34 additions & 35 deletions modules/juce_core/profiling/juce_Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,64 +77,63 @@ void Profiler::startTracing (uint32 sizeInKilobytes)
{
perfetto::TraceConfig traceConfig;
traceConfig.add_buffers()->set_size_kb (sizeInKilobytes);

auto dataSourceConfig = traceConfig.add_data_sources()->mutable_config();
dataSourceConfig->set_name ("track_event");

session = perfetto::Tracing::NewTrace();
session->Setup (traceConfig);
session->StartBlocking();
}

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

void Profiler::stopTracing()
{
if (session == nullptr)
return;

perfetto::TrackEvent::Flush();

session->StopBlocking();
std::vector<char> traceData (session->ReadTraceBlocking());

String fileName;
fileName
<< "yup-profile"
<< JUCE_PROFILING_FILE_PREFIX
#if JUCE_DEBUG
<< "-DEBUG-"
#else
<< "-RELEASE-"
#endif
<< Time::getCurrentTime().formatted ("%Y-%m-%d_%H%M%S")
<< Time::getCurrentTime().formatted ("%Y%m%d%H%M%S")
<< "-" << String::toHexString (static_cast<uint16> (Random::getSystemRandom().nextInt()))
<< ".pftrace";

const auto destination = File::getSpecialLocation (File::userHomeDirectory) // TODO - make it configurable
.getChildFile (fileName);
File destination;
if (outputFolder != File() && outputFolder.isDirectory())
destination = outputFolder;
else
destination = File::getSpecialLocation (File::userHomeDirectory);

destination = destination.getChildFile (fileName);

if (destination.existsAsFile())
destination.deleteFile();

if (auto output = destination.createOutputStream(); output != nullptr && output->openedOk())
{
output->write (traceData.data(), traceData.size());
fileDescriptor = open (destination.getFullPathName().toRawUTF8(), O_RDWR | O_CREAT | O_TRUNC, 0600);

String message;
message
<< "Trace written in " << destination.getFullPathName() << ". "
<< "To read this trace in text form, `./tools/traceconv text " << destination.getFullPathName() << "`";
session = perfetto::Tracing::NewTrace();
session->Setup (traceConfig, fileDescriptor);
session->StartBlocking();
}

DBG (message);
}
else
{
DBG ("Failed to write trace file. Check for missing permissions.");
//==============================================================================

void Profiler::stopTracing()
{
if (session == nullptr)
return;

jassertfalse;
}
perfetto::TrackEvent::Flush();

session->StopBlocking();

close (fileDescriptor);

Profiler::deleteInstance();
}

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

void Profiler::setOutputFolder (const File& newOutputFolder)
{
outputFolder = newOutputFolder;
}

} // namespace juce

#endif
31 changes: 26 additions & 5 deletions modules/juce_core/profiling/juce_Profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class JUCE_API Profiler

This method starts the tracing process using a default buffer size. The tracing session is managed internally
and will continue until `stopTracing()` is called.

@see YUP_PROFILE_START
*/
void startTracing();

Expand All @@ -54,16 +56,30 @@ class JUCE_API Profiler
This method allows you to specify the buffer size used for tracing. The buffer size is defined in kilobytes.

@param sizeInKilobytes The size of the tracing buffer in kilobytes.

@see YUP_PROFILE_START
*/
void startTracing (uint32 sizeInKilobytes);

/** Stops the current tracing session.

This method stops the tracing process and finalizes the trace data.
Once tracing is stopped, the data can be retrieved and analyzed.

@see YUP_PROFILE_STOP
*/
void stopTracing();

/** Define the output folder of the traces.

Call this method as erly as possible to

@param newOutputFolder The output folder where to save traces.

@see YUP_PROFILE_SET_OUTPUT_FOLDER
*/
void setOutputFolder (const File& newOutputFolder);

/** A constexpr function that prettifies a function name at compile time.

This template function accepts a function name and formats it in a more readable manner at compile time.
Expand All @@ -84,6 +100,8 @@ class JUCE_API Profiler
Profiler();

std::unique_ptr<perfetto::TracingSession> session;
File outputFolder;
int fileDescriptor;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Profiler);
};
Expand Down Expand Up @@ -153,6 +171,9 @@ constexpr auto Profiler::compileTimePrettierFunction (F func)
*/
#define YUP_PROFILE_STOP(...) ::juce::Profiler::getInstance()->stopTracing()

/** Define the output folder of the traces. */
#define YUP_PROFILE_SET_OUTPUT_FOLDER(path) ::juce::Profiler::getInstance()->setOutputFolder (path)

#if ! YUP_PROFILE_DISABLE_TRACE
/** Records a profiling trace event.

Expand All @@ -167,7 +188,7 @@ constexpr auto Profiler::compileTimePrettierFunction (F func)
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__)

#define YUP_PROFILE_NAMED_TRACE(category, name, ...) \
#define YUP_PROFILE_NAMED_TRACE(category, name, ...) \
TRACE_EVENT (category, ::perfetto::StaticString (#name), ##__VA_ARGS__)

/** Records a profiling internal trace event.
Expand All @@ -176,18 +197,18 @@ constexpr auto Profiler::compileTimePrettierFunction (F func)

@param ... Optional additional arguments for the trace event.
*/
#define YUP_PROFILE_INTERNAL_TRACE(...) \
#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__)

#define YUP_PROFILE_NAMED_INTERNAL_TRACE(name, ...) \
#define YUP_PROFILE_NAMED_INTERNAL_TRACE(name, ...) \
TRACE_EVENT ("yup", ::perfetto::StaticString (#name), ##__VA_ARGS__)

#else
#define YUP_PROFILE_TRACE(category, ...)
#define YUP_PROFILE_NAMED_TRACE(category, name, ...) \
#define YUP_PROFILE_NAMED_TRACE(category, name, ...)
#define YUP_PROFILE_INTERNAL_TRACE(...)
#define YUP_PROFILE_NAMED_INTERNAL_TRACE(name, ...) \
#define YUP_PROFILE_NAMED_INTERNAL_TRACE(name, ...)

#endif
// clang-format on
Expand Down
14 changes: 3 additions & 11 deletions modules/juce_events/native/juce_MessageQueue_apple.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,13 @@ class InternalMessageQueue
{
YUP_PROFILE_INTERNAL_TRACE();

auto timeoutDetector = TimeoutDetector (1.0 / 60.0);

if (! deliverNextMessage())
return;

if (! timeoutDetector.hasTimedOut())
for (int i = 3; --i >= 0;)
{
for (int i = 3; --i >= 0;)
{
if (! deliverNextMessage())
break;

if (timeoutDetector.hasTimedOut())
break;
}
if (! deliverNextMessage())
break;
}

wakeUp();
Expand Down
2 changes: 1 addition & 1 deletion modules/yup_graphics/native/yup_GraphicsContext_metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LowLevelRenderContextMetal : public GraphicsContext
m_swapchain.contentsScale = dpiScale (window);
m_swapchain.maximumDrawableCount = 2;
#if ! TARGET_OS_IOS
m_swapchain.displaySyncEnabled = YES;
m_swapchain.displaySyncEnabled = NO;
#endif

#if TARGET_OS_IOS
Expand Down
13 changes: 9 additions & 4 deletions modules/yup_gui/artboard/yup_Artboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,19 @@ void Artboard::setNumberInput (const String& name, double value)

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

void Artboard::refreshDisplay (double lastFrameTimeSeconds)
{
if (! paused)
advanceAndApply (static_cast<float> (lastFrameTimeSeconds));
}

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

void Artboard::paint (Graphics& g)
{
if (rivFile == nullptr || scene == nullptr)
if (scene == nullptr)
return;

if (! paused && getNativeComponent() != nullptr)
scene->advanceAndApply (1.0f / getNativeComponent()->getDesiredFrameRate());

auto* renderer = g.getRenderer();

renderer->save();
Expand Down
2 changes: 2 additions & 0 deletions modules/yup_gui/artboard/yup_Artboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class JUCE_API Artboard : public Component
virtual void propertyChanged (const String& eventName, const String& propertyName, const var& oldValue, const var& newValue);

//==============================================================================
void refreshDisplay (double lastFrameTimeSeconds) override;
void paint (Graphics& g) override;
void resized() override;
void mouseEnter (const MouseEvent& event) override;
Expand All @@ -71,6 +72,7 @@ class JUCE_API Artboard : public Component
int artboardIndex = -1;
int animationIndex = -1;
int stateMachineIndex = -1;
float animationTime = 0.0f;

bool useStateMachines = true;
bool paused = false;
Expand Down
7 changes: 7 additions & 0 deletions modules/yup_gui/component/yup_ComponentNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,18 @@ class JUCE_API ComponentNative
return *this;
}

Options& withUpdateOnlyFocused (bool onlyWhenFocused) noexcept
{
updateOnlyWhenFocused = onlyWhenFocused;
return *this;
}

Flags flags = defaultFlags; ///<
std::optional<GraphicsContext::Api> graphicsApi; ///<
std::optional<float> framerateRedraw; ///<
std::optional<Color> clearColor; ///<
std::optional<RelativeTime> doubleClickTime; ///<
bool updateOnlyWhenFocused = false; ///<
};

//==============================================================================
Expand Down
Loading
Loading