Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render,core: Improve EditText's border and background rendering #16619

Merged
merged 20 commits into from
Jul 2, 2024

Conversation

kjarosh
Copy link
Member

@kjarosh kjarosh commented Jun 6, 2024

This PR removes the drawing used for rendering the border and
the background and renders them using primitives instead.

It provides two methods for drawing the border and the background:

  • draw_device_text_box -- when device fonts are used,
  • draw_text_box -- when fonts are embedded.

In order to draw the border properly new methods have been added:

  • draw_line -- for drawing a single line (always 1px thick),
  • draw_line_rect -- for drawing a rectangle using lines (always 1px thick).

These primitives have been implemented for wgpu, WebGL, and canvas.

Before After

Additional notes:

  • draw_line added in this PR may also be used for rendering the selection caret in the future.

Related to #15003, #1881 (the border is not being transformed anymore).

@kjarosh kjarosh force-pushed the edittext-border branch 7 times, most recently from 2d04a8d to 7861875 Compare June 10, 2024 22:43
@kjarosh kjarosh changed the title core: Improve EditText's border and background rendering render,core: Improve EditText's border and background rendering Jun 10, 2024
@kjarosh kjarosh force-pushed the edittext-border branch 5 times, most recently from 156ede0 to ad0f23b Compare June 11, 2024 11:49
@kjarosh kjarosh added A-rendering Area: Rendering & Graphics waiting-on-author Waiting on the PR author to make the requested changes labels Jun 11, 2024
@kjarosh kjarosh force-pushed the edittext-border branch 2 times, most recently from 4d8fc81 to 07490dc Compare June 14, 2024 15:19
@kjarosh kjarosh marked this pull request as ready for review June 18, 2024 18:58
@kjarosh kjarosh added waiting-on-review Waiting on review from a Ruffle team member and removed waiting-on-author Waiting on the PR author to make the requested changes labels Jun 18, 2024
Copy link
Contributor

@Dinnerbone Dinnerbone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the "draw lines or emulate lines" the responsibility of core, and not the backend itself?

@kjarosh
Copy link
Member Author

kjarosh commented Jun 23, 2024

Why is the "draw lines or emulate lines" the responsibility of core, and not the backend itself?

Originally I thought about making that the responsibility of the backend, but wgpu required quite a refactor to implement that cleanly, and I was frustrated by DirectX at that time 😅

So anyway, I did the refactor now. The whole "drawing lines" thing came out bigger than expected, so if you wish I could split this PR into multiple ones (so that this one does not include the necessary refactors).

@kjarosh kjarosh requested a review from Dinnerbone June 23, 2024 18:41
Copy link
Contributor

@Dinnerbone Dinnerbone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

kjarosh added 20 commits July 2, 2024 23:26
Moving draw_rect to draw_quad prevents code duplication when
methods related to drawing lines are added.
This patch changes the mode of drawing quads to Gl::TRIANGLE_FAN.
This makes the buffers smaller, as we need only 4 vertices instead of 6,
and allows them to be reused for rendering lines.
Twips::HALF represents 10 twips, i.e. 0.5 pixels.
This constant is useful when calculating exact positions of lines
to be drawn, as they are often drawn on whole pixels.
This method is used to instantiate ColorTransform with its
multiplicative component equal to the given color.
This patch splits the current method of create_box into
1. create_box -- without rotation, and
2. create_box_with_rotation -- with rotation.

The reason for that refactor is that create_box was often used without
rotation, and always passing 0.0 as rotation and having
a dedicated condition for 0.0 was superfluous.
This refactor simplifies code, gets rid of the large number of
parameters, and allows calling other rendering methods from themselves.
The latter is useful for emulating lines on Dx12.
This patch adds draw_line and draw_line_rect methods to CommandHandler,
providing empty impls to be overridden by corresponding backends.

The ability to draw lines is described using a new bitflags struct
RenderBackendFeatures, which contains a set of features
supported by the given render backend.
Currently, it contains a DRAW_LINES flag, which informs whether
the backend supports drawing lines as primitives.
This patch provides an efficient implementation of draw_line
and draw_line_rect for wgpu using PrimitiveTopology::LineStrip.
This patch provides an efficient implementation of draw_line
and draw_line_rect for WebGL using Gl::LINE_STRIP.
This patch provides an efficient implementation of draw_line
and draw_line_rect for canvas using strokes.
This patch removes the drawing used for rendering the border and
the background and renders them using primitives instead.

It provides two methods for drawing the border and the background:
* draw_device_text_box -- when device fonts are used,
* draw_text_box -- when fonts are embedded.

Updated expected images in tests as they are closer to FP now:
* text/auto_size/height,
* text/auto_size/return,
* text/auto_size/width,
* visual/shumway_acid_tests/acid_color_0.

For the test avm2/stage3d_texture it's hard to say whether the current
output is closer to FP or not, as FP renders it with a different scale.
However, I have confirmed that there exists a scale at which FP renders
the text fields exactly as Ruffle after this patch.
This test checks whether text field borders are rendered properly.
This test checks whether text field borders are rendered properly
at zoom 200%.
This test checks whether text fields with filters are rendered correctly.
This test verifies the basic rendering of text field's backgrounds.
This test verifies the basic rendering of text field's backgrounds
at zoom 200%.
This test produces vastly different results compared to FP.
@kjarosh kjarosh force-pushed the edittext-border branch from a19fbb9 to e905934 Compare July 2, 2024 21:26
@kjarosh kjarosh merged commit 03518e5 into ruffle-rs:master Jul 2, 2024
17 checks passed
@kjarosh kjarosh deleted the edittext-border branch July 2, 2024 21:40
@danielhjacobs danielhjacobs removed the waiting-on-review Waiting on review from a Ruffle team member label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rendering Area: Rendering & Graphics newsworthy
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants