Skip to content

Commit 97ce101

Browse files
Graphics: Hide rendering helpers from public API
This should help speed up includes of the juce_graphics header file
1 parent f22e958 commit 97ce101

File tree

6 files changed

+217
-12
lines changed

6 files changed

+217
-12
lines changed

modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp

Lines changed: 164 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,30 @@
3535
namespace juce
3636
{
3737

38+
class LowLevelGraphicsSoftwareRenderer::Impl : public RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
39+
{
40+
public:
41+
using SavedStateType = RenderingHelpers::SoftwareRendererSavedState;
42+
43+
using StackBasedLowLevelGraphicsContext::StackBasedLowLevelGraphicsContext;
44+
45+
std::unique_ptr<ImageType> getPreferredImageTypeForTemporaryImages() const override
46+
{
47+
jassertfalse;
48+
return {};
49+
}
50+
};
51+
3852
LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image)
39-
: RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
40-
(new RenderingHelpers::SoftwareRendererSavedState (image, image.getBounds()))
53+
: impl (std::make_unique<Impl> (std::make_unique<Impl::SavedStateType> (image, image.getBounds())))
4154
{
4255
JUCE_TRACE_LOG_PAINT_CALL (etw::startGDIImage, getFrameId());
4356
}
4457

4558
LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image, Point<int> origin,
4659
const RectangleList<int>& initialClip)
47-
: RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
48-
(new RenderingHelpers::SoftwareRendererSavedState (image, initialClip, origin))
60+
: impl (std::make_unique<Impl> (std::make_unique<Impl::SavedStateType> (image, initialClip, origin)))
4961
{
50-
5162
JUCE_TRACE_EVENT_INT_RECT_LIST (etw::startGDIFrame, etw::softwareRendererKeyword, getFrameId(), initialClip);
5263
}
5364

@@ -56,4 +67,152 @@ LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
5667
JUCE_TRACE_LOG_PAINT_CALL (etw::endGDIFrame, getFrameId());
5768
}
5869

70+
bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
71+
{
72+
return impl->isVectorDevice();
73+
}
74+
75+
Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
76+
{
77+
return impl->getClipBounds();
78+
}
79+
80+
bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
81+
{
82+
return impl->isClipEmpty();
83+
}
84+
85+
void LowLevelGraphicsSoftwareRenderer::setOrigin (Point<int> o)
86+
{
87+
impl->setOrigin (o);
88+
}
89+
90+
void LowLevelGraphicsSoftwareRenderer::addTransform (const AffineTransform& t)
91+
{
92+
impl->addTransform (t);
93+
}
94+
95+
float LowLevelGraphicsSoftwareRenderer::getPhysicalPixelScaleFactor() const
96+
{
97+
return impl->getPhysicalPixelScaleFactor();
98+
}
99+
100+
bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
101+
{
102+
return impl->clipRegionIntersects (r);
103+
}
104+
105+
bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
106+
{
107+
return impl->clipToRectangle (r);
108+
}
109+
110+
bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList<int>& r)
111+
{
112+
return impl->clipToRectangleList (r);
113+
}
114+
115+
void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
116+
{
117+
impl->excludeClipRectangle (r);
118+
}
119+
120+
void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& t)
121+
{
122+
impl->clipToPath (path, t);
123+
}
124+
125+
void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& im, const AffineTransform& t)
126+
{
127+
impl->clipToImageAlpha (im, t);
128+
}
129+
130+
void LowLevelGraphicsSoftwareRenderer::saveState()
131+
{
132+
impl->saveState();
133+
}
134+
135+
void LowLevelGraphicsSoftwareRenderer::restoreState()
136+
{
137+
impl->restoreState();
138+
}
139+
140+
void LowLevelGraphicsSoftwareRenderer::beginTransparencyLayer (float opacity)
141+
{
142+
impl->beginTransparencyLayer (opacity);
143+
}
144+
145+
void LowLevelGraphicsSoftwareRenderer::endTransparencyLayer()
146+
{
147+
impl->endTransparencyLayer();
148+
}
149+
150+
void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
151+
{
152+
impl->setFill (fillType);
153+
}
154+
155+
void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
156+
{
157+
impl->setOpacity (newOpacity);
158+
}
159+
160+
void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
161+
{
162+
impl->setInterpolationQuality (quality);
163+
}
164+
165+
void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, bool replace)
166+
{
167+
impl->fillRect (r, replace);
168+
}
169+
170+
void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<float>& r)
171+
{
172+
impl->fillRect (r);
173+
}
174+
175+
void LowLevelGraphicsSoftwareRenderer::fillRectList (const RectangleList<float>& list)
176+
{
177+
impl->fillRectList (list);
178+
}
179+
180+
void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& t)
181+
{
182+
impl->fillPath (path, t);
183+
}
184+
185+
void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& im, const AffineTransform& t)
186+
{
187+
impl->drawImage (im, t);
188+
}
189+
190+
void LowLevelGraphicsSoftwareRenderer::drawLine (const Line<float>& line)
191+
{
192+
impl->drawLine (line);
193+
}
194+
195+
void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
196+
{
197+
impl->setFont (newFont);
198+
}
199+
200+
const Font& LowLevelGraphicsSoftwareRenderer::getFont()
201+
{
202+
return impl->getFont();
203+
}
204+
205+
uint64_t LowLevelGraphicsSoftwareRenderer::getFrameId() const
206+
{
207+
return impl->getFrameId();
208+
}
209+
210+
211+
void LowLevelGraphicsSoftwareRenderer::drawGlyphs (Span<const uint16_t> glyphs,
212+
Span<const Point<float>> positions,
213+
const AffineTransform& t)
214+
{
215+
return impl->drawGlyphs (glyphs, positions, t);
216+
}
217+
59218
} // namespace juce

