Commit Graph

135 Commits (main)

Author SHA1 Message Date
Mitchell Hashimoto 0112607532
Zig 0.15: zig build test macOS 2025-10-03 07:10:43 -07:00
Mitchell Hashimoto 7ec57aeebd
Zig 0.15: zig fmt 2025-10-03 07:10:43 -07:00
Qwerasd efc6e0d673 fix(font/coretext): always prevent shaper from emitting rtl
The solution we had before worked in most cases but there were some
which caused problems still. This is what HarfBuzz's CoreText shaper
backend does, it uses a CTTypesetter with the forced embedding level
attribute. This fixes the failure case I found that was causing non-
monotonic outputs which can have all sorts of unexpected results, and
causes a crash in Debug modes because we assert the monotonicity while
rendering.
2025-10-02 15:32:21 -06:00
Qwerasd d6063428bd font/coretext: tiny shaper improvements
Reduce potential allocation while processing glyphs by ensuring capacity
in the buffer ahead of time and also using CTRunGet*Ptr functions first
and only allocating for those if that didn't work (it should almost
always work in practice.)
2025-10-02 14:06:58 -06:00
Mitchell Hashimoto c979ece916
build-system: Replace deprecated usages of root_source_file on addTests (#8031)
Yet another low-hanging fruit
2025-07-22 15:28:11 -07:00
Jayson Reis d5995ac45c
build-system: Replace deprecated usages of root_source_file on addTests 2025-07-23 00:03:44 +02:00
Jayson Reis acc2ea724f
build-system: Replace deprecated usages of addStaticLibrary with addLibrary (#8029)
Hi there, this is just a low-hanging fruit and it also prepares the way
for the future 0.15, which removes addStaticLibrary.
Please, let me know what to do on the `// TODO` comments.
2025-07-22 14:47:18 -07:00
Mitchell Hashimoto c990d35d6d
macos: add benchmark tests to our Xcode project 2025-07-09 15:06:24 -07:00
Mitchell Hashimoto 20bb71c627
libghostty: export benchmark CLI API 2025-07-09 15:06:24 -07:00
Mitchell Hashimoto 01b2545d1d
macos: fix signpost API to use proper mach header base addr 2025-07-09 15:06:24 -07:00
Mitchell Hashimoto d30771ecff
pkg/macos: use new @ptrcast for os.log 2025-07-09 15:06:24 -07:00
Mitchell Hashimoto 8506637ae6
macos: add signpost API 2025-07-09 15:06:23 -07:00
Qwerasd e441094af0 font: add constraint logic to rasterizers
This is in preparation to move constraint off the GPU to simplify our
shaders, instead we only need to constrain once at raster time and never
again.

This also significantly reworks the freetype renderGlyph function to be
generally much cleaner and more straightforward.

This commit doesn't actually apply the constraints to anything yet, that
will be in following commits.
2025-07-04 15:47:28 -06:00
Qwerasd ea1e507af7 unwrap unnecessary @"" identifiers 2025-06-20 15:18:41 -06:00
Qwerasd 371d62a82c renderer: big rework, graphics API abstraction layers, unified logic
This commit is very large, representing about a month of work with many
interdependent changes that don't separate cleanly in to atomic commits.

The main change here is unifying the renderer logic to a single generic
renderer, implemented on top of an abstraction layer over OpenGL/Metal.

I'll write a more complete summary of the changes in the description of
the PR.
2025-06-20 15:18:41 -06:00
Mitchell Hashimoto 0f1860f066
build: use a libc txt file to point to correct Apple SDK
This fixes an issue where Ghostty would not build against the macOS 15.5 SDK.

What was happening was that Zig was adding its embedded libc paths to
the clang command line, which included old headers that were
incompatible with the latest (macOS 15.5) SDK. Ghostty was adding the
newer paths but they were being overridden by the embedded libc paths.

The reason this was happening is because Zig was using its own logic to
find the libc paths and this was colliding with the paths we were
setting manually. To fix this, we now use a `libc.txt` file that
explicitly tells Zig where to find libc, and we base this on our own SDK
search logic.
2025-05-29 15:04:05 -07:00
Jeffrey C. Ollie e8c845b758
core: fixup callconv(.C) -> callconv(.c)
https://ziglang.org/download/0.14.0/release-notes.html#Calling-Convention-Enhancements-and-setAlignStack-Replaced
2025-05-07 08:41:09 -05:00
Mitchell Hashimoto 5ad8ea6b22
pkg/macos: clean up for Zig 0.14, consolidate C imports into one decl
Fixes #6727

The major change in this commit is to consolidate all the C imports in
a single decl in main.zig. This is required for Zig 0.14. Without it,
the problem in #6727 will happen. I was never able to minimize why this
happens in order to open a Zig bug.

Beyond this, I fixed the build.zig and build.zig.zon to work with Zig
0.14 so that we can test building `pkg/macos` in isolation. There are no
downstream impacting changes in the build.zig files.
2025-03-15 07:02:53 -07:00
Mitchell Hashimoto 7e9be00924
working on macos 2025-03-12 10:15:14 -07:00
Mitchell Hashimoto 7e2286eb8c
Zig 0.14 2025-03-11 14:39:04 -07:00
Qwerasd fca336c32d Metal: blend in Display P3 color space, add option for linear blending
This commit is quite large because it's fairly interconnected and can't
be split up in a logical way. The main part of this commit is that alpha
blending is now always done in the Display P3 color space, and depending
on the configured `window-colorspace` colors will be converted from sRGB
or assumed to already be Display P3 colors. In addition, a config option
`text-blending` has been added which allows the user to configure linear
blending (AKA "gamma correction"). Linear alpha blending also applies to
images and makes custom shaders receive linear colors rather than sRGB.

In addition, an experimental option has been added which corrects linear
blending's tendency to make dark text look too thin and bright text look
too thick. Essentially it's a correction curve on the alpha channel that
depends on the luminance of the glyph being drawn.
2025-01-13 13:50:29 -08:00
Qwerasd 5cd214066d font(coretext): tolerate fonts without OS/2 tables
This creates big problems if we don't, since a lot of symbols end up
falling back to Apple Gothic, which doesn't have an OS/2 table.
2024-12-16 14:52:07 -05:00
Qwerasd fb50143cec font(coretext): add metrics test case for CT, fix variable font init
Variable font init used to just select the first available predefined
instance, if there were any, which is often not desirable- using
createFontDescriptorFromData instead of createFontDescritorsFromData
ensures that the default variation config is selected. In the future we
should probably allow selection of predefined instances, but for now
this is the correct behavior.

I found this bug when adding the metrics calculation test case for
CoreText, hence why fixing it is part of the same commit.
2024-12-11 21:14:21 -05:00
Mitchell Hashimoto 1aa932f810
font/coretext: use CTFontCreateForString for final codepoint fallback
Fixes #2499

We rely on CoreText's font discovery to find the best font for a
fallback by using the character set attribute. It appears that for some
codepoints, the character set attribute is not enough to find a font
that supports the codepoint.

In this case, we use CTFontCreateForString to find the font that
CoreText would use. The one subtlety here is we need to ignore the
last resort font, which just has replacement glyphs for all codepoints.

We already had a function to do this for CJK characters (#1637)
thankfully so we can just reuse that!

This also fixes a bug where CTFontCreateForString range param expects
the range length to be utf16 code units, not utf32.
2024-10-25 21:29:45 -07:00
Qwerasd 3ec36e4d23 coretext: improve strikethrough position calculation 2024-09-23 19:01:15 -06:00
Mitchell Hashimoto c26da4ea06
pkg/macos: expose carbon API 2024-09-19 09:22:07 -07:00
Mitchell Hashimoto f5234e286a
pkg/macos: copyAttribute should return optional 2024-08-24 20:35:41 -07:00
Mitchell Hashimoto 318dc85c02
pkg/macos: yeet more usingns 2024-08-16 16:50:41 -07:00
Mitchell Hashimoto 17d844e7bf
pkg/macos: more 2024-08-16 16:39:33 -07:00
Mitchell Hashimoto a4c05e4a32
pkg/macos: graphics usingns yeet 2024-08-16 16:38:04 -07:00
Mitchell Hashimoto 097b978052
pkg/macos: animation yeet usingns 2024-08-16 16:35:07 -07:00
Mitchell Hashimoto 2f578a0b97
pkg/macos: foundation yeet usingns 2024-08-16 16:33:47 -07:00
Mitchell Hashimoto 14a42fcdb7
renderer/metal: load shaders from precompiled lib 2024-08-06 15:05:10 -07:00
Mitchell Hashimoto a30e791c85
begin 0.13 update process -- very broken 2024-06-24 15:16:22 -07:00
Qwerasd 626ec2b5ac perf: introduce CFReleaseThread for running CoreFoundation releases
Some CoreFoundation objects, such as those produced by CoreText, have
expensive callbacks that run when they are released. By offloading the
CFRelease calls to another thread, we can avoid important threads being
blocked by unexpectedly expensive callbacks.

This commit also changes the way that the coretext shaper's run iterator
builds its string. Rather than using a CFMutableString, an ArrayList of
unichars is built which is passed to CFStringCreateWithCharactersNoCopy,
which is a lot more efficient since it avoids all the CoreFoundation
overhead.
2024-06-14 01:43:02 -04:00
Mitchell Hashimoto 1a7cde9e3e
font/coretext: can read font tables 2024-05-27 20:23:10 -07:00
Mitchell Hashimoto 9f4d4d3c61
font: treated fonts with mixed color/non-color glyphs as text
Related to #1768 but doesn't fix it properly.

This is a temporary hack to avoid some issues with fonts that have mixed
color/non-color glyphs. If there are mixed presentations and the font
does not have emoji codepoints, then we assume it is text. This fixes
the typical scenarios.

This is not a long term solution. A proper long term solution is to
detect this scenario and on a per-glyph basis handle colorization (or
the lack thereof) correctly. It looks like to do this we'll have to
parse some font tables which is considerably more work so I wanted to do
this first.
2024-05-26 10:17:20 -07:00
Mitchell Hashimoto 1cb70d6e40
font/coretext: force LTR shaping 2024-05-08 10:11:57 -07:00
Mitchell Hashimoto eeb7f7aa02
pkg/macos: add more text APIs 2024-05-08 09:49:16 -07:00
Mitchell Hashimoto 1189817dd8
pkg/macos: CTFontCreateForString 2024-05-05 21:38:19 -07:00
Mitchell Hashimoto a29a0a1e5c
pkg/macos: add more CoreText APIs 2024-05-05 21:01:44 -07:00
Mitchell Hashimoto cc72e6de23
pkg/macos: display link callback slightly more typesafe 2024-05-04 14:49:49 -07:00
Mitchell Hashimoto f76af48613
pkg/macos: add CVDisplayLinkSetCurrentCGDisplay 2024-05-04 14:49:49 -07:00
Gordon Cassie abd782a7aa
Fix typo. 2024-04-30 10:20:31 -07:00
Mitchell Hashimoto 61d3da1bf6
font/coretext: respect quirks fonts for shaper 2024-04-04 12:02:43 -07:00
Mitchell Hashimoto 290496d7fe
pkg/macos: add missing functions to macos/foundation 2024-04-04 11:25:34 -07:00
Mitchell Hashimoto 7b3deb13d8
renderer/metal: apply layerContentsPlacement on macOS to fix stretching
Fixes #42
2024-02-02 08:39:08 -08:00
Mitchell Hashimoto 3360a008cd
build: build produces a broken object file for iOS
This gets `zig build -Dtarget=aarch64-ios` working. By "working" I mean
it produces an object file without compiler errors. However, the object
file certainly isn't useful since it uses a number of features that will
not work in the iOS sandbox.

This is just an experiment more than anything to see how hard it would be to
get libghostty working within iOS to render a terminal. Note iOS doesn't
support ptys so this wouldn't be a true on-device terminal. The
challenge right now is to just get a terminal rendering (not usable).
2024-01-13 21:38:58 -08:00
Mitchell Hashimoto 22648d60e7
pkg/apple-sdk: detect apple sdk based on target 2024-01-09 22:24:34 -08:00
Mitchell Hashimoto 829776bebd
pkg/apple-sdk: always require a module 2024-01-09 22:11:03 -08:00