paavohtl Claude Opus 4.6 (1M context) commited on
Commit
e9f6a81
·
1 Parent(s): 059b365

refactor: use impl PixelWriter instead of dyn for monomorphization

Browse files

Eliminates vtable dispatch overhead on put_pixel_clipped, which is
called 8 times per step in the thick line rasterizer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-core/src/display/line_draw.rs CHANGED
@@ -131,7 +131,7 @@ fn clip_line(
131
  y1: &mut Fixed,
132
  x2: &mut Fixed,
133
  y2: &mut Fixed,
134
- writer: &dyn PixelWriter,
135
  ) -> bool {
136
  let cl = Fixed::from_int(writer.clip_left());
137
  let ct = Fixed::from_int(writer.clip_top());
@@ -240,7 +240,7 @@ fn clip_line(
240
  ///
241
  /// Iterates from x1 to x2 (pixel-rounded), computing y via Fixed-point slope.
242
  fn raster_hmajor(
243
- writer: &mut dyn PixelWriter,
244
  x1: Fixed,
245
  y1: Fixed,
246
  x2: Fixed,
@@ -269,7 +269,7 @@ fn raster_hmajor(
269
  ///
270
  /// Iterates from y1 to y2 (pixel-rounded), computing x via Fixed-point slope.
271
  fn raster_vmajor(
272
- writer: &mut dyn PixelWriter,
273
  x1: Fixed,
274
  y1: Fixed,
275
  _x2: Fixed,
@@ -296,7 +296,7 @@ fn raster_vmajor(
296
 
297
  /// Draw a single-color clipped line. Port of 0x4F7500.
298
  pub fn draw_line_clipped(
299
- writer: &mut dyn PixelWriter,
300
  mut x1: Fixed,
301
  mut y1: Fixed,
302
  mut x2: Fixed,
@@ -335,7 +335,7 @@ pub fn draw_line_clipped(
335
  ///
336
  /// Draws 8 surrounding pixels per step around a 2x2 body center.
337
  fn raster_thick_hmajor_wide(
338
- writer: &mut dyn PixelWriter,
339
  x1: Fixed,
340
  y1: Fixed,
341
  x2: Fixed,
@@ -376,7 +376,7 @@ fn raster_thick_hmajor_wide(
376
  ///
377
  /// Draws 4 body pixels per step (2x2 center), overwriting the wide pass.
378
  fn raster_thick_hmajor_narrow(
379
- writer: &mut dyn PixelWriter,
380
  x1: Fixed,
381
  y1: Fixed,
382
  x2: Fixed,
@@ -413,7 +413,7 @@ fn raster_thick_hmajor_narrow(
413
  ///
414
  /// Transposed version — draws 8 surrounding pixels per step.
415
  fn raster_thick_vmajor_wide(
416
- writer: &mut dyn PixelWriter,
417
  x1: Fixed,
418
  y1: Fixed,
419
  x2: Fixed,
@@ -451,7 +451,7 @@ fn raster_thick_vmajor_wide(
451
  ///
452
  /// Transposed version — draws 4 body pixels per step.
453
  fn raster_thick_vmajor_narrow(
454
- writer: &mut dyn PixelWriter,
455
  x1: Fixed,
456
  y1: Fixed,
457
  x2: Fixed,
@@ -486,7 +486,7 @@ fn raster_thick_vmajor_narrow(
486
  /// Draws a 2px-wide line. First pass draws 8 surrounding pixels in `color2`,
487
  /// second pass overwrites 4 center pixels in `color1`.
488
  pub fn draw_line_two_color(
489
- writer: &mut dyn PixelWriter,
490
  mut x1: Fixed,
491
  mut y1: Fixed,
492
  mut x2: Fixed,
 
131
  y1: &mut Fixed,
132
  x2: &mut Fixed,
133
  y2: &mut Fixed,
134
+ writer: &impl PixelWriter,
135
  ) -> bool {
136
  let cl = Fixed::from_int(writer.clip_left());
137
  let ct = Fixed::from_int(writer.clip_top());
 
240
  ///
241
  /// Iterates from x1 to x2 (pixel-rounded), computing y via Fixed-point slope.
242
  fn raster_hmajor(
243
+ writer: &mut impl PixelWriter,
244
  x1: Fixed,
245
  y1: Fixed,
246
  x2: Fixed,
 
269
  ///
270
  /// Iterates from y1 to y2 (pixel-rounded), computing x via Fixed-point slope.
271
  fn raster_vmajor(
272
+ writer: &mut impl PixelWriter,
273
  x1: Fixed,
274
  y1: Fixed,
275
  _x2: Fixed,
 
296
 
297
  /// Draw a single-color clipped line. Port of 0x4F7500.
298
  pub fn draw_line_clipped(
299
+ writer: &mut impl PixelWriter,
300
  mut x1: Fixed,
301
  mut y1: Fixed,
302
  mut x2: Fixed,
 
335
  ///
336
  /// Draws 8 surrounding pixels per step around a 2x2 body center.
337
  fn raster_thick_hmajor_wide(
338
+ writer: &mut impl PixelWriter,
339
  x1: Fixed,
340
  y1: Fixed,
341
  x2: Fixed,
 
376
  ///
377
  /// Draws 4 body pixels per step (2x2 center), overwriting the wide pass.
378
  fn raster_thick_hmajor_narrow(
379
+ writer: &mut impl PixelWriter,
380
  x1: Fixed,
381
  y1: Fixed,
382
  x2: Fixed,
 
413
  ///
414
  /// Transposed version — draws 8 surrounding pixels per step.
415
  fn raster_thick_vmajor_wide(
416
+ writer: &mut impl PixelWriter,
417
  x1: Fixed,
418
  y1: Fixed,
419
  x2: Fixed,
 
451
  ///
452
  /// Transposed version — draws 4 body pixels per step.
453
  fn raster_thick_vmajor_narrow(
454
+ writer: &mut impl PixelWriter,
455
  x1: Fixed,
456
  y1: Fixed,
457
  x2: Fixed,
 
486
  /// Draws a 2px-wide line. First pass draws 8 surrounding pixels in `color2`,
487
  /// second pass overwrites 4 center pixels in `color1`.
488
  pub fn draw_line_two_color(
489
+ writer: &mut impl PixelWriter,
490
  mut x1: Fixed,
491
  mut y1: Fixed,
492
  mut x2: Fixed,