Commit Graph

16 Commits

Author SHA1 Message Date
George Sokianos c155f797cf First commit of compilable code for OS4 2021-12-21 17:52:44 +00:00
Francesco Abbate aa0b2bb5fc Fix crash problem with rencache and font access
In some cases rencache was using a FontDesc pointer that was actually freed by
Lua giving segfaults errors.

In addition, some FontDesc object were not freed in some cases if the
rencache_end_frame was not called when performing the "restart" command.

The invalid access problem can happen because rencache keep some pointers to
FontDesc object but these are Lua userdata that Lua can dispose of. This
situation is prone to hard errors and we should avoid to keep pointers to
objects managed by Lua.

To this purpose we use luaL_ref/unref to bind the FontDesc into the Lua's
registry while rencache need them. We still keeps pointer to FontDesc object but
using luaL_ref we are assured they will not be disposed by Lua.

Since we are using luaL_ref/unref to inform the GC about when the objects are in
use we can now finalize the objects directly when Lua collects them. Previously
the GC metamethods was issuing a FREE command to rencache and the font was
actually freed only from the rencache_end_frame function.
2021-05-21 23:38:54 +02:00
Francesco Abbate d8244120e9 Ensure the rencache commands buffer is cleared on restart
Fix issue #176 but it should be tested more thoroughly.
2021-05-05 09:32:24 +02:00
Francesco Abbate 46c3bdea67 First implementation of scaling for retina display
Introduce a new approach that discriminate coordinates in
points and pixels. Now all the logic from the Lua side and in
rencache is to always use points. The coordinates are converted
to pixels only within the renderer, in the file renderer.c.
In this way the application logic does not need to care about the
scaling of the retina displays.

For non-retina display the scaling between points and pixels is
equal to one so nothing will change.

There is nevertheless a change that leak into the Lua side. The
subpixel coordinates are in sub-pixel, not sub-points so they are
scaled by the retina scaling factor. But no change in the code is
required because the subpixel scaling factor take into account the
retina scaling, when present.

Because the retina scaling factor is not know when the application
starts but only when a window is actually available we introduce a
mechanism to render the font with a given scaling factor only from
the renderer when they are needed. We use therefore FontDesc to
describe the font information but without actually rasterizing the
font at a given scale.
2021-04-26 15:16:34 +02:00
Francesco Abbate c97fa9a3a6 Fix bug with wrong hashing of rencache commands
The command in rencache.c (Command struct + variable length text) was
incorrectly sized. As a result some bites at the end of the command payload
were uninitialized and was causing hash to randomly change forcing the
system to redraw many more areas.

Since the text of the command for DRAW_TEXT commands is written beginning
at the offset of the text field we compute the bare size of the command as
offsetof(Command, text) instead of sizeof(Command).
2021-04-20 21:54:05 +02:00
Francesco Abbate 3b040aabc7 Implement unicode character replacements
Useful to draw whitespaces with alternate characters and colors
without slowing down the text rendering.

A new API is implemented. A renderer.replacements object can be created
to list the replacements.

In turns the function renderer.draw_text and draw_text_subpixel now accept
two optional arguments for replacements.
2021-04-01 18:05:59 +02:00
Francesco Abbate 88bec172a1 Fix problem with tab size and subpixel positioning
Solve github issue https://github.com/franko/lite-xl/issues/109
2021-03-18 13:54:33 +01:00
Francesco Abbate 3426bc5d73 Introduce subpixel text positioning within rencache
In order to fix the issue with cursor positioning a subpixel-aware draw
text operation within rencache was required.

With this modification the cursor positioning problem is completely
resolved.

A new function renderer.draw_text_subpixel is introduced to perform
consecutive, inline, text drawings with subpixel accuracy.
2021-03-06 18:12:02 +01:00
Francesco Abbate 9ff6a0325e Mostly fix problem of offset with cursor positioning when using mouse
In order to get right the cursor position on text on mouse clicks it is
needed to take into account text's subpixel positioning.

This fix mostly corrects the problem but cursor positioning is still
somewhat inaccurate for long lines due to repeated commands to draw a text
along a line. Repeated draw text calls make the subpixel information
lost and small errors will add-up.
2021-03-06 16:18:24 +01:00
rxi 878c94a334 Changed rencache to store font tab_width with font command
Fixes bug where text would be drawn/cached wrongly if more than one tab_width
was used in a given frame
2020-09-05 15:09:54 +01:00
rxi 35b642d434 Added rencache invalidation on window-exposed event
Fixes #63
2020-05-22 09:00:48 +01:00
rxi 1abb979490 Added null-checks for all push_command() calls in rencache.c 2020-05-17 13:18:26 +01:00
rxi 9bf0ed2419 Made rencache warn on exhausting command buffer instead of panicing 2020-05-14 08:52:07 +01:00
rxi 4c2c03ed4d Made draw_text/draw_rect not push command if result is not on-screen 2020-05-14 08:45:45 +01:00
rxi 774d95d800 Comment improvement in rencache.c 2020-05-07 22:24:12 +01:00
rxi d8c4bfa6ba Initial commit 2019-12-28 11:17:56 +00:00