From 7775a787efa9a895b3d9ff4e32c9808e482ab8a1 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Mon, 13 Jul 2026 10:05:34 -0500 Subject: [PATCH] rebuild iggy's native shape renderer --- .../src/reconstructed/CMakeLists.txt | 16 + iggy-decompiled/src/reconstructed/README.md | 8 + iggy-decompiled/src/reconstructed/modules.tsv | 2 + .../src/reconstructed/swf_draw_shape.c | 297 +++++ .../src/reconstructed/swf_draw_shape.h | 91 ++ .../src/reconstructed/swf_draw_shape_char.inc | 316 +++++ .../reconstructed/swf_draw_shape_export.inc | 127 ++ .../reconstructed/swf_draw_shape_render.inc | 454 +++++++ tests/support/swf_draw_shape_test_support.c | 527 ++++++++ tests/test_reconstructed_swf_draw_shape.py | 1135 +++++++++++++++++ ...test_reconstructed_swf_draw_shape_cross.py | 173 +++ 11 files changed, 3146 insertions(+) create mode 100644 iggy-decompiled/src/reconstructed/swf_draw_shape.c create mode 100644 iggy-decompiled/src/reconstructed/swf_draw_shape.h create mode 100644 iggy-decompiled/src/reconstructed/swf_draw_shape_char.inc create mode 100644 iggy-decompiled/src/reconstructed/swf_draw_shape_export.inc create mode 100644 iggy-decompiled/src/reconstructed/swf_draw_shape_render.inc create mode 100644 tests/support/swf_draw_shape_test_support.c create mode 100644 tests/test_reconstructed_swf_draw_shape.py create mode 100644 tests/test_reconstructed_swf_draw_shape_cross.py diff --git a/iggy-decompiled/src/reconstructed/CMakeLists.txt b/iggy-decompiled/src/reconstructed/CMakeLists.txt index e78e87e..1a67c23 100644 --- a/iggy-decompiled/src/reconstructed/CMakeLists.txt +++ b/iggy-decompiled/src/reconstructed/CMakeLists.txt @@ -219,6 +219,22 @@ foreach(platform IN ITEMS durango orbis ps3 vita) endif() endforeach() +foreach(platform IN ITEMS durango orbis ps3 vita) + string(TOUPPER ${platform} platform_upper) + set(target iggy_reconstructed_swf_draw_shape_${platform}) + add_library(${target} STATIC swf_draw_shape.c) + target_compile_definitions( + ${target} + PRIVATE IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_${platform_upper} + ) + configure_iggy_reconstructed_target(${target} c_std_11) + if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU") + target_compile_options(${target} PRIVATE -fno-builtin) + elseif(MSVC) + target_compile_options(${target} PRIVATE /Oi-) + endif() +endforeach() + add_library( iggy_reconstructed_as3vm_debugger_interface STATIC diff --git a/iggy-decompiled/src/reconstructed/README.md b/iggy-decompiled/src/reconstructed/README.md index 7c90daf..bad640f 100644 --- a/iggy-decompiled/src/reconstructed/README.md +++ b/iggy-decompiled/src/reconstructed/README.md @@ -128,6 +128,14 @@ evicted-handle behavior, nested CPU ownership, measurement and flush paths, the mutable cache switch, and the shipping 32/64-bit layouts and import surfaces. The original SWF/AVM2 UI remains the caller and is not replaced or bypassed. +`swf_draw_shape.c` restores the nine native shape, bitmap, glyph, font-cache, +and exporter entry points plus the bitmap-smoothing control used by the existing +SWF renderer. Its four variants preserve cached and temporary fill batches, +render-target antialiasing and stroke submission, direct and indirect bitmap +routing, embedded and substituted font paths, texture-stat packet chunking, +telemetry, and the shipping 32/64-bit layouts and import surfaces. The original +SWF/AVM2 assets and AVM2 behavior remain unchanged. + `as3vm_debugger_interface.c` and `as3vm_op_strings.c` preserve the three intentional zero-return stubs in the shipping archives. Every platform object contains the same compiled-out behavior with no debugger metadata, opcode diff --git a/iggy-decompiled/src/reconstructed/modules.tsv b/iggy-decompiled/src/reconstructed/modules.tsv index 187149f..ac255e5 100644 --- a/iggy-decompiled/src/reconstructed/modules.tsv +++ b/iggy-decompiled/src/reconstructed/modules.tsv @@ -19,6 +19,8 @@ swf_draw_texture 15 10 durango,orbis,ps3,vita complete swf_draw_interface 31 30 durango,orbis,ps3,vita complete triangulate_ears 21 2 durango,orbis,ps3,vita complete swf_draw_triangulate 19 11 durango,orbis,ps3,vita complete +swf_draw_shape 14 9 durango complete +swf_draw_shape 11 9 orbis,ps3,vita complete as3vm_debugger_interface 2 2 durango,orbis,ps3,vita complete as3vm_op_strings 1 1 durango,orbis,ps3,vita complete iggy_platform_audio 2 2 durango complete diff --git a/iggy-decompiled/src/reconstructed/swf_draw_shape.c b/iggy-decompiled/src/reconstructed/swf_draw_shape.c new file mode 100644 index 0000000..d92c55d --- /dev/null +++ b/iggy-decompiled/src/reconstructed/swf_draw_shape.c @@ -0,0 +1,297 @@ +#include "swf_draw_shape.h" + +#include +#include + +#if defined(__clang__) || defined(__GNUC__) +#define IGGY_USED __attribute__((used)) +#else +#define IGGY_USED +#endif + +#if (defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_DURANGO) + \ + defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_ORBIS) + \ + defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_PS3) + \ + defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_VITA)) != 1 +#error "select exactly one swf_draw_shape target" +#endif + +_Static_assert(sizeof(IggyExpShapeStats) == + (sizeof(void *) == 8 ? 0x330 : 0x1b0), + "export accumulator size"); +_Static_assert(offsetof(IggyExpShapeStats, textures) == 0x28, + "texture queue offset"); +_Static_assert(sizeof(IggyShapeSectionSource) == + (sizeof(void *) == 8 ? 0x40 : 0x28), + "section source size"); + +typedef void (*IggyShapeTelemetryCall)(void *, ...); +typedef void (*IggyDescribeTextureCall)(uintptr_t, void *); +typedef void (*IggyExportCall)(void *, void *, int32_t, const void *, uint32_t); +typedef void (*IggyFlushBatchesCall)(void); +typedef void (*IggyStrokeMeshCallback)(const IggyStrokeMesh *, void *); + +typedef struct IggyTextureDescription { + uint16_t width; + uint16_t height; + uint32_t format; +} IggyTextureDescription; + +typedef struct IggyExpTextureRecord { + uint64_t handle; + uint32_t format; + uint16_t width; + uint16_t height; +} IggyExpTextureRecord; + +typedef struct IggyExpBitmapRecord { + uint64_t record; + uint32_t pixels; + uint16_t width; + uint16_t height; +} IggyExpBitmapRecord; + +typedef struct IggyShapeTelemetryPacket { + uint8_t bytes[0x330]; +} IggyShapeTelemetryPacket; + +extern uint8_t as3vm_nullundef_storage[]; +extern void *iggy_gdraw; +extern void *iggy_tm_normal; +extern int32_t iggy_max_visible_chars; +extern void iggy_9slice_set_fill_xform(void *, const void *); +extern void iggy_compute_bounds(float *, const void *, const float *); +extern void iggy_free_alloc(void *, void *); +extern void iggy_free_shape_for_glyph(void *, int32_t, void *); +extern void *iggy_get_fallback_font(void *); +extern void *iggy_get_glyph_metrics(void *, int32_t, void *); +extern void iggy_get_shape_for_glyph(void *, int32_t, void *); +extern int32_t iggy_glyph_is_empty(void *, int32_t); +extern void *iggy_malloc_CANFAIL_fileline( + int32_t, uint32_t, uint32_t, const char *, int32_t); +extern void iggy_matrix_concatenate(float *, const float *, const float *); +extern void iggy_send_error(void *, int32_t, const char *); +extern void iggy_stroke_path( + void *, void *, const float *, const float *, const float *, + const IggyShapeSectionSource *, float, const IggyShapeSectionSource *, + int32_t, int32_t, IggyStrokeMeshCallback, void *); +extern void *memmove(void *, const void *, size_t); +extern void *memset(void *, int, size_t); + +static const char source_path[] = + "c:\\projects\\g\\src\\flash\\swf_draw_shape.c"; +static const char bitmap_cache_error[] = + "Bitmap character was not in fontcache so could not be displayed. " + "Try IggySetFontCachingCalculationBuffer."; +static const char embedded_font[] = "embedded font"; +static const char substituted_font[] = "substituted font"; +static const char shape_zone[] = "(iggy/render)iggy_draw_shape"; +static const char char_zone[] = "(iggy/render)iggy_draw_char"; +static const char aa_zone[] = "(iggy/render)iggy_AA_using_rendertarget"; +static const char aa_composite_zone[] = + "(iggy/render)iggy_draw_aa_rendertarget"; +static uint32_t telemetry_formats[4]; + +uint8_t iggy_fix_bitmap_smoothing = 1; + +#if defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_DURANGO) || \ + defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_ORBIS) +enum { + player_cache_max_height = 0x1e9c, + player_cache_max_width = 0x1ea0, + player_cache_ratio_low = 0x1eb0, + player_cache_ratio_high = 0x1eb4, + player_quality = 0x1e98, + player_batch_capacity = 0x1f14, + player_rt_aa_enabled = 0x1f2c, + player_scale_x = 0x1f3c, + player_scale_y = 0x1f40, + player_stroke_scale_x = 0x1f4c, + player_stroke_scale_y = 0x1f50, + player_matrix = 0x1f54, + player_rt_depth = 0x2290, + player_rt_active = 0x2294, + player_rt_disabled = 0x2295, + player_slice_enabled = 0x2298, + player_slice_bounds = 0x229c, + player_frame = 0x2878, + player_exporter = 0x2888, + player_buffered_chars = 0x28e0, + player_shape_chars = 0x28e4, + player_object_to_world = 0x468, + player_debug_label = 0x3520, + player_debug_glyph = 0x3530, + player_render_frames = 0x1f80, + player_render_frame_count = 0x00, + player_render_frame_gate = 0x06 +}; +#else +enum { + player_cache_max_height = 0x1940, + player_cache_max_width = 0x1944, + player_cache_ratio_low = 0x1954, + player_cache_ratio_high = 0x1958, + player_quality = 0x193c, + player_batch_capacity = 0x19a4, + player_rt_aa_enabled = 0x19bc, + player_scale_x = 0x19cc, + player_scale_y = 0x19d0, + player_stroke_scale_x = 0x19dc, + player_stroke_scale_y = 0x19e0, + player_matrix = 0x19e4, + player_rt_depth = 0x1cf4, + player_rt_active = 0x1cf8, + player_rt_disabled = 0x1cf9, + player_slice_enabled = 0x1cfc, + player_slice_bounds = 0x1d00, + player_frame = 0x2198, + player_exporter = 0x21a8, + player_buffered_chars = 0x21f8, + player_shape_chars = 0x21fc, + player_object_to_world = 0x318, + player_debug_label = 0x2bb4, + player_debug_glyph = 0x2bbc, + player_render_frames = 0x1a00, + player_render_frame_count = 0x04, + player_render_frame_gate = 0x0a +}; +#endif + +#if UINTPTR_MAX == UINT64_MAX +enum { + section_path = 0x10, + section_fill_styles = 0x20, + section_stroke_styles = 0x28, + section_slice_bounds = 0x30, + section_flags = 0x38, + font_glyph_count = 0x34, + font_type = 0x18, + font_bitmap_heads = 0x40, + font_shape_cache = 0x48, + font_substitute_owner = 0x50, + font_shape_provider = 0xc8, + font_cache_callback = 0xd8, + font_cache_callback_present = 0xe0, + bitmap_next = 0x8, + bitmap_uv = 0x20, + bitmap_scale_x = 0x30, + bitmap_scale_y = 0x34, + bitmap_rectangle = 0x38, + bitmap_last_frame = 0x48, + bitmap_alternate_key = 0x50, + bitmap_range_low = 0x54, + bitmap_range_high = 0x58, + bitmap_slot = 0x5c, + display_bitmap = 0xa8, + display_smoothing = 0xbb, + display_direct_texture = 0x148, + display_indirect_bitmap = 0x150, + indirect_bitmap_pointer = 0x27, + direct_texture_width = 0x28, + direct_texture_height = 0x2c, + embedded_bitmap_width = 0x20, + embedded_bitmap_height = 0x22 +}; +#else +enum { + section_path = 0x10, + section_fill_styles = 0x18, + section_stroke_styles = 0x1c, + section_slice_bounds = 0x20, + section_flags = 0x24, + font_glyph_count = 0x20, + font_type = 0x0c, + font_bitmap_heads = 0x28, + font_shape_cache = 0x2c, + font_substitute_owner = 0x30, + font_shape_provider = 0x80, + font_cache_callback = 0x88, + font_cache_callback_present = 0x8c, + bitmap_next = 0x4, + bitmap_uv = 0x10, + bitmap_scale_x = 0x20, + bitmap_scale_y = 0x24, + bitmap_rectangle = 0x28, + bitmap_last_frame = 0x38, + bitmap_alternate_key = 0x40, + bitmap_range_low = 0x44, + bitmap_range_high = 0x48, + bitmap_slot = 0x4c, + display_bitmap = 0x58, + display_smoothing = 0x63, + display_direct_texture = 0xe8, + display_indirect_bitmap = 0xec, + indirect_bitmap_pointer = 0x17, + direct_texture_width = 0x14, + direct_texture_height = 0x18, + embedded_bitmap_width = 0x10, + embedded_bitmap_height = 0x12 +}; +#endif + +static uintptr_t read_pointer(const void *base, size_t offset) { + uintptr_t value; + __builtin_memcpy(&value, (const uint8_t *)base + offset, sizeof(value)); + return value; +} + +static void write_pointer(void *base, size_t offset, uintptr_t value) { + __builtin_memcpy((uint8_t *)base + offset, &value, sizeof(value)); +} + +static int32_t read_i32(const void *base, size_t offset) { + int32_t value; + __builtin_memcpy(&value, (const uint8_t *)base + offset, sizeof(value)); + return value; +} + +static void write_i32(void *base, size_t offset, int32_t value) { + __builtin_memcpy((uint8_t *)base + offset, &value, sizeof(value)); +} + +static float read_f32(const void *base, size_t offset) { + float value; + __builtin_memcpy(&value, (const uint8_t *)base + offset, sizeof(value)); + return value; +} + +static int16_t read_i16(const void *base, size_t offset) { + int16_t value; + __builtin_memcpy(&value, (const uint8_t *)base + offset, sizeof(value)); + return value; +} + +static void *player_pointer(void *iggy, size_t offset) { + return (void *)read_pointer(iggy, offset); +} + +static IggyShapeTelemetryCall telemetry_slot(size_t index) { + return ((IggyShapeTelemetryCall *)iggy_tm_normal)[index]; +} + +static void telemetry_begin(uint32_t line, uint32_t *format, const char *zone) { + if (iggy_tm_normal == NULL) return; + IggyShapeTelemetryCall const begin = telemetry_slot(20); +#if defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_VITA) + begin(iggy_tm_normal, 0, 0, line, 0, 0, 0, source_path, line, format, zone); +#elif defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_PS3) + (void)zone; + begin(iggy_tm_normal, 0, 0, 0, 0, source_path, line, format); +#else + begin(iggy_tm_normal, 0, 0, 0, 0, source_path, line, format, zone); +#endif +} + +static void telemetry_end(uint32_t line) { + if (iggy_tm_normal == NULL) return; + IggyShapeTelemetryCall const end = telemetry_slot(21); +#if defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_VITA) + end(iggy_tm_normal, line, 0, 0, 0, source_path, line); +#else + end(iggy_tm_normal, 0, 0, source_path, line); +#endif +} + +#include "swf_draw_shape_render.inc" +#include "swf_draw_shape_export.inc" +#include "swf_draw_shape_char.inc" diff --git a/iggy-decompiled/src/reconstructed/swf_draw_shape.h b/iggy-decompiled/src/reconstructed/swf_draw_shape.h new file mode 100644 index 0000000..5f80ff8 --- /dev/null +++ b/iggy-decompiled/src/reconstructed/swf_draw_shape.h @@ -0,0 +1,91 @@ +#ifndef IGGY_RECONSTRUCTED_SWF_DRAW_SHAPE_H +#define IGGY_RECONSTRUCTED_SWF_DRAW_SHAPE_H + +#include + +#include "swf_draw_filltype.h" +#include "swf_draw_interface.h" +#include "swf_draw_triangulate.h" + +typedef struct IggyBitmapCacheRecord IggyBitmapCacheRecord; +typedef struct IggyFont IggyFont; + +typedef struct IggyShapeSectionSource { +#if UINTPTR_MAX == UINT64_MAX + uint8_t bytes[0x40]; +#else + uint8_t bytes[0x28]; +#endif +} IggyShapeSectionSource; + +typedef struct IggyVisibleGlyph { + IggyFont *font; + int32_t glyph; + float scale_x; + float scale_y; +} IggyVisibleGlyph; + +typedef struct IggyExpShapeStats { + uint64_t id; + uintptr_t cache_entry; +#if UINTPTR_MAX != UINT64_MAX + uint32_t reserved_pointer_padding; +#endif + uint32_t reserved; + uint32_t sections; + uint32_t draws; + uint32_t vertices; + uint32_t indices; + uint32_t vertex_buffer_bytes; + uintptr_t textures[32]; + uintptr_t bitmap_records[64]; + int32_t texture_count; + int32_t bitmap_count; +} IggyExpShapeStats; + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint8_t iggy_fix_bitmap_smoothing; + +void iggy_draw_bitmap_raw( + void *iggy, void *display_object, + const IggyRenderColorTransform *transform); +void iggy_draw_char( + void *iggy, IggyFont *font, float scale, int32_t glyph, + float x, float y, const uint8_t rgba[4], + const IggyRenderColorTransform *transform); +int32_t iggy_draw_shape_raw( + void *iggy, IggyShapeCacheOwner *shape, float morph_ratio, + const IggyShapeSectionSource *morph_sections, + const IggyRenderColorTransform *transform, + const IggyRenderBounds *bounds, const float *matrix, + int32_t disable_render_target_aa, int32_t suppress_aa); +void iggy_draw_text_bitmap( + void *iggy, IggyBitmap *bitmap, + const IggyRenderColorTransform *transform, + float x, float y, float width, float height, int32_t smoothing); +void iggy_flush_textureinfo_for_iggyexp( + void *iggy, IggyExpShapeStats *stats); +void iggy_fontcache_char( + void *iggy, IggyFont *font, float scale, int32_t glyph, + float unused_x, float unused_y, const float *matrix, + IggyVisibleGlyph *visible, int32_t *visible_count, + float scale_x, float scale_y); +void iggy_get_char_renderstate( + void *iggy, IggyRenderState *state, const uint8_t rgba[4], + const IggyRenderColorTransform *transform); +void iggy_get_shape_stats( + void *iggy, uint64_t id, IggyShapeCacheOwner *shape, + float morph_ratio, const IggyShapeSectionSource *morph_sections, + const float *slice_transform); +void iggy_iggyexp_char( + void *iggy, IggyFont *font, float scale, int32_t glyph, + IggyExpShapeStats *stats); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/iggy-decompiled/src/reconstructed/swf_draw_shape_char.inc b/iggy-decompiled/src/reconstructed/swf_draw_shape_char.inc new file mode 100644 index 0000000..dddd399 --- /dev/null +++ b/iggy-decompiled/src/reconstructed/swf_draw_shape_char.inc @@ -0,0 +1,316 @@ +#if defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_DURANGO) || \ + defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_VITA) +static uint8_t font_bitmap_cache IGGY_USED = 1; +#endif + +static int32_t last_error_frame; + +#if UINTPTR_MAX == UINT64_MAX +enum { embedded_shape_table = 0x30 }; +#else +enum { embedded_shape_table = 0x1c }; +#endif + +#if defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_DURANGO) +enum { glyph_shape_section = 0x30 }; +#elif defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_ORBIS) +enum { glyph_shape_section = 0x18 }; +#elif defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_PS3) +enum { glyph_shape_section = 0x68 }; +#else +enum { glyph_shape_section = 0x20 }; +#endif + +static int32_t character_cacheable( + void *iggy, IggyFont *font, int32_t glyph, float scale, + float scale_x, float scale_y) { +#if defined(IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_DURANGO) + if (font_bitmap_cache == 0) return 0; +#endif + if (iggy_glyph_is_empty(font, glyph) != 0) return 1; + if (read_pointer(font, font_cache_callback_present) != 0) { + const uintptr_t callback_value = read_pointer(font, font_cache_callback); + if (callback_value == 0) return 1; + typedef int32_t (*CacheableCallback)(void *, int32_t, float); + CacheableCallback const callback = (CacheableCallback)callback_value; + if (callback( + (void *)read_pointer(font, sizeof(void *)), glyph, + scale * scale_y) != 0) { + return 1; + } + if (read_pointer(font, font_shape_provider) == 0) return 0; + } + + float metrics[6] = {0}; + float const *const result = + (float *)iggy_get_glyph_metrics(font, glyph, metrics); + const float width = (result[2] - result[0]) * scale * scale_x; + const float height = (result[3] - result[1]) * scale * scale_y; + return width < read_f32(iggy, player_cache_max_width) && + height < read_f32(iggy, player_cache_max_height); +} + +static IggyBitmapCacheRecord *find_bitmap_cache( + void *iggy, IggyFont *font, int32_t glyph, + float scaled_x, float scaled_y) { + const uintptr_t table = read_pointer(font, font_bitmap_heads); + if (table == 0) return NULL; + uintptr_t record = read_pointer( + (const void *)table, (size_t)glyph * sizeof(uintptr_t)); + const float low = read_f32(iggy, player_cache_ratio_low); + const float high = read_f32(iggy, player_cache_ratio_high); + while (record != 0) { + int32_t matches; + if (read_f32((const void *)record, bitmap_alternate_key) == 0.0f) { + const float record_x = read_f32((const void *)record, bitmap_scale_x); + const float record_y = read_f32((const void *)record, bitmap_scale_y); + matches = low * scaled_x <= record_x && record_x <= high * scaled_x && + low * scaled_y <= record_y && record_y <= high * scaled_y; + } else { + matches = read_f32((const void *)record, bitmap_range_low) <= scaled_y && + scaled_y <= read_f32((const void *)record, bitmap_range_high); + } + if (matches != 0) { + write_i32( + (void *)record, bitmap_last_frame, + read_i32(iggy, player_frame)); + return (IggyBitmapCacheRecord *)record; + } + record = read_pointer((const void *)record, bitmap_next); + } + return NULL; +} + +static IggyFont *resolve_font(void *iggy, IggyFont *font, int32_t *glyph) { + if (font == NULL) return NULL; + const int32_t count = read_i32(font, font_glyph_count); + if (*glyph < count) return font; + *glyph -= count; + return (IggyFont *)iggy_get_fallback_font(iggy); +} + +static void draw_cached_character( + void *iggy, const IggyBitmapCacheRecord *record, + float scale, float x, float y) { + iggy_draw_buffered_rect( + iggy, + scale * read_f32(record, bitmap_rectangle) + x, + scale * read_f32(record, bitmap_rectangle + 4U) + y, + scale * read_f32(record, bitmap_rectangle + 8U) + x, + scale * read_f32(record, bitmap_rectangle + 12U) + y, + read_f32(record, bitmap_uv), read_f32(record, bitmap_uv + 4U), + read_f32(record, bitmap_uv + 8U), read_f32(record, bitmap_uv + 12U), + read_i16(record, bitmap_slot)); + write_i32( + iggy, player_buffered_chars, + read_i32(iggy, player_buffered_chars) + 1); +} + +static IggyShapeCacheOwner *embedded_character_shape( + IggyFont *font, int32_t glyph) { + const uintptr_t root = read_pointer(font, 0); + if (root == 0) return NULL; + const uintptr_t shapes = read_pointer((const void *)root, embedded_shape_table); + return shapes == 0 + ? NULL + : &((IggyShapeCacheOwner *)shapes)[glyph]; +} + +static IggyShapeCacheOwner *substituted_character_shape( + IggyFont *font, int32_t glyph, int32_t allocate) { + const uintptr_t table = read_pointer(font, font_shape_cache); + if (table == 0) return NULL; + IggyShapeCacheOwner *owner = (IggyShapeCacheOwner *)read_pointer( + (const void *)table, (size_t)glyph * sizeof(uintptr_t)); + if (owner != NULL || allocate == 0) return owner; + owner = (IggyShapeCacheOwner *)iggy_malloc_CANFAIL_fileline( + 2, (uint32_t)(4U * sizeof(void *)), + 0x28U, source_path, 0x219); + if (owner == NULL) return NULL; + memset(owner, 0, sizeof(*owner)); + owner->section_count = 1; + owner->cache_policy = 1; + owner->indirect_owner = 1; + owner->allocator_owner = + (void *)(read_pointer(font, font_substitute_owner) != 0 + ? read_pointer(font, font_substitute_owner) + : (uintptr_t)font); + owner->section_sources = (void *)(uintptr_t)(uint32_t)glyph; + write_pointer( + (void *)table, (size_t)glyph * sizeof(uintptr_t), (uintptr_t)owner); + return owner; +} + +static void report_missing_font_cache(void *iggy) { + const int32_t frame = read_i32(iggy, player_frame); + if (frame == last_error_frame) return; + iggy_send_error(iggy, 0x194, bitmap_cache_error); + last_error_frame = frame; +} + +static int32_t draw_character_shape( + void *iggy, IggyFont *font, int32_t glyph, float scale, + float x, float y, const uint8_t rgba[4], + const IggyRenderColorTransform *transform) { + uint8_t glyph_shape[0x80] = {0}; + IggyShapeCacheOwner *owner; + IggyShapeSectionSource *source; + IggyCachedDrawResult local_result; + IggyCachedDrawResult *results = NULL; + int32_t allocated = 0; + int32_t failed = 0; + + telemetry_begin(0x1eeU, &telemetry_formats[1], char_zone); + if (read_i32(font, font_type) == 1) { + owner = embedded_character_shape(font, glyph); + if (owner == NULL) { + telemetry_end(0x233U); + return 0; + } + source = (IggyShapeSectionSource *)owner->section_sources; + write_pointer(iggy, player_debug_label, (uintptr_t)embedded_font); + write_i32(iggy, player_debug_glyph, glyph); + allocated = iggy_triangulate_cached( + iggy, owner, source, (float *)((uint8_t *)iggy + player_matrix), + scale, read_f32(iggy, player_scale_x), read_f32(iggy, player_scale_y), + -1.0f, NULL, 1, &failed, &results); + write_pointer(iggy, player_debug_label, 0); + } else { + if (read_pointer(font, font_shape_provider) == 0) { + report_missing_font_cache(iggy); + telemetry_end(0x233U); + return 0; + } + owner = substituted_character_shape(font, glyph, 1); + if (owner == NULL) { + telemetry_end(0x233U); + return 0; + } + if (iggy_onesection_get_cached_triangulation( + iggy, owner, (const float *)((uint8_t *)iggy + player_matrix), + scale, read_f32(iggy, player_scale_x), + read_f32(iggy, player_scale_y), 1, &local_result) != 0) { + results = &local_result; + source = (IggyShapeSectionSource *)(glyph_shape + glyph_shape_section); + } else { + iggy_get_shape_for_glyph(font, glyph, glyph_shape); + source = (IggyShapeSectionSource *)(glyph_shape + glyph_shape_section); + write_pointer(iggy, player_debug_label, (uintptr_t)substituted_font); + write_i32(iggy, player_debug_glyph, glyph); + allocated = iggy_triangulate_cached( + iggy, owner, source, (float *)((uint8_t *)iggy + player_matrix), + scale, read_f32(iggy, player_scale_x), + read_f32(iggy, player_scale_y), -1.0f, NULL, 1, &failed, &results); + write_pointer(iggy, player_debug_label, 0); + iggy_free_shape_for_glyph(font, glyph, glyph_shape); + } + } + + if (failed == 0) { + float local[6] = {scale, 0.0f, 0.0f, scale, x, y}; + float saved[6]; + float combined[6]; + __builtin_memcpy( + saved, (const uint8_t *)iggy + player_matrix, sizeof(saved)); + iggy_matrix_concatenate( + combined, saved, local); + iggy_lowlevel_set_xform(iggy, combined); + for (int32_t index = 0; index < owner->section_count; ++index) { + draw_section( + iggy, owner, &source[index], NULL, 0.0f, rgba, 1, transform, + NULL, combined, 0, results == NULL ? NULL : &results[index], 0); + } + iggy_lowlevel_set_xform(iggy, saved); + if (allocated != 0) release_temporary_results(iggy, owner, results, 1); + telemetry_end(0x255U); + return 1; + } + telemetry_end(0x233U); + return 0; +} + +void iggy_draw_char( + void *iggy, IggyFont *font, float scale, int32_t glyph, + float x, float y, const uint8_t rgba[4], + const IggyRenderColorTransform *transform) { + font = resolve_font(iggy, font, &glyph); + if (font == NULL || iggy_glyph_is_empty(font, glyph) != 0) return; + if (character_cacheable( + iggy, font, glyph, scale, + read_f32(iggy, player_scale_x), read_f32(iggy, player_scale_y))) { + IggyBitmapCacheRecord *const record = find_bitmap_cache( + iggy, font, glyph, scale * read_f32(iggy, player_scale_x), + scale * read_f32(iggy, player_scale_y)); + if (record != NULL) { + draw_cached_character(iggy, record, scale, x, y); + return; + } + } + (void)draw_character_shape( + iggy, font, glyph, scale, x, y, rgba, transform); + write_i32( + iggy, player_shape_chars, read_i32(iggy, player_shape_chars) + 1); +} + +void iggy_iggyexp_char( + void *iggy, IggyFont *font, float scale, int32_t glyph, + IggyExpShapeStats *stats) { + font = resolve_font(iggy, font, &glyph); + if (font == NULL || iggy_glyph_is_empty(font, glyph) != 0) return; + if (character_cacheable( + iggy, font, glyph, scale, + read_f32(iggy, player_scale_x), read_f32(iggy, player_scale_y))) { + IggyBitmapCacheRecord *const record = find_bitmap_cache( + iggy, font, glyph, scale * read_f32(iggy, player_scale_x), + scale * read_f32(iggy, player_scale_y)); + if (record != NULL) { + stats->bitmap_records[stats->bitmap_count++] = (uintptr_t)record; + if (stats->bitmap_count == 64) { + iggy_flush_textureinfo_for_iggyexp(iggy, stats); + } + return; + } + } + + IggyShapeCacheOwner *owner = NULL; + if (read_i32(font, font_type) == 1) { + owner = embedded_character_shape(font, glyph); + } else if (read_pointer(font, font_shape_provider) != 0) { + owner = substituted_character_shape(font, glyph, 0); + } + if (owner == NULL) return; + if (iggy_measure_cached_triangulation( + iggy, owner, (const float *)((uint8_t *)iggy + player_matrix), + scale, read_f32(iggy, player_scale_x), + read_f32(iggy, player_scale_y), -1.0f, NULL, 1, + (IggyCachedTriangulationMeasure *)stats) != 0) { + const uint64_t id = stats->id; + send_shape_stats(iggy, id, stats); + memset(stats, 0, sizeof(*stats)); + stats->id = id; + } +} + +void iggy_fontcache_char( + void *iggy, IggyFont *font, float scale, int32_t glyph, + float unused_x, float unused_y, const float *matrix, + IggyVisibleGlyph *visible, int32_t *visible_count, + float scale_x, float scale_y) { + (void)unused_x; + (void)unused_y; + (void)matrix; + font = resolve_font(iggy, font, &glyph); + if (font == NULL || iggy_glyph_is_empty(font, glyph) != 0 || + !character_cacheable(iggy, font, glyph, scale, scale_x, scale_y)) { + return; + } + const int32_t index = *visible_count; + if (index >= iggy_max_visible_chars) return; + visible[index].font = font; + visible[index].glyph = glyph; + visible[index].scale_x = scale * scale_x; + visible[index].scale_y = scale * scale_y; + *visible_count = index + 1; + (void)find_bitmap_cache( + iggy, font, glyph, visible[index].scale_x, visible[index].scale_y); +} diff --git a/iggy-decompiled/src/reconstructed/swf_draw_shape_export.inc b/iggy-decompiled/src/reconstructed/swf_draw_shape_export.inc new file mode 100644 index 0000000..bfbb0ee --- /dev/null +++ b/iggy-decompiled/src/reconstructed/swf_draw_shape_export.inc @@ -0,0 +1,127 @@ +static IggyDescribeTextureCall gdraw_describe_texture(void) { + return ((IggyDescribeTextureCall *)iggy_gdraw)[25]; +} + +static IggyExportCall player_export_callback(void *iggy, void **exporter) { + *exporter = player_pointer(iggy, player_exporter); + if (*exporter == NULL) return NULL; + return *(IggyExportCall *)((uint8_t *)*exporter + 2U * sizeof(void *)); +} + +static void emit_export_packet(void *iggy, const IggyShapeTelemetryPacket *packet) { + void *exporter; + IggyExportCall const callback = player_export_callback(iggy, &exporter); + if (callback != NULL) callback(iggy, exporter, 0x88, packet, 0x330U); +} + +static void describe_queued_textures( + IggyShapeTelemetryPacket *packet, const IggyExpShapeStats *stats, + int32_t count) { + IggyExpTextureRecord *const records = + (IggyExpTextureRecord *)(packet->bytes + 0x28); + IggyDescribeTextureCall const describe = gdraw_describe_texture(); + for (int32_t index = 0; index < count; ++index) { + IggyTextureDescription description = {0}; + if (describe != NULL) describe(stats->textures[index], &description); + records[index].handle = (uint64_t)stats->textures[index]; + records[index].format = description.format; + records[index].width = description.width; + records[index].height = description.height; + } +} + +static void describe_queued_bitmaps( + IggyShapeTelemetryPacket *packet, const IggyExpShapeStats *stats, + int32_t count) { + IggyExpBitmapRecord *const records = + (IggyExpBitmapRecord *)(packet->bytes + 0x128); + for (int32_t index = 0; index < count; ++index) { + const uintptr_t bitmap = stats->bitmap_records[index]; + records[index].record = (uint64_t)bitmap; + if (bitmap == 0) continue; + const int16_t width = read_i16((const void *)bitmap, bitmap_slot - 0x10U); + const int16_t height = read_i16((const void *)bitmap, bitmap_slot - 0x0eU); + records[index].width = (uint16_t)width; + records[index].height = (uint16_t)height; + records[index].pixels = (uint32_t)((int32_t)(width + 1) * (int32_t)height); + } +} + +void iggy_flush_textureinfo_for_iggyexp( + void *iggy, IggyExpShapeStats *stats) { + while (stats->texture_count != 0 || stats->bitmap_count != 0) { + IggyShapeTelemetryPacket packet; + memset(&packet, 0, sizeof(packet)); + __builtin_memcpy(packet.bytes, &stats->id, sizeof(stats->id)); + const int32_t texture_count = + stats->texture_count < 16 ? stats->texture_count : 16; + const int32_t bitmap_count = + stats->bitmap_count < 32 ? stats->bitmap_count : 32; + describe_queued_textures(&packet, stats, texture_count); + describe_queued_bitmaps(&packet, stats, bitmap_count); + __builtin_memcpy(packet.bytes + 0x328, &texture_count, sizeof(texture_count)); + __builtin_memcpy(packet.bytes + 0x32c, &bitmap_count, sizeof(bitmap_count)); + emit_export_packet(iggy, &packet); + memmove( + stats->textures, stats->textures + texture_count, + (size_t)(stats->texture_count - texture_count) * sizeof(uintptr_t)); + memmove( + stats->bitmap_records, stats->bitmap_records + bitmap_count, + (size_t)(stats->bitmap_count - bitmap_count) * sizeof(uintptr_t)); + stats->texture_count -= texture_count; + stats->bitmap_count -= bitmap_count; + } +} + +static void send_shape_stats( + void *iggy, uint64_t id, IggyExpShapeStats *measurement) { + IggyShapeTelemetryPacket packet; + memset(&packet, 0, sizeof(packet)); + __builtin_memcpy(packet.bytes, &id, sizeof(id)); + const uint64_t cache_total = + (uint64_t)measurement->cache_entry + measurement->reserved; + __builtin_memcpy(packet.bytes + 8, &cache_total, sizeof(cache_total)); + __builtin_memcpy( + packet.bytes + 0x10, &measurement->sections, + 5U * sizeof(uint32_t)); + emit_export_packet(iggy, &packet); + iggy_flush_textureinfo_for_iggyexp(iggy, measurement); +} + +void iggy_get_shape_stats( + void *iggy, uint64_t id, IggyShapeCacheOwner *shape, + float morph_ratio, const IggyShapeSectionSource *morph_sections, + const float *slice_transform) { + if (read_i32(iggy, player_slice_enabled) != 0) { + iggy_9slice_set_fill_xform(iggy, slice_transform); + } + IggyExpShapeStats measurement; + memset(&measurement, 0, sizeof(measurement)); + if (iggy_measure_cached_triangulation( + iggy, shape, (const float *)((uint8_t *)iggy + player_matrix), + 1.0f, read_f32(iggy, player_scale_x), read_f32(iggy, player_scale_y), + morph_ratio, morph_sections, 0, + (IggyCachedTriangulationMeasure *)&measurement) != 0) { + send_shape_stats(iggy, id, &measurement); + } + + memset(&measurement, 0, sizeof(measurement)); + measurement.id = id; + IggyShapeSectionSource *const sources = + (IggyShapeSectionSource *)shape->section_sources; + for (int32_t section = 0; section < shape->section_count; ++section) { + const int32_t fill_count = section_fill_count(&sources[section]); + for (int32_t fill = 0; fill < fill_count; ++fill) { + const uintptr_t texture = (uintptr_t)iggy_get_fill_style_texture( + iggy, section_fill_style(&sources[section], fill)); + if (texture == 0) continue; + if (measurement.texture_count == 32) { + iggy_flush_textureinfo_for_iggyexp(iggy, &measurement); + } + measurement.textures[measurement.texture_count++] = texture; + } + } + if (measurement.texture_count != 0) { + iggy_flush_textureinfo_for_iggyexp(iggy, &measurement); + } +} diff --git a/iggy-decompiled/src/reconstructed/swf_draw_shape_render.inc b/iggy-decompiled/src/reconstructed/swf_draw_shape_render.inc new file mode 100644 index 0000000..423cd70 --- /dev/null +++ b/iggy-decompiled/src/reconstructed/swf_draw_shape_render.inc @@ -0,0 +1,454 @@ +static int32_t bitmap_smoothing(const void *display_object) { + const uint8_t flags = ((const uint8_t *)display_object)[display_smoothing]; + return (int32_t)(((flags >> 4U) & 1U) ^ iggy_fix_bitmap_smoothing); +} + +void iggy_get_char_renderstate( + void *iggy, IggyRenderState *state, const uint8_t rgba[4], + const IggyRenderColorTransform *transform) { + iggy_clear_renderstate(iggy, state); + state->flags &= ~4U; + state->blend_mode = 1; + iggy_setcolor_4ub_cxf( + state, rgba[0], rgba[1], rgba[2], rgba[3], transform); + state->color_transform_add = + transform != NULL && transform->additive_enabled != 0 + ? (int16_t *)((uint8_t *)transform + 0x14) + : NULL; + state->textures[0] = read_pointer(iggy, player_object_to_world); + state->texture_mode = ((uint8_t *)iggy)[player_rt_active] != 0 ? 5 : 2; +} + +void iggy_draw_text_bitmap( + void *iggy, IggyBitmap *bitmap, + const IggyRenderColorTransform *transform, + float x, float y, float width, float height, int32_t smoothing) { + IggyRenderState state; + iggy_setup_bitmap_renderstate( + iggy, &state, bitmap, transform, 1, smoothing); + state.flags &= ~4U; + state.texgen0_enabled = 0; + iggy_draw_rectangle( + iggy, &state, x, y, x + width, y + height, + 0.0f, 0.0f, 1.0f, 1.0f); + iggy_gdraw_UnlockHandles(iggy); +} + +static IggyBitmap *lookup_indirect_bitmap(const void *display_object) { + const uintptr_t slot = read_pointer(display_object, display_indirect_bitmap); + if (slot == 0) return NULL; + const uintptr_t entry = read_pointer((const void *)slot, 0); + if (entry == (uintptr_t)(as3vm_nullundef_storage + 1)) return NULL; + return entry == 0 + ? NULL + : (IggyBitmap *)read_pointer( + (const void *)entry, indirect_bitmap_pointer); +} + +void iggy_draw_bitmap_raw( + void *iggy, void *display_object, + const IggyRenderColorTransform *transform) { + IggyRenderState state; + const int32_t smoothing = bitmap_smoothing(display_object); + const uintptr_t direct = read_pointer(display_object, display_direct_texture); + float width; + float height; + + if (direct != 0) { + iggy_setup_bitmap_texture_renderstate( + iggy, &state, (IggyDirectTexture *)direct, transform, 1, smoothing); + width = (float)read_i32((const void *)direct, direct_texture_width); + height = (float)read_i32((const void *)direct, direct_texture_height); + } else { + IggyBitmap *bitmap = (IggyBitmap *)read_pointer(display_object, display_bitmap); + if (bitmap == NULL || ((const uint8_t *)bitmap)[0] != 4 || + read_i16(bitmap, 2) == 0) { + bitmap = lookup_indirect_bitmap(display_object); + if (bitmap == NULL) return; + } + iggy_setup_bitmap_renderstate( + iggy, &state, bitmap, transform, 1, smoothing); + width = (float)read_i16(bitmap, embedded_bitmap_width); + height = (float)read_i16(bitmap, embedded_bitmap_height); + } + + state.flags &= ~4U; + iggy_draw_rectangle_texgen(iggy, &state, 0.0f, 0.0f, width, height); + iggy_gdraw_UnlockHandles(iggy); +} + +static int32_t section_fill_count(const IggyShapeSectionSource *source) { + const uintptr_t fills = read_pointer(source, section_fill_styles); + return fills == 0 ? 0 : read_i32((const void *)fills, 0); +} + +static IggyFillStyle *section_fill_style( + const IggyShapeSectionSource *source, int32_t index) { + const uintptr_t fills = read_pointer(source, section_fill_styles); + return fills == 0 + ? NULL + : (IggyFillStyle *)((uint8_t *)fills + sizeof(void *) + + (size_t)index * sizeof(IggyFillStyle)); +} + +static IggyCachedVertexBufferSection make_temporary_section( + IggyCachedTriangulationSection *triangulation, + IggyPackedPrimitive *primitives) { + const uint16_t aa_count = triangulation->winding_count; + for (uint16_t index = 0; index < aa_count; ++index) { + IggyCachedAAChunk const *const chunk = &triangulation->bridged_windings[index]; + primitives[index].vertex_offset = (uintptr_t)chunk->vertices; + primitives[index].index_offset = (uintptr_t)chunk->indices; + primitives[index].vertex_count = chunk->vertex_count; + primitives[index].index_count = chunk->index_count; + primitives[index].joins_previous = 1; + primitives[index].vertex_format = 2; + primitives[index].reserved = 0; + } + + IggyPackedPrimitive *const fill = &primitives[aa_count]; + fill->vertex_offset = (uintptr_t)triangulation->vertices; + fill->index_offset = (uintptr_t)triangulation->indices; + fill->vertex_count = triangulation->vertex_count; + fill->index_count = triangulation->index_count; + fill->joins_previous = 0; + fill->vertex_format = 5; + fill->reserved = 0; + + IggyCachedVertexBufferSection section = {0}; + section.primitives = primitives; + section.primitive_count = (uint16_t)(aa_count + 1U); + __builtin_memcpy(section.bounds, triangulation->bounds, sizeof(section.bounds)); + __builtin_memcpy( + section.inverse_transform, triangulation->inverse_transform, + sizeof(section.inverse_transform)); + return section; +} + +static void draw_fill_section( + void *iggy, const IggyShapeSectionSource *source, + const IggyShapeSectionSource *morph_source, float morph_ratio, + const uint8_t *solid_rgba, const IggyRenderColorTransform *transform, + const IggyRenderBounds *bounds, const float *matrix, + IggyCachedVertexBufferSection *section, uintptr_t vertex_buffer, + int32_t render_target_aa, int32_t suppress_aa) { + const int32_t fill_count = solid_rgba != NULL ? 1 : section_fill_count(source); + for (int32_t fill_index = 0; fill_index < fill_count; ++fill_index) { + IggyCachedVertexBufferSection *const geometry = §ion[fill_index]; + if (geometry->primitive_count == 0) continue; + + IggyRenderState state; + if (solid_rgba != NULL) { + iggy_get_char_renderstate(iggy, &state, solid_rgba, transform); + } else { + const IggyShapeSectionSource *const morph = morph_source; + IggyFillStyle *const style = section_fill_style(source, fill_index); + const IggyRenderBounds *new_bounds = NULL; + const IggyRenderBounds *old_bounds = NULL; + if (read_i32(iggy, player_slice_enabled) != 0 && + read_pointer(source, section_slice_bounds) != 0) { + new_bounds = (const IggyRenderBounds *)( + read_pointer(source, section_slice_bounds) + + (uintptr_t)fill_index * sizeof(IggyRenderBounds)); + old_bounds = (const IggyRenderBounds *)geometry->bounds; + } + (void)morph; + iggy_setup_fill_style( + iggy, &state, style, morph_ratio, transform, new_bounds, + old_bounds, (const IggyFillMatrix *)matrix); + } + state.flags &= ~4U; + state.blend_mode = (uint8_t)(render_target_aa != 0 ? 3 : 1); + state.edge_matrix = geometry->inverse_transform; + uint8_t batch_mask = 4; + const size_t frame = + player_render_frames + + (size_t)read_i32(iggy, player_rt_depth) * 0x1cU; + if (((uint8_t *)iggy)[frame + player_render_frame_gate] == 0 && + suppress_aa == 0) { + int32_t count = read_i32(iggy, frame + player_render_frame_count); + if ((uint32_t)read_i32(iggy, player_batch_capacity) <= + (uint32_t)(count + fill_count)) { + IggyFlushBatchesCall const flush = + ((IggyFlushBatchesCall *)iggy_gdraw)[6]; + if (flush != NULL) flush(); + count = 1; + } + ++count; + write_i32(iggy, frame + player_render_frame_count, count); + state.identifier = count; + state.flags |= 3U; + batch_mask = 3; + } + for (uint16_t primitive = 0; primitive < geometry->primitive_count; + ++primitive) { + IggyPackedPrimitive const *const batch = &geometry->primitives[primitive]; + if ((batch->vertex_format & batch_mask) != 0) { + iggy_draw_batch( + iggy, &state, (const IggyDrawBatch *)batch, vertex_buffer); + state.flags |= 0x10U; + } + } + (void)bounds; + } +} + +static int32_t render_target_aa_count( + const IggyCachedVertexBufferSection *sections, int32_t fill_count) { + int32_t count = 0; + for (int32_t fill = 0; fill < fill_count; ++fill) { + if (sections[fill].primitive_count != 0 && + (sections[fill].flags & 1U) != 0) { + ++count; + } + } + return count; +} + +static void render_target_aa_bounds( + IggyRenderBounds *output, + const IggyShapeSectionSource *source, void *iggy, + const IggyCachedVertexBufferSection *sections, int32_t fill_count, + const float *matrix) { + const IggyRenderBounds *input = (const IggyRenderBounds *)source; + int32_t first = 1; + IggyRenderBounds combined = {0}; + if (read_i32(iggy, player_slice_enabled) != 0 && + read_i32(iggy, player_slice_bounds) != 0) { + for (int32_t fill = 0; fill < fill_count; ++fill) { + IggyRenderBounds const *const bounds = + (const IggyRenderBounds *)sections[fill].bounds; + if (first != 0) { + combined = *bounds; + first = 0; + } else { + if (bounds->minimum_x < combined.minimum_x) + combined.minimum_x = bounds->minimum_x; + if (bounds->minimum_y < combined.minimum_y) + combined.minimum_y = bounds->minimum_y; + if (bounds->maximum_x > combined.maximum_x) + combined.maximum_x = bounds->maximum_x; + if (bounds->maximum_y > combined.maximum_y) + combined.maximum_y = bounds->maximum_y; + } + } + input = &combined; + } + iggy_compute_bounds((float *)output, input, matrix); +} + +static int32_t should_use_render_target_aa( + void *iggy, const IggyCachedVertexBufferSection *sections, + int32_t fill_count, const IggyRenderBounds *bounds, const float *matrix, + int32_t disable_render_target_aa, int32_t suppress_aa) { + return sections != NULL && fill_count > 1 && bounds != NULL && + matrix != NULL && disable_render_target_aa == 0 && suppress_aa == 0 && + read_i32(iggy, player_rt_aa_enabled) != 0 && + ((uint8_t *)iggy)[player_rt_disabled] == 0 && + ((uint8_t *)iggy)[ + player_render_frames + + (size_t)read_i32(iggy, player_rt_depth) * 0x1cU + + player_render_frame_gate] == 0 && + read_i32(iggy, player_quality) > 9 && + render_target_aa_count(sections, fill_count) > 1; +} + +static void draw_stroke_mesh_cb( + const IggyStrokeMesh *mesh, void *context_pointer) { + void **const context = (void **)context_pointer; + iggy_draw_stroke_mesh(context[0], mesh, context[1]); +} + +static void draw_section_strokes( + void *iggy, IggyShapeCacheOwner *shape, + const IggyShapeSectionSource *source, + const IggyShapeSectionSource *morph_source, float morph_ratio, + const IggyRenderColorTransform *transform, const float *matrix, + int32_t suppress_aa) { + const uintptr_t stroke_list = read_pointer(source, section_stroke_styles); + if (stroke_list == 0) return; + const int32_t stroke_count = read_i32((const void *)stroke_list, 0); + const size_t header = sizeof(void *); + const size_t stride = sizeof(void *) == 8 ? 0x58U : 0x4cU; + for (int32_t stroke = 0; stroke < stroke_count; ++stroke) { + IggyFillStyle *const style = (IggyFillStyle *)( + stroke_list + header + (size_t)stroke * stride); + iggy_predraw_stroke_mesh(iggy, style); + } + const float stroke_scale_x = read_f32(iggy, player_stroke_scale_x); + const float stroke_scale_y = read_f32(iggy, player_stroke_scale_y); + const float matrix_values[4] = { + stroke_scale_x * read_f32(iggy, player_matrix), + stroke_scale_x * read_f32(iggy, player_matrix + 4U), + stroke_scale_y * read_f32(iggy, player_matrix + 8U), + stroke_scale_y * read_f32(iggy, player_matrix + 12U), + }; + const float translation[2] = { + stroke_scale_x * read_f32(iggy, player_matrix + 16U), + stroke_scale_y * read_f32(iggy, player_matrix + 20U), + }; + float x_extent = + read_f32(iggy, player_matrix) + read_f32(iggy, player_matrix + 4U); + float y_extent = + read_f32(iggy, player_matrix + 8U) + + read_f32(iggy, player_matrix + 12U); + if (x_extent < 0.0f) x_extent = 0.0f; + if (y_extent < 0.0f) y_extent = 0.0f; + const float stroke_bounds[4] = { + (read_f32(iggy, player_scale_x) + + read_f32(iggy, player_scale_y)) * 0.5f, + y_extent, + x_extent, + 1.0f, + }; + void *context[2] = {iggy, (void *)transform}; + iggy_stroke_path( + (void *)read_pointer(source, section_path), iggy, + matrix_values, translation, stroke_bounds, + source, morph_ratio, morph_source, suppress_aa, 0, + draw_stroke_mesh_cb, context); + (void)shape; + (void)matrix; +} + +static void draw_section( + void *iggy, IggyShapeCacheOwner *shape, + const IggyShapeSectionSource *source, + const IggyShapeSectionSource *morph_source, float morph_ratio, + const uint8_t *solid_rgba, int32_t character_mode, + const IggyRenderColorTransform *transform, + const IggyRenderBounds *bounds, const float *matrix, + int32_t disable_render_target_aa, IggyCachedDrawResult *result, + int32_t suppress_aa) { + const int32_t fill_count = solid_rgba != NULL ? 1 : section_fill_count(source); + if (solid_rgba == NULL && fill_count == 0 && + read_pointer(source, section_path) == 0) { + return; + } + + IggyCachedVertexBufferSection *sections = + result == NULL ? NULL : result->cpu_vertex_buffers; + if (sections == NULL && result != NULL && result->triangulation != NULL) { + size_t primitive_count = 0; + for (int32_t fill = 0; fill < fill_count; ++fill) { + primitive_count += + (size_t)result->triangulation[fill].winding_count + 1U; + } + IggyPackedPrimitive *const primitives = + (IggyPackedPrimitive *)__builtin_alloca( + primitive_count * sizeof(IggyPackedPrimitive)); + IggyCachedVertexBufferSection *const temporary = + (IggyCachedVertexBufferSection *)__builtin_alloca( + (size_t)fill_count * sizeof(IggyCachedVertexBufferSection)); + size_t primitive_offset = 0; + for (int32_t fill = 0; fill < fill_count; ++fill) { + temporary[fill] = make_temporary_section( + &result->triangulation[fill], &primitives[primitive_offset]); + primitive_offset += + (size_t)result->triangulation[fill].winding_count + 1U; + } + draw_fill_section( + iggy, source, morph_source, morph_ratio, solid_rgba, transform, + bounds, matrix, temporary, 0, 0, suppress_aa); + } else if (sections != NULL) { + const uintptr_t vertex_buffer = result == NULL ? 0 : result->vertex_buffer; + const int32_t render_target_aa = should_use_render_target_aa( + iggy, sections, fill_count, bounds, matrix, + disable_render_target_aa, suppress_aa); + IggyRenderBounds aa_bounds; + if (render_target_aa != 0) { + render_target_aa_bounds( + &aa_bounds, source, iggy, sections, fill_count, matrix); + telemetry_begin(0xc2U, &telemetry_formats[2], aa_zone); + if (iggy_start_nested_draw(iggy, &aa_bounds, 1, 0, 1) == 0) { + telemetry_end(0xc4U); + return; + } + } + draw_fill_section( + iggy, source, morph_source, morph_ratio, solid_rgba, transform, + bounds, matrix, sections, vertex_buffer, render_target_aa, + suppress_aa); + if (render_target_aa != 0) { + const IggyRenderTexture texture = iggy_end_nested_draw(iggy); + telemetry_end(0xfeU); + telemetry_begin(0xffU, &telemetry_formats[3], aa_composite_zone); + IggyRenderState state; + iggy_clear_renderstate(iggy, &state); + state.texture_mode = 1; + state.blend_mode = 1; + state.textures[0] = texture; + iggy_draw_screen_rect(iggy, &state, (const IggyDrawRect *)&aa_bounds); + iggy_gdraw_UnlockHandles(iggy); + iggy_gdraw_FreeTexture(iggy, texture, NULL); + telemetry_end(0x10dU); + } + } + + iggy_gdraw_UnlockHandles(iggy); + if (solid_rgba == NULL && character_mode == 0 && + ((const uint8_t *)source)[section_flags] == 0) { + draw_section_strokes( + iggy, shape, source, morph_source, morph_ratio, transform, matrix, + read_i32(iggy, player_quality) >= 4 && suppress_aa == 0); + } +} + +static void release_temporary_results( + void *iggy, IggyShapeCacheOwner *shape, + IggyCachedDrawResult *results, int32_t one_section) { + if (results == NULL) return; + const int32_t section_count = one_section != 0 ? 1 : shape->section_count; + IggyShapeSectionSource *const sources = + (IggyShapeSectionSource *)shape->section_sources; + for (int32_t section_index = 0; section_index < section_count; ++section_index) { + IggyCachedDrawResult *const result = &results[section_index]; + if (result->vertex_buffer != 0 || result->triangulation == NULL) continue; + const int32_t fills = section_fill_count(&sources[section_index]); + for (int32_t fill = 0; fill < fills; ++fill) { + result->triangulation[fill].status = 9; + } + iggy_free_triangulation( + iggy, &sources[section_index], result->triangulation, one_section); + iggy_free_alloc(iggy, result->triangulation); + } + iggy_free_alloc(iggy, results); +} + +int32_t iggy_draw_shape_raw( + void *iggy, IggyShapeCacheOwner *shape, float morph_ratio, + const IggyShapeSectionSource *morph_sections, + const IggyRenderColorTransform *transform, + const IggyRenderBounds *bounds, const float *matrix, + int32_t disable_render_target_aa, int32_t suppress_aa) { + telemetry_begin(0x1a1U, &telemetry_formats[0], shape_zone); + if (read_i32(iggy, player_slice_enabled) != 0) { + iggy_9slice_set_fill_xform(iggy, matrix); + } + + int32_t failed = 0; + IggyCachedDrawResult *results = NULL; + const int32_t allocated = iggy_triangulate_cached( + iggy, shape, shape->section_sources, + (float *)((uint8_t *)iggy + player_matrix), + 1.0f, read_f32(iggy, player_scale_x), read_f32(iggy, player_scale_y), + morph_ratio, morph_sections, 0, &failed, &results); + if (failed != 0) { + telemetry_end(0x1bdU); + return 0; + } + + const float draw_morph = morph_ratio < 0.0f ? 0.0f : morph_ratio; + IggyShapeSectionSource *const sources = + (IggyShapeSectionSource *)shape->section_sources; + for (int32_t index = 0; index < shape->section_count; ++index) { + draw_section( + iggy, shape, &sources[index], + morph_sections == NULL ? NULL : &morph_sections[index], draw_morph, + NULL, 0, transform, bounds, matrix, disable_render_target_aa, + results == NULL ? NULL : &results[index], suppress_aa); + } + if (allocated != 0) release_temporary_results(iggy, shape, results, 0); + telemetry_end(0x1e1U); + return 1; +} diff --git a/tests/support/swf_draw_shape_test_support.c b/tests/support/swf_draw_shape_test_support.c new file mode 100644 index 0000000..90a9af5 --- /dev/null +++ b/tests/support/swf_draw_shape_test_support.c @@ -0,0 +1,527 @@ +#include +#include +#include +#include + +enum { SHAPE_TEST_STATE_BYTES = 240, SHAPE_TEST_PACKET_BYTES = 0x330 }; + +typedef struct ShapeTestDrawResult { + void *triangulation; + uintptr_t vertex_buffer; + void *cpu_vertex_buffers; +} ShapeTestDrawResult; + +int shape_test_setup_bitmap_calls; +int shape_test_setup_texture_calls; +int shape_test_rectangle_calls; +int shape_test_texgen_calls; +int shape_test_unlock_calls; +int shape_test_clear_calls; +int shape_test_setcolor_calls; +int shape_test_describe_calls; +int shape_test_export_calls; +int shape_test_free_alloc_calls; +int shape_test_free_triangulation_calls; +int shape_test_draw_batch_calls; +int shape_test_triangulate_calls; +int shape_test_triangulate_failed; +int shape_test_triangulate_allocated; +int shape_test_compute_bounds_calls; +int shape_test_start_nested_calls; +int shape_test_end_nested_calls; +int shape_test_screen_rect_calls; +int shape_test_free_texture_calls; +int shape_test_predraw_stroke_calls; +int shape_test_stroke_path_calls; +int shape_test_buffered_rect_calls; +int shape_test_measure_calls; +int shape_test_measure_result; +int shape_test_fill_texture_calls; +int shape_test_onesection_calls; +int shape_test_onesection_result; +int shape_test_get_shape_calls; +int shape_test_lowlevel_xform_calls; +int shape_test_glyph_empty; +int shape_test_fallback_calls; +int shape_test_glyph_empty_calls; +int shape_test_metrics_calls; +int shape_test_cacheable_callback_calls; +int shape_test_cacheable_callback_result; +int shape_test_send_error_calls; +int shape_test_last_error_code; +int shape_test_free_shape_calls; +int shape_test_malloc_calls; +int shape_test_malloc_fail; +int shape_test_triangulate_null_result; +int shape_test_last_glyph; +int shape_test_start_nested_result; +int shape_test_start_nested_needs_identifier; +int shape_test_telemetry_begin_calls; +int shape_test_telemetry_end_calls; +int shape_test_last_smoothing; +int shape_test_last_event; +int shape_test_last_packet_size; +int shape_test_describe_width; +int shape_test_describe_height; +uint32_t shape_test_describe_format; +uintptr_t shape_test_setup_resource; +uintptr_t shape_test_setup_transform; +uintptr_t shape_test_nested_texture; +uintptr_t shape_test_fill_texture_result; +uintptr_t shape_test_fallback_font; +uintptr_t shape_test_last_vertex_buffer; +uintptr_t shape_test_last_predraw_style; +uintptr_t shape_test_last_stroke_path; +uintptr_t shape_test_fill_new_bounds; +uintptr_t shape_test_fill_old_bounds; +uintptr_t shape_test_fill_extra_matrix; +uintptr_t shape_test_glyph_shape_output; +uintptr_t shape_test_triangulate_source; +uintptr_t shape_test_freed[16]; +uintptr_t shape_test_free_triangulations[16]; +float shape_test_rectangle[8]; +float shape_test_texgen[4]; +float shape_test_buffered_rect[8]; +float shape_test_metrics[6]; +float shape_test_cacheable_callback_scale; +uint8_t shape_test_captured_state[SHAPE_TEST_STATE_BYTES]; +uint8_t shape_test_packets[4][SHAPE_TEST_PACKET_BYTES]; +uint8_t shape_test_drawn_vertex_formats[16]; +uint8_t shape_test_call_order[64]; +int shape_test_call_order_count; +ShapeTestDrawResult shape_test_draw_result; + +uint8_t as3vm_nullundef_storage[16]; +int32_t iggy_max_visible_chars = 1024; +void *iggy_tm_normal; +void *iggy_gdraw; + +static void *shape_test_gdraw_table[32]; +static void *shape_test_telemetry_table[22]; +static uint8_t shape_test_exporter[32]; + +static void shape_test_note(uint8_t event) { + if (shape_test_call_order_count < (int)sizeof(shape_test_call_order)) { + shape_test_call_order[shape_test_call_order_count] = event; + } + ++shape_test_call_order_count; +} + +static void shape_test_telemetry_begin(void *context, ...) { + (void)context; + ++shape_test_telemetry_begin_calls; +} + +static void shape_test_telemetry_end(void *context, ...) { + (void)context; + ++shape_test_telemetry_end_calls; +} + +void shape_test_install_telemetry(void) { + memset(shape_test_telemetry_table, 0, sizeof(shape_test_telemetry_table)); + shape_test_telemetry_table[20] = + (void *)(uintptr_t)(void (*)(void))shape_test_telemetry_begin; + shape_test_telemetry_table[21] = + (void *)(uintptr_t)(void (*)(void))shape_test_telemetry_end; + iggy_tm_normal = shape_test_telemetry_table; +} + +static void shape_test_describe_texture(uintptr_t handle, void *description) { + (void)handle; + ++shape_test_describe_calls; + *(uint16_t *)description = (uint16_t)shape_test_describe_width; + *(uint16_t *)((uint8_t *)description + 2) = (uint16_t)shape_test_describe_height; + *(uint32_t *)((uint8_t *)description + 4) = shape_test_describe_format; +} + +static void shape_test_export( + void *iggy, void *exporter, int32_t event, const void *packet, + uint32_t packet_size) { + (void)iggy; + (void)exporter; + shape_test_last_event = event; + shape_test_last_packet_size = (int)packet_size; + if (shape_test_export_calls < 4 && packet != 0) { + memcpy(shape_test_packets[shape_test_export_calls], packet, + packet_size < SHAPE_TEST_PACKET_BYTES ? packet_size + : SHAPE_TEST_PACKET_BYTES); + } + ++shape_test_export_calls; +} + +void shape_test_install_exporter(void *iggy, uintptr_t offset) { + *(void **)((uint8_t *)iggy + offset) = shape_test_exporter; +} + +void shape_test_set_draw_result( + void *triangulation, uintptr_t vertex_buffer, void *cpu_vertex_buffers) { + shape_test_draw_result.triangulation = triangulation; + shape_test_draw_result.vertex_buffer = vertex_buffer; + shape_test_draw_result.cpu_vertex_buffers = cpu_vertex_buffers; +} + +void shape_test_reset(void) { + shape_test_setup_bitmap_calls = 0; + shape_test_setup_texture_calls = 0; + shape_test_rectangle_calls = 0; + shape_test_texgen_calls = 0; + shape_test_unlock_calls = 0; + shape_test_clear_calls = 0; + shape_test_setcolor_calls = 0; + shape_test_describe_calls = 0; + shape_test_export_calls = 0; + shape_test_free_alloc_calls = 0; + shape_test_free_triangulation_calls = 0; + shape_test_draw_batch_calls = 0; + shape_test_triangulate_calls = 0; + shape_test_triangulate_failed = 0; + shape_test_triangulate_allocated = 0; + shape_test_compute_bounds_calls = 0; + shape_test_start_nested_calls = 0; + shape_test_end_nested_calls = 0; + shape_test_screen_rect_calls = 0; + shape_test_free_texture_calls = 0; + shape_test_predraw_stroke_calls = 0; + shape_test_stroke_path_calls = 0; + shape_test_buffered_rect_calls = 0; + shape_test_measure_calls = 0; + shape_test_measure_result = 0; + shape_test_fill_texture_calls = 0; + shape_test_onesection_calls = 0; + shape_test_onesection_result = 0; + shape_test_get_shape_calls = 0; + shape_test_lowlevel_xform_calls = 0; + shape_test_glyph_empty = 0; + shape_test_fallback_calls = 0; + shape_test_glyph_empty_calls = 0; + shape_test_metrics_calls = 0; + shape_test_cacheable_callback_calls = 0; + shape_test_cacheable_callback_result = 0; + shape_test_send_error_calls = 0; + shape_test_last_error_code = 0; + shape_test_free_shape_calls = 0; + shape_test_malloc_calls = 0; + shape_test_malloc_fail = 0; + shape_test_triangulate_null_result = 0; + shape_test_last_glyph = -1; + shape_test_start_nested_result = 1; + shape_test_start_nested_needs_identifier = 0; + shape_test_telemetry_begin_calls = 0; + shape_test_telemetry_end_calls = 0; + shape_test_last_smoothing = -1; + shape_test_last_event = 0; + shape_test_last_packet_size = 0; + shape_test_describe_width = 17; + shape_test_describe_height = 9; + shape_test_describe_format = 0x12345678U; + shape_test_setup_resource = 0; + shape_test_setup_transform = 0; + shape_test_nested_texture = 0x8888; + shape_test_fill_texture_result = 0; + shape_test_fallback_font = 0; + shape_test_last_vertex_buffer = 0; + shape_test_last_predraw_style = 0; + shape_test_last_stroke_path = 0; + shape_test_fill_new_bounds = 0; + shape_test_fill_old_bounds = 0; + shape_test_fill_extra_matrix = 0; + shape_test_glyph_shape_output = 0; + shape_test_triangulate_source = 0; + memset(shape_test_freed, 0, sizeof(shape_test_freed)); + memset(shape_test_free_triangulations, 0, + sizeof(shape_test_free_triangulations)); + memset(shape_test_rectangle, 0, sizeof(shape_test_rectangle)); + memset(shape_test_texgen, 0, sizeof(shape_test_texgen)); + memset(shape_test_buffered_rect, 0, sizeof(shape_test_buffered_rect)); + memset(shape_test_metrics, 0, sizeof(shape_test_metrics)); + shape_test_cacheable_callback_scale = 0.0f; + memset(shape_test_captured_state, 0, sizeof(shape_test_captured_state)); + memset(shape_test_packets, 0, sizeof(shape_test_packets)); + memset(shape_test_drawn_vertex_formats, 0, + sizeof(shape_test_drawn_vertex_formats)); + memset(shape_test_call_order, 0, sizeof(shape_test_call_order)); + shape_test_call_order_count = 0; + memset(&shape_test_draw_result, 0, sizeof(shape_test_draw_result)); + memset(shape_test_gdraw_table, 0, sizeof(shape_test_gdraw_table)); + shape_test_gdraw_table[25] = (void *)(uintptr_t)(void (*)(void))shape_test_describe_texture; + memset(shape_test_exporter, 0, sizeof(shape_test_exporter)); + *(void **)(shape_test_exporter + 16) = + (void *)(uintptr_t)(void (*)(void))shape_test_export; + iggy_gdraw = shape_test_gdraw_table; + iggy_tm_normal = 0; + iggy_max_visible_chars = 1024; +} + +void iggy_clear_renderstate(void *iggy, void *state) { + (void)iggy; + ++shape_test_clear_calls; + memset(state, 0, SHAPE_TEST_STATE_BYTES); + *(uint32_t *)((uint8_t *)state + 4) = UINT32_MAX; + shape_test_note(5); +} + +void iggy_setcolor_4ub_cxf( + void *state, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha, + const void *transform) { + (void)state; + (void)red; + (void)green; + (void)blue; + (void)alpha; + shape_test_setup_transform = (uintptr_t)transform; + ++shape_test_setcolor_calls; +} + +void iggy_setup_bitmap_renderstate( + void *iggy, void *state, const void *resource, const void *transform, + int32_t texture, int32_t smoothing) { + (void)iggy; + (void)texture; + memset(state, 0, SHAPE_TEST_STATE_BYTES); + *(uint32_t *)((uint8_t *)state + 4) = UINT32_MAX; + shape_test_setup_resource = (uintptr_t)resource; + shape_test_setup_transform = (uintptr_t)transform; + shape_test_last_smoothing = smoothing; + ++shape_test_setup_bitmap_calls; +} + +void iggy_setup_bitmap_texture_renderstate( + void *iggy, void *state, const void *resource, const void *transform, + int32_t texture, int32_t smoothing) { + ++shape_test_setup_texture_calls; + iggy_setup_bitmap_renderstate( + iggy, state, resource, transform, texture, smoothing); + --shape_test_setup_bitmap_calls; +} + +void iggy_draw_rectangle( + void *iggy, const void *state, float x0, float y0, float x1, float y1, + float s0, float t0, float s1, float t1) { + (void)iggy; + const float values[8] = {x0, y0, x1, y1, s0, t0, s1, t1}; + memcpy(shape_test_rectangle, values, sizeof(values)); + memcpy(shape_test_captured_state, state, SHAPE_TEST_STATE_BYTES); + ++shape_test_rectangle_calls; +} + +void iggy_draw_rectangle_texgen( + void *iggy, const void *state, float x0, float y0, float x1, float y1) { + (void)iggy; + const float values[4] = {x0, y0, x1, y1}; + memcpy(shape_test_texgen, values, sizeof(values)); + memcpy(shape_test_captured_state, state, SHAPE_TEST_STATE_BYTES); + ++shape_test_texgen_calls; +} + +void iggy_gdraw_UnlockHandles(void *iggy) { + (void)iggy; + ++shape_test_unlock_calls; + shape_test_note(7); +} + +int32_t iggy_triangulate_cached( + void *iggy, void *shape, const void *source, float *matrix, float scale, + float scale_x, float scale_y, float morph_ratio, + const void *morph_sections, int32_t one_section, int32_t *failed, + ShapeTestDrawResult **results) { + (void)iggy; + (void)shape; + shape_test_triangulate_source = (uintptr_t)source; + (void)matrix; + (void)scale; + (void)scale_x; + (void)scale_y; + (void)morph_ratio; + (void)morph_sections; + (void)one_section; + ++shape_test_triangulate_calls; + *failed = shape_test_triangulate_failed; + *results = shape_test_triangulate_failed || shape_test_triangulate_null_result + ? 0 + : &shape_test_draw_result; + return shape_test_triangulate_allocated; +} + +void iggy_free_alloc(void *iggy, void *allocation) { + (void)iggy; + if (shape_test_free_alloc_calls < 16) { + shape_test_freed[shape_test_free_alloc_calls] = (uintptr_t)allocation; + } + ++shape_test_free_alloc_calls; +} + +void iggy_free_triangulation( + void *iggy, const void *source, void *triangulation, int32_t one_section) { + (void)iggy; + (void)source; + (void)one_section; + if (shape_test_free_triangulation_calls < 16) { + shape_test_free_triangulations[shape_test_free_triangulation_calls] = + (uintptr_t)triangulation; + } + ++shape_test_free_triangulation_calls; +} + +void iggy_9slice_set_fill_xform(void *iggy, const void *matrix) { + (void)iggy; + (void)matrix; +} +void iggy_compute_bounds(float *output, const void *input, const float *matrix) { + (void)input; + (void)matrix; + memset(output, 0, 16); + ++shape_test_compute_bounds_calls; + shape_test_note(1); +} +void iggy_draw_batch(void *iggy, void *state, const void *batch, uintptr_t buffer) { + (void)iggy; (void)state; + const uint8_t format = *((const uint8_t *)batch + 25); + if (shape_test_draw_batch_calls < 16) { + shape_test_drawn_vertex_formats[shape_test_draw_batch_calls] = format; + } + shape_test_last_vertex_buffer = buffer; + ++shape_test_draw_batch_calls; + shape_test_note(3); +} +void iggy_draw_buffered_rect( + void *iggy, float x0, float y0, float x1, float y1, + float s0, float t0, float s1, float t1, int32_t nearest) { + (void)iggy; + (void)nearest; + const float values[8] = {x0, y0, x1, y1, s0, t0, s1, t1}; + memcpy(shape_test_buffered_rect, values, sizeof(values)); + ++shape_test_buffered_rect_calls; +} +void iggy_draw_screen_rect(void *iggy, void *state, const void *bounds) { + (void)iggy; (void)state; (void)bounds; + ++shape_test_screen_rect_calls; + shape_test_note(6); +} +void iggy_draw_stroke_mesh(void *iggy, const void *mesh, const void *transform) { + (void)iggy; (void)mesh; (void)transform; +} +uintptr_t iggy_end_nested_draw(void *iggy) { + (void)iggy; + ++shape_test_end_nested_calls; + shape_test_note(4); + return shape_test_nested_texture; +} +void iggy_free_shape_for_glyph(void *font, int32_t glyph, void *shape) { + (void)font; (void)glyph; (void)shape; + ++shape_test_free_shape_calls; +} +void iggy_gdraw_FreeTexture(void *iggy, uintptr_t texture, void *id) { + (void)iggy; (void)id; + shape_test_nested_texture = texture; + ++shape_test_free_texture_calls; + shape_test_note(8); +} +void *iggy_get_fallback_font(void *iggy) { + (void)iggy; + ++shape_test_fallback_calls; + return (void *)shape_test_fallback_font; +} +void *iggy_get_fill_style_texture(void *iggy, const void *style) { + (void)iggy; (void)style; + ++shape_test_fill_texture_calls; + return (void *)shape_test_fill_texture_result; +} +void *iggy_get_glyph_metrics(void *font, int32_t glyph, void *metrics) { + (void)font; (void)glyph; + ++shape_test_metrics_calls; + memcpy(metrics, shape_test_metrics, sizeof(shape_test_metrics)); + return metrics; +} +void iggy_get_shape_for_glyph(void *font, int32_t glyph, void *shape) { + (void)font; (void)glyph; memset(shape, 0, 32); + shape_test_glyph_shape_output = (uintptr_t)shape; + ++shape_test_get_shape_calls; +} +int32_t iggy_glyph_is_empty(void *font, int32_t glyph) { + (void)font; + ++shape_test_glyph_empty_calls; + shape_test_last_glyph = glyph; + return shape_test_glyph_empty; +} +void iggy_lowlevel_set_xform(void *iggy, const float *matrix) { + (void)iggy; (void)matrix; + ++shape_test_lowlevel_xform_calls; +} +void *iggy_malloc_CANFAIL_fileline( + int32_t arena, uint32_t count, uint32_t size, const char *file, + int32_t line) { + (void)arena; (void)count; (void)file; (void)line; + ++shape_test_malloc_calls; + if (shape_test_malloc_fail != 0) return NULL; + return calloc(1, size); +} +void iggy_matrix_concatenate(float *output, const float *left, const float *right) { + (void)left; memcpy(output, right, 24); +} +int32_t iggy_measure_cached_triangulation( + void *iggy, void *shape, const float *matrix, float scale, + float scale_x, float scale_y, float morph_ratio, const void *morph, + int32_t one_section, void *measurement) { + (void)iggy; (void)shape; (void)matrix; (void)scale; (void)scale_x; + (void)scale_y; (void)morph_ratio; (void)morph; (void)one_section; + ++shape_test_measure_calls; + if (shape_test_measure_result != 0) { + *(uintptr_t *)((uint8_t *)measurement + 8) = 0x1000; + *(uint32_t *)((uint8_t *)measurement + 16) = 0x20; + *(uint32_t *)((uint8_t *)measurement + 20) = 2; + *(uint32_t *)((uint8_t *)measurement + 24) = 3; + *(uint32_t *)((uint8_t *)measurement + 28) = 4; + *(uint32_t *)((uint8_t *)measurement + 32) = 5; + *(uint32_t *)((uint8_t *)measurement + 36) = 6; + } + return shape_test_measure_result; +} +int32_t iggy_onesection_get_cached_triangulation( + void *iggy, void *shape, const float *matrix, float scale, + float scale_x, float scale_y, int32_t one_section, + ShapeTestDrawResult *result) { + (void)iggy; (void)shape; (void)matrix; (void)scale; (void)scale_x; + (void)scale_y; (void)one_section; + ++shape_test_onesection_calls; + if (shape_test_onesection_result != 0) *result = shape_test_draw_result; + return shape_test_onesection_result; +} +void iggy_predraw_stroke_mesh(void *iggy, const void *style) { + (void)iggy; + shape_test_last_predraw_style = (uintptr_t)style; + ++shape_test_predraw_stroke_calls; +} +void iggy_send_error(void *iggy, int32_t code, const char *message) { + (void)iggy; (void)message; + ++shape_test_send_error_calls; + shape_test_last_error_code = code; +} +int32_t shape_test_cacheable_callback( + void *font_data, int32_t glyph, float scale) { + (void)font_data; + shape_test_last_glyph = glyph; + shape_test_cacheable_callback_scale = scale; + ++shape_test_cacheable_callback_calls; + return shape_test_cacheable_callback_result; +} +void iggy_setup_fill_style( + void *iggy, void *state, void *style, float morph, const void *transform, + const void *new_bounds, const void *old_bounds, const void *extra_matrix) { + (void)iggy; (void)state; (void)style; (void)morph; (void)transform; + shape_test_fill_new_bounds = (uintptr_t)new_bounds; + shape_test_fill_old_bounds = (uintptr_t)old_bounds; + shape_test_fill_extra_matrix = (uintptr_t)extra_matrix; +} +int32_t iggy_start_nested_draw( + void *iggy, const void *bounds, int32_t needs_color, + int32_t needs_stencil, int32_t needs_identifier) { + (void)iggy; (void)bounds; (void)needs_color; (void)needs_stencil; + shape_test_start_nested_needs_identifier = needs_identifier; + ++shape_test_start_nested_calls; + shape_test_note(2); + return shape_test_start_nested_result; +} +void iggy_stroke_path(void *path, ...) { + shape_test_last_stroke_path = (uintptr_t)path; + ++shape_test_stroke_path_calls; +} diff --git a/tests/test_reconstructed_swf_draw_shape.py b/tests/test_reconstructed_swf_draw_shape.py new file mode 100644 index 0000000..62521ed --- /dev/null +++ b/tests/test_reconstructed_swf_draw_shape.py @@ -0,0 +1,1135 @@ +import ctypes +import os +from pathlib import Path +import shlex +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed" +SOURCE = RECONSTRUCTED / "swf_draw_shape.c" +HEADER = RECONSTRUCTED / "swf_draw_shape.h" +SUPPORT = ROOT / "tests/support/swf_draw_shape_test_support.c" +VARIANTS = { + name: f"IGGY_RECONSTRUCT_SWF_DRAW_SHAPE_{name.upper()}" + for name in ("durango", "orbis", "ps3", "vita") +} +OFFSETS = { + "durango": {"o2w": 0x468, "mode": 0x2294, "exporter": 0x2888, + "scale": 0x1F3C, "matrix": 0x1F54, "cache_max": 0x1E9C, + "cache_ratio": 0x1EB0, "frame": 0x2878, + "buffered": 0x28E0, "shape_chars": 0x28E4, + "rt_aa": 0x1F2C, "quality": 0x1E98, "rt_disabled": 0x2295, + "slice": 0x2298, "slice_bounds": 0x229C}, + "orbis": {"o2w": 0x468, "mode": 0x2294, "exporter": 0x2888, + "scale": 0x1F3C, "matrix": 0x1F54, "cache_max": 0x1E9C, + "cache_ratio": 0x1EB0, "frame": 0x2878, + "buffered": 0x28E0, "shape_chars": 0x28E4, + "rt_aa": 0x1F2C, "quality": 0x1E98, "rt_disabled": 0x2295, + "slice": 0x2298, "slice_bounds": 0x229C}, + "ps3": {"o2w": 0x318, "mode": 0x1CF8, "exporter": 0x21A8, + "scale": 0x19CC, "matrix": 0x19E4, "cache_max": 0x1940, + "cache_ratio": 0x1954, "frame": 0x2198, + "buffered": 0x21F8, "shape_chars": 0x21FC, + "rt_aa": 0x19BC, "quality": 0x193C, "rt_disabled": 0x1CF9, + "slice": 0x1CFC, "slice_bounds": 0x1D00}, + "vita": {"o2w": 0x318, "mode": 0x1CF8, "exporter": 0x21A8, + "scale": 0x19CC, "matrix": 0x19E4, "cache_max": 0x1940, + "cache_ratio": 0x1954, "frame": 0x2198, + "buffered": 0x21F8, "shape_chars": 0x21FC, + "rt_aa": 0x19BC, "quality": 0x193C, "rt_disabled": 0x1CF9, + "slice": 0x1CFC, "slice_bounds": 0x1D00}, +} + + +class PackedPrimitive(ctypes.Structure): + _fields_ = [ + ("vertices", ctypes.c_size_t), ("indices", ctypes.c_size_t), + ("vertex_count", ctypes.c_int32), ("index_count", ctypes.c_int32), + ("joins_previous", ctypes.c_uint8), ("vertex_format", ctypes.c_uint8), + ("reserved", ctypes.c_uint16), + ] + + +class VertexBufferSection(ctypes.Structure): + _fields_ = [ + ("primitives", ctypes.POINTER(PackedPrimitive)), + ("primitive_count", ctypes.c_uint16), ("status", ctypes.c_uint8), + ("flags", ctypes.c_uint8), ("bounds", ctypes.c_float * 4), + ("inverse", ctypes.c_float * 4), + ] + + +class VisibleGlyph(ctypes.Structure): + _fields_ = [ + ("font", ctypes.c_void_p), ("glyph", ctypes.c_int32), + ("scale_x", ctypes.c_float), ("scale_y", ctypes.c_float), + ] + + +class ShapeOwner(ctypes.Structure): + _fields_ = [ + ("cache_head", ctypes.c_void_p), + ("section_count", ctypes.c_int16), + ("cache_policy", ctypes.c_uint8), + ("indirect_owner", ctypes.c_uint8), + ("allocator_owner", ctypes.c_void_p), + ("section_sources", ctypes.c_void_p), + ] + + +class ExpShapeStats(ctypes.Structure): + _fields_ = [ + ("id", ctypes.c_uint64), ("cache_entry", ctypes.c_size_t), + ("reserved", ctypes.c_uint32), ("sections", ctypes.c_uint32), + ("draws", ctypes.c_uint32), ("vertices", ctypes.c_uint32), + ("indices", ctypes.c_uint32), ("vertex_buffer_bytes", ctypes.c_uint32), + ("textures", ctypes.c_size_t * 32), + ("bitmap_records", ctypes.c_size_t * 64), + ("texture_count", ctypes.c_int32), ("bitmap_count", ctypes.c_int32), + ] + + +class ReconstructedSwfDrawShapeTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + missing = [str(path) for path in (SOURCE, HEADER) if not path.exists()] + if missing: + raise AssertionError("missing reconstructed swf_draw_shape source/header: " + + ", ".join(missing)) + 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 = {} + for platform, define in VARIANTS.items(): + output = build / f"swf_draw_shape_{platform}.dylib" + result = subprocess.run([ + "clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra", + "-Werror", 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)) + library = ctypes.CDLL(str(output)) + cls.configure(library) + cls.libs[platform] = library + + @classmethod + def tearDownClass(cls): + cls.temp.cleanup() + + @staticmethod + def configure(lib): + lib.shape_test_reset.argtypes = [] + lib.shape_test_install_telemetry.argtypes = [] + lib.shape_test_install_exporter.argtypes = [ctypes.c_void_p, ctypes.c_size_t] + lib.shape_test_set_draw_result.argtypes = [ + ctypes.c_void_p, ctypes.c_size_t, ctypes.c_void_p] + lib.iggy_get_char_renderstate.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p] + lib.iggy_draw_text_bitmap.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, + ctypes.c_float, ctypes.c_float, ctypes.c_float, ctypes.c_float, + ctypes.c_int32] + lib.iggy_draw_bitmap_raw.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p] + lib.iggy_flush_textureinfo_for_iggyexp.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p] + lib.iggy_draw_shape_raw.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_void_p, + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, + ctypes.c_uint32, ctypes.c_int32] + lib.iggy_draw_shape_raw.restype = ctypes.c_int32 + lib.iggy_get_shape_stats.argtypes = [ + ctypes.c_void_p, ctypes.c_uint64, ctypes.c_void_p, + ctypes.c_float, ctypes.c_void_p, ctypes.c_void_p] + lib.iggy_draw_char.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_int32, + ctypes.c_float, ctypes.c_float, ctypes.c_void_p, ctypes.c_void_p] + lib.iggy_iggyexp_char.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_int32, + ctypes.POINTER(ExpShapeStats)] + lib.iggy_fontcache_char.argtypes = [ + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_float, ctypes.c_int32, + ctypes.c_float, ctypes.c_float, ctypes.c_void_p, + ctypes.POINTER(VisibleGlyph), ctypes.POINTER(ctypes.c_int32), + ctypes.c_float, ctypes.c_float] + lib.shape_test_cacheable_callback.argtypes = [ + ctypes.c_void_p, ctypes.c_int32, ctypes.c_float] + lib.shape_test_cacheable_callback.restype = ctypes.c_int32 + + def setUp(self): + for lib in self.libs.values(): + lib.shape_test_reset() + ctypes.c_uint8.in_dll(lib, "iggy_fix_bitmap_smoothing").value = 1 + + @staticmethod + def integer(lib, name): + return ctypes.c_int.in_dll(lib, name).value + + @staticmethod + def floats(lib, name, count): + return tuple((ctypes.c_float * count).in_dll(lib, name)) + + @staticmethod + def player(platform): + player = (ctypes.c_uint8 * 0x3600)() + offsets = OFFSETS[platform] + ctypes.c_float.from_buffer(player, offsets["scale"]).value = 2.0 + ctypes.c_float.from_buffer(player, offsets["scale"] + 4).value = 3.0 + matrix = (ctypes.c_float * 6).from_buffer(player, offsets["matrix"]) + matrix[:] = (1, 0, 0, 1, 0, 0) + return player + + @staticmethod + def font(glyph_count=1): + font = (ctypes.c_uint8 * 0x100)() + ctypes.c_int32.from_buffer(font, 0x34).value = glyph_count + return font + + @staticmethod + def set_cache_limits(player, platform, maximum=1000.0): + offsets = OFFSETS[platform] + ctypes.c_float.from_buffer(player, offsets["cache_max"]).value = maximum + ctypes.c_float.from_buffer(player, offsets["cache_max"] + 4).value = maximum + ctypes.c_float.from_buffer(player, offsets["cache_ratio"]).value = 0.5 + ctypes.c_float.from_buffer(player, offsets["cache_ratio"] + 4).value = 2.0 + + def test_get_char_renderstate_sets_exact_flags_transform_and_mode(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + state = (ctypes.c_uint8 * 240)() + rgba = (ctypes.c_uint8 * 4)(1, 2, 3, 4) + transform = (ctypes.c_uint8 * 64)() + transform[1] = 1 + ctypes.c_void_p.from_buffer(player, OFFSETS[platform]["o2w"]).value = 0x12345678 + player[OFFSETS[platform]["mode"]] = 0 + + lib.iggy_get_char_renderstate( + player, state, rgba, ctypes.byref(transform)) + + self.assertEqual(self.integer(lib, "shape_test_clear_calls"), 1, platform) + self.assertEqual(self.integer(lib, "shape_test_setcolor_calls"), 1, platform) + self.assertEqual(state[12], 1, platform) + self.assertEqual(ctypes.c_uint32.from_buffer(state, 4).value & 4, 0, platform) + self.assertEqual(state[9], 2, platform) + self.assertEqual(ctypes.c_void_p.from_buffer(state, 24).value, + ctypes.addressof(transform) + 0x14, platform) + self.assertEqual(ctypes.c_void_p.from_buffer(state, 32).value, + 0x12345678, platform) + player[OFFSETS[platform]["mode"]] = 1 + transform[1] = 0 + lib.iggy_get_char_renderstate(player, state, rgba, transform) + self.assertEqual(state[9], 5, platform) + self.assertIsNone(ctypes.c_void_p.from_buffer(state, 24).value, platform) + + def test_text_bitmap_uses_canonical_argument_order_and_rectangle(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + bitmap = (ctypes.c_uint8 * 64)() + transform = (ctypes.c_uint8 * 64)() + lib.iggy_draw_text_bitmap( + player, bitmap, transform, 10.0, 20.0, 30.0, 40.0, 7) + self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 1, + platform) + self.assertEqual(ctypes.c_size_t.in_dll( + lib, "shape_test_setup_resource").value, ctypes.addressof(bitmap)) + self.assertEqual(self.integer(lib, "shape_test_last_smoothing"), 7) + self.assertEqual(self.floats(lib, "shape_test_rectangle", 8), + (10, 20, 40, 60, 0, 0, 1, 1), platform) + state = (ctypes.c_uint8 * 240).in_dll(lib, "shape_test_captured_state") + self.assertEqual(ctypes.c_uint32.from_buffer(state, 4).value & 4, 0) + self.assertEqual(state[16], 0) + self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1) + + def test_bitmap_raw_direct_texture_and_embedded_bitmap_routes(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + obj = (ctypes.c_uint8 * 0x180)() + texture = (ctypes.c_uint8 * 0x50)() + transform = (ctypes.c_uint8 * 32)() + is_64 = ctypes.sizeof(ctypes.c_void_p) == 8 + direct_offset = 0x148 if is_64 else 0xE8 + width_offset = 0x28 if is_64 else 0x14 + height_offset = 0x2C if is_64 else 0x18 + flag_offset = 0xBB if is_64 else 0x63 + ctypes.c_void_p.from_buffer(obj, direct_offset).value = ctypes.addressof(texture) + ctypes.c_int32.from_buffer(texture, width_offset).value = 37 + ctypes.c_int32.from_buffer(texture, height_offset).value = 19 + obj[flag_offset] = 0x10 + lib.iggy_draw_bitmap_raw(player, obj, transform) + self.assertEqual(self.integer(lib, "shape_test_setup_texture_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_last_smoothing"), 0, + platform) + self.assertEqual(self.floats(lib, "shape_test_texgen", 4), + (0, 0, 37, 19), platform) + + lib.shape_test_reset() + ctypes.c_uint8.in_dll(lib, "iggy_fix_bitmap_smoothing").value = 1 + obj = (ctypes.c_uint8 * 0x180)() + bitmap = (ctypes.c_uint8 * 0x50)() + bitmap[0] = 4 + ctypes.c_int16.from_buffer(bitmap, 2).value = 1 + bitmap_width = 0x20 if is_64 else 0x10 + ctypes.c_int16.from_buffer(bitmap, bitmap_width).value = -7 + ctypes.c_int16.from_buffer(bitmap, bitmap_width + 2).value = 11 + ctypes.c_void_p.from_buffer(obj, 0xA8 if is_64 else 0x58).value = \ + ctypes.addressof(bitmap) + lib.iggy_draw_bitmap_raw(player, obj, transform) + self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_last_smoothing"), 1, + platform) + self.assertEqual(self.floats(lib, "shape_test_texgen", 4), + (0, 0, -7, 11), platform) + self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1) + + def test_bitmap_raw_indirect_resource_and_null_sentinel(self): + for platform in ("durango", "orbis"): + lib = self.libs[platform] + player = self.player(platform) + obj = (ctypes.c_uint8 * 0x180)() + bitmap = (ctypes.c_uint8 * 0x60)() + resource = (ctypes.c_uint8 * 0x40)() + slot = (ctypes.c_void_p * 1)() + is_64 = ctypes.sizeof(ctypes.c_void_p) == 8 + indirect_offset = 0x150 if is_64 else 0xEC + bitmap_pointer_offset = 0x27 if is_64 else 0x17 + size_offset = 0x20 if is_64 else 0x10 + ctypes.c_int16.from_buffer(bitmap, size_offset).value = 23 + ctypes.c_int16.from_buffer(bitmap, size_offset + 2).value = 29 + ctypes.c_void_p.from_buffer(resource, bitmap_pointer_offset).value = \ + ctypes.addressof(bitmap) + slot[0] = ctypes.addressof(resource) + ctypes.c_void_p.from_buffer(obj, indirect_offset).value = ctypes.addressof(slot) + + lib.iggy_draw_bitmap_raw(player, obj, None) + self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 1, + platform) + self.assertEqual(self.floats(lib, "shape_test_texgen", 4), + (0, 0, 23, 29), platform) + self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1, + platform) + + lib.shape_test_reset() + sentinel = (ctypes.c_uint8 * 16).in_dll( + lib, "as3vm_nullundef_storage") + slot[0] = ctypes.addressof(sentinel) + 1 + lib.iggy_draw_bitmap_raw(player, obj, None) + self.assertEqual(self.integer(lib, "shape_test_setup_bitmap_calls"), 0, + platform) + self.assertEqual(self.integer(lib, "shape_test_texgen_calls"), 0, + platform) + self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 0, + platform) + + def test_exporter_flush_chunks_texture_and_glyph_queues(self): + for platform in ("durango", "orbis"): + lib = self.libs[platform] + player = self.player(platform) + lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"]) + stats = (ctypes.c_uint8 * 0x330)() + ctypes.c_uint64.from_buffer(stats, 0).value = 0x1122334455667788 + handles = (ctypes.c_size_t * 17).from_buffer(stats, 0x28) + for index in range(17): + handles[index] = 0x1000 + index + ctypes.c_int32.from_buffer(stats, 0x328).value = 17 + glyphs = [(ctypes.c_uint8 * 0x60)() for _ in range(33)] + glyph_slots = (ctypes.c_size_t * 33).from_buffer(stats, 0x128) + for index, glyph in enumerate(glyphs): + ctypes.c_int16.from_buffer(glyph, 0x4C).value = index + 1 + ctypes.c_int16.from_buffer(glyph, 0x4E).value = index + 2 + glyph_slots[index] = ctypes.addressof(glyph) + ctypes.c_int32.from_buffer(stats, 0x32C).value = 33 + + lib.iggy_flush_textureinfo_for_iggyexp(player, stats) + + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 2, + platform) + self.assertEqual(self.integer(lib, "shape_test_describe_calls"), 17, + platform) + self.assertEqual(self.integer(lib, "shape_test_last_event"), 0x88) + self.assertEqual(self.integer(lib, "shape_test_last_packet_size"), 0x330) + self.assertEqual(ctypes.c_int32.from_buffer(stats, 0x328).value, 0) + self.assertEqual(ctypes.c_int32.from_buffer(stats, 0x32C).value, 0) + packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll(lib, "shape_test_packets") + self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 0).value, + 0x1122334455667788) + self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 0x28).value, + 0x1000) + self.assertEqual(ctypes.c_uint64.from_buffer(packets[1], 0x28).value, + 0x1010) + self.assertEqual(ctypes.c_uint64.from_buffer(packets[1], 0x128).value, + ctypes.addressof(glyphs[32])) + self.assertEqual( + (ctypes.c_int32.from_buffer(packets[0], 0x328).value, + ctypes.c_int32.from_buffer(packets[0], 0x32C).value), + (16, 32), platform) + self.assertEqual( + (ctypes.c_int32.from_buffer(packets[1], 0x328).value, + ctypes.c_int32.from_buffer(packets[1], 0x32C).value), + (1, 1), platform) + + def test_exporter_null_callback_still_describes_and_drains(self): + for platform in ("durango", "orbis"): + lib = self.libs[platform] + player = self.player(platform) + stats = (ctypes.c_uint8 * 0x330)() + ctypes.c_size_t.from_buffer(stats, 0x28).value = 0x4444 + ctypes.c_int32.from_buffer(stats, 0x328).value = 1 + lib.iggy_flush_textureinfo_for_iggyexp(player, stats) + self.assertEqual(self.integer(lib, "shape_test_describe_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 0, + platform) + self.assertEqual(ctypes.c_int32.from_buffer(stats, 0x328).value, 0, + platform) + + def test_shape_stats_emits_native_counter_packet(self): + for platform in ("durango", "orbis"): + lib = self.libs[platform] + player = self.player(platform) + lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"]) + shape = (ctypes.c_uint8 * 32)() + ctypes.c_int.in_dll(lib, "shape_test_measure_result").value = 1 + lib.iggy_get_shape_stats(player, 0x8877665544332211, + shape, 0.25, None, None) + self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 1, + platform) + packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll( + lib, "shape_test_packets") + self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 0).value, + 0x8877665544332211) + self.assertEqual(ctypes.c_uint64.from_buffer(packets[0], 8).value, + 0x1020) + self.assertEqual(tuple(ctypes.c_uint32.from_buffer( + packets[0], 0x10 + index * 4).value for index in range(5)), + (2, 3, 4, 5, 6)) + + @staticmethod + def shape_with_fills(platform, fill_count): + shape = (ctypes.c_uint8 * 32)() + source = (ctypes.c_uint8 * 0x40)() + fills = (ctypes.c_uint8 * (8 + max(fill_count, 1) * 0x48))() + ctypes.c_int16.from_buffer(shape, 8).value = 1 + ctypes.c_void_p.from_buffer(shape, 24).value = ctypes.addressof(source) + ctypes.c_int32.from_buffer(fills, 0).value = fill_count + fill_offset = 0x20 if ctypes.sizeof(ctypes.c_void_p) == 8 else 0x18 + ctypes.c_void_p.from_buffer(source, fill_offset).value = ctypes.addressof(fills) + return shape, source, fills + + def test_shape_stats_fill_textures_flush_at_32_and_zero_bitmap(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + shape, source, fills = self.shape_with_fills(platform, 33) + lib.iggy_get_shape_stats( + player, 0x4444, shape, 0.0, None, None) + self.assertEqual(self.integer(lib, "shape_test_fill_texture_calls"), 33, + platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 0, + platform) + + lib.shape_test_reset() + lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"]) + ctypes.c_size_t.in_dll( + lib, "shape_test_fill_texture_result").value = 0x7777 + lib.iggy_get_shape_stats( + player, 0x5555, shape, 0.0, None, None) + self.assertEqual(self.integer(lib, "shape_test_fill_texture_calls"), 33, + platform) + self.assertEqual(self.integer(lib, "shape_test_describe_calls"), 33, + platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 3, + platform) + packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll( + lib, "shape_test_packets") + self.assertEqual(ctypes.c_uint64.from_buffer( + packets[0], 0x28).value, 0x7777, platform) + self.assertEqual(ctypes.c_uint64.from_buffer( + packets[2], 0x28).value, 0x7777, platform) + + lib.shape_test_reset() + stats = ExpShapeStats(id=0x6666, bitmap_count=1) + lib.iggy_flush_textureinfo_for_iggyexp(player, ctypes.byref(stats)) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 1, + platform) + packets = ((ctypes.c_uint8 * 0x330) * 4).in_dll( + lib, "shape_test_packets") + self.assertEqual(bytes(packets[0][0x128:0x138]), bytes(16), platform) + + def test_cached_vertex_buffer_filters_primitive_formats(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + shape, source, fills = self.shape_with_fills(platform, 1) + source[0x38 if ctypes.sizeof(ctypes.c_void_p) == 8 else 0x24] = 1 + primitives = (PackedPrimitive * 3)() + primitives[0].vertex_format = 4 + primitives[1].vertex_format = 1 + primitives[2].vertex_format = 5 + section = VertexBufferSection(primitives, 3, 9, 0) + lib.shape_test_set_draw_result(None, 0xABCDEF, ctypes.byref(section)) + result = lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, None, None, 0, 0) + self.assertEqual(result, 1, platform) + self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 2, + platform) + formats = (ctypes.c_uint8 * 16).in_dll( + lib, "shape_test_drawn_vertex_formats") + self.assertEqual(tuple(formats[:2]), (1, 5), platform) + self.assertEqual(ctypes.c_size_t.in_dll( + lib, "shape_test_last_vertex_buffer").value, 0xABCDEF) + self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 1) + + def test_render_target_aa_nested_composite_and_all_cleanup(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + offsets = OFFSETS[platform] + ctypes.c_int32.from_buffer(player, offsets["rt_aa"]).value = 1 + ctypes.c_int32.from_buffer(player, offsets["quality"]).value = 10 + ctypes.c_int32.from_buffer(player, offsets["slice"]).value = 1 + ctypes.c_int32.from_buffer(player, offsets["slice_bounds"]).value = 1 + shape, source, fills = self.shape_with_fills(platform, 2) + source[0x38 if ctypes.sizeof(ctypes.c_void_p) == 8 else 0x24] = 1 + slice_bounds = (ctypes.c_float * 8)(0, 0, 4, 4, 1, 1, 5, 5) + ctypes.c_void_p.from_buffer(source, 0x30).value = \ + ctypes.addressof(slice_bounds) + primitive_arrays = [(PackedPrimitive * 1)() for _ in range(2)] + sections = (VertexBufferSection * 2)() + for index in range(2): + primitive_arrays[index][0].vertex_format = 1 + sections[index].primitives = primitive_arrays[index] + sections[index].primitive_count = 1 + sections[index].flags = 1 + sections[0].bounds[:] = (2, 2, 5, 5) + sections[1].bounds[:] = (1, 3, 6, 4) + lib.shape_test_set_draw_result(None, 0x7777, sections) + bounds = (ctypes.c_float * 4)(1, 2, 3, 4) + matrix = (ctypes.c_float * 6)(1, 0, 0, 1, 0, 0) + + result = lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, bounds, matrix, 0, 0) + self.assertEqual(result, 1, platform) + self.assertEqual(self.integer(lib, "shape_test_compute_bounds_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_start_nested_calls"), 1, + platform) + self.assertEqual(self.integer( + lib, "shape_test_start_nested_needs_identifier"), 1, platform) + self.assertEqual(self.integer(lib, "shape_test_end_nested_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_screen_rect_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_free_texture_calls"), 1, + platform) + order_count = self.integer(lib, "shape_test_call_order_count") + order = (ctypes.c_uint8 * 64).in_dll(lib, "shape_test_call_order") + self.assertEqual(tuple(order[:order_count]), + (1, 2, 3, 3, 4, 5, 6, 7, 8, 7), platform) + self.assertEqual(ctypes.c_size_t.in_dll( + lib, "shape_test_fill_new_bounds").value, + ctypes.addressof(slice_bounds) + 16, platform) + self.assertEqual(ctypes.c_size_t.in_dll( + lib, "shape_test_fill_old_bounds").value, + ctypes.addressof(sections[1]) + VertexBufferSection.bounds.offset, + platform) + self.assertEqual(ctypes.c_size_t.in_dll( + lib, "shape_test_fill_extra_matrix").value, + ctypes.addressof(matrix), platform) + + gates = ( + ("rt-off", bounds, matrix, 0, 0, 0, 10, 0, 1), + ("quality", bounds, matrix, 0, 0, 1, 9, 0, 1), + ("disabled-byte", bounds, matrix, 0, 0, 1, 10, 1, 1), + ("disable-arg", bounds, matrix, 1, 0, 1, 10, 0, 1), + ("suppress-arg", bounds, matrix, 0, 1, 1, 10, 0, 1), + ("null-bounds", None, matrix, 0, 0, 1, 10, 0, 1), + ("null-matrix", bounds, None, 0, 0, 1, 10, 0, 1), + ("one-eligible", bounds, matrix, 0, 0, 1, 10, 0, 0), + ) + for (gate, gate_bounds, gate_matrix, disable_arg, suppress_arg, + aa_enabled, quality, disabled_byte, second_flags) in gates: + lib.shape_test_reset() + ctypes.c_uint8.in_dll(lib, "iggy_fix_bitmap_smoothing").value = 1 + ctypes.c_int32.from_buffer(player, offsets["rt_aa"]).value = aa_enabled + ctypes.c_int32.from_buffer(player, offsets["quality"]).value = quality + player[offsets["rt_disabled"]] = disabled_byte + sections[1].flags = second_flags + lib.shape_test_set_draw_result(None, 0x7777, sections) + lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, gate_bounds, gate_matrix, + disable_arg, suppress_arg) + self.assertEqual(self.integer(lib, "shape_test_start_nested_calls"), + 0, (platform, gate)) + + lib.shape_test_reset() + ctypes.c_int32.from_buffer(player, offsets["rt_aa"]).value = 1 + ctypes.c_int32.from_buffer(player, offsets["quality"]).value = 10 + player[offsets["rt_disabled"]] = 0 + sections[1].flags = 1 + lib.shape_test_set_draw_result(None, 0x7777, sections) + ctypes.c_int.in_dll(lib, "shape_test_start_nested_result").value = 0 + lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, bounds, matrix, 0, 0) + self.assertEqual(self.integer(lib, "shape_test_start_nested_calls"), 1) + self.assertEqual(self.integer(lib, "shape_test_end_nested_calls"), 0) + self.assertEqual(self.integer(lib, "shape_test_screen_rect_calls"), 0) + self.assertEqual(self.integer(lib, "shape_test_free_texture_calls"), 0) + self.assertEqual(self.integer(lib, "shape_test_unlock_calls"), 0) + + def test_stroke_predraw_and_path_respect_section_gate(self): + for platform in ("durango", "orbis"): + lib = self.libs[platform] + player = self.player(platform) + shape, source, fills = self.shape_with_fills(platform, 0) + is_64 = ctypes.sizeof(ctypes.c_void_p) == 8 + source_path_offset = 0x10 + strokes_offset = 0x28 if is_64 else 0x1C + flags_offset = 0x38 if is_64 else 0x24 + strokes = (ctypes.c_uint8 * 0x80)() + ctypes.c_int32.from_buffer(strokes, 0).value = 1 + ctypes.c_void_p.from_buffer(source, source_path_offset).value = 0x1234 + ctypes.c_void_p.from_buffer(source, strokes_offset).value = \ + ctypes.addressof(strokes) + lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, None, None, 0, 0) + self.assertEqual(self.integer(lib, "shape_test_predraw_stroke_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_stroke_path_calls"), 1, + platform) + self.assertEqual(ctypes.c_size_t.in_dll( + lib, "shape_test_last_stroke_path").value, 0x1234, platform) + lib.shape_test_reset() + source[flags_offset] = 1 + lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, None, None, 0, 0) + self.assertEqual(self.integer(lib, "shape_test_predraw_stroke_calls"), 0, + platform) + self.assertEqual(self.integer(lib, "shape_test_stroke_path_calls"), 0, + platform) + + def test_character_cached_bitmap_cached_vector_and_fontcache_queue(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + offsets = OFFSETS[platform] + ctypes.c_float.from_buffer(player, offsets["cache_max"]).value = 1000 + ctypes.c_float.from_buffer(player, offsets["cache_max"] + 4).value = 1000 + ctypes.c_float.from_buffer(player, offsets["cache_ratio"]).value = 0.5 + ctypes.c_float.from_buffer(player, offsets["cache_ratio"] + 4).value = 2.0 + ctypes.c_int32.from_buffer(player, offsets["frame"]).value = 77 + is_64 = ctypes.sizeof(ctypes.c_void_p) == 8 + font = (ctypes.c_uint8 * 0x100)() + glyph_count = 0x34 if is_64 else 0x20 + heads_offset = 0x40 if is_64 else 0x28 + record_scale = 0x30 if is_64 else 0x20 + record_rect = 0x38 if is_64 else 0x28 + record_frame = 0x48 if is_64 else 0x38 + record_slot = 0x5C if is_64 else 0x4C + ctypes.c_int32.from_buffer(font, glyph_count).value = 1 + heads = (ctypes.c_void_p * 1)() + record = (ctypes.c_uint8 * 0x70)() + heads[0] = ctypes.addressof(record) + ctypes.c_void_p.from_buffer(font, heads_offset).value = ctypes.addressof(heads) + ctypes.c_float.from_buffer(record, record_scale).value = 2.0 + ctypes.c_float.from_buffer(record, record_scale + 4).value = 3.0 + (ctypes.c_float * 4).from_buffer(record, record_rect)[:] = (1, 2, 4, 6) + (ctypes.c_float * 4).from_buffer(record, 0x20 if is_64 else 0x10)[:] = \ + (0.1, 0.2, 0.8, 0.9) + ctypes.c_int16.from_buffer(record, record_slot).value = 5 + rgba = (ctypes.c_uint8 * 4)(255, 255, 255, 255) + lib.iggy_draw_char(player, font, 1.0, 0, 10, 20, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 1, + platform) + rectangle = self.floats(lib, "shape_test_buffered_rect", 8) + self.assertEqual(rectangle[:4], (11, 22, 14, 26), platform) + for actual, expected in zip(rectangle[4:], (0.1, 0.2, 0.8, 0.9)): + self.assertAlmostEqual(actual, expected, places=6, msg=platform) + self.assertEqual(ctypes.c_int32.from_buffer(record, record_frame).value, + 77, platform) + self.assertEqual(ctypes.c_int32.from_buffer( + player, offsets["buffered"]).value, 1, platform) + + lib.shape_test_reset() + ctypes.c_void_p.from_buffer(font, heads_offset).value = 0 + visible = (VisibleGlyph * 2)() + count = ctypes.c_int32() + lib.iggy_fontcache_char( + player, font, 2.0, 0, 0, 0, None, + visible, ctypes.byref(count), 3.0, 4.0) + self.assertEqual(count.value, 1, platform) + self.assertEqual((visible[0].font, visible[0].glyph, + visible[0].scale_x, visible[0].scale_y), + (ctypes.addressof(font), 0, 6.0, 8.0), platform) + + lib.shape_test_reset() + owner = (ctypes.c_uint8 * 32)() + source = (ctypes.c_uint8 * 0x40)() + ctypes.c_int16.from_buffer(owner, 8).value = 1 + ctypes.c_void_p.from_buffer(owner, 24).value = ctypes.addressof(source) + cache = (ctypes.c_void_p * 1)(ctypes.addressof(owner)) + ctypes.c_void_p.from_buffer(font, 0x48 if is_64 else 0x2C).value = \ + ctypes.addressof(cache) + ctypes.c_void_p.from_buffer(font, 0xC8 if is_64 else 0x80).value = 1 + ctypes.c_float.from_buffer(player, offsets["cache_max"]).value = 0 + ctypes.c_float.from_buffer(player, offsets["cache_max"] + 4).value = 0 + primitive = PackedPrimitive(vertex_format=5) + section = VertexBufferSection(ctypes.pointer(primitive), 1, 9, 0) + lib.shape_test_set_draw_result(None, 0x5151, ctypes.byref(section)) + ctypes.c_int.in_dll(lib, "shape_test_onesection_result").value = 1 + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_onesection_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_get_shape_calls"), 0, + platform) + self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 2, + platform) + + def test_character_fallback_callback_empty_and_fontcache_limits(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + self.set_cache_limits(player, platform) + rgba = (ctypes.c_uint8 * 4)(255, 255, 255, 255) + + lib.iggy_draw_char(player, None, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_glyph_empty_calls"), 0, + platform) + + font = self.font() + lib.iggy_draw_char(player, font, 1.0, 1, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_fallback_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_glyph_empty_calls"), 0, + platform) + + fallback = self.font() + ctypes.c_size_t.in_dll(lib, "shape_test_fallback_font").value = \ + ctypes.addressof(fallback) + ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 1 + lib.iggy_draw_char(player, font, 1.0, 1, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_last_glyph"), 0, platform) + + lib.shape_test_reset() + font = self.font() + font[0xE0] = 1 + callback = ctypes.cast( + lib.shape_test_cacheable_callback, ctypes.c_void_p).value + ctypes.c_void_p.from_buffer(font, 0xD8).value = callback + visible = (VisibleGlyph * 2)() + count = ctypes.c_int32() + lib.iggy_fontcache_char( + player, font, 2.0, 0, 0, 0, None, + visible, ctypes.byref(count), 3.0, 4.0) + self.assertEqual(count.value, 0, platform) + + self.assertEqual(self.integer(lib, "shape_test_cacheable_callback_calls"), + 1, platform) + self.assertEqual(self.integer(lib, "shape_test_metrics_calls"), 0, + platform) + self.assertAlmostEqual(ctypes.c_float.in_dll( + lib, "shape_test_cacheable_callback_scale").value, 8.0, + places=6, msg=platform) + + ctypes.c_void_p.from_buffer(font, 0xC8).value = 1 + lib.iggy_fontcache_char( + player, font, 2.0, 0, 0, 0, None, + visible, ctypes.byref(count), 3.0, 4.0) + self.assertEqual(count.value, 1, platform) + self.assertEqual(self.integer(lib, "shape_test_metrics_calls"), 1, + platform) + count.value = 0 + ctypes.c_void_p.from_buffer(font, 0xC8).value = 0 + + ctypes.c_int.in_dll( + lib, "shape_test_cacheable_callback_result").value = 1 + lib.iggy_fontcache_char( + player, font, 2.0, 0, 0, 0, None, + visible, ctypes.byref(count), 3.0, 4.0) + self.assertEqual(count.value, 1, platform) + + ctypes.c_int.in_dll(lib, "iggy_max_visible_chars").value = 1 + lib.iggy_fontcache_char( + player, font, 2.0, 0, 0, 0, None, + visible, ctypes.byref(count), 3.0, 4.0) + self.assertEqual(count.value, 1, platform) + + lib.shape_test_reset() + ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 1 + count.value = 0 + lib.iggy_fontcache_char( + player, font, 1.0, 0, 0, 0, None, + visible, ctypes.byref(count), 1.0, 1.0) + self.assertEqual(count.value, 0, platform) + + lib.shape_test_reset() + font = self.font() + self.set_cache_limits(player, platform, 0.0) + lib.iggy_fontcache_char( + player, font, 1.0, 0, 0, 0, None, + visible, ctypes.byref(count), 1.0, 1.0) + self.assertEqual(count.value, 0, platform) + self.assertEqual(self.integer(lib, "shape_test_metrics_calls"), 1, + platform) + + lib.shape_test_reset() + font = self.font() + font[0xE0] = 1 + self.set_cache_limits(player, platform) + count.value = 0 + lib.iggy_fontcache_char( + player, font, 1.0, 0, 0, 0, None, + visible, ctypes.byref(count), 1.0, 1.0) + self.assertEqual(count.value, 1, platform) + + lib.shape_test_reset() + font = self.font() + self.set_cache_limits(player, platform) + ctypes.c_float.from_buffer( + player, OFFSETS[platform]["cache_max"]).value = 1.0 + metrics = (ctypes.c_float * 6).in_dll(lib, "shape_test_metrics") + metrics[3] = 2.0 + count.value = 0 + lib.iggy_fontcache_char( + player, font, 1.0, 0, 0, 0, None, + visible, ctypes.byref(count), 1.0, 1.0) + self.assertEqual(count.value, 0, platform) + + def test_fontcache_callback_presence_uses_the_native_pointer_width(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + self.set_cache_limits(player, platform) + font = self.font() + callback = ctypes.cast( + lib.shape_test_cacheable_callback, ctypes.c_void_p).value + for callback_offset, present_offset in ((0xD8, 0xE0), + (0x88, 0x8C)): + ctypes.c_void_p.from_buffer(font, callback_offset).value = callback + ctypes.c_size_t.from_buffer(font, present_offset).value = 0x100 + visible = (VisibleGlyph * 1)() + count = ctypes.c_int32() + + lib.iggy_fontcache_char( + player, font, 1.0, 0, 0, 0, None, + visible, ctypes.byref(count), 1.0, 1.0) + + self.assertEqual( + self.integer(lib, "shape_test_cacheable_callback_calls"), + 1, platform) + + def test_character_cache_miss_chain_and_alternate_range(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + self.set_cache_limits(player, platform) + ctypes.c_int32.from_buffer( + player, OFFSETS[platform]["frame"]).value = 91 + font = self.font() + heads = (ctypes.c_void_p * 1)() + first = (ctypes.c_uint8 * 0x70)() + alternate = (ctypes.c_uint8 * 0x70)() + heads[0] = ctypes.addressof(first) + ctypes.c_void_p.from_buffer(font, 0x40).value = ctypes.addressof(heads) + ctypes.c_void_p.from_buffer(first, 0x08).value = \ + ctypes.addressof(alternate) + ctypes.c_float.from_buffer(first, 0x30).value = 100.0 + ctypes.c_float.from_buffer(first, 0x34).value = 100.0 + ctypes.c_float.from_buffer(alternate, 0x50).value = 1.0 + ctypes.c_float.from_buffer(alternate, 0x54).value = 2.5 + ctypes.c_float.from_buffer(alternate, 0x58).value = 3.5 + (ctypes.c_float * 4).from_buffer(alternate, 0x20)[:] = \ + (0.1, 0.2, 0.3, 0.4) + (ctypes.c_float * 4).from_buffer(alternate, 0x38)[:] = (1, 2, 3, 4) + ctypes.c_int16.from_buffer(alternate, 0x5C).value = 7 + rgba = (ctypes.c_uint8 * 4)(1, 2, 3, 4) + + lib.iggy_draw_char(player, font, 1.0, 0, 5, 6, rgba, None) + + self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 1, + platform) + self.assertEqual(ctypes.c_int32.from_buffer(first, 0x48).value, 0, + platform) + self.assertEqual(ctypes.c_int32.from_buffer(alternate, 0x48).value, 91, + platform) + self.assertEqual(ctypes.c_int32.from_buffer( + player, OFFSETS[platform]["shape_chars"]).value, 0, platform) + + lib.shape_test_reset() + ctypes.c_void_p.from_buffer(first, 0x08).value = 0 + ctypes.c_float.from_buffer(first, 0x50).value = 0.0 + ctypes.c_float.from_buffer(first, 0x30).value = 0.1 + ctypes.c_float.from_buffer(first, 0x34).value = 3.0 + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 0, + platform) + self.assertEqual(ctypes.c_int32.from_buffer( + player, OFFSETS[platform]["shape_chars"]).value, 1, platform) + + ctypes.c_float.from_buffer(first, 0x50).value = 1.0 + ctypes.c_float.from_buffer(first, 0x54).value = 4.0 + ctypes.c_float.from_buffer(first, 0x58).value = 5.0 + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + ctypes.c_float.from_buffer(first, 0x54).value = 2.0 + ctypes.c_float.from_buffer(first, 0x58).value = 2.5 + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_buffered_rect_calls"), 0, + platform) + + def test_embedded_and_substituted_character_shapes(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + self.set_cache_limits(player, platform, 0.0) + font = self.font() + ctypes.c_int32.from_buffer(font, 0x18).value = 1 + root = (ctypes.c_uint8 * 0x40)() + source = (ctypes.c_uint8 * 0x40)() + owner = ShapeOwner(section_count=1, + section_sources=ctypes.addressof(source)) + ctypes.c_void_p.from_buffer(font, 0).value = ctypes.addressof(root) + ctypes.c_void_p.from_buffer(root, 0x30).value = ctypes.addressof(owner) + primitive = PackedPrimitive(vertex_format=5) + section = VertexBufferSection(ctypes.pointer(primitive), 1, 9, 0) + lib.shape_test_set_draw_result(None, 0x7171, ctypes.byref(section)) + ctypes.c_int.in_dll( + lib, "shape_test_triangulate_allocated").value = 1 + rgba = (ctypes.c_uint8 * 4)(255, 200, 100, 50) + + lib.iggy_draw_char(player, font, 1.0, 0, 2, 3, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_triangulate_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 2, + platform) + self.assertEqual(self.integer(lib, "shape_test_free_alloc_calls"), 1, + platform) + + lib.shape_test_reset() + ctypes.c_int.in_dll( + lib, "shape_test_triangulate_null_result").value = 1 + lib.iggy_draw_char(player, font, 1.0, 0, 2, 3, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 2, + platform) + self.assertEqual(self.integer(lib, "shape_test_draw_batch_calls"), 0, + platform) + + lib.shape_test_reset() + font = self.font() + ctypes.c_void_p.from_buffer(font, 0xC8).value = 1 + ctypes.c_void_p.from_buffer(font, 0x50).value = 0xBEEF + table = (ctypes.c_void_p * 1)() + ctypes.c_void_p.from_buffer(font, 0x48).value = ctypes.addressof(table) + lib.shape_test_set_draw_result(None, 0x8181, ctypes.byref(section)) + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + self.assertNotEqual(table[0], None, platform) + allocated_owner = ShapeOwner.from_address(table[0]) + self.assertEqual((allocated_owner.section_count, + allocated_owner.cache_policy, + allocated_owner.indirect_owner), (1, 1, 1), platform) + self.assertEqual(allocated_owner.allocator_owner, 0xBEEF, platform) + self.assertEqual(self.integer(lib, "shape_test_malloc_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_get_shape_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_free_shape_calls"), 1, + platform) + glyph_shape = ctypes.c_size_t.in_dll( + lib, "shape_test_glyph_shape_output").value + triangulate_source = ctypes.c_size_t.in_dll( + lib, "shape_test_triangulate_source").value + self.assertEqual( + triangulate_source - glyph_shape, + {"durango": 0x30, "orbis": 0x18, + "ps3": 0x68, "vita": 0x20}[platform], platform) + + lib.shape_test_reset() + ctypes.c_int.in_dll(lib, "shape_test_triangulate_failed").value = 1 + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_triangulate_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_free_shape_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_lowlevel_xform_calls"), 0, + platform) + + lib.shape_test_reset() + failed_table = (ctypes.c_void_p * 1)() + ctypes.c_void_p.from_buffer(font, 0x48).value = \ + ctypes.addressof(failed_table) + ctypes.c_int.in_dll(lib, "shape_test_malloc_fail").value = 1 + lib.iggy_draw_char(player, font, 1.0, 0, 0, 0, rgba, None) + self.assertIsNone(failed_table[0], platform) + self.assertEqual(self.integer(lib, "shape_test_malloc_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_triangulate_calls"), 0, + platform) + + lib.shape_test_reset() + missing = self.font() + frame = 1001 + tuple(self.libs).index(platform) + ctypes.c_int32.from_buffer( + player, OFFSETS[platform]["frame"]).value = frame + lib.iggy_draw_char(player, missing, 1.0, 0, 0, 0, rgba, None) + lib.iggy_draw_char(player, missing, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_send_error_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_last_error_code"), 0x194, + platform) + ctypes.c_int32.from_buffer( + player, OFFSETS[platform]["frame"]).value = frame + 1 + lib.iggy_draw_char(player, missing, 1.0, 0, 0, 0, rgba, None) + self.assertEqual(self.integer(lib, "shape_test_send_error_calls"), 2, + platform) + + def test_iggyexp_character_bitmap_and_vector_paths(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + self.set_cache_limits(player, platform) + lib.shape_test_install_exporter(player, OFFSETS[platform]["exporter"]) + font = self.font() + heads = (ctypes.c_void_p * 1)() + record = (ctypes.c_uint8 * 0x70)() + heads[0] = ctypes.addressof(record) + ctypes.c_void_p.from_buffer(font, 0x40).value = ctypes.addressof(heads) + ctypes.c_float.from_buffer(record, 0x30).value = 2.0 + ctypes.c_float.from_buffer(record, 0x34).value = 3.0 + stats = ExpShapeStats(id=0x123456789ABCDEF0) + + lib.iggy_iggyexp_char(player, None, 1.0, 0, ctypes.byref(stats)) + ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 1 + lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats)) + ctypes.c_int.in_dll(lib, "shape_test_glyph_empty").value = 0 + + lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats)) + self.assertEqual(stats.bitmap_count, 1, platform) + self.assertEqual(stats.bitmap_records[0], ctypes.addressof(record), + platform) + for index in range(1, 63): + stats.bitmap_records[index] = ctypes.addressof(record) + stats.bitmap_count = 63 + lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats)) + self.assertEqual(stats.bitmap_count, 0, platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 2, + platform) + + lib.shape_test_reset() + font = self.font() + ctypes.c_int32.from_buffer(font, 0x18).value = 1 + root = (ctypes.c_uint8 * 0x40)() + source = (ctypes.c_uint8 * 0x40)() + owner = ShapeOwner(section_count=1, + section_sources=ctypes.addressof(source)) + ctypes.c_void_p.from_buffer(font, 0).value = ctypes.addressof(root) + ctypes.c_void_p.from_buffer(root, 0x30).value = ctypes.addressof(owner) + self.set_cache_limits(player, platform, 0.0) + ctypes.c_int.in_dll(lib, "shape_test_measure_result").value = 1 + stats = ExpShapeStats(id=0xABCDEF) + lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats)) + self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 1, + platform) + self.assertEqual(stats.id, 0xABCDEF, platform) + self.assertEqual(stats.sections, 0, platform) + + lib.shape_test_reset() + rootless = self.font() + ctypes.c_int32.from_buffer(rootless, 0x18).value = 1 + stats = ExpShapeStats(id=55) + lib.iggy_iggyexp_char( + player, rootless, 1.0, 0, ctypes.byref(stats)) + empty_root = (ctypes.c_uint8 * 0x40)() + ctypes.c_void_p.from_buffer(rootless, 0).value = \ + ctypes.addressof(empty_root) + lib.iggy_iggyexp_char( + player, rootless, 1.0, 0, ctypes.byref(stats)) + self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 0, + platform) + + no_table = self.font() + ctypes.c_void_p.from_buffer(no_table, 0xC8).value = 1 + lib.iggy_iggyexp_char( + player, no_table, 1.0, 0, ctypes.byref(stats)) + no_provider = self.font() + lib.iggy_iggyexp_char( + player, no_provider, 1.0, 0, ctypes.byref(stats)) + self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 0, + platform) + + lib.shape_test_reset() + font = self.font() + ctypes.c_void_p.from_buffer(font, 0xC8).value = 1 + table = (ctypes.c_void_p * 1)(ctypes.addressof(owner)) + ctypes.c_void_p.from_buffer(font, 0x48).value = ctypes.addressof(table) + stats = ExpShapeStats(id=77) + lib.iggy_iggyexp_char(player, font, 1.0, 0, ctypes.byref(stats)) + self.assertEqual(self.integer(lib, "shape_test_measure_calls"), 1, + platform) + self.assertEqual(self.integer(lib, "shape_test_export_calls"), 0, + platform) + self.assertEqual(stats.id, 77, platform) + + def test_draw_shape_failure_success_and_temporary_cleanup(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + shape = (ctypes.c_uint8 * 32)() + ctypes.c_int.in_dll(lib, "shape_test_triangulate_failed").value = 1 + result = lib.iggy_draw_shape_raw( + player, shape, -2.0, None, None, None, None, 0, 0) + self.assertEqual(result, 0, platform) + self.assertEqual(self.integer(lib, "shape_test_free_alloc_calls"), 0) + + lib.shape_test_reset() + result = lib.iggy_draw_shape_raw( + player, shape, -2.0, None, None, None, None, 0, 0) + self.assertEqual(result, 1, platform) + + lib.shape_test_reset() + sections = (ctypes.c_uint8 * 0x40)() + fills = (ctypes.c_uint8 * 16)() + triangulation = (ctypes.c_uint8 * 0xB0)() + ctypes.c_int32.from_buffer(fills, 0).value = 2 + ctypes.c_int16.from_buffer(shape, 8).value = 1 + ctypes.c_void_p.from_buffer(shape, 24).value = ctypes.addressof(sections) + is_64 = ctypes.sizeof(ctypes.c_void_p) == 8 + fill_offset = 0x20 if is_64 else 0x18 + ctypes.c_void_p.from_buffer(sections, fill_offset).value = \ + ctypes.addressof(fills) + sections[0x38 if is_64 else 0x24] = 1 + lib.shape_test_set_draw_result(triangulation, 0, None) + ctypes.c_int.in_dll(lib, "shape_test_triangulate_allocated").value = 1 + result = lib.iggy_draw_shape_raw( + player, shape, 1.0, None, None, None, None, 0, 0) + self.assertEqual(result, 1, platform) + self.assertEqual(ctypes.c_uint16.from_buffer(triangulation, 0x32).value, + 9, platform) + self.assertEqual(ctypes.c_uint16.from_buffer(triangulation, 0x8A).value, + 9, platform) + self.assertEqual(self.integer(lib, "shape_test_free_triangulation_calls"), + 1, platform) + freed = (ctypes.c_size_t * 16).in_dll(lib, "shape_test_freed") + self.assertEqual(freed[0], ctypes.addressof(triangulation), platform) + self.assertEqual(self.integer(lib, "shape_test_free_alloc_calls"), 2, + platform) + + def test_shape_telemetry_begin_and_end_callbacks(self): + for platform, lib in self.libs.items(): + player = self.player(platform) + shape = (ctypes.c_uint8 * 32)() + lib.shape_test_install_telemetry() + ctypes.c_int.in_dll(lib, "shape_test_triangulate_failed").value = 1 + self.assertEqual(lib.iggy_draw_shape_raw( + player, shape, 0.0, None, None, None, None, 0, 0), 0, platform) + self.assertEqual(self.integer(lib, "shape_test_telemetry_begin_calls"), + 1, platform) + self.assertEqual(self.integer(lib, "shape_test_telemetry_end_calls"), + 1, platform) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_reconstructed_swf_draw_shape_cross.py b/tests/test_reconstructed_swf_draw_shape_cross.py new file mode 100644 index 0000000..bde51ea --- /dev/null +++ b/tests/test_reconstructed_swf_draw_shape_cross.py @@ -0,0 +1,173 @@ +from pathlib import Path +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed" +SOURCE = RECONSTRUCTED / "swf_draw_shape.c" +HEADER = RECONSTRUCTED / "swf_draw_shape.h" +LLVM_NM = Path("/opt/homebrew/opt/llvm/bin/llvm-nm") +VARIANTS = { + "durango": ("clang", "x86_64-pc-windows-msvc", 8), + "orbis": ("clang", "x86_64-unknown-freebsd", 8), + "vita": ("clang", "armv7a-unknown-linux-gnueabihf", 4), +} +PS3_CLANG = Path("/opt/homebrew/opt/llvm/bin/clang") +if PS3_CLANG.exists(): + VARIANTS["ps3"] = (str(PS3_CLANG), "powerpc-unknown-linux-gnu", 4) + +EXPECTED_EXPORTS = { + "iggy_draw_bitmap_raw", "iggy_draw_char", "iggy_draw_shape_raw", + "iggy_draw_text_bitmap", "iggy_fix_bitmap_smoothing", + "iggy_flush_textureinfo_for_iggyexp", "iggy_fontcache_char", + "iggy_get_char_renderstate", "iggy_get_shape_stats", "iggy_iggyexp_char", +} +COMMON_IMPORTS = { + "as3vm_nullundef_storage", "iggy_9slice_set_fill_xform", + "iggy_clear_renderstate", "iggy_compute_bounds", "iggy_draw_batch", + "iggy_draw_buffered_rect", "iggy_draw_rectangle", + "iggy_draw_rectangle_texgen", "iggy_draw_screen_rect", + "iggy_draw_stroke_mesh", "iggy_end_nested_draw", "iggy_free_alloc", + "iggy_free_shape_for_glyph", "iggy_free_triangulation", "iggy_gdraw", + "iggy_gdraw_FreeTexture", "iggy_gdraw_UnlockHandles", + "iggy_get_fallback_font", "iggy_get_fill_style_texture", + "iggy_get_glyph_metrics", "iggy_get_shape_for_glyph", + "iggy_glyph_is_empty", "iggy_lowlevel_set_xform", + "iggy_malloc_CANFAIL_fileline", "iggy_matrix_concatenate", + "iggy_max_visible_chars", "iggy_measure_cached_triangulation", + "iggy_onesection_get_cached_triangulation", "iggy_predraw_stroke_mesh", + "iggy_send_error", "iggy_setcolor_4ub_cxf", "iggy_setup_bitmap_renderstate", + "iggy_setup_bitmap_texture_renderstate", "iggy_setup_fill_style", + "iggy_start_nested_draw", "iggy_stroke_path", "iggy_tm_normal", + "iggy_triangulate_cached", "memmove", "memset", +} +COMPILER_IMPORTS = { + "durango": {"__chkstk", "_fltused"}, + "orbis": set(), + "ps3": set(), + "vita": set(), +} + + +class ReconstructedSwfDrawShapeCrossTests(unittest.TestCase): + def test_native_inventory_and_initializer(self): + expected = { + "durango": (14, 1580), + "orbis": (11, 1291), + "ps3": (11, 1400), + "vita": (11, 1463), + } + for platform, (functions, lines) in expected.items(): + modules = ROOT / f"iggy-decompiled/symbols/iggy_{platform}.modules.tsv" + row = next(line for line in modules.read_text(encoding="utf-8").splitlines() + if line.startswith("swf_draw_shape\t")) + fields = row.split("\t") + self.assertEqual(int(fields[2]), functions, platform) + raw = ROOT / f"iggy-decompiled/raw/{platform}/swf_draw_shape.c" + self.assertEqual(len(raw.read_text(encoding="utf-8").splitlines()), lines, platform) + obj = ROOT / f"work/iggy-native-decomp/{platform}-objects/swf_draw_shape.obj" + symbols = subprocess.run(["nm", "-a", str(obj)], capture_output=True, text=True) + self.assertEqual(symbols.returncode, 0, (platform, symbols.stderr)) + for symbol in EXPECTED_EXPORTS: + self.assertIn(symbol, symbols.stdout, (platform, symbol)) + dump = subprocess.run(["objdump", "-s", str(obj)], capture_output=True, text=True) + self.assertEqual(dump.returncode, 0, (platform, dump.stderr)) + if platform == "orbis": + self.assertRegex( + dump.stdout, + r"(?s)section \.data\.iggy_fix_bitmap_smoothing:.*?0000 01", + platform) + else: + self.assertRegex( + dump.stdout, r"(?s)Contents of section \.data:.*?0000 01", platform) + + def test_source_literals_and_preserved_swf_contract(self): + literals = { + r"c:\\projects\\g\\src\\flash\\swf_draw_shape.c", + "(iggy/render)iggy_draw_shape", "(iggy/render)iggy_draw_char", + "(iggy/render)iggy_AA_using_rendertarget", + "(iggy/render)iggy_draw_aa_rendertarget", "embedded font", + "substituted font", + "Bitmap character was not in fontcache so could not be displayed. " + "Try IggySetFontCachingCalculationBuffer.", + } + combined = "\n".join( + (ROOT / f"iggy-decompiled/raw/{platform}/swf_draw_shape.c").read_text( + encoding="utf-8") for platform in ("durango", "orbis", "ps3", "vita")) + for literal in literals: + self.assertIn(literal, combined) + + def test_exact_exports_imports_layouts_and_caller_abi(self): + self.assertTrue(SOURCE.exists(), f"missing {SOURCE}") + self.assertTrue(HEADER.exists(), f"missing {HEADER}") + with tempfile.TemporaryDirectory() as directory: + temporary = Path(directory) + for platform, (compiler, target, pointer_size) in VARIANTS.items(): + extra = ["-mthumb"] if platform == "vita" else [] + output = temporary / f"swf_draw_shape_{platform}.o" + build = subprocess.run([ + compiler, "-target", target, "-ffreestanding", "-fno-builtin", + "-c", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror", *extra, + f"-DIGGY_RECONSTRUCT_SWF_DRAW_SHAPE_{platform.upper()}=1", + "-I", str(RECONSTRUCTED), str(SOURCE), "-o", str(output), + ], capture_output=True, text=True) + self.assertEqual(build.returncode, 0, (platform, build.stderr)) + if LLVM_NM.exists(): + defined = subprocess.run( + [str(LLVM_NM), "--defined-only", str(output)], + capture_output=True, text=True) + undefined = subprocess.run( + [str(LLVM_NM), "--undefined-only", str(output)], + capture_output=True, text=True) + names = { + parts[-1].removeprefix(".") + for line in defined.stdout.splitlines() + if (parts := line.split()) and len(parts) >= 2 and + parts[-2].upper() in {"T", "D"} + } + imports = { + line.split()[-1].removeprefix(".") + for line in undefined.stdout.splitlines() if line.split() + } + self.assertEqual(names & EXPECTED_EXPORTS, EXPECTED_EXPORTS, platform) + self.assertEqual(imports - COMPILER_IMPORTS[platform], COMMON_IMPORTS, + (platform, imports)) + + exporter_size = 0x330 if pointer_size == 8 else 0x1B0 + glyph_offset = 0x128 if pointer_size == 8 else 0xA8 + texture_count = 0x328 if pointer_size == 8 else 0x1A8 + glyph_count = 0x32C if pointer_size == 8 else 0x1AC + probe = temporary / f"shape_layout_{platform}.c" + probe.write_text( + '#include \n#include "swf_draw_shape.h"\n' + f'_Static_assert(sizeof(IggyExpShapeStats) == {exporter_size}, "exporter");\n' + '_Static_assert(offsetof(IggyExpShapeStats, textures) == 0x28, "textures");\n' + f'_Static_assert(offsetof(IggyExpShapeStats, bitmap_records) == {glyph_offset}, "glyphs");\n' + f'_Static_assert(offsetof(IggyExpShapeStats, texture_count) == {texture_count}, "texture count");\n' + f'_Static_assert(offsetof(IggyExpShapeStats, bitmap_count) == {glyph_count}, "glyph count");\n' + f'_Static_assert(sizeof(IggyVisibleGlyph) == {24 if pointer_size == 8 else 16}, "visible glyph");\n' + 'typedef void (*BitmapAbi)(void *, void *, const IggyRenderColorTransform *);\n' + 'typedef void (*TextBitmapAbi)(void *, IggyBitmap *, const IggyRenderColorTransform *, float, float, float, float, int32_t);\n' + 'typedef int32_t (*ShapeAbi)(void *, IggyShapeCacheOwner *, float, const IggyShapeSectionSource *, const IggyRenderColorTransform *, const IggyRenderBounds *, const float *, int32_t, int32_t);\n' + 'typedef void (*CharAbi)(void *, IggyFont *, float, int32_t, float, float, const uint8_t *, const IggyRenderColorTransform *);\n' + 'typedef void (*StatsAbi)(void *, uint64_t, IggyShapeCacheOwner *, float, const IggyShapeSectionSource *, const float *);\n' + 'static BitmapAbi bitmap_abi = &iggy_draw_bitmap_raw;\n' + 'static TextBitmapAbi text_bitmap_abi = &iggy_draw_text_bitmap;\n' + 'static ShapeAbi shape_abi = &iggy_draw_shape_raw;\n' + 'static CharAbi char_abi = &iggy_draw_char;\n' + 'static StatsAbi stats_abi = &iggy_get_shape_stats;\n' + 'int use_abis(void) { return bitmap_abi && text_bitmap_abi && shape_abi && char_abi && stats_abi; }\n', + encoding="utf-8") + syntax = subprocess.run([ + compiler, "-target", target, "-ffreestanding", "-fsyntax-only", + "-std=c11", "-Wall", "-Wextra", "-Werror", *extra, + f"-DIGGY_RECONSTRUCT_SWF_DRAW_SHAPE_{platform.upper()}=1", + "-I", str(RECONSTRUCTED), str(probe), + ], capture_output=True, text=True) + self.assertEqual(syntax.returncode, 0, (platform, syntax.stderr)) + + +if __name__ == "__main__": + unittest.main()