Reduce code duplication in batch.rs
Categories
(Core :: Graphics: WebRender, task, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox145 | --- | fixed |
People
(Reporter: nical, Assigned: nical)
References
(Blocks 1 open bug)
Details
Attachments
(3 files)
batch.rs contains a pretty large amount of code duplication (see the 2k+ lines add_prim_to_bacth), to the point that making some changes is tedious/error-prone and adding new types of primitives is discouraging.
The structure of a big chunk of the duplicated code looks like this:
match type {
PrimType::Foo(foo) => {
// resolve handles
// compute belnd mode
// make batch key
// iterate tiles or segments
}
PrimType::Bar(bar) => {
// mostly the same as the above with small differences
}
// etc.
}
Primitives that use the image brush shader
There are multiple primitives that have almost the exact same code in the big match statement and do exactly the same thing: resolve a handle to some image data which we'll render with the brush shader. The image primitive is one example but all primitives that render their pattern in an image are in the same boat (all cached gradients for example).
For these it would be great to to desugar into an image primitive before batching to avoid 100-ish lines of code that get duplicated.
Not having to deal with these during batching would also make it easier to add new types of pre-rendered patterns.
Other primitive types
More generally the flow remains mostly the same, so it would be great to rework the code so that in the end it looks more like:
let blend_mode = ...
let batch_key = // ...
for handle in prim.handle_to_resolves {
handles.push(render_tasks.resolve(handle));
});
match type {
PrimType::Foo(foo) => {
// very few specific things
}
PrimType::Bar(bar) => {
// very few specific things
}
}
if prim.segments.is_empty() {
add_prim_to_batch(...)
} else {
for segment in &prim.segments {
// etc.
add_prim_to_batch(...)
}
}
| Assignee | ||
Comment 1•5 months ago
|
||
Updated•5 months ago
|
| Assignee | ||
Comment 2•5 months ago
|
||
| Assignee | ||
Comment 3•5 months ago
|
||
Comment 5•5 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/7e7f652905fc
https://hg.mozilla.org/mozilla-central/rev/fba813b71f18
https://hg.mozilla.org/mozilla-central/rev/59d3d68fff17
Updated•4 months ago
|
Description
•