Files
neoLegacy-mac/tests/test_reconstructed_swf_draw_interface.py
2026-07-13 08:08:50 -05:00

386 lines
24 KiB
Python

import ctypes
import math
import os
from pathlib import Path
import shlex
import struct
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
SOURCE = RECONSTRUCTED / "swf_draw_interface.c"
SUPPORT = ROOT / "tests/support/swf_draw_interface_test_support.c"
VARIANTS = {name: f"IGGY_RECONSTRUCT_SWF_DRAW_INTERFACE_{name.upper()}"
for name in ("durango", "orbis", "ps3", "vita")}
OFFSETS = {
"durango": (0x1F54, 0x1F3C, 0x235C, 0x2360, 0x2370, 0x2460, 0x2890, 0x2894, 0x21C0),
"orbis": (0x1F54, 0x1F3C, 0x235C, 0x2360, 0x2370, 0x2460, 0x2890, 0x2894, 0x21C0),
"ps3": (0x19E4, 0x19CC, 0x1DBC, 0x1DC0, 0x1DC8, 0x1EA0, 0x21AC, 0x21B0, 0x1C44),
"vita": (0x19E4, 0x19CC, 0x1DBC, 0x1DC0, 0x1DC8, 0x1EA0, 0x21AC, 0x21B0, 0x1C44),
}
AGGREGATE_STATS = {"durango": 0x28B0, "orbis": 0x28B0,
"ps3": 0x21C8, "vita": 0x21C8}
class RenderState(ctypes.Structure):
_fields_ = [
("identifier", ctypes.c_int32), ("flags", ctypes.c_uint32),
("modes", ctypes.c_uint8 * 12), ("blur", ctypes.c_int32),
("cxf_add", ctypes.c_void_p), ("textures", ctypes.c_void_p * 3),
("edge", ctypes.c_void_p), ("xform", ctypes.c_void_p),
("color", ctypes.c_float * 4), ("scissor", ctypes.c_int32 * 4),
("s", ctypes.c_float * 4), ("t", ctypes.c_float * 4),
("focal", ctypes.c_float * 4), ("trailing", ctypes.c_float * 22),
]
class Rect(ctypes.Structure):
_fields_ = [(name, ctypes.c_float) for name in ("x0", "y0", "x1", "y1")]
class Batch(ctypes.Structure):
_fields_ = [("vertices", ctypes.c_void_p), ("indices", ctypes.c_void_p),
("vertex_count", ctypes.c_uint32), ("index_count", ctypes.c_uint32),
("primitive", ctypes.c_uint8), ("padding", ctypes.c_uint8 * 7)]
class Stats(ctypes.Structure):
_fields_ = [("flags", ctypes.c_uint16), ("counts", ctypes.c_uint16 * 7),
("indices", ctypes.c_uint32), ("vertices", ctypes.c_uint32),
("blit_pixels", ctypes.c_uint32), ("texture_bytes", ctypes.c_uint32),
("freed_bytes", ctypes.c_uint32), ("defrag_bytes", ctypes.c_uint32),
("clear_pixels", ctypes.c_uint32), ("reserved", ctypes.c_uint32)]
class StrokeMesh(ctypes.Structure):
_fields_ = [("reserved", ctypes.c_void_p), ("fill_style", ctypes.c_void_p),
("indices", ctypes.c_void_p), ("vertices", ctypes.c_void_p),
("index_count", ctypes.c_uint32), ("vertex_count", ctypes.c_uint32)]
class ColorTransform(ctypes.Structure):
_fields_ = [("reserved", ctypes.c_uint8), ("additive_enabled", ctypes.c_uint8),
("multiply_enabled", ctypes.c_uint8), ("padding", ctypes.c_uint8),
("multiply", ctypes.c_float * 4), ("additive", ctypes.c_int16 * 4)]
class ReconstructedSwfDrawInterfaceTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.temp = tempfile.TemporaryDirectory()
build = Path(os.environ.get("IGGY_TEST_BUILD_DIR", cls.temp.name))
build.mkdir(parents=True, exist_ok=True)
cls.libs = {}
selected = os.environ.get("IGGY_TEST_PLATFORM")
variants = VARIANTS if selected is None else {selected: VARIANTS[selected]}
for platform, define in variants.items():
output = build / f"swf_draw_interface_{platform}.dylib"
result = subprocess.run([
"clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror",
"-DIGGY_SWF_DRAW_INTERFACE_TEST=1", f"-D{define}=1", "-I", str(RECONSTRUCTED),
str(SOURCE), str(SUPPORT), *shlex.split(os.environ.get("IGGY_TEST_CFLAGS", "")),
"-o", str(output),
], capture_output=True, text=True)
if result.returncode:
raise AssertionError((platform, result.stdout + result.stderr))
lib = ctypes.CDLL(str(output))
cls.configure(lib)
cls.libs[platform] = lib
@classmethod
def tearDownClass(cls): cls.temp.cleanup()
@staticmethod
def configure(lib):
for name in ("IggyPlayerDebugBatchSplit", "IggyPlayerDebugBatchInit", "IggyPlayerDebugBatchStartFrame"):
getattr(lib, name).argtypes = []
lib.IggyPlayerDebugBatchMove.argtypes = [ctypes.c_int32]
lib.IggyPlayerDebugBatchChooseEnd.argtypes = [ctypes.c_int32]
lib.iggy_lowlevel_set_xform.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float)]
lib.iggy_lowlevel_set_xform_translation.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float)]
quad = [ctypes.c_void_p, *([ctypes.c_float] * 8)]
lib.iggy_draw_rectangle.argtypes = [ctypes.c_void_p, ctypes.POINTER(RenderState), *([ctypes.c_float] * 8)]
lib.iggy_draw_rectangle_texgen.argtypes = [ctypes.c_void_p, ctypes.POINTER(RenderState), *([ctypes.c_float] * 4)]
lib.iggy_start_buffered_rects.argtypes = [ctypes.c_void_p, ctypes.POINTER(RenderState)]
lib.iggy_flush_buffered_rects.argtypes = [ctypes.c_void_p]
lib.iggy_draw_buffered_rect_would_flush.argtypes = [ctypes.c_void_p, ctypes.c_int32]
lib.iggy_draw_buffered_rect_would_flush.restype = ctypes.c_int32
lib.iggy_draw_buffered_rect.argtypes = quad + [ctypes.c_int32]
lib.iggy_end_buffered_rects.argtypes = [ctypes.c_void_p]
for name in ("iggy_draw_filter_quad", "iggy_draw_screen_rect"):
getattr(lib, name).argtypes = [ctypes.c_void_p, ctypes.POINTER(RenderState), ctypes.POINTER(Rect)]
lib.iggy_draw_pixel_box.argtypes = [ctypes.c_void_p, *([ctypes.c_float] * 4), ctypes.c_uint32]
lib.iggy_draw_text_cursor.argtypes = [ctypes.c_void_p, *([ctypes.c_float] * 3), ctypes.c_uint32]
lib.iggy_draw_text_border.argtypes = [ctypes.c_void_p, *([ctypes.c_float] * 4), ctypes.c_int32, ctypes.c_int32, ctypes.c_void_p]
lib.iggy_draw_batch.argtypes = [ctypes.c_void_p, ctypes.POINTER(RenderState), ctypes.POINTER(Batch), ctypes.c_void_p]
lib.iggy_predraw_stroke_mesh.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
lib.iggy_draw_stroke_mesh.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
for name in ("iggy_gdraw_FreeTexture", "iggy_gdraw_FreeVertexBuffer"):
getattr(lib, name).argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p]
for name in ("iggy_gdraw_TryToLockTexture", "iggy_gdraw_TryToLockVertexBuffer"):
getattr(lib, name).argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p]
getattr(lib, name).restype = ctypes.c_int32
lib.iggy_gdraw_UnlockHandles.argtypes = [ctypes.c_void_p]
lib.iggy_gdraw_stats.argtypes = [ctypes.c_void_p, ctypes.POINTER(Stats)]
lib.iggy_start_masking.argtypes = [ctypes.c_void_p, ctypes.POINTER(Rect), ctypes.c_int32]
lib.iggy_end_masking.argtypes = [ctypes.c_void_p, ctypes.c_int32]
def setUp(self):
for lib in self.libs.values(): lib.interface_test_reset()
@staticmethod
def context(): return (ctypes.c_uint8 * 0x2A00)()
@staticmethod
def integer(lib, name): return ctypes.c_int.in_dll(lib, name).value
def test_debug_exports_are_noops_and_cursor_is_two(self):
for lib in self.libs.values():
lib.IggyPlayerDebugBatchSplit(); lib.IggyPlayerDebugBatchInit()
lib.IggyPlayerDebugBatchStartFrame(); lib.IggyPlayerDebugBatchMove(-7)
lib.IggyPlayerDebugBatchChooseEnd(9)
self.assertEqual(ctypes.c_float.in_dll(lib, "iggy_cursor_width").value, 2)
def test_xform_and_translation_offsets(self):
matrix = (ctypes.c_float * 6)(3, 4, 4, 3, 11, 12)
for platform, lib in self.libs.items():
context = self.context(); transform, scales = OFFSETS[platform][:2]
lib.iggy_lowlevel_set_xform(context, matrix)
self.assertEqual(tuple(ctypes.c_float.from_buffer(context, transform + i * 4).value for i in range(6)), tuple(matrix))
self.assertEqual((ctypes.c_float.from_buffer(context, scales).value,
ctypes.c_float.from_buffer(context, scales + 4).value), (5, 5))
replacement = (ctypes.c_float * 6)(99, 99, 99, 99, 21, 22)
lib.iggy_lowlevel_set_xform_translation(context, replacement)
self.assertEqual(tuple(ctypes.c_float.from_buffer(context, transform + i * 4).value for i in range(6)), (3, 4, 4, 3, 21, 22))
def test_rectangle_and_texgen_emit_exact_vertices(self):
expected = (1, 2, 5, 6, 3, 2, 7, 6, 3, 4, 7, 8, 1, 4, 5, 8)
for lib in self.libs.values():
state = RenderState(); context = self.context()
lib.iggy_draw_rectangle(context, ctypes.byref(state), 1, 2, 3, 4, 5, 6, 7, 8)
raw = bytes((ctypes.c_uint8 * 64).in_dll(lib, "interface_test_last_vertices"))
self.assertEqual(struct.unpack("=16f", raw), expected)
self.assertEqual(self.integer(lib, "interface_test_last_vertex_count"), 4)
lib.interface_test_reset()
lib.iggy_draw_rectangle_texgen(context, ctypes.byref(state), 1, 2, 3, 4)
raw = bytes((ctypes.c_uint8 * 32).in_dll(lib, "interface_test_last_vertices"))
self.assertEqual(struct.unpack("=8f", raw), (1, 2, 3, 2, 3, 4, 1, 4))
def test_buffered_rect_capacity_mode_flush_and_end(self):
for platform, lib in self.libs.items():
context = self.context(); count, pointer, _, sentinel = OFFSETS[platform][2:6]
state = RenderState(); state.modes[3] = 6
lib.iggy_start_buffered_rects(context, ctypes.byref(state))
self.assertEqual(ctypes.c_int32.from_buffer(context, count).value, 0)
self.assertEqual(context[sentinel], 0xFF)
self.assertTrue(lib.iggy_draw_buffered_rect_would_flush(context, 5))
lib.iggy_draw_buffered_rect(context, 1, 2, 3, 4, 5, 6, 7, 8, 5)
self.assertEqual(ctypes.c_int32.from_buffer(context, count).value, 16)
self.assertFalse(lib.iggy_draw_buffered_rect_would_flush(context, 5))
self.assertTrue(lib.iggy_draw_buffered_rect_would_flush(context, 6))
ctypes.c_int32.from_buffer(context, count).value = 0x7F0
self.assertFalse(lib.iggy_draw_buffered_rect_would_flush(context, 5))
ctypes.c_int32.from_buffer(context, count).value = 0x800
self.assertTrue(lib.iggy_draw_buffered_rect_would_flush(context, 5))
ctypes.c_int32.from_buffer(context, count).value = 16
lib.iggy_flush_buffered_rects(context)
self.assertEqual((ctypes.c_int32.from_buffer(context, count).value, context[sentinel]), (0, 0xFF))
lib.iggy_end_buffered_rects(context)
self.assertEqual(self.integer(lib, "interface_test_unlock_calls"), 1)
self.assertEqual(self.integer(lib, "interface_test_temp_free_calls"), 1)
def test_buffered_rect_mode_capacity_and_null_allocation_paths(self):
expected = (1, 2, 5, 6, 3, 2, 7, 6, 3, 4, 7, 8, 1, 4, 5, 8)
for platform, lib in self.libs.items():
context = self.context(); count, _, _, sentinel = OFFSETS[platform][2:6]
state = RenderState(); lib.iggy_start_buffered_rects(context, ctypes.byref(state))
lib.iggy_draw_buffered_rect(context, 1, 2, 3, 4, 5, 6, 7, 8, 5)
raw = bytes((ctypes.c_uint8 * 64).in_dll(lib, "interface_test_last_vertices"))
self.assertEqual(struct.unpack("=16f", raw), expected)
lib.iggy_draw_buffered_rect(context, 9, 10, 11, 12, 0, 0, 1, 1, 6)
self.assertEqual(self.integer(lib, "interface_test_draw_calls"), 1)
self.assertEqual((ctypes.c_int32.from_buffer(context, count).value, context[sentinel]), (16, 6))
ctypes.c_int32.from_buffer(context, count).value = 0x800
lib.iggy_draw_buffered_rect(context, 1, 2, 3, 4, 0, 0, 0, 0, 7)
self.assertEqual((ctypes.c_int32.from_buffer(context, count).value, context[sentinel]), (16, 0xFF))
lib.interface_test_reset(); context = self.context()
ctypes.c_size_t.in_dll(lib, "interface_test_alloc_result").value = 0
lib.iggy_start_buffered_rects(context, ctypes.byref(state))
lib.iggy_draw_buffered_rect(context, 1, 2, 3, 4, 0, 0, 0, 0, 1)
self.assertEqual(ctypes.c_int32.from_buffer(context, count).value, 0)
lib.iggy_end_buffered_rects(context)
self.assertEqual((self.integer(lib, "interface_test_unlock_calls"),
self.integer(lib, "interface_test_temp_free_calls")), (1, 1))
def test_filter_and_screen_rect_round_outward(self):
for lib in self.libs.values():
context = self.context(); state = RenderState(); rect = Rect(-1.2, 2.9, 3.01, 4.0)
for name in ("iggy_draw_filter_quad", "iggy_draw_screen_rect"):
getattr(lib, name)(context, ctypes.byref(state), ctypes.byref(rect))
actual = tuple((ctypes.c_int * 4).in_dll(lib, "interface_test_last_rect"))
self.assertEqual(actual, (-2, 2, 4, 4))
def test_pixel_box_emits_five_quads(self):
for lib in self.libs.values():
lib.iggy_draw_pixel_box(self.context(), 1, 2, 10, 20, 0x123456)
self.assertEqual(self.integer(lib, "interface_test_filter_calls"), 5)
self.assertEqual(tuple((ctypes.c_int * 4).in_dll(lib, "interface_test_last_rect")), (1, 2, 10, 20))
rects = ((ctypes.c_int * 4) * 5).in_dll(lib, "interface_test_rects")
self.assertEqual([tuple(row) for row in rects], [
(1, 2, 10, 3), (1, 2, 2, 20), (1, 19, 10, 20),
(9, 2, 10, 20), (1, 2, 10, 20)])
self.assertEqual(tuple((ctypes.c_uint8 * 5).in_dll(lib, "interface_test_blends")), (0, 0, 0, 0, 1))
alphas = tuple((ctypes.c_float * 5).in_dll(lib, "interface_test_alphas"))
self.assertEqual(alphas, (1, 1, 1, 1, 0.0625))
def test_text_cursor_and_border_paths(self):
for platform, lib in self.libs.items():
context = self.context(); scales = OFFSETS[platform][1]
ctypes.c_float.from_buffer(context, scales).value = 2
ctypes.c_float.from_buffer(context, scales + 4).value = 4
lib.iggy_draw_text_cursor(context, 10, 2, 8, 0xAABBCC)
self.assertEqual(self.integer(lib, "interface_test_draw_calls"), 1)
lib.interface_test_reset()
lib.iggy_draw_text_border(context, 0, 0, 20, 20, 0, 0, None)
self.assertEqual(self.integer(lib, "interface_test_clear_calls"), 0)
lib.iggy_draw_text_border(context, 0, 0, 20, 20, -1, 0x010203, None)
self.assertGreaterEqual(self.integer(lib, "interface_test_draw_calls"), 1)
lib.interface_test_reset()
transform = ColorTransform(); transform.additive_enabled = 1
transform.multiply_enabled = 1; transform.multiply[:] = (1, 1, 1, .5)
lib.iggy_draw_text_border(context, 0, 0, 20, 20, 0x102030, -1, ctypes.byref(transform))
self.assertEqual((self.integer(lib, "interface_test_draw_calls"),
self.integer(lib, "interface_test_unlock_calls")), (1, 1))
self.assertEqual(ctypes.c_uint8.in_dll(lib, "interface_test_last_draw_blend").value, 1)
lib.interface_test_reset(); transform.multiply[3] = math.nan
lib.iggy_draw_text_border(context, 0, 0, 20, 20, 0x102030, -1, ctypes.byref(transform))
self.assertEqual(ctypes.c_uint8.in_dll(lib, "interface_test_last_draw_blend").value, 0)
def test_batch_predraw_and_stroke_paths(self):
vertices = (ctypes.c_float * 8)(1, 2, 3, 4, 5, 6, 7, 8)
batch = Batch(ctypes.addressof(vertices), None, 2, 0, 7)
for lib in self.libs.values():
state = RenderState(); indices = (ctypes.c_uint16 * 3)(0, 1, 0)
lib.iggy_draw_batch(self.context(), ctypes.byref(state), ctypes.byref(batch), indices)
self.assertEqual(self.integer(lib, "interface_test_draw_calls"), 1)
self.assertEqual(self.integer(lib, "interface_test_last_primitive"), 7)
self.assertEqual(ctypes.c_size_t.in_dll(lib, "interface_test_last_vertex_buffer").value,
ctypes.addressof(indices))
lib.iggy_predraw_stroke_mesh(self.context(), ctypes.byref(batch))
self.assertEqual(ctypes.c_float.in_dll(lib, "interface_test_fill_morph").value, -1)
stroke = StrokeMesh(None, None, ctypes.addressof(indices), ctypes.addressof(vertices), 3, 2)
lib.iggy_draw_stroke_mesh(self.context(), ctypes.byref(stroke), None)
self.assertEqual(self.integer(lib, "interface_test_draw_calls"), 2)
def test_stroke_inverse_success_failure_and_empty_path(self):
vertices = (ctypes.c_float * 4)(0, 0, 1, 1)
indices = (ctypes.c_uint16 * 2)(0, 1)
for lib in self.libs.values():
context = self.context(); matrix = (ctypes.c_float * 6)(1, 0, 0, 1, 0, 0)
lib.iggy_lowlevel_set_xform(context, matrix)
ctypes.c_int.in_dll(lib, "interface_test_use_edge_matrix").value = 1
mesh = StrokeMesh(None, None, ctypes.addressof(indices), ctypes.addressof(vertices), 2, 2)
lib.iggy_draw_stroke_mesh(context, ctypes.byref(mesh), None)
self.assertEqual(self.integer(lib, "interface_test_invert_calls"), 1)
ctypes.c_int.in_dll(lib, "interface_test_invert_result").value = 0
lib.iggy_draw_stroke_mesh(context, ctypes.byref(mesh), None)
empty = StrokeMesh(None, None, None, None, 0, 0)
lib.iggy_draw_stroke_mesh(context, ctypes.byref(empty), None)
self.assertEqual(self.integer(lib, "interface_test_draw_calls"), 2)
def test_gdraw_resource_wrappers_and_unlock(self):
for lib in self.libs.values():
context = self.context(); unique = ctypes.c_size_t()
lib.iggy_gdraw_FreeTexture(context, 0x11, ctypes.byref(unique))
lib.iggy_gdraw_FreeVertexBuffer(context, 0x22, ctypes.byref(unique))
self.assertEqual(lib.iggy_gdraw_TryToLockTexture(context, 0x33, ctypes.byref(unique)), 1)
self.assertEqual(lib.iggy_gdraw_TryToLockVertexBuffer(context, 0x44, ctypes.byref(unique)), 1)
lib.iggy_gdraw_UnlockHandles(context)
self.assertEqual((self.integer(lib, "interface_test_free_texture_calls"), self.integer(lib, "interface_test_free_vertex_calls")), (1, 1))
self.assertEqual((self.integer(lib, "interface_test_lock_texture_calls"), self.integer(lib, "interface_test_lock_vertex_calls")), (1, 1))
def test_stats_aggregate_flag_paths_and_guards(self):
for platform, lib in self.libs.items():
context = self.context(); aggregate, enabled = OFFSETS[platform][6:8]
ctypes.c_int32.from_buffer(context, aggregate).value = 1
ctypes.c_int32.from_buffer(context, enabled).value = 1
stats = Stats(flags=0x6B, indices=30, vertices=12, blit_pixels=99, clear_pixels=77)
stats.counts[:] = (2, 3, 4, 5, 6, 7, 8)
lib.interface_test_enable_telemetry()
lib.iggy_gdraw_stats(context, ctypes.byref(stats))
total = Stats.from_buffer(context, AGGREGATE_STATS[platform])
self.assertEqual(tuple(total.counts), (2, 3, 4, 0, 0, 7, 8))
self.assertEqual((total.indices, total.vertices, total.blit_pixels, total.texture_bytes,
total.freed_bytes, total.defrag_bytes, total.clear_pixels),
(30, 12, 99, 0, 0, 0, 77))
self.assertGreater(self.integer(lib, "interface_test_telemetry_calls"), 0)
before = bytes(context)
lib.iggy_gdraw_stats(ctypes.c_void_p(2), ctypes.byref(stats))
self.assertEqual(bytes(context), before)
stats.flags = 0; lib.iggy_gdraw_stats(context, ctypes.byref(stats))
self.assertEqual(bytes(context), before)
def test_instrumented_wrappers_lock_failure_and_mask_absence(self):
for platform, lib in self.libs.items():
context = self.context(); aggregate, enabled = OFFSETS[platform][6:8]
ctypes.c_int32.from_buffer(context, aggregate).value = 1
ctypes.c_int32.from_buffer(context, enabled).value = 1
ctypes.c_int.in_dll(lib, "interface_test_stats_flags").value = 1
ctypes.c_int.in_dll(lib, "interface_test_lock_result").value = 0
lib.interface_test_enable_telemetry()
state = RenderState(); rect = Rect(1, 2, 3, 4); unique = ctypes.c_size_t()
lib.iggy_draw_rectangle(context, ctypes.byref(state), 0, 0, 1, 1, 0, 0, 1, 1)
lib.iggy_gdraw_UnlockHandles(context)
self.assertEqual(lib.iggy_gdraw_TryToLockTexture(context, 1, ctypes.byref(unique)), 0)
self.assertEqual(lib.iggy_gdraw_TryToLockVertexBuffer(context, 2, ctypes.byref(unique)), 0)
lib.iggy_start_masking(context, ctypes.byref(rect), 0)
lib.iggy_end_masking(context, 0)
self.assertGreater(self.integer(lib, "interface_test_telemetry_calls"), 0)
ctypes.c_int.in_dll(lib, "interface_test_mask_begin_present").value = 0
ctypes.c_int.in_dll(lib, "interface_test_mask_end_present").value = 0
lib.iggy_start_masking(context, ctypes.byref(rect), 1)
lib.iggy_end_masking(context, 1)
self.assertEqual((self.integer(lib, "interface_test_start_mask_calls"),
self.integer(lib, "interface_test_end_mask_calls")), (1, 1))
def test_telemetry_span_ids_dimensions_counts_and_stats_payloads(self):
vertices = (ctypes.c_float * 4)(0, 0, 1, 1)
indices = (ctypes.c_uint16 * 2)(0, 1)
for platform, lib in self.libs.items():
context = self.context(); state = RenderState(); lib.interface_test_enable_telemetry()
rect = Rect(-1.2, 2.9, 3.01, 4.0)
lib.iggy_draw_filter_quad(context, ctypes.byref(state), ctypes.byref(rect))
mesh = StrokeMesh(None, None, ctypes.addressof(indices), ctypes.addressof(vertices), 2, 2)
lib.iggy_draw_stroke_mesh(context, ctypes.byref(mesh), None)
begins = (ctypes.c_uint32 * 64).in_dll(lib, "interface_test_begin_lines")
ends = (ctypes.c_uint32 * 64).in_dll(lib, "interface_test_end_lines")
self.assertEqual(tuple(begins[:2]), (0x266, 0x29F))
self.assertEqual(tuple(ends[:2]), (0x269, 0x2D6))
self.assertEqual((self.integer(lib, "interface_test_filter_width"),
self.integer(lib, "interface_test_filter_height")), (6, 2))
self.assertEqual((self.integer(lib, "interface_test_stroke_vertices"),
self.integer(lib, "interface_test_stroke_indices")), (2, 2))
_, enabled = OFFSETS[platform][6:8]
ctypes.c_int32.from_buffer(context, enabled).value = 1
ctypes.c_int.in_dll(lib, "interface_test_stats_flags").value = 1
lib.iggy_draw_rectangle(context, ctypes.byref(state), 0, 0, 1, 1, 0, 0, 1, 1)
self.assertEqual(begins[2], 0xFE)
self.assertEqual(ends[2], 0x101)
counters = (ctypes.c_uint32 * 16).in_dll(lib, "interface_test_counter_values")
self.assertEqual(tuple(counters[:2]), (1, 3))
def test_masking_saves_physical_rect_and_reuses_it(self):
for platform, lib in self.libs.items():
context = self.context(); base = OFFSETS[platform][8]; rect = Rect(-1.2, 2.9, 8.1, 9.0)
lib.iggy_start_masking(context, ctypes.byref(rect), 2)
saved = tuple(ctypes.c_float.from_buffer(context, base + 0x20 + i * 4).value for i in range(4))
self.assertEqual(saved, (rect.x0, rect.y0, rect.x1, rect.y1))
self.assertEqual(tuple((ctypes.c_int * 4).in_dll(lib, "interface_test_last_rect")), (-2, 2, 9, 9))
lib.iggy_end_masking(context, 2)
self.assertEqual(self.integer(lib, "interface_test_end_mask_calls"), 1)
if __name__ == "__main__": unittest.main()