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

602 commits

Author SHA1 Message Date
reuk
7bb71cc1ba Direct2D: Make path-rendering behaviour consistent with CoreGraphics and the software renderer
The other renderers implicitly start a new supath at the last path
location when a line or bezier segment is added without explicitly
starting a new subpath.
2024-06-26 14:33:26 +01:00
reuk
815da2ec6d Direct2D: Tidy up clearWindowRedirectionBitmap 2024-06-26 14:33:26 +01:00
reuk
fe1a11908e Direct2D: Fix data race when creating Direct2DPixelData instances on a background thread 2024-06-26 14:33:25 +01:00
Matt Gonzalez
0789048777 Direct2D: Set transform for tiled image brush 2024-06-26 14:33:25 +01:00
reuk
9ae52f3d7a Direct2D: Update backbuffer implementation
Problem description
===================

Firstly, the linked-list of pending presentations acted as a stack
(FILO).  If the swap chain thread and main thread processed frames at
varying rates, then the following sequence of events was possible:

Main thread           Swap chain thread       Queue state
---------------------------------------------------------
Push frame (1)                                [1]
Push frame (2)                                [2, 1]
                      Pop frame (2)           [1]
Push frame (3)                                [3, 1]
                      Pop frame (3)           [1]
                      Pop frame (1)           [] <--  Out of sequence!

Secondly, the swap chain's sequential flip model can only maintain a
valid back-buffer state as long as the list of dirty rects is correct,
and every pixel within the dirty rects is painted incrementally.

In the example above, if the main thread were to produce two frames
before the swap chain thread could present any frame, then presenting
*only* the frame 2 (skipping frame 1) may produce incorrect results when
combined with the existing back buffer. This is because regions updated
in frame 1 may not be updated in frame 2, so regions *only* updated in
frame 1 will be omitted from the back buffer.

Mitigation
==========

This patch removes the old stack of presentations and replaces it with a
slightly more complex mechanism that tracks two different Presentation
objects. At any time, up to one Presentation may be in use by the swap
chain thread (i.e. actively presenting), up to one Presentation may be
accumulating updated/dirty regions (i.e. painting), and up to one region
may be ready, awaiting display.

This scheme resolves the first issue described above by ensuring that
old frame data is not kept around. There is never more than one frame
awaiting display, which means that if the swap chain thread attempts to
display twice in a row (before the main thread produces a new frame),
the second attempt will be a no-op.

The second issue is resolved by accumulating changes into a single
Presentation whenever the main thread produces two or more frames in a
row. If there is already a 'ready' Presentation when the main thread
finishes painting, then all updated regions from the newest Presentation
will be added to the 'ready' Presentation, rather than replacing it.
When the swap chain thread is ready to present, it will therefore see
the result of all the accumulated Presentations produced by the main
thread, instead of just the newest Presentation.
2024-06-26 14:33:25 +01:00
reuk
2301f398aa
Fonts: Replace heavyweight leak detector in FTFaceWrapper 2024-06-20 17:52:22 +01:00
reuk
8acd81e587
Direct2D: Allow drawing rects with very small widths/heights 2024-06-11 11:34:05 +01:00
reuk
2a264390e8
Direct2D: Update assertion to check for alignment against screen rather than current transform
This assertion is intended to mirror the behaviour of an
informational/performance diagnostic message raised by the D2D debugging
layer.

It seems the D2D diagnostic is raised when the proposed clip region is
aligned to the screen, not to the current transform.

Before this change, the assertion could incorrectly fire when clipping
to transformed rectangles. This could be seen when clicking the
star-shaped buttons in the ComponentTransformsDemo.

With this change in place, the assertion will still fire when e.g.
calling Graphics::reduceClipRegion on a screen-aligned rectangular path,
but will not fire when this path is skewed/rotated etc.
2024-06-11 11:34:04 +01:00
reuk
659de5842f
Direct2D: Fix flickery resizing when using an internal resizer
Resizing using window manager functionality (e.g. clicking and dragging
in the non-client area) will send WM_SIZING to the window, which in turn
will enable continuous repainting in the D2D renderer until the resize
operation ends.

