paavohtl Claude Opus 4.6 (1M context) commited on
Commit
22001e9
·
1 Parent(s): c39b4d4

refactor: use typed BitGrid fields instead of raw pointer offsets

Browse files

The layer objects at DisplayGfx+0x3D9C are DisplayBitGrid instances —
their clip_left/top/right/bottom and width/height/data fields match
the BitGrid struct layout exactly. Replace raw pointer arithmetic
with typed field access.

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

crates/openwa-core/src/display/dd_display.rs CHANGED
@@ -385,28 +385,24 @@ pub unsafe extern "thiscall" fn set_clip_rect(
385
  cy2 = base.display_height as i32;
386
  }
387
 
388
- // Mirror clip rect to layer_0 object (0x4C-byte layer context).
389
- // Layout: +0x14 = width, +0x18 = height, +0x1C-0x28 = clip rect.
390
- let layer = (*gfx).layer_0 as *mut u8;
391
- let layer_w = *(layer.add(0x14) as *const i32);
392
- let layer_h = *(layer.add(0x18) as *const i32);
393
-
394
- *(layer.add(0x1C) as *mut i32) = cx1;
395
- *(layer.add(0x20) as *mut i32) = cy1;
396
- *(layer.add(0x24) as *mut i32) = cx2;
397
- *(layer.add(0x28) as *mut i32) = cy2;
398
 
399
  if cx1 < 0 {
400
- *(layer.add(0x1C) as *mut i32) = 0;
401
  }
402
  if cy1 < 0 {
403
- *(layer.add(0x20) as *mut i32) = 0;
404
  }
405
- if cx2 > layer_w {
406
- *(layer.add(0x24) as *mut i32) = layer_w;
407
  }
408
- if cy2 > layer_h {
409
- *(layer.add(0x28) as *mut i32) = layer_h;
410
  }
411
  }
412
 
@@ -424,8 +420,7 @@ pub unsafe extern "thiscall" fn set_clip_rect(
424
  unsafe fn flush_render_lock(gfx: *mut DisplayGfx) {
425
  if (*gfx).render_lock != 0 {
426
  let wrapper = *(rb(va::G_DD_DISPLAY_WRAPPER) as *const *mut DDDisplayWrapper);
427
- let layer = (*gfx).layer_0 as *mut u8;
428
- let data = *(layer.add(0x08) as *const u32);
429
  let mut buf = FastcallResult::default();
430
  DDDisplayWrapper::unlock_surface_write_raw(wrapper, &mut buf, data);
431
  (*gfx).render_lock = 0;
 
385
  cy2 = base.display_height as i32;
386
  }
387
 
388
+ // Mirror clip rect to the layer_0 BitGrid.
389
+ let layer = (*gfx).layer_0;
390
+ (*layer).clip_left = cx1 as u32;
391
+ (*layer).clip_top = cy1 as u32;
392
+ (*layer).clip_right = cx2 as u32;
393
+ (*layer).clip_bottom = cy2 as u32;
 
 
 
 
394
 
395
  if cx1 < 0 {
396
+ (*layer).clip_left = 0;
397
  }
398
  if cy1 < 0 {
399
+ (*layer).clip_top = 0;
400
  }
401
+ if cx2 > (*layer).width as i32 {
402
+ (*layer).clip_right = (*layer).width;
403
  }
404
+ if cy2 > (*layer).height as i32 {
405
+ (*layer).clip_bottom = (*layer).height;
406
  }
407
  }
408
 
 
420
  unsafe fn flush_render_lock(gfx: *mut DisplayGfx) {
421
  if (*gfx).render_lock != 0 {
422
  let wrapper = *(rb(va::G_DD_DISPLAY_WRAPPER) as *const *mut DDDisplayWrapper);
423
+ let data = (*(*gfx).layer_0).data as u32;
 
424
  let mut buf = FastcallResult::default();
425
  DDDisplayWrapper::unlock_surface_write_raw(wrapper, &mut buf, data);
426
  (*gfx).render_lock = 0;