925 Commits

Author SHA1 Message Date
Mitchell Hashimoto
b4a83d98c4 window no longer makes any OpenGL calls 2022-10-28 09:24:40 -07:00
Mitchell Hashimoto
209cad609c update zig 2022-10-27 17:06:54 -07:00
Mitchell Hashimoto
7d3eb2579a Objective-C Runtime (Low-level ObjC interfacing)
This adds a new homemade package `pkg/objc` that wraps the Objective-C runtime so that Zig can interface with ObjC. This doesn't have 100% API coverage but all the hard problems (mainly `objc_msgSend`) are done. We can merge this now, start working on ObjC stuff, and expand APIs as we need them.

The `objc` package is of course only available to Mac builds.
2022-10-25 21:32:56 -07:00
Mitchell Hashimoto
59cb774cdd pkg/objc: properties 2022-10-25 21:25:07 -07:00
Mitchell Hashimoto
aaaae38fa1 pkg/objc: more message send stuff 2022-10-25 20:55:41 -07:00
Mitchell Hashimoto
f587b222e7 don't need fstage1 2022-10-25 20:55:34 -07:00
Mitchell Hashimoto
7d48e564b5 pkg/objc: message send 2022-10-25 20:30:42 -07:00
Mitchell Hashimoto
10ee05b435 pkg/objc: selectors 2022-10-25 16:33:45 -07:00
Mitchell Hashimoto
dd8fde52d9 pkg/objc starting 2022-10-25 16:21:11 -07:00
Mitchell Hashimoto
e7ffb823af propertly deinit the GPA so we can detect leaks in debug 2022-10-25 15:49:21 -07:00
Mitchell Hashimoto
d8cdd5d8fe Fix the primary leak with config 2022-10-25 15:48:13 -07:00
Mitchell Hashimoto
233ee2b3eb fixing more memory leaks 2022-10-25 15:40:26 -07:00
Mitchell Hashimoto
bcf485342e fix a couple more memory leaks 2022-10-24 16:17:18 -07:00
Mitchell Hashimoto
ef57e1e56a free memory in cells LRU 2022-10-24 16:09:08 -07:00
Mitchell Hashimoto
8dd9e7b325 Fix memory leak forgetting to clean up fontconfig 2022-10-24 15:55:57 -07:00
Mitchell Hashimoto
9ef431c632 use the c allocator when running under valgrind 2022-10-24 15:34:30 -07:00
Mitchell Hashimoto
cf14ea506f update zig 2022-10-24 14:35:42 -07:00
Mitchell Hashimoto
d346309cb3 pkg/libuv: generate cimport.zig for specific platforms 2022-10-24 14:35:30 -07:00
Mitchell Hashimoto
672e0d1d63 Multi-threaded Rendering
This moves the OpenGL renderer out to a dedicated thread. The immediate effect
is noticeably improved FPS under high load scenarios. But the future impact is
also important: (1) required for multiple windows, tabs, etc. one day (2) forced
a refactor to support pluggable renderers.

== Architectural Notes

Windowing events and IO remain on the main thread for now, but I plan to move
IO to a dedicated thread in a future PR. Windowing events have to remain on the
main thread for eternity since some platforms force all Window events onto one
thread.

This is one of the reasons that this will be required for multi-window. As more
windows are opened, the windowing system will send more and more window events
to our main thread, taking more and more time away from other tasks on the main
thread. Windowing events are effectively free, so if the thread is ONLY handling
windowing events, this can scale basically forever.

Further, with OpenGL, each window must have its own "context." A context is the
state used to draw. OpenGL mandates at most one context is active at any given
time _per OS thread_. For multiple windows, this means that a single thread
would have to draw one window at a time in serial. With multiple rendering
threads, each thread can have its own context activated and draw in parallel.

The renderer thread and main thread **do have shared state** and will have some
shared state forever. The terminal screen state for example is shared memory.
An immutable data structure or double buffering would be too expensive (I think,
I'll check one day) so we use a mutex to protect access to the terminal state.

The primary instigator of terminal state change is PTY read. This is the
primary motivator to eventually move IO to its own dedicated thread as well.
As multiple windows come up, each PTY under heavy load conditions will block
only its own thread and hold the lock only for its own terminal state (and
therefore its own renderer thread).

We can continue to optimize critical areas from this point forward though and
lower any contention.

== Performance Notes

I haven't done any hard benchmarking on this, only did some cursory
memory measurements, CPU measurements, etc. I also ran superficial test
programs such as `cat`-ing large files, scrolling through large buffers
in vim, etc.

In any case, it seems that responsivity is generally higher, although it
appears that `cat`-ing large files slowed down by roughly 10%. This is
probably due to the lock overhead with the renderer and optimizing for
higher framerates with this setup.
2022-10-24 11:20:21 -07:00
Mitchell Hashimoto
c2ce158342 remove the max timer 2022-10-24 10:55:16 -07:00
Mitchell Hashimoto
c0f96f591b remove render timer from window 2022-10-24 10:50:42 -07:00
Mitchell Hashimoto
536f5c4487 set proper opengl background 2022-10-24 10:04:40 -07:00
Mitchell Hashimoto
b4859625bf bring back out of focus no blink 2022-10-24 10:01:38 -07:00
Mitchell Hashimoto
dc908cb73d support screen size, rip out shared state 2022-10-24 09:52:08 -07:00
Mitchell Hashimoto
45ff936ddf no longer store grid size on the renderer 2022-10-24 09:32:51 -07:00
Mitchell Hashimoto
ce384c2356 renderer: extract the size structs to a shared file 2022-10-24 09:27:09 -07:00
Mitchell Hashimoto
aa3d132947 run rendering on another real thread (still bugs) 2022-10-24 09:17:48 -07:00
Mitchell Hashimoto
77b981950c pkg/libuv: Idle handles 2022-10-23 21:15:58 -07:00
Mitchell Hashimoto
aeb592bae9 move to new renderstate, new render method 2022-10-23 21:04:52 -07:00
Mitchell Hashimoto
b347ff458b prepare our render state on the window 2022-10-23 20:55:04 -07:00
Mitchell Hashimoto
9913bba2e8 introduce renderer thread logic (not starting it yet) 2022-10-23 20:18:10 -07:00
Mitchell Hashimoto
89a4c59f3c make opengl loader context-aware 2022-10-23 19:39:02 -07:00
Mitchell Hashimoto
de9731da1f rename grid to a renderer, extract to subfolder
"Grid" was a really antiquated name when it had both the screen state
AND the renderering functionality tied together. This hasn't been true
for a LONG time and it is long overdue that this is renamed to its
proper name.

This also begins setting up a folder structure to anticipate future
renderers and rendering functionality. I'm not working on any alternate
renderers right now so the interface isn't expected to be good, just
laying out the files in this way.
2022-10-23 16:47:34 -07:00
Mitchell Hashimoto
c3d9ee1d85 pkg/libuv: get rid of sleep state, it did nothing 2022-10-23 16:15:47 -07:00
Mitchell Hashimoto
34e1c96dd7 workaround for https://github.com/ziglang/zig/issues/13277 2022-10-23 11:39:21 -07:00
Mitchell Hashimoto
bc3762e85b update zig to latest, fix todos 2022-10-23 10:54:39 -07:00
Mitchell Hashimoto
79f69885ca update to latest zig which renames @min/@max 2022-10-19 10:42:31 -07:00
Mitchell Hashimoto
366ea2ff4c cell under cursor always remains visible by inverting fg colors 2022-10-18 15:28:31 -07:00
Mitchell Hashimoto
fa0028f104 coretext: rasterize glyph with a padding to prevent artifacting 2022-10-18 14:57:44 -07:00
Mitchell Hashimoto
c00c8f52b5 coretext: render glyph on its own bounding box, calculate bearings 2022-10-18 14:49:23 -07:00
Mitchell Hashimoto
38e0c258d0 coretext: we do want to smooth and anti-alias glyphs 2022-10-18 12:56:02 -07:00
Mitchell Hashimoto
4669032e56 face: coretext zero the bitmap before render 2022-10-18 12:52:37 -07:00
Mitchell Hashimoto
58c107dceb freetype: resize glyphs that are too tall prior to storing in texture
Most emoji fonts are massive glyphs (128x128, 256x256, etc.). This means
the texture we need to store emoji is also massive. For a 128x128 emoji
font (both Apple and Noto), we can only store 12 emoji before resizing
prior to this commit.

This commit now threads through a max height through to the font face
and resizes the bitmap in memory before putting it in the atlas. This
results in significant savings. The max height is the cell height. We
allow the glyphs to be as wide as necessary due to double (and more)
wide glyphs.

For the unicode emoji test file, the atlas size before and after:

  Before: 262 MB
  After: 16 MB
2022-10-17 19:14:30 -07:00
Mitchell Hashimoto
c103a278f1 render font info in dev mode 2022-10-17 14:47:51 -07:00
Mitchell Hashimoto
7cb3f2267f use our built-in font for dev mode 2022-10-17 11:56:46 -07:00
Mitchell Hashimoto
20f1077e86 enable freetype with imgui 2022-10-17 11:41:46 -07:00
Mitchell Hashimoto
ab721b5b26 disable inputs when they're captured by dev mode 2022-10-17 11:19:35 -07:00
Mitchell Hashimoto
15a57983a6 pkg/freetype: remove unused API 2022-10-16 21:03:17 -07:00
Mitchell Hashimoto
a39fe6baed Use scalable check rather than fixed size check for setting char size 2022-10-16 20:55:06 -07:00
Mitchell Hashimoto
2e1bc7bb01 Bring back freetype font bitmap conversion
Monaco on Mac is mono
2022-10-16 20:47:21 -07:00