Continuous repainting is required in order for the window to display
correctly during the resize. Without continuous repainting, some frames
may not be completely painted, and may display with black areas,
producing a flickery effect.

When a resize is controlled entirely by the client, e.g. using the
corner resizer in the AudioPluginDemo standalone, WM_SIZING is never
posted. Instead, we assume that if the window has captured the cursor
during a setBounds call then it is probably resizing. We enable
continuous repainting in this case, and stop repainting once the window
releases the mouse.

An alternative appropach would be to add some kind of start/stop resize
API to ComponentPeer. I'm currently reluctant to do that because the
ComponentPeer API is already so large.
2024-05-31 11:43:30 +01:00
Matt Gonzalez
00c958ff3e
DirectWrite: Rework custom font collection loader
Removes redundant memory copies and sorts out issues with ownership of the font data
2024-05-31 11:43:29 +01:00
attila
51955453ef Remove TextLayout::createNativeLayout() 2024-05-30 12:21:35 +01:00
Matt Gonzalez
99adac2871
Direct2D: Skip invalid path elements when converting a Path to a Geometry 2024-05-28 16:08:55 +01:00
Matt Gonzalez
77f6eb00ff
Direct2D: Reset pending clip list after setting device space origin
https://forum.juce.com/t/the-juce-8-preview-branch-is-available-now/60950/144?u=matt
2024-05-28 16:08:55 +01:00
Matt Gonzalez
dfb21da572
Direct2D: Use axis-aligned clip layer when possible in clipToImageAlpha 2024-05-28 16:08:55 +01:00
Matt Gonzalez
6ca54e8c97
Direct2D: Add debug check for axis-aligned clip layers
This is similar to the check performed by the D2D debug layer that will still work with the debug layer disabled.
2024-05-28 16:08:55 +01:00
reuk
2ca5fdf18d
Direct2D: Avoid continuous repainting when moving but not resizing windows 2024-05-28 11:28:51 +01:00
reuk
5b2f9d4019
GraphicsContext: Avoid attempting to paint empty rectangles in all renderers 2024-05-20 12:49:56 +01:00
reuk
06137fb7f5
Direct2D: Slightly shrink excluded clip regions in order to draw transformed opaque components without border artefacts 2024-05-20 12:49:55 +01:00
reuk
e11b8f5ccb
CoreGraphics: Slightly shrink excluded clip regions in order to draw transformed opaque components without border artefacts
Previously, drawing an opaque, scaled component with CoreGraphics could
lead to visible artefacts around the edge of the component.