modules/juce_graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace juce
4545
4646
@tags{Graphics}
4747
*/
48-
class JUCE_API LowLevelGraphicsSoftwareRenderer : public RenderingHelpers::StackBasedLowLevelGraphicsContext<RenderingHelpers::SoftwareRendererSavedState>
48+
class JUCE_API LowLevelGraphicsSoftwareRenderer : public LowLevelGraphicsContext
4949
{
5050
public:
5151
//==============================================================================
@@ -64,7 +64,44 @@ class JUCE_API LowLevelGraphicsSoftwareRenderer : public RenderingHelpers::S
6464
return std::make_unique<SoftwareImageType>();
6565
}
6666

67+
bool isVectorDevice() const override;
68+
Rectangle<int> getClipBounds() const override;
69+
bool isClipEmpty() const override;
70+
71+
void setOrigin (Point<int> o) override;
72+
void addTransform (const AffineTransform& t) override;
73+
float getPhysicalPixelScaleFactor() const override;
74+
bool clipRegionIntersects (const Rectangle<int>& r) override;
75+
bool clipToRectangle (const Rectangle<int>& r) override;
76+
bool clipToRectangleList (const RectangleList<int>& r) override;
77+
void excludeClipRectangle (const Rectangle<int>& r) override;
78+
void clipToPath (const Path& path, const AffineTransform& t) override;
79+
void clipToImageAlpha (const Image& im, const AffineTransform& t) override;
80+
void saveState() override;
81+
void restoreState() override;
82+
void beginTransparencyLayer (float opacity) override;
83+
void endTransparencyLayer() override;
84+
void setFill (const FillType& fillType) override;
85+
void setOpacity (float newOpacity) override;
86+
void setInterpolationQuality (Graphics::ResamplingQuality quality) override;
87+
void fillRect (const Rectangle<int>& r, bool replace) override;
88+
void fillRect (const Rectangle<float>& r) override;
89+
void fillRectList (const RectangleList<float>& list) override;
90+
void fillPath (const Path& path, const AffineTransform& t) override;
91+
void drawImage (const Image& im, const AffineTransform& t) override;
92+
void drawLine (const Line<float>& line) override;
93+
void setFont (const Font& newFont) override;
94+
const Font& getFont() override;
95+
uint64_t getFrameId() const override;
96+
97+
void drawGlyphs (Span<const uint16_t> glyphs,
98+
Span<const Point<float>> positions,
99+
const AffineTransform& t) override;
100+
67101
private:
102+
class Impl;
103+
std::unique_ptr<Impl> impl;
104+
68105
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LowLevelGraphicsSoftwareRenderer)
69106
};
70107

modules/juce_graphics/juce_graphics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define JUCE_CORE_INCLUDE_JNI_HELPERS 1
4747
#define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1
4848
#define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1
49+
#define JUCE_GRAPHICS_INCLUDE_RENDERING_HELPERS 1
4950

5051
#include "juce_graphics.h"
5152

modules/juce_graphics/juce_graphics.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,16 @@ namespace juce
149149
#include "contexts/juce_LowLevelGraphicsContext.h"
150150
#include "images/juce_ScaledImage.h"
151151
#include "detail/juce_FontRendering.h"
152-
#include "native/juce_RenderingHelpers.h"
153152
#include "contexts/juce_LowLevelGraphicsSoftwareRenderer.h"
154153
#include "effects/juce_ImageEffectFilter.h"
155154
#include "effects/juce_DropShadowEffect.h"
156155
#include "effects/juce_GlowEffect.h"
157156
#include "detail/juce_Unicode.h"
158157

158+
#if JUCE_GRAPHICS_INCLUDE_RENDERING_HELPERS
159+
#include "native/juce_RenderingHelpers.h"
160+
#endif
161+
159162
#if JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS && (JUCE_MAC || JUCE_IOS)
160163
#include "native/juce_CoreGraphicsHelpers_mac.h"
161164
#include "native/juce_CoreGraphicsContext_mac.h"

modules/juce_graphics/native/juce_RenderingHelpers.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,8 +2527,8 @@ template <class StateObjectType>
25272527
class SavedStateStack
25282528
{
25292529
public:
2530-
SavedStateStack (StateObjectType* initialState) noexcept
2531-
: currentState (initialState)
2530+
explicit SavedStateStack (std::unique_ptr<StateObjectType> initialState) noexcept
2531+
: currentState (std::move (initialState))
25322532
{}
25332533

25342534
SavedStateStack() = default;
@@ -2589,6 +2589,13 @@ class StackBasedLowLevelGraphicsContext : public LowLevelGraphicsContext
25892589
{
25902590
}
25912591

2592+
explicit StackBasedLowLevelGraphicsContext (std::unique_ptr<SavedStateType> initialState)
2593+
: stack (std::move (initialState))
2594+
{
2595+
}
2596+
2597+
StackBasedLowLevelGraphicsContext() = default;
2598+
25922599
bool isVectorDevice() const override { return false; }
25932600
Rectangle<int> getClipBounds() const override { return stack->getClipBounds(); }
25942601
bool isClipEmpty() const override { return stack->clip == nullptr; }
@@ -2694,9 +2701,6 @@ class StackBasedLowLevelGraphicsContext : public LowLevelGraphicsContext
26942701
}
26952702
}
26962703

2697-
explicit StackBasedLowLevelGraphicsContext (SavedStateType* initialState) : stack (initialState) {}
2698-
StackBasedLowLevelGraphicsContext() = default;
2699-
27002704
RenderingHelpers::SavedStateStack<SavedStateType> stack;
27012705
uint64_t frame = 0;
27022706
};

modules/juce_opengl/juce_opengl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define JUCE_CORE_INCLUDE_JNI_HELPERS 1
4646
#define JUCE_CORE_INCLUDE_NATIVE_HEADERS 1
4747
#define JUCE_GRAPHICS_INCLUDE_COREGRAPHICS_HELPERS 1
48+
#define JUCE_GRAPHICS_INCLUDE_RENDERING_HELPERS 1
4849
#define JUCE_GUI_BASICS_INCLUDE_XHEADERS 1
4950
#define JUCE_GUI_BASICS_INCLUDE_SCOPED_THREAD_DPI_AWARENESS_SETTER 1
5051

0 commit comments

Comments
 (0)