From 97ce101d6ae3406dab96be925f86bdec1bbc2dfb Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Mon, 15 Dec 2025 10:05:28 +0000 Subject: [PATCH] Graphics: Hide rendering helpers from public API This should help speed up includes of the juce_graphics header file --- .../juce_LowLevelGraphicsSoftwareRenderer.cpp | 169 +++++++++++++++++- .../juce_LowLevelGraphicsSoftwareRenderer.h | 39 +++- modules/juce_graphics/juce_graphics.cpp | 1 + modules/juce_graphics/juce_graphics.h | 5 +- .../native/juce_RenderingHelpers.h | 14 +- modules/juce_opengl/juce_opengl.cpp | 1 + 6 files changed, 217 insertions(+), 12 deletions(-) diff --git a/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index 9af41bf287..756f093e6e 100644 --- a/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -35,19 +35,30 @@ namespace juce { +class LowLevelGraphicsSoftwareRenderer::Impl : public RenderingHelpers::StackBasedLowLevelGraphicsContext +{ +public: + using SavedStateType = RenderingHelpers::SoftwareRendererSavedState; + + using StackBasedLowLevelGraphicsContext::StackBasedLowLevelGraphicsContext; + + std::unique_ptr getPreferredImageTypeForTemporaryImages() const override + { + jassertfalse; + return {}; + } +}; + LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image) - : RenderingHelpers::StackBasedLowLevelGraphicsContext - (new RenderingHelpers::SoftwareRendererSavedState (image, image.getBounds())) + : impl (std::make_unique (std::make_unique (image, image.getBounds()))) { JUCE_TRACE_LOG_PAINT_CALL (etw::startGDIImage, getFrameId()); } LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image, Point origin, const RectangleList& initialClip) - : RenderingHelpers::StackBasedLowLevelGraphicsContext - (new RenderingHelpers::SoftwareRendererSavedState (image, initialClip, origin)) + : impl (std::make_unique (std::make_unique (image, initialClip, origin))) { - JUCE_TRACE_EVENT_INT_RECT_LIST (etw::startGDIFrame, etw::softwareRendererKeyword, getFrameId(), initialClip); } @@ -56,4 +67,152 @@ LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer() JUCE_TRACE_LOG_PAINT_CALL (etw::endGDIFrame, getFrameId()); } +bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const +{ + return impl->isVectorDevice(); +} + +Rectangle LowLevelGraphicsSoftwareRenderer::getClipBounds() const +{ + return impl->getClipBounds(); +} + +bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const +{ + return impl->isClipEmpty(); +} + +void LowLevelGraphicsSoftwareRenderer::setOrigin (Point o) +{ + impl->setOrigin (o); +} + +void LowLevelGraphicsSoftwareRenderer::addTransform (const AffineTransform& t) +{ + impl->addTransform (t); +} + +float LowLevelGraphicsSoftwareRenderer::getPhysicalPixelScaleFactor() const +{ + return impl->getPhysicalPixelScaleFactor(); +} + +bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle& r) +{ + return impl->clipRegionIntersects (r); +} + +bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle& r) +{ + return impl->clipToRectangle (r); +} + +bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& r) +{ + return impl->clipToRectangleList (r); +} + +void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle& r) +{ + impl->excludeClipRectangle (r); +} + +void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& t) +{ + impl->clipToPath (path, t); +} + +void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& im, const AffineTransform& t) +{ + impl->clipToImageAlpha (im, t); +} + +void LowLevelGraphicsSoftwareRenderer::saveState() +{ + impl->saveState(); +} + +void LowLevelGraphicsSoftwareRenderer::restoreState() +{ + impl->restoreState(); +} + +void LowLevelGraphicsSoftwareRenderer::beginTransparencyLayer (float opacity) +{ + impl->beginTransparencyLayer (opacity); +} + +void LowLevelGraphicsSoftwareRenderer::endTransparencyLayer() +{ + impl->endTransparencyLayer(); +} + +void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType) +{ + impl->setFill (fillType); +} + +void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity) +{ + impl->setOpacity (newOpacity); +} + +void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality) +{ + impl->setInterpolationQuality (quality); +} + +void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle& r, bool replace) +{ + impl->fillRect (r, replace); +} + +void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle& r) +{ + impl->fillRect (r); +} + +void LowLevelGraphicsSoftwareRenderer::fillRectList (const RectangleList& list) +{ + impl->fillRectList (list); +} + +void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& t) +{ + impl->fillPath (path, t); +} + +void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& im, const AffineTransform& t) +{ + impl->drawImage (im, t); +} + +void LowLevelGraphicsSoftwareRenderer::drawLine (const Line& line) +{ + impl->drawLine (line); +} + +void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont) +{ + impl->setFont (newFont); +} + +const Font& LowLevelGraphicsSoftwareRenderer::getFont() +{ + return impl->getFont(); +} + +uint64_t LowLevelGraphicsSoftwareRenderer::getFrameId() const +{ + return impl->getFrameId(); +} + + +void LowLevelGraphicsSoftwareRenderer::drawGlyphs (Span glyphs, + Span> positions, + const AffineTransform& t) +{ + return impl->drawGlyphs (glyphs, positions, t); +} + } // namespace juce diff --git a/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h b/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h index ea1385ef5a..dda263fee6 100644 --- a/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h +++ b/modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h @@ -45,7 +45,7 @@ namespace juce @tags{Graphics} */ -class JUCE_API LowLevelGraphicsSoftwareRenderer : public RenderingHelpers::StackBasedLowLevelGraphicsContext +class JUCE_API LowLevelGraphicsSoftwareRenderer : public LowLevelGraphicsContext { public: //============================================================================== @@ -64,7 +64,44 @@ public: return std::make_unique(); } + bool isVectorDevice() const override; + Rectangle getClipBounds() const override; + bool isClipEmpty() const override; + + void setOrigin (Point o) override; + void addTransform (const AffineTransform& t) override; + float getPhysicalPixelScaleFactor() const override; + bool clipRegionIntersects (const Rectangle& r) override; + bool clipToRectangle (const Rectangle& r) override; + bool clipToRectangleList (const RectangleList& r) override; + void excludeClipRectangle (const Rectangle& r) override; + void clipToPath (const Path& path, const AffineTransform& t) override; + void clipToImageAlpha (const Image& im, const AffineTransform& t) override; + void saveState() override; + void restoreState() override; + void beginTransparencyLayer (float opacity) override; + void endTransparencyLayer() override; + void setFill (const FillType& fillType) override; + void setOpacity (float newOpacity) override; + void setInterpolationQuality (Graphics::ResamplingQuality quality) override; + void fillRect (const Rectangle& r, bool replace) override; + void fillRect (const Rectangle& r) override; + void fillRectList (const RectangleList& list) override; + void fillPath (const Path& path, const AffineTransform& t) override; + void drawImage (const Image& im, const AffineTransform& t) override; + void drawLine (const Line& line) override; + void setFont (const Font& newFont) override; + const Font& getFont() override; + uint64_t getFrameId() const override; + + void drawGlyphs (Span glyphs, + Span> positions, + const AffineTransform& t) override; + private: + class Impl; + std::unique_ptr impl; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LowLevelGraphicsSoftwareRenderer) }; diff --git a/modules/juce_graphics/juce_graphics.cpp b/modules/juce_graphics/juce_graphics.cpp index 8a0c74864f..6c303e38d2 100644 --- a/modules/juce_graphics/juce_graphics.cpp +++ b/modules/juce_graphics/juce_graphics.cpp @@ -46,6 +46,7 @@ #define JUCE_CORE_INCLUDE_JNI_HELPERS 1 #define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1 #define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1 +#define JUCE_GRAPHICS_INCLUDE_RENDERING_HELPERS 1 #include "juce_graphics.h" diff --git a/modules/juce_graphics/juce_graphics.h b/modules/juce_graphics/juce_graphics.h index 287c11873f..5482c8b8e7 100644 --- a/modules/juce_graphics/juce_graphics.h +++ b/modules/juce_graphics/juce_graphics.h @@ -149,13 +149,16 @@ namespace juce #include "contexts/juce_LowLevelGraphicsContext.h" #include "images/juce_ScaledImage.h" #include "detail/juce_FontRendering.h" -#include "native/juce_RenderingHelpers.h" #include "contexts/juce_LowLevelGraphicsSoftwareRenderer.h" #include "effects/juce_ImageEffectFilter.h" #include "effects/juce_DropShadowEffect.h" #include "effects/juce_GlowEffect.h" #include "detail/juce_Unicode.h" +#if JUCE_GRAPHICS_INCLUDE_RENDERING_HELPERS + #include "native/juce_RenderingHelpers.h" +#endif + #if JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS && (JUCE_MAC || JUCE_IOS) #include "native/juce_CoreGraphicsHelpers_mac.h" #include "native/juce_CoreGraphicsContext_mac.h" diff --git a/modules/juce_graphics/native/juce_RenderingHelpers.h b/modules/juce_graphics/native/juce_RenderingHelpers.h index 9b57cf84d3..0bb90968e6 100644 --- a/modules/juce_graphics/native/juce_RenderingHelpers.h +++ b/modules/juce_graphics/native/juce_RenderingHelpers.h @@ -2527,8 +2527,8 @@ template class SavedStateStack { public: - SavedStateStack (StateObjectType* initialState) noexcept - : currentState (initialState) + explicit SavedStateStack (std::unique_ptr initialState) noexcept + : currentState (std::move (initialState)) {} SavedStateStack() = default; @@ -2589,6 +2589,13 @@ public: { } + explicit StackBasedLowLevelGraphicsContext (std::unique_ptr initialState) + : stack (std::move (initialState)) + { + } + + StackBasedLowLevelGraphicsContext() = default; + bool isVectorDevice() const override { return false; } Rectangle getClipBounds() const override { return stack->getClipBounds(); } bool isClipEmpty() const override { return stack->clip == nullptr; } @@ -2694,9 +2701,6 @@ protected: } } - explicit StackBasedLowLevelGraphicsContext (SavedStateType* initialState) : stack (initialState) {} - StackBasedLowLevelGraphicsContext() = default; - RenderingHelpers::SavedStateStack stack; uint64_t frame = 0; }; diff --git a/modules/juce_opengl/juce_opengl.cpp b/modules/juce_opengl/juce_opengl.cpp index 8916e4f58d..7b46d28c02 100644 --- a/modules/juce_opengl/juce_opengl.cpp +++ b/modules/juce_opengl/juce_opengl.cpp @@ -45,6 +45,7 @@ #define JUCE_CORE_INCLUDE_JNI_HELPERS 1 #define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1 #define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1 +#define JUCE_GRAPHICS_INCLUDE_RENDERING_HELPERS 1 #define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1 #define JUCE_GUI_BASICS_INCLUDE_SCOPED_THREAD_DPI_AWARENESS_SETTER 1