Skip to content

Commit bb47dfa

Browse files
authored
Merge pull request #1131 from jaytaph/cleanup-render-pipeline
Cleanup render pipeline
2 parents e1f6a82 + cf17342 commit bb47dfa

80 files changed

Lines changed: 838 additions & 1625 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ getrandom = { workspace = true, features = ["wasm_js"] }
201201
# The renamed aliases force Cargo to merge features on those resolved versions.
202202
getrandom_v02 = { package = "getrandom", version = "0.2", features = ["js"] }
203203
getrandom_v03 = { package = "getrandom", version = "0.3", features = ["wasm_js"] }
204-
# No default features on WASM: excludes sqlite_cookie_store (needs C SQLite) and parley_layout (needs freetype).
204+
# No default features on WASM: excludes sqlite_cookie_store (needs C SQLite).
205205
gosub_engine = { path = "./crates/gosub_engine", default-features = false }
206206
gosub_render_pipeline = { path = "./crates/gosub_render_pipeline" }
207207
gosub_renderer_vello = { path = "./crates/gosub_renderer_vello" }

crates/gosub_engine/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ gdk4-wayland = { workspace = true, features = [
8080
gdk4-x11 = { workspace = true, optional = true }
8181

8282
[features]
83-
default = ["sqlite_cookie_store", "parley_layout"]
83+
default = ["sqlite_cookie_store"]
8484
ui_eframe = ["dep:eframe", "dep:egui"]
8585
winit = ["dep:winit", "dep:wgpu"]
8686
sqlite_cookie_store = ["r2d2", "r2d2_sqlite"]
87-
parley_layout = []
8887
metrics = []
8988

9089
wayland = ["gdk4-wayland"]

crates/gosub_engine/src/engine/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ fn pipeline_hover_repaint(
976976
continue;
977977
}
978978

979-
tile.state = TileState::Clean;
979+
tile.state = TileState::Ready;
980980
let key = (tile_rect.x.to_bits(), tile_rect.y.to_bits(), tile.layer_id.as_u64());
981981
if let Some(baked) = prev_by_pos.remove(&key) {
982982
clean_baked.push(baked);

crates/gosub_render_pipeline/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ base64 = { workspace = true }
2626
anyhow = { workspace = true }
2727
cow-utils = { workspace = true }
2828
parking_lot = { workspace = true }
29-
parley = { workspace = true, default-features = true }
3029
gosub_shared = { version = "0.1.1", path = "../gosub_shared", registry = "gosub" }
3130
rayon = "1"
3231
gosub_interface = { version = "0.1.2", path = "../gosub_interface", registry = "gosub" }
@@ -43,7 +42,6 @@ gosub_css3 = { path = "../gosub_css3", registry = "gosub" }
4342
url = { workspace = true }
4443

4544
[features]
46-
parley_layout = []
4745
wayland = ["gdk4-wayland"]
4846
x11 = ["gdk4-x11"]
4947

crates/gosub_render_pipeline/src/common/browser_state.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,19 @@ pub enum WireframeState {
1313

1414
/// Per-tab render settings passed through the pipeline instead of living in a global.
1515
pub struct BrowserState {
16-
/// List of layers that will be visible are set to true
16+
/// Indexed by layer id; `true` means the layer is drawn.
1717
pub visible_layer_list: Vec<bool>,
18-
/// Defines if we need to draw wireframes, or the actual content, or both
18+
/// Whether to draw wireframes, the actual content, or both.
1919
pub wireframed: WireframeState,
20-
/// Just show the hovered debug node in wireframe
20+
/// Restrict wireframing to the hovered node only.
2121
pub debug_hover: bool,
22-
/// Show the tile grid
2322
pub show_tilegrid: bool,
2423
/// Draw a 1px red border around every table-cell element (set via GOSUB_DEBUG_TABLE_CELLS=1)
2524
pub debug_table_cells: bool,
26-
/// When set, this is the element that is currently hovered upon
2725
pub current_hovered_element: Option<LayoutElementId>,
2826
/// Current viewport offset + size
2927
pub viewport: Rect,
30-
/// LayerList that is currently being rendered
3128
pub tile_list: Option<RwLock<TileList>>,
32-
/// Scale factor for DPI
3329
pub dpi_scale_factor: f32,
3430
}
3531

crates/gosub_render_pipeline/src/common/document/inline_style.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use crate::common::document::style::{
44
use cow_utils::CowUtils;
55
use std::collections::HashMap;
66

7-
/// Parses a CSS inline `style` attribute value (e.g. `"color: red; width: 100px"`)
8-
/// into a `NodeStyle`.
7+
/// Parses an inline `style` attribute value (e.g. `"color: red; width: 100px"`).
98
pub fn parse_inline_style_attr(style_attr: &str) -> NodeStyle {
109
let mut style = NodeStyle::new();
1110
for declaration in style_attr.split(';') {
@@ -20,8 +19,7 @@ pub fn parse_inline_style_attr(style_attr: &str) -> NodeStyle {
2019
style
2120
}
2221

23-
/// Extract the target of a `url(...)` token from a CSS value string, stripping surrounding
24-
/// quotes. Returns `None` when there is no `url()` (e.g. a gradient or plain color).
22+
/// Target of a `url(...)` token, dequoted. `None` when there is no `url()` (gradient, color, ...).
2523
fn parse_css_url(value: &str) -> Option<String> {
2624
let start = value.find("url(")? + "url(".len();
2725
let rest = &value[start..];
@@ -204,12 +202,9 @@ fn apply_border_shorthand(style: &mut NodeStyle, value: &str) {
204202
}
205203

206204
fn apply_style_kv(style: &mut NodeStyle, key: &str, value: &str) {
207-
// Inline `style="…"` parsing has no access to custom properties (`--*`), which live in the
208-
// stylesheet cascade. A `var(...)` value therefore can't be resolved here; storing its raw
209-
// text would produce an invalid keyword that still *overrides* the (correctly resolved)
210-
// cascade declaration - e.g. `style="color:var(--accent-glow)"` would paint black instead of
211-
// deferring to `.arrow-link { color: var(--accent-light) }`. Per CSS, a declaration we can't
212-
// compute is ignored, so skip it and let the cascade win.
205+
// Custom properties (`--*`) live in the cascade, so `var(...)` can't be resolved here. Storing
206+
// the raw text would yield an invalid keyword that still overrides the correctly-resolved
207+
// cascade declaration. Per CSS an uncomputable declaration is ignored, so let the cascade win.
213208
if value.cow_to_ascii_lowercase().contains("var(") {
214209
return;
215210
}
@@ -481,9 +476,8 @@ fn parse_font_weight(value: &str) -> Value {
481476
}
482477
}
483478

484-
/// Map HTML presentation attributes (e.g. `bgcolor`, `width`) to CSS `Value`s.
485-
/// These have lower specificity than any real CSS rule and are only consulted
486-
/// when neither the `style` attribute nor the stylesheet provides a value.
479+
/// Maps HTML presentation attributes (`bgcolor`, `width`, ...) to CSS values. They lose to any
480+
/// real CSS rule, so consult this only when neither `style` nor the stylesheet supplies a value.
487481
pub fn html_presentation_attr(attrs: &HashMap<String, String>, prop: &StyleProperty) -> Option<Value> {
488482
match prop {
489483
StyleProperty::BackgroundColor => {
@@ -523,13 +517,12 @@ mod tests {
523517

524518
#[test]
525519
fn var_inline_declaration_is_ignored() {
526-
// `var()` can't be resolved during inline parsing, so the declaration is dropped
527-
// (leaving the cascade to supply the color) rather than stored as an invalid keyword
528-
// that would paint black.
520+
// Dropped rather than stored as an invalid keyword that would paint black, so the
521+
// cascade still supplies the color.
529522
let style = parse_inline_style_attr("color: var(--accent-glow)");
530523
assert!(style.get_own(&StyleProperty::Color).is_none());
531524

532-
// A concrete color alongside the var() one still applies; only the var() part is skipped.
525+
// Only var() is skipped - a concrete color still applies.
533526
let style = parse_inline_style_attr("color: #123456");
534527
assert!(matches!(
535528
style.get_own(&StyleProperty::Color),

crates/gosub_render_pipeline/src/common/document/node.rs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::collections::HashMap;
44

55
pub use gosub_shared::node::NodeId;
66

7-
/// Map of attributes for a html element (a href, src, data-*, etc)
87
#[derive(Debug, Clone)]
98
pub struct AttrMap {
109
attributes: HashMap<String, String>,
@@ -30,11 +29,6 @@ impl AttrMap {
3029
pub fn set(&mut self, key: &str, value: &str) {
3130
self.attributes.insert(key.to_string(), value.to_string());
3231
}
33-
34-
#[allow(unused)]
35-
pub fn all(&self) -> &HashMap<String, String> {
36-
&self.attributes
37-
}
3832
}
3933

4034
impl std::fmt::Display for AttrMap {
@@ -49,28 +43,19 @@ impl std::fmt::Display for AttrMap {
4943
}
5044
}
5145

52-
/// Data for a html element (tag name, attributes, styles etc)
5346
#[derive(Clone, Debug)]
5447
pub struct ElementData {
5548
pub tag_name: String,
5649
pub attributes: AttrMap,
57-
#[allow(unused)]
58-
pub self_closing: bool,
5950
/// Own CSS properties for this element (only explicitly-set values; no inheritance).
6051
pub styles: NodeStyle,
6152
}
6253

6354
impl ElementData {
64-
pub fn new(
65-
tag_name: String,
66-
attributes: Option<AttrMap>,
67-
is_self_closing: bool,
68-
styles: Option<NodeStyle>,
69-
) -> ElementData {
55+
pub fn new(tag_name: String, attributes: Option<AttrMap>, styles: Option<NodeStyle>) -> ElementData {
7056
ElementData {
7157
tag_name,
7258
attributes: attributes.unwrap_or_default(),
73-
self_closing: is_self_closing,
7459
styles: styles.unwrap_or_default(),
7560
}
7661
}
@@ -79,21 +64,10 @@ impl ElementData {
7964
self.styles.get_own(key)
8065
}
8166

82-
#[allow(unused)]
8367
pub fn get_attribute(&self, key: &str) -> Option<&String> {
8468
self.attributes.get(key)
8569
}
8670

87-
#[allow(unused)]
88-
pub fn set_attribute(&mut self, key: &str, value: &str) {
89-
self.attributes.set(key, value);
90-
}
91-
92-
#[allow(unused)]
93-
pub fn is_self_closing(&self) -> bool {
94-
self.self_closing
95-
}
96-
9771
pub fn is_inline_element(&self) -> bool {
9872
matches!(
9973
self.get_style(&StyleProperty::Display),
@@ -154,10 +128,9 @@ impl Node {
154128
match &self.node_type {
155129
NodeType::Element(data) => match data.get_style(&StyleProperty::Display) {
156130
Some(Value::Display(Display::Inline)) => true,
157-
// When no display is explicitly set, use the HTML element's intrinsic type.
158-
// CSS initial value is `inline`, but UA stylesheets set `block` for most
159-
// HTML structural elements. Defaulting unknown elements to inline here
160-
// would incorrectly group <li>, <h2>, <div> etc. into inline flows.
131+
// The CSS initial value is `inline`, but UA stylesheets make most structural
132+
// elements `block` - defaulting to inline would group <li>, <h2>, <div> etc.
133+
// into inline flows, so fall back to the tag's intrinsic type.
161134
None => is_intrinsically_inline(&data.tag_name),
162135
_ => false,
163136
},
@@ -181,10 +154,8 @@ impl Node {
181154
}
182155
}
183156

184-
/// Returns true if `tag` is an HTML element that is inline by spec when no CSS is applied.
185-
/// Block-level elements (`div`, `p`, `h1`–`h6`, `li`, `section`, etc.) return false so that
186-
/// missing `display` in NodeStyle (e.g. from a UA-stylesheet gap) does not accidentally put
187-
/// them into an inline formatting context.
157+
/// Inline-by-spec HTML elements. Block-level tags return false so a missing `display` (e.g. a
158+
/// UA-stylesheet gap) never drops them into an inline formatting context.
188159
fn is_intrinsically_inline(tag: &str) -> bool {
189160
matches!(
190161
tag.cow_to_ascii_lowercase().as_ref(),

0 commit comments

Comments
 (0)