dymokomi/luce-browser-render
Source of release 0.6.2
0.6.2 / src / display_list / tests_cpu_player_2.lucb
#==============================================================================================
#
# tests_cpu_player_2 - the CPU player's paths, glyph runs, layers and filters against Skia
#
# DESCRIPTION:
# Scenes that reach regions r10 (gfx.Path, gfx.Filter) and r09 (glyph outlines) through
# the player's seams, compared with DisplayListPlayerSkia's pixels
# (tests_skia_reference_data_2.lucb) under Ladybird's fuzzy reftest rule, as
# tests_cpu_player.lucb does. Paths, layers and SerenitySans' glyphs match exactly
# (tests_cpu_glyph_run.lucb has more glyph scenes); Lato's glyphs do not: Lato carries
# TrueType instructions, which FreeType's bytecode interpreter runs for Skia's hinted
# masks (outlines snapped to the pixel grid along y), and there is no interpreter here.
#
#==============================================================================================
# mark: Helpers ================================================================================
## A Gfx::FloatPoint.
func test_float_point(x: f32, y: f32) -> gfx.FloatPoint:
return gfx.FloatPoint(m_x = x, m_y = y)
## The five-pointed star of the path scenes (it overlaps itself).
func test_star_path() -> gfx.Path:
var path: gfx.Path
gfx.path_move_to(&path, test_float_point(12.0, 1.0))
gfx.path_line_to(&path, test_float_point(15.0, 21.0))
gfx.path_line_to(&path, test_float_point(2.0, 8.0))
gfx.path_line_to(&path, test_float_point(22.0, 8.0))
gfx.path_line_to(&path, test_float_point(9.0, 21.0))
gfx.path_close(&path)
return path
## A cubic and a quadratic curve, closed.
func test_curves_path() -> gfx.Path:
var path: gfx.Path
gfx.path_move_to(&path, test_float_point(2.0, 12.0))
gfx.path_cubic_bezier_curve_to(&path, test_float_point(2.0, 2.0), test_float_point(22.0, 2.0), test_float_point(22.0, 12.0))
gfx.path_quadratic_bezier_curve_to(&path, test_float_point(12.0, 26.0), test_float_point(2.0, 12.0))
gfx.path_close(&path)
return path
## DisplayListRecorder::fill_path's FillPath for `path`.
func test_fill_path(path: gfx.Path, color: gfx.Color, winding_rule: gfx.WindingRule, opacity: f32) -> FillPath:
let bounds = gfx.enclosing_int_rect(gfx.path_bounding_box(&path))
return FillPath(path_bounding_rect = bounds, path = path, opacity = opacity, paint_style_or_color = .color(value = color), winding_rule = winding_rule, should_anti_alias = ShouldAntiAlias.yes)
## The font of the glyph scenes: the test font at `path` (from the repository root) at
## `point_size`.
func test_font(path: str, point_size: f32) -> const web_fonts.Font*:
let data = web_fonts.font_data_create_from_file(path) else trap("cannot read a test font")
let typeface = web_fonts.typeface_try_load_from_font_data(data, 0) else trap("cannot load a test font")
return web_fonts.typeface_font(typeface, point_size)
## Gfx::shape_text({ 0, 0 }, 0, text, font, Common) with its text blob made at `scale`, as
## DisplayListRecorder::draw_glyph_run makes it.
func test_glyph_run(text: str, font: const web_fonts.Font*, scale: f32) -> const web_fonts.GlyphRun*:
let string = ak.utf16_string_from_str(text)
let run = web_fonts.shape_text_f32(test_float_point(0.0, 0.0), 0.0, ak.utf16_string_base_utf16_view(&string.utf16_string_base), font, web_fonts.GlyphRunTextType.common)
web_fonts.glyph_run_ensure_text_blob(run, scale)
return run
# mark: Paths ==================================================================================
test "cpu player 2: fill_path, even-odd":
let scene = test_scene_new(24, 24)
defer test_scene_release(&scene)
display_list_player_fill_path(test_scene_player(&scene), test_fill_path(test_star_path(), test_color(0, 0, 255, 255), gfx.WindingRule.even_odd, 1.0))
expect_like_skia(&scene, "fill_path_even_odd", skia_fill_path_even_odd, 0, 0)
test "cpu player 2: fill_path, nonzero":
let scene = test_scene_new(24, 24)
defer test_scene_release(&scene)
display_list_player_fill_path(test_scene_player(&scene), test_fill_path(test_star_path(), test_color(0, 128, 0, 255), gfx.WindingRule.nonzero, 1.0))
expect_like_skia(&scene, "fill_path_nonzero", skia_fill_path_nonzero, 0, 0)
test "cpu player 2: fill_path, curves (a color ignores the opacity)":
let scene = test_scene_new(24, 24)
defer test_scene_release(&scene)
display_list_player_fill_path(test_scene_player(&scene), test_fill_path(test_curves_path(), test_color(200, 30, 60, 255), gfx.WindingRule.nonzero, 0.75))
expect_like_skia(&scene, "fill_path_curves", skia_fill_path_curves, 0, 0)
test "cpu player 2: stroke_path, round caps and joins":
let scene = test_scene_new(24, 24)
defer test_scene_release(&scene)
let path = test_curves_path()
let bounds = gfx.enclosing_int_rect(gfx.path_bounding_box(&path))
let command = StrokePath(cap_style = gfx.PathCapStyle.round, join_style = gfx.PathJoinStyle.round, miter_limit = 4.0, dash_array = ak.Vector[f32](), dash_offset = 0.0,
path_bounding_rect = bounds, path = path, opacity = 1.0, paint_style_or_color = .color(value = test_color(0, 0, 0, 255)), thickness = 2.5, should_anti_alias = ShouldAntiAlias.yes)
display_list_player_stroke_path(test_scene_player(&scene), command)
expect_like_skia(&scene, "stroke_path", skia_stroke_path, 0, 0)
# mark: Layers =================================================================================
test "cpu player 2: a layer inside a rounded clip is clipped once":
let scene = test_scene_new(16, 16)
defer test_scene_release(&scene)
let player = test_scene_player(&scene)
display_list_player_fill_rect(player, FillRect(rect = test_rect(0, 0, 16, 16), color = test_color(0, 0, 255, 255)))
display_list_player_save(player, Save())
display_list_player_add_rounded_rect_clip(player, AddRoundedRectClip(corner_radii = test_uniform_radii(6), border_rect = test_rect(2, 2, 12, 12), corner_clip = CornerClip.outside))
display_list_player_apply_effects(player, ApplyEffects(opacity = 0.5, compositing_and_blending_operator = gfx.CompositingAndBlendingOperator.normal))
display_list_player_fill_rect(player, FillRect(rect = test_rect(0, 0, 16, 16), color = test_color(255, 0, 0, 255)))
display_list_player_restore(player, Restore())
display_list_player_restore(player, Restore())
expect_like_skia(&scene, "layer_in_rounded_clip", skia_layer_in_rounded_clip, 0, 0)
# mark: Glyph runs =============================================================================
test "cpu player 2: draw_glyph_run":
with memory.heap:
let scene = test_scene_new(40, 20)
defer test_scene_release(&scene)
let run = test_glyph_run("Hi, fox", test_font("tests/web_fonts/fonts/SerenitySans-Regular.ttf", 12.0), 1.0)
display_list_player_draw_glyph_run(test_scene_player(&scene), DrawGlyphRun(glyph_run = run, rect = test_rect(0, 0, 40, 20), translation = test_float_point(2.0, 15.0), color = test_color(0, 0, 0, 255), orientation = gfx.Orientation.horizontal))
expect_like_skia(&scene, "glyph_run", skia_glyph_run, test_glyph_level, test_glyph_pixels)
test "cpu player 2: draw_glyph_run with a text blob at scale 1.5":
with memory.heap:
let scene = test_scene_new(48, 32)
defer test_scene_release(&scene)
let run = test_glyph_run("AVo", test_font("tests/web_fonts/fonts/Lato-Bold.ttf", 15.0), 1.5)
display_list_player_draw_glyph_run(test_scene_player(&scene), DrawGlyphRun(glyph_run = run, rect = test_rect(0, 0, 48, 32), translation = test_float_point(1.5, 25.25), color = test_color(20, 90, 200, 255), orientation = gfx.Orientation.horizontal))
expect_like_skia(&scene, "glyph_run_scaled", skia_glyph_run_scaled, 150, 300)