menios
menios copied to clipboard
Implement composition engine with damage tracking
Summary
Implement the composition engine that efficiently renders all windows to the screen using damage tracking and dirty rectangle optimization.
Goals
- Render windows in Z-order
- Damage tracking (only redraw changed areas)
- Double buffering
- Vsync synchronization
- Performance optimization
Implementation
Damage Tracking
```c struct damage_rect { int x, y, width, height; struct damage_rect *next; };
void compositor_damage(struct compositor *comp, int x, int y, int w, int h) { struct damage_rect *rect = malloc(sizeof(*rect)); rect->x = x; rect->y = y; rect->width = w; rect->height = h; // Add to damage list comp->damage_dirty = 1; } ```
Composition
```c void compositor_render(struct compositor *comp) { cairo_t *cr = cairo_create(comp->screen);
// Clear damaged areas
cairo_set_source_rgb(cr, 0.2, 0.2, 0.2);
cairo_paint(cr);
// Composite each window
for (struct window *w = comp->windows; w; w = w->next) {
if (!w->visible) continue;
cairo_set_source_surface(cr, w->surface, w->x, w->y);
cairo_rectangle(cr, w->x, w->y, w->width, w->height);
cairo_fill(cr);
}
cairo_destroy(cr);
} ```
Timeline
Total: 2-3 weeks
Definition of Done
- [ ] Windows composite correctly
- [ ] Damage tracking works
- [ ] Only damaged areas redrawn
- [ ] Smooth 60fps
- [ ] No tearing
Dependencies
- #396: Cairo
- #403: Compositor core
See docs/road/road_to_gui.md for complete roadmap.