When drawing the parent of an opaque component, the area covered by the
opaque component is excluded from the clip region. If the clip region is
non-integral when transformed into device space, anti-aliasing will be
applied on the edges of the clip region. Similarly, when drawing the
opaque component itself, anti-aliasing will be applied at the edges of
the component. When the two drawings are superimposed, the foreground
anti-aliased pixels will be blended with the background anti-aliased
pixels, leading to a noticeable border around the component. Ideally,
only the foreground anti-aliasing should be applied, and the background
should not be anti-aliased around its edges.
2024-05-20 12:49:55 +01:00
Matt Gonzalez
dfa94981e4 D2D: Pass the clearImage flag to the BitmapData backup image
https://forum.juce.com/t/the-juce-8-preview-branch-is-available-now/60950/123
2024-05-10 11:55:28 +01:00
reuk
f333875386
D2D: Fix formatting 2024-04-29 16:08:24 +01:00
reuk
590e22f320
D2D: Add faster two-pass blur implementation 2024-04-29 16:08:24 +01:00
reuk
acae73e980
RenderingHelpers: DRY implementation of fillRectWithColour 2024-04-29 16:08:24 +01:00
reuk
7991c91fb2
D2D: Move null checks 2024-04-29 16:08:24 +01:00
reuk
248a400b88
D2D: Use currently-selected colour when replace-clearing NativeImage 2024-04-29 16:08:23 +01:00
reuk
793af50964
D2D: Fix typo which caused window to repaint continuously after resize 2024-04-29 16:08:23 +01:00
reuk
bfccf7f81c
D2D: Fix intersection test for Line 2024-04-29 16:08:23 +01:00
reuk
203e99c57d
D2D: Update Direct2DGraphicsContext::getPhysicalPixelScaleFactor to include context transform for consistency with other renderer backends 2024-04-29 16:08:23 +01:00
reuk
c2d86693ff
D2D: Avoid calling setPhysicalPixelScaleFactor 2024-04-29 16:08:23 +01:00
reuk
e005a41d6b
D2D: Remove unnecessary scaling in HwndPimpl::setSize 2024-04-29 16:08:23 +01:00
reuk
238edf6437
D2D: Remove unused function 2024-04-29 16:08:23 +01:00
reuk
49dec0a32a
D2D: Apply physical scale factor inside startFrame 2024-04-29 16:08:23 +01:00
reuk
122b75909e
D2D: Avoid setting DPI when resizing context, as it is already set per-frame 2024-04-29 16:08:23 +01:00
reuk
83ba2cba5d
D2D: Tidy up in typeface implementation 2024-04-29 16:08:22 +01:00
reuk
06903573d2
D2D: Refactor SwapChainThread and attempt to ensure correct alignment of slist entries 2024-04-29 16:08:22 +01:00
reuk
c5a9e26960
Typeface: Add support for querying the default system UI typeface 2024-04-29 16:08:21 +01:00
reuk
19061e6d17
Direct2D: Add initial support 2024-04-18 14:16:02 +01:00
reuk
7e87d3e7a6
RenderingHelpers: Fix transformed linear gradients
Previously, the software renderer could render transformed gradients
incorrectly. This could be seen in the backgrounds of the tabs in the
ComponentTransformsDemo when the view was rotated through around 45
degrees.

The new behaviour appears more consistent with the other renderers.
2024-04-18 14:16:02 +01:00
reuk
1560f87111
LowLevelGraphicsContext: Replace glyph drawing functions with single drawGlyphs() 2024-04-18 14:16:01 +01:00
reuk
c2fce879c5
Font: Allow switching between legacy non-portable metrics, and new portable metrics 2024-04-18 14:16:00 +01:00
reuk
4f2c287f9b
Font: Deprecate old Font constructors 2024-04-18 14:16:00 +01:00
reuk
9c1c61a06e
Android: Attempt to load legacy emoji font if fallback selects incompatible font 2024-04-18 14:15:59 +01:00
reuk
6c4c78baac
Typeface: Fix advances for Apple Color Emoji
The glyph spacing for this font does not scale linearly with the font
size; at smaller font sizes, the spacing is relatively larger.

Typeface::getStringWidth, Typeface::getGlyphPositions, and the
equivalent Font member functions now take the font size and horizontal
scale into account when computing advances on Apple platforms.
2024-04-18 14:15:59 +01:00
reuk
4e90ef831b
Typeface: Add support for rendering COLRv0 glyphs and png-based glyphs
This is sufficient for initial support of the system emoji fonts on each
platform:

- Noto Color Emoji on Linux and Android, png-based
- Apple Color Emoji on macOS and iOS, png-based
- Segoe UI Emoji on Windows 10 and 11, COLRv0-based
    - This font also provides COLRv1 support, at least on Windows 11,
      but JUCE will ignore that and use the COLRv0 data instead
2024-04-18 14:15:59 +01:00
reuk
0da52a8e7b
FreeType: Enable non-scalable glyphs, required for png emoji support 2024-04-18 14:15:59 +01:00
reuk
72819437e7
RenderingHelpers: Move drawGlyph to a common location 2024-04-18 14:15:59 +01:00
reuk
722ff41d66
RenderingHelpers: Individually template ClipRegion types 2024-04-18 14:15:59 +01:00
reuk
830bccd05f
RenderingHelpers: Disable gamma correction, which breaks colour emoji rendering 2024-04-18 14:15:59 +01:00
reuk
c40da067cd
RenderingHelpers: Implement GlyphCache in terms of LruCache 2024-04-18 14:15:59 +01:00
reuk
bc654f8007
RenderingHelpers: Reduce templating of GlyphCache 2024-04-18 14:15:58 +01:00