1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Graphics: Hide rendering helpers from public API

This should help speed up includes of the juce_graphics header file
This commit is contained in:
Anthony Nicholls 2025-12-15 10:05:28 +00:00 committed by Anthony Nicholls
parent f22e9585d4
commit 97ce101d6a
6 changed files with 217 additions and 12 deletions

View file

@ -35,19 +35,30 @@
namespace juce
{
class LowLevelGraphicsSoftwareRenderer::Impl : public RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
{
public:
using SavedStateType = RenderingHelpers::SoftwareRendererSavedState;
using StackBasedLowLevelGraphicsContext::StackBasedLowLevelGraphicsContext;
std::unique_ptr<ImageType> getPreferredImageTypeForTemporaryImages() const override
{
jassertfalse;
return {};
}
};
LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image)
: RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
(new RenderingHelpers::SoftwareRendererSavedState (image, image.getBounds()))
: impl (std::make_unique<Impl> (std::make_unique<Impl::SavedStateType> (image, image.getBounds())))
{
JUCE_TRACE_LOG_PAINT_CALL (etw::startGDIImage, getFrameId());
}
LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image, Point<int> origin,
const RectangleList<int>& initialClip)
: RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
(new RenderingHelpers::SoftwareRendererSavedState (image, initialClip, origin))
: impl (std::make_unique<Impl> (std::make_unique<Impl::SavedStateType> (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<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
{
return impl->getClipBounds();
}
bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
{
return impl->isClipEmpty();
}
void LowLevelGraphicsSoftwareRenderer::setOrigin (Point<int> 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<int>& r)
{
return impl->clipRegionIntersects (r);
}
bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
{
return impl->clipToRectangle (r);
}
bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList<int>& r)
{
return impl->clipToRectangleList (r);
}
void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& 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<int>& r, bool replace)
{
impl->fillRect (r, replace);
}
void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<float>& r)
{
impl->fillRect (r);
}
void LowLevelGraphicsSoftwareRenderer::fillRectList (const RectangleList<float>& 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<float>& 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<const uint16_t> glyphs,
Span<const Point<float>> positions,
const AffineTransform& t)
{
return impl->drawGlyphs (glyphs, positions, t);
}
} // namespace juce

View file

@ -45,7 +45,7 @@ namespace juce
@tags{Graphics}
*/
class JUCE_API LowLevelGraphicsSoftwareRenderer : public RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
class JUCE_API LowLevelGraphicsSoftwareRenderer : public LowLevelGraphicsContext
{
public:
//==============================================================================
@ -64,7 +64,44 @@ public:
return std::make_unique<SoftwareImageType>();
}
bool isVectorDevice() const override;
Rectangle<int> getClipBounds() const override;
bool isClipEmpty() const override;
void setOrigin (Point<int> o) override;
void addTransform (const AffineTransform& t) override;
float getPhysicalPixelScaleFactor() const override;
bool clipRegionIntersects (const Rectangle<int>& r) override;
bool clipToRectangle (const Rectangle<int>& r) override;
bool clipToRectangleList (const RectangleList<int>& r) override;
void excludeClipRectangle (const Rectangle<int>& 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<int>& r, bool replace) override;
void fillRect (const Rectangle<float>& r) override;
void fillRectList (const RectangleList<float>& list) override;
void fillPath (const Path& path, const AffineTransform& t) override;
void drawImage (const Image& im, const AffineTransform& t) override;
void drawLine (const Line<float>& line) override;
void setFont (const Font& newFont) override;
const Font& getFont() override;
uint64_t getFrameId() const override;
void drawGlyphs (Span<const uint16_t> glyphs,
Span<const Point<float>> positions,
const AffineTransform& t) override;
private:
class Impl;
std::unique_ptr<Impl> impl;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LowLevelGraphicsSoftwareRenderer)
};

View file

@ -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"

View file

@ -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"

View file

@ -2527,8 +2527,8 @@ template <class StateObjectType>
class SavedStateStack
{
public:
SavedStateStack (StateObjectType* initialState) noexcept
: currentState (initialState)
explicit SavedStateStack (std::unique_ptr<StateObjectType> initialState) noexcept
: currentState (std::move (initialState))
{}
SavedStateStack() = default;
@ -2589,6 +2589,13 @@ public:
{
}
explicit StackBasedLowLevelGraphicsContext (std::unique_ptr<SavedStateType> initialState)
: stack (std::move (initialState))
{
}
StackBasedLowLevelGraphicsContext() = default;
bool isVectorDevice() const override { return false; }
Rectangle<int> 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<SavedStateType> stack;
uint64_t frame = 0;
};

View file

@ -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