Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,16 @@ if(EMSCRIPTEN)
"-sEXPORT_NAME=\"createWAFlashCore\""
"-sALLOW_MEMORY_GROWTH=1"
"-sUSE_ZLIB=1"
"-sUSE_LIBJPEG=1"
"-sEXPORTED_FUNCTIONS=['_malloc','_free','_wasm_get_audio_samples']"
"-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap','getValue','HEAPU8','HEAP16','HEAPU32']"
"-O3"
)

target_compile_definitions(gameswf_core PUBLIC
TU_CONFIG_LINK_TO_JPEGLIB=1
TU_CONFIG_LINK_TO_ZLIB=1
)
endif()

# Target 1: Libretro Core Shared Library
Expand Down
63 changes: 52 additions & 11 deletions src/gameswf_render_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ extern std::vector<uint32_t> g_wasm_framebuffer;
extern uint32_t g_wasm_width;
extern uint32_t g_wasm_height;

struct dummy_bitmap_info : public gameswf::bitmap_info {
int get_width() const override { return 1; }
int get_height() const override { return 1; }
};

class glyph_provider_wasm : public gameswf::glyph_provider {
gameswf::gc_ptr<gameswf::bitmap_info> m_stub_bi;
public:
glyph_provider_wasm() {
m_stub_bi = new dummy_bitmap_info();
}
~glyph_provider_wasm() override {}

gameswf::bitmap_info* get_char_image(gameswf::character_def* shape_glyph, Uint16 code,
const tu_string& fontname, bool is_bold, bool is_italic,
int fontsize, gameswf::rect* bounds, float* advance) override {
(void)shape_glyph; (void)code; (void)fontname; (void)is_bold; (void)is_italic;
if (bounds) {
bounds->m_x_min = 0.0f;
bounds->m_x_max = 0.0f;
bounds->m_y_min = 0.0f;
bounds->m_y_max = 0.0f;
}
if (advance) {
float em_size = static_cast<float>(fontsize);
if (em_size <= 0.0f) em_size = 1024.0f;
*advance = em_size * 0.6f;
}
return m_stub_bi.get_ptr();
}
};

class render_handler_wasm : public gameswf::render_handler {
gameswf::matrix m_current_matrix;
gameswf::cxform m_current_cxform;
Expand All @@ -19,18 +51,19 @@ class render_handler_wasm : public gameswf::render_handler {
render_handler_wasm() {}
~render_handler_wasm() override {}

struct dummy_bitmap_info : public gameswf::bitmap_info {};

gameswf::bitmap_info* create_bitmap_info_empty() override {
return new dummy_bitmap_info();
}
gameswf::bitmap_info* create_bitmap_info_alpha(int w, int h, unsigned char* data) override {
(void)w; (void)h; (void)data;
return new dummy_bitmap_info();
}
gameswf::bitmap_info* create_bitmap_info_rgb(image::rgb* im) override {
(void)im;
return new dummy_bitmap_info();
}
gameswf::bitmap_info* create_bitmap_info_rgba(image::rgba* im) override {
(void)im;
return new dummy_bitmap_info();
}
gameswf::video_handler* create_video_handler() override {
Expand All @@ -41,6 +74,8 @@ class render_handler_wasm : public gameswf::render_handler {
int viewport_x0, int viewport_y0,
int viewport_width, int viewport_height,
float x0, float x1, float y0, float y1) override {
(void)viewport_x0; (void)viewport_y0; (void)viewport_width; (void)viewport_height;
(void)x0; (void)x1; (void)y0; (void)y1;
uint32_t bg_xrgb = (background_color.m_r << 16) | (background_color.m_g << 8) | background_color.m_b;
if (!g_wasm_framebuffer.empty()) {
std::fill(g_wasm_framebuffer.begin(), g_wasm_framebuffer.end(), bg_xrgb);
Expand All @@ -57,18 +92,21 @@ class render_handler_wasm : public gameswf::render_handler {
m_current_cxform = cx;
}

void fill_style_disable(int fill_side) override {}
void fill_style_disable(int fill_side) override { (void)fill_side; }

void fill_style_color(int fill_side, const gameswf::rgba& color) override {
(void)fill_side;
m_current_color = color;
}

void fill_style_bitmap(int fill_side, gameswf::bitmap_info* bi, const gameswf::matrix& m,
bitmap_wrap_mode wm, bitmap_blend_mode bm) override {}
bitmap_wrap_mode wm, bitmap_blend_mode bm) override {
(void)fill_side; (void)bi; (void)m; (void)wm; (void)bm;
}

void line_style_disable() override {}
void line_style_color(gameswf::rgba color) override {}
void line_style_width(float width) override {}
void line_style_color(gameswf::rgba color) override { (void)color; }
void line_style_width(float width) override { (void)width; }

void draw_mesh_strip(const void* coords, int vertex_count) override {
if (!coords || vertex_count < 3 || g_wasm_framebuffer.empty()) return;
Expand Down Expand Up @@ -114,20 +152,23 @@ class render_handler_wasm : public gameswf::render_handler {
}
}

void draw_line_strip(const void* coords, int vertex_count) override {}
void draw_line_strip(const void* coords, int vertex_count) override { (void)coords; (void)vertex_count; }

void draw_bitmap(const gameswf::matrix& m, gameswf::bitmap_info* bi,
const gameswf::rect& coords, const gameswf::rect& uv_coords, gameswf::rgba color) override {}
const gameswf::rect& coords, const gameswf::rect& uv_coords, gameswf::rgba color) override {
(void)m; (void)bi; (void)coords; (void)uv_coords; (void)color;
}

void set_antialiased(bool enable) override {}
bool test_stencil_buffer(const gameswf::rect& bound, Uint8 pattern) override { return false; }
void set_antialiased(bool enable) override { (void)enable; }
bool test_stencil_buffer(const gameswf::rect& bound, Uint8 pattern) override { (void)bound; (void)pattern; return false; }
void begin_submit_mask() override {}
void end_submit_mask() override {}
void disable_mask() override {}
bool is_visible(const gameswf::rect& bound) override { return true; }
bool is_visible(const gameswf::rect& bound) override { (void)bound; return true; }
void open() override {}
};

gameswf::render_handler* create_render_handler_wasm() {
gameswf::set_glyph_provider(new glyph_provider_wasm());
return new render_handler_wasm();
}
Loading
Loading