rebuild iggy's native shape renderer
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
297
iggy-decompiled/src/reconstructed/swf_draw_shape.c
Normal file
297
iggy-decompiled/src/reconstructed/swf_draw_shape.c
Normal file
@@ -0,0 +1,297 @@
|
||||
#include "swf_draw_shape.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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"
|
||||
91
iggy-decompiled/src/reconstructed/swf_draw_shape.h
Normal file
91
iggy-decompiled/src/reconstructed/swf_draw_shape.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#ifndef IGGY_RECONSTRUCTED_SWF_DRAW_SHAPE_H
|
||||
#define IGGY_RECONSTRUCTED_SWF_DRAW_SHAPE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
316
iggy-decompiled/src/reconstructed/swf_draw_shape_char.inc
Normal file
316
iggy-decompiled/src/reconstructed/swf_draw_shape_char.inc
Normal file
@@ -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);
|
||||
}
|
||||
127
iggy-decompiled/src/reconstructed/swf_draw_shape_export.inc
Normal file
127
iggy-decompiled/src/reconstructed/swf_draw_shape_export.inc
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
454
iggy-decompiled/src/reconstructed/swf_draw_shape_render.inc
Normal file
454
iggy-decompiled/src/reconstructed/swf_draw_shape_render.inc
Normal file
@@ -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;
|
||||
}
|
||||
527
tests/support/swf_draw_shape_test_support.c
Normal file
527
tests/support/swf_draw_shape_test_support.c
Normal file
@@ -0,0 +1,527 @@
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
1135
tests/test_reconstructed_swf_draw_shape.py
Normal file
1135
tests/test_reconstructed_swf_draw_shape.py
Normal file
File diff suppressed because it is too large
Load Diff
173
tests/test_reconstructed_swf_draw_shape_cross.py
Normal file
173
tests/test_reconstructed_swf_draw_shape_cross.py
Normal file
@@ -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 <stddef.h>\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()
|
||||
Reference in New Issue
Block